@villedemontreal/scripting
Version:
Scripting core utilities
61 lines • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.configs = exports.Configs = void 0;
const fs = require("fs");
const os = require("os");
const path = require("path");
class Configs {
constructor() {
// From the "dist/src/config" folder
this.libRoot = path.normalize(__dirname + '/../../..');
this.isWindows = os.platform() === 'win32';
}
/**
* The proper Caporal instance to use in the code!
* It is on this instance that commands and options
* have been registered.
*/
get caporal() {
if (!this.caporalVar) {
throw new Error(`The Caporal instance must have been set on the configurations!`);
}
return this.caporalVar;
}
setCaporal(caporal) {
this.caporalVar = caporal;
}
get projectRoot() {
if (!this.projectRootVar) {
throw new Error(`The project root must have been set on the configurations!`);
}
return this.projectRootVar;
}
setProjectRoot(projectRoot) {
this.projectRootVar = projectRoot;
}
get projectOutDir() {
if (!this.projectOutDirVar) {
throw new Error(`The project output directory must have been set on the configurations!`);
}
return this.projectOutDirVar;
}
setProjectOutDir(projectOutDir) {
this.projectOutDirVar = projectOutDir;
}
findModulePath(subPath) {
let current = this.libRoot;
let counter = 0;
while (counter < 10 && current !== '/' && fs.existsSync(current)) {
const p = path.join(current, subPath);
if (fs.existsSync(p)) {
return path.normalize(p);
}
current = path.normalize(path.join(current, '..'));
counter += 1;
}
throw new Error(`Could not find module "${subPath}"`);
}
}
exports.Configs = Configs;
exports.configs = new Configs();
//# sourceMappingURL=configs.js.map