| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.bundleSwift = exports.toSwift = exports.bundleKotlin = exports.toKotlin = exports.parse = void 0;
- const path_1 = require("path");
- const utils_1 = require("./utils");
- const bindingsOverride = process.env['UTS_BINARY_PATH'];
- const bindings = !!bindingsOverride
- ? require((0, path_1.resolve)(bindingsOverride))
- : require('./binding').default;
- function resolveOptions(options) {
- const { input, output } = options;
- if (!input?.root) {
- return;
- }
- if (!input?.filename) {
- return;
- }
- if (!output?.outDir) {
- return;
- }
- if (output.sourceMap === true) {
- output.sourceMap = output.outDir;
- }
- else if (output.sourceMap === false ||
- typeof output.sourceMap === 'undefined') {
- output.sourceMap = '';
- }
- if (!output.imports) {
- // TODO
- output.imports = [];
- }
- input.root = (0, utils_1.normalizePath)(input.root);
- input.filename = (0, utils_1.normalizePath)(input.filename);
- output.outDir = (0, utils_1.normalizePath)(output.outDir);
- output.sourceMap = (0, utils_1.normalizePath)(output.sourceMap);
- output.logFilename = !!output.logFilename;
- output.noColor = !!output.noColor;
- return options;
- }
- function parse(source, options = {}) {
- options.noColor = !!options.noColor;
- return bindings
- .parse(source, toBuffer(options))
- .then((res) => JSON.parse(res));
- }
- exports.parse = parse;
- function toKotlin(options) {
- const kotlinOptions = resolveOptions(options);
- if (!kotlinOptions) {
- return Promise.resolve({});
- }
- return bindings
- .toKotlin(toBuffer(kotlinOptions))
- .then((res) => JSON.parse(res));
- }
- exports.toKotlin = toKotlin;
- function bundleKotlin(options) {
- const bundleOptions = resolveOptions(options);
- if (!bundleOptions) {
- return Promise.resolve({});
- }
- return bindings
- .bundleKotlin(toBuffer(bundleOptions))
- .then((res) => JSON.parse(res))
- .catch((error) => {
- return { error };
- });
- }
- exports.bundleKotlin = bundleKotlin;
- function toSwift(options) {
- const swiftOptions = resolveOptions(options);
- if (!swiftOptions) {
- return Promise.resolve({});
- }
- return bindings
- .toSwift(toBuffer(swiftOptions))
- .then((res) => JSON.parse(res))
- .catch((error) => {
- return { error };
- });
- }
- exports.toSwift = toSwift;
- function bundleSwift(options) {
- const bundleOptions = resolveOptions(options);
- if (!bundleOptions) {
- return Promise.resolve({});
- }
- return bindings
- .bundleSwift(toBuffer(bundleOptions))
- .then((res) => JSON.parse(res));
- }
- exports.bundleSwift = bundleSwift;
- function toBuffer(t) {
- // @ts-ignore 'Buffer' only refers to a type, but is being used as a value here
- return Buffer.from(JSON.stringify(t));
- }
|