1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const cli_table3_1 = __importDefault(require("cli-table3"));
|
7 | const dottie_1 = __importDefault(require("dottie"));
|
8 | const envfile_1 = __importDefault(require("envfile"));
|
9 | const fs_extra_1 = require("fs-extra");
|
10 | const fs_extra_2 = require("fs-extra");
|
11 | const path_1 = require("path");
|
12 | exports.renderTable = (head, callback) => {
|
13 | const table = new cli_table3_1.default({
|
14 | head,
|
15 | chars: { mid: "", "left-mid": "", "mid-mid": "", "right-mid": "" },
|
16 | });
|
17 | callback(table);
|
18 | console.log(table.toString());
|
19 | };
|
20 | exports.updateEnvironmentVariables = (envFile, variables) => {
|
21 | if (!fs_extra_2.existsSync(envFile)) {
|
22 | throw new Error(`No environment file found at ${envFile}`);
|
23 | }
|
24 | const env = envfile_1.default.parseFileSync(envFile);
|
25 | for (const [key, value] of Object.entries(variables)) {
|
26 | env[key] = value;
|
27 | }
|
28 | fs_extra_1.writeFileSync(envFile, envfile_1.default.stringifySync(env));
|
29 | };
|
30 | exports.getCliConfig = (flags, paths, defaultValue = {}) => {
|
31 | const configPaths = [`${paths.config}/app.js`, path_1.resolve(__dirname, `../bin/config/${flags.network}/app.js`)];
|
32 | let configPath;
|
33 | for (const path of configPaths) {
|
34 | if (fs_extra_2.existsSync(path)) {
|
35 | configPath = path;
|
36 | break;
|
37 | }
|
38 | }
|
39 | if (!configPath) {
|
40 | return defaultValue;
|
41 | }
|
42 | const key = `cli.${flags.suffix}.run.plugins`;
|
43 | const configuration = require(path_1.resolve(configPath));
|
44 | if (!dottie_1.default.exists(configuration, key)) {
|
45 | return defaultValue;
|
46 | }
|
47 | return dottie_1.default.get(configuration, key);
|
48 | };
|
49 |
|
\ | No newline at end of file |