piral-cli
Version:
The standard CLI for creating and building a Piral instance or a Pilet.
51 lines • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.config = void 0;
exports.updateConfig = updateConfig;
const os_1 = require("os");
const path_1 = require("path");
const promises_1 = require("fs/promises");
const constants_1 = require("./constants");
const external_1 = require("../external");
exports.config = (0, external_1.rc)(constants_1.appName, {
apiKey: undefined,
apiKeys: {},
auth: {},
url: undefined,
cert: undefined,
npmClient: 'npm',
bundler: 'webpack5',
piletApi: '/$pilet-api',
validators: {},
schemaVersion: 'v2',
openBrowser: false,
allowSelfSigned: false,
port: 1234,
strictPort: false,
language: 'ts',
host: 'localhost',
registry: constants_1.defaultRegistry,
}, {});
function mergeConfig(existing, area, value) {
const current = existing[area];
// update already existing config
Object.assign(existing, {
[area]: typeof current === 'object'
? {
...current,
...value,
}
: value,
});
}
async function updateConfig(area, value) {
// update already existing config
mergeConfig(exports.config, area, value);
// update user-global config
const path = (0, path_1.resolve)((0, os_1.homedir)(), `.${constants_1.appName}rc`);
const content = await (0, promises_1.readFile)(path, 'utf8').catch(() => '{}');
const configFile = JSON.parse(content);
mergeConfig(configFile, area, value);
await (0, promises_1.writeFile)(path, JSON.stringify(configFile, undefined, 2), 'utf8');
}
//# sourceMappingURL=config.js.map