@quo0/stiletto
Version:
With stiletto library you will be able to mock requests and choose between preconfigured responses right on the fly via UI
100 lines • 3.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProcessService = void 0;
const tslib_1 = require("tslib");
const inversify_1 = require("inversify");
const constants_1 = require("../../constants");
const ioc_1 = require("../../../ioc");
let ProcessService = class ProcessService {
constructor(process) {
this.process = process;
}
cwd() {
return this.process.cwd();
}
exit(code) {
this.process.exit(code);
}
parseArguments() {
const sliced = this.process.argv.slice(2);
if (sliced.includes(constants_1.PROCESS_ARGUMENTS.HELP_KEY)) {
return {
isInit: false,
isHelp: true,
isNewSetup: false,
isLaunch: false,
};
}
if (sliced.includes(constants_1.PROCESS_ARGUMENTS.INIT_KEY)) {
return {
isInit: true,
isHelp: false,
isNewSetup: false,
isLaunch: false,
};
}
if (sliced.includes(constants_1.PROCESS_ARGUMENTS.NEW_SETUP_KEY)) {
return {
isInit: false,
isHelp: false,
isNewSetup: true,
isLaunch: false,
};
}
// TODO:IMPLEMENTATION allow to launch stiletto --setup-name withouth passing --launch
if (!sliced.includes(constants_1.PROCESS_ARGUMENTS.LAUNCH_SETUP_KEY)) {
return {
isInit: false,
isHelp: true,
isNewSetup: false,
isLaunch: false,
};
}
const mapped = sliced.map((arg, index) => ({
value: arg,
isKey: arg.startsWith('--'),
index,
}));
const keys = mapped.filter((arg) => arg.isKey);
const parsed = keys.map((keyArg) => {
const name = this.getArgName(keyArg);
const value = this.getArgValue(mapped, keyArg);
return { name, value };
});
const setupName = parsed.find((arg) => arg.name === constants_1.PROCESS_ARGUMENTS.SETUP_NAME_KEY);
const setupPath = parsed.find((arg) => arg.name === constants_1.PROCESS_ARGUMENTS.SETUP_PATH_KEY);
const browserName = parsed.find((arg) => arg.name === constants_1.PROCESS_ARGUMENTS.BROWSER_NAME_KEY);
return {
isInit: false,
isHelp: false,
isNewSetup: false,
isLaunch: true,
setupName: setupName === null || setupName === void 0 ? void 0 : setupName.value,
setupPath: setupPath === null || setupPath === void 0 ? void 0 : setupPath.value,
browserName: browserName === null || browserName === void 0 ? void 0 : browserName.value,
};
}
getArgName(keyArg) {
if (keyArg.value.includes('=')) {
return keyArg.value.slice(0, keyArg.value.indexOf('='));
}
return keyArg.value;
}
getArgValue(mapped, keyArg) {
if (keyArg.value.includes('=')) {
return keyArg.value.slice(keyArg.value.indexOf('=') + 1);
}
const nextMappedIndex = keyArg.index + 1;
if (!mapped[nextMappedIndex]) {
return;
}
return mapped[nextMappedIndex].value.startsWith('--') ? undefined : mapped[nextMappedIndex].value;
}
};
ProcessService = (0, tslib_1.__decorate)([
(0, inversify_1.injectable)(),
(0, tslib_1.__param)(0, (0, inversify_1.inject)(ioc_1.TOKENS.nodeProcess)),
(0, tslib_1.__metadata)("design:paramtypes", [Object])
], ProcessService);
exports.ProcessService = ProcessService;
//# sourceMappingURL=process.service.js.map