@5minds/processcube_engine
Version:
The ProcessCube Engine. Stores and executes BPMNs.
188 lines (182 loc) • 7.75 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStartupArgs = getStartupArgs;
exports.default = parseArguments;
const fs_1 = __importDefault(require("fs"));
const inversify_1 = require("inversify");
const path_1 = __importDefault(require("path"));
const processcube_engine_sdk_1 = require("@5minds/processcube_engine_sdk");
const Contracts_1 = require("../Contracts");
const environment = __importStar(require("./Environment"));
const logger = new processcube_engine_sdk_1.Logger('application');
let startUpArgs;
function getStartupArgs() {
return startUpArgs;
}
async function parseArguments(args) {
startUpArgs = args;
if (args?.version) {
printVersionAndExit();
}
if (args?.help) {
printHelpAndExit();
}
if (args.skipDBIntegrityChecks) {
process.env.skipDBIntegrityChecks = 'true';
}
if (process.env.enableHttp == undefined) {
process.env.enableHttp = 'true';
}
const parseAndValidateConfigPath = async (configPath) => {
const configDirNameNormalized = path_1.default.normalize(configPath);
const resolvedPath = path_1.default.resolve(configDirNameNormalized);
const fileExists = fs_1.default.existsSync(resolvedPath);
if (fileExists) {
return resolvedPath;
}
logger.error(`Failure in setup: Unable to locate provided Config File '${configPath}'.`);
if (!path_1.default.isAbsolute(configPath)) {
logger.error(`Failure in setup: Please make sure the file exists at '${resolvedPath}'.`);
}
// Killing the Process immediately would result in the error not being logged.
await new Promise((resolve) => setTimeout(resolve, 10));
process.exit(1);
};
if (args.configFile) {
logger.info(`Using Config File provided via command argument '--config-file': '${args.configFile}'`);
process.env.CONFIG_PATH = await parseAndValidateConfigPath(args.configFile);
}
else if (process.env.CONFIG_PATH) {
logger.info(`Using Config File provided via environment variable 'CONFIG_PATH': '${process.env.CONFIG_PATH}'`);
await parseAndValidateConfigPath(process.env.CONFIG_PATH);
}
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = environment.getReleaseChannel();
}
if (args?.id != undefined) {
process.env.application__id = args.id;
}
if (args?.name != undefined) {
process.env.name = args.name;
process.env.application__name = args.name;
}
if (args?.port != undefined) {
process.env.httpServer__port = args?.port;
}
if (args?.seedDir) {
process.env.seedDir = args?.seedDir;
}
if (args?.sqlitePath != undefined) {
logger.info(`Using sqlitePath ${args.sqlitePath}`);
process.env.sqlitePath = args.sqlitePath;
}
if (args?.workDir != undefined) {
if (!path_1.default.isAbsolute(args.workDir)) {
logger.error('Failure in process: The path in startup parameter "workDir" must be absolute!');
process.exit(1);
}
process.env.workDir = args.workDir;
}
if (args?.enableHttp != undefined) {
logger.trace(`Enable http endpoints: ${args.enableHttp}`);
process.env.enableHttp = `${args.enableHttp}`;
}
if (args?.extensionsDir != undefined) {
process.env.extensionsDir = args?.extensionsDir;
}
const argsForEmbeddedSetup = {
...args,
minimalSetup: false,
};
if (args?.container != undefined) {
if (!(args.container instanceof inversify_1.Container)) {
logger.error('Failure in setup: Injected containers must be an instance of an inversify Container!');
process.exit(1);
}
logger.trace('Using provided ioc container');
argsForEmbeddedSetup.container = args.container;
}
else {
argsForEmbeddedSetup.container = createIoCContainer();
}
if (args?.minimalSetup === true) {
logger.trace(`Minimal Setup: ${args.minimalSetup}`);
argsForEmbeddedSetup.minimalSetup = args.minimalSetup;
}
return argsForEmbeddedSetup;
}
function createIoCContainer() {
const container = new inversify_1.Container();
container.bind(Contracts_1.IocRegistrationKeys.internal.Container).toConstantValue(container);
return container;
}
function printVersionAndExit() {
const packageJson = environment.readPackageJson();
console.log(packageJson.version);
process.exit(0);
}
function printHelpAndExit() {
console.log(`
Usage: processcube-engine [OPTIONS]
Starts a 5Minds Engine.
Options:
--enable-http If set to true, all HTTP endpoints the Engine uses will be loaded
- Use 'false' to prevent the Engine from providing HTTP endpoints
- Defaults to 'true'
--extensions-dir A path to an extensions directory.
- By default extensions will be loaded from '\${HOME}/.processcube/engine/extensions'.
- The path must be absolute.
--name Sets the name of the Engine instance.
--seed-dir A path to a folder of BPMN files that are imported at startup. The path must be absolute.
--sqlite-path A path to where the server should store its SQlite databases.
- Works in conjunction with 'NODE_ENV=sqlite'.
- The path must be absolute.
--use-http-root-routes If set to 'true', the routes '/' and '/security/authority' will be set by the Engine
- Set to 'false' if you want to use these routes for other purposes
- Defaults to 'true'
--config-file A path to a JSON File that the engine should use as config.
--work-dir A path to where the server will store its working data (i.e. 'workspace'). The path must be absolute.
--port The port that the Engine should listen on.
General options:
--help Displays this help text and quits.
--version Shows the engine's version number and quits.
`);
process.exit(0);
}
//# sourceMappingURL=ArgumentParser.js.map