UNPKG

@procore/core-scripts

Version:

A CLI to enhance your development experience

70 lines 2.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Workspace = void 0; const tslib_1 = require("tslib"); const debug_1 = tslib_1.__importDefault(require("debug")); const fs_1 = tslib_1.__importDefault(require("fs")); const path_1 = tslib_1.__importDefault(require("path")); class Workspace { constructor(env, context) { this.debug = (0, debug_1.default)('@procore/core-scripts/workspace'); this.cwd = process.cwd(); this.context = context; this.env = env; } get packageJson() { if (this.$packageJson) { return this.$packageJson; } this.$packageJson = this.loadPackageJson(); return this.$packageJson; } get procoreConfig() { if (this.$procoreConfig) { return this.$procoreConfig; } this.$procoreConfig = this.loadProcoreConfig(); return this.$procoreConfig; } savePackageJson() { this.writeFileSync('package.json', JSON.stringify(this.packageJson, null, 2)); } resolve(...pathSegments) { return path_1.default.resolve(this.context, ...pathSegments); } existsSync(...pathSegments) { const filePath = this.resolve(...pathSegments); return fs_1.default.existsSync(filePath); } writeFileSync(path, data) { const filePath = this.resolve(path); if (this.isEnabled('skipWriteConfig')) { this.debug(`Skipping writing file: ${filePath}`); return; } this.debug(`Writing File: ${filePath}`); return fs_1.default.writeFileSync(filePath, data); } isEnabled(key) { var _a; const value = Boolean((_a = this.procoreConfig.experimental) === null || _a === void 0 ? void 0 : _a[key]); this.debug(`Checking if ${key} is enabled: ${value}`); return value; } loadPackageJson() { const filePath = this.resolve('package.json'); this.debug(`Loading Package JSON: ${filePath}`); return require(filePath); } loadProcoreConfig() { const filePath = this.resolve('procore.config.js'); if (!fs_1.default.existsSync(filePath)) { return {}; } this.debug(`Loading Procore Config: ${filePath}`); const configFactory = require(filePath); return configFactory({ env: this.env }); } } exports.Workspace = Workspace; //# sourceMappingURL=Workspace.js.map