"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseConfig = void 0; const utils_fs_1 = require("@ionic/utils-fs"); const fs = require("fs"); const lodash = require("lodash"); const path = require("path"); const writeFileAtomic = require("write-file-atomic"); class BaseConfig { constructor(p, { pathPrefix = [] } = {}) { this.p = p; this.pathPrefix = pathPrefix; } get file() { try { return this._getFile(); } catch (e) { return {}; } } get c() { try { const file = this._getFile(); const navigated = this.pathPrefix.length === 0 ? file : lodash.get(file, [...this.pathPrefix]); const config = typeof navigated === 'object' ? navigated : {}; return lodash.assign({}, this.provideDefaults(config), config); } catch (e) { if (e.code === 'ENOENT' || e.name === 'SyntaxError') { const value = this.provideDefaults({}); const v = this.pathPrefix.length === 0 ? value : lodash.set({}, [...this.pathPrefix], value); this._setFile(v); return value; } throw e; } } set c(value) { const v = this.pathPrefix.length === 0 ? value : lodash.set(this.file, [...this.pathPrefix], value); this._setFile(v); } get(property, defaultValue) { const value = this.c[property]; if (defaultValue && typeof value === 'undefined') { return defaultValue; } return value; } set(property, value) { const config = this.c; config[property] = value; this.c = config; } unset(property) { const config = this.c; delete config[property]; this.c = config; } _getFile() { const contents = fs.readFileSync(this.p, 'utf8'); return JSON.parse(contents); } _setFile(value) { utils_fs_1.mkdirpSync(path.dirname(this.p)); writeFileAtomic.sync(this.p, JSON.stringify(value, undefined, 2) + '\n'); } } exports.BaseConfig = BaseConfig;
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
colors.d.ts | File | 658 B | 0644 |
|
colors.js | File | 1.52 KB | 0644 |
|
command.d.ts | File | 4.19 KB | 0644 |
|
command.js | File | 9.7 KB | 0644 |
|
completion.d.ts | File | 1.26 KB | 0644 |
|
completion.js | File | 1.84 KB | 0644 |
|
config.d.ts | File | 994 B | 0644 |
|
config.js | File | 2.14 KB | 0644 |
|
executor.d.ts | File | 4.73 KB | 0644 |
|
executor.js | File | 5.93 KB | 0644 |
|
help.d.ts | File | 11.16 KB | 0644 |
|
help.js | File | 25.15 KB | 0644 |
|
index.d.ts | File | 218 B | 0644 |
|
index.js | File | 537 B | 0644 |
|
options.d.ts | File | 4.6 KB | 0644 |
|
options.js | File | 10.38 KB | 0644 |
|
validators.d.ts | File | 401 B | 0644 |
|
validators.js | File | 3.4 KB | 0644 |
|