nativescript
Version:
Command-line interface for building NativeScript projects
59 lines • 2.44 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
// NOTE: This file is used to call JS functions when cleaning resources used by CLI, after the CLI is killed.
// The instances here are not shared with the ones in main CLI process.
const fs = require("fs");
const uuid_1 = require("uuid");
const file_log_service_1 = require("./file-log-service");
const yok_1 = require("../common/yok");
const pathToBootstrap = process.argv[2];
if (!pathToBootstrap || !fs.existsSync(pathToBootstrap)) {
throw new Error("Invalid path to bootstrap.");
}
// After requiring the bootstrap we can use $injector
require(pathToBootstrap);
const logFile = process.argv[3];
const jsFilePath = process.argv[4];
const fileLogService = yok_1.injector.resolve(file_log_service_1.FileLogService, {
logFile,
});
const uniqueId = (0, uuid_1.v4)();
fileLogService.logData({
message: `Initializing Cleanup process for path: ${jsFilePath} Unique id: ${uniqueId}`,
});
if (!fs.existsSync(jsFilePath)) {
throw new Error(`Unable to find file ${jsFilePath}. Ensure it exists.`);
}
let data;
try {
data = process.argv[5] && JSON.parse(process.argv[5]);
}
catch (err) {
throw new Error(`Unable to parse data from argv ${process.argv[5]}.`);
}
const logMessage = (msg, type) => {
fileLogService.logData({ message: `[${uniqueId}] ${msg}`, type });
};
/* tslint:disable:no-floating-promises */
(async () => {
try {
logMessage(`Requiring file ${jsFilePath}`);
const func = require(jsFilePath);
if (func && typeof func === "function") {
try {
logMessage(`Passing data: ${JSON.stringify(data)} to the default function exported by currently required file ${jsFilePath}`);
await func(data);
logMessage(`Finished execution with data: ${JSON.stringify(data)} to the default function exported by currently required file ${jsFilePath}`);
}
catch (err) {
logMessage(`Unable to execute action of file ${jsFilePath} when passed data is ${JSON.stringify(data)}. Error is: ${err}.`, "Error" /* FileLogMessageType.Error */);
}
}
}
catch (err) {
logMessage(`Unable to require file: ${jsFilePath}. Error is: ${err}.`, "Error" /* FileLogMessageType.Error */);
}
})();
/* tslint:enable:no-floating-promises */
//# sourceMappingURL=cleanup-js-subprocess.js.map
;