zcatalyst-cli 1.7.1 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -10
- package/docs/apig-utils.toml +69 -0
- package/docs/authentication/index.toml +15 -0
- package/docs/authentication/login.toml +14 -0
- package/docs/client-utils.toml +24 -0
- package/docs/command_needs/auth.toml +4 -0
- package/docs/command_needs/rc.toml +24 -0
- package/docs/commands/apig/disable.toml +4 -0
- package/docs/commands/apig/enable.toml +4 -0
- package/docs/commands/apig/status.toml +4 -0
- package/docs/commands/client/delete.toml +34 -0
- package/docs/commands/ds/export.toml +4 -0
- package/docs/commands/ds/import.toml +15 -0
- package/docs/commands/ds/status.toml +9 -0
- package/docs/commands/event/generate/index.toml +29 -0
- package/docs/commands/event/generate/integ.toml +4 -0
- package/docs/commands/functions/config.toml +11 -0
- package/docs/commands/functions/delete.toml +29 -0
- package/docs/commands/project/use.toml +9 -0
- package/docs/dc.toml +4 -0
- package/docs/deploy/features/apig.toml +4 -0
- package/docs/deploy/features/functions/index.toml +4 -0
- package/docs/event_generate/cache.toml +4 -0
- package/docs/event_generate/custom.toml +4 -0
- package/docs/event_generate/datastore.toml +4 -0
- package/docs/event_generate/filestore.toml +4 -0
- package/docs/event_generate/integration/cliq.toml +9 -0
- package/docs/execute-script.toml +19 -0
- package/docs/fn-utils/lib/common.toml +25 -0
- package/docs/fn-utils/lib/java.toml +34 -0
- package/docs/fn-utils/lib/node.toml +4 -0
- package/docs/init/index.toml +4 -0
- package/docs/internal/command.toml +4 -0
- package/docs/internal/config.toml +9 -0
- package/docs/internal/credential.toml +14 -0
- package/docs/option-filter.toml +45 -0
- package/docs/port-resolver.toml +9 -0
- package/docs/pull/index.toml +4 -0
- package/docs/serve/index.toml +4 -0
- package/docs/shell/index.toml +4 -0
- package/docs/util_modules/project.toml +9 -0
- package/lib/apig-utils.js +133 -43
- package/lib/archiver.js +4 -2
- package/lib/authentication/index.js +44 -9
- package/lib/authentication/login.js +51 -8
- package/lib/bin/catalyst.js +14 -7
- package/lib/client-utils.js +47 -14
- package/lib/client.js +1 -1
- package/lib/command_needs/auth.js +5 -3
- package/lib/command_needs/rc.js +35 -13
- package/lib/commands/apig/disable.js +8 -3
- package/lib/commands/apig/enable.js +8 -3
- package/lib/commands/apig/status.js +29 -9
- package/lib/commands/client/delete.js +65 -26
- package/lib/commands/client/setup.js +2 -2
- package/lib/commands/deploy.js +2 -2
- package/lib/commands/ds/export.js +16 -8
- package/lib/commands/ds/import.js +20 -14
- package/lib/commands/ds/status.js +22 -11
- package/lib/commands/event/generate/index.js +62 -12
- package/lib/commands/event/generate/integ.js +7 -3
- package/lib/commands/functions/add.js +2 -2
- package/lib/commands/functions/config.js +11 -3
- package/lib/commands/functions/delete.js +36 -13
- package/lib/commands/functions/setup.js +2 -2
- package/lib/commands/functions/shell.js +2 -2
- package/lib/commands/help.js +1 -1
- package/lib/commands/index.js +2 -3
- package/lib/commands/init.js +4 -4
- package/lib/commands/login.js +2 -2
- package/lib/commands/logout.js +2 -2
- package/lib/commands/project/list.js +2 -2
- package/lib/commands/project/reset.js +1 -1
- package/lib/commands/project/use.js +18 -2
- package/lib/commands/pull.js +5 -5
- package/lib/commands/run.js +2 -2
- package/lib/commands/serve.js +7 -6
- package/lib/commands/token/generate.js +2 -2
- package/lib/commands/token/list.js +2 -2
- package/lib/commands/token/revoke.js +2 -2
- package/lib/commands/whoami.js +1 -1
- package/lib/dc.js +11 -1
- package/lib/deploy/features/apig.js +33 -33
- package/lib/deploy/features/client.js +12 -19
- package/lib/deploy/features/functions/index.js +14 -4
- package/lib/deploy/features/index.js +1 -1
- package/lib/deploy/index.js +2 -9
- package/lib/endpoints/index.js +5 -2
- package/lib/endpoints/lib/apig.js +15 -5
- package/lib/endpoints/lib/applogic.js +12 -4
- package/lib/endpoints/lib/cache.js +9 -3
- package/lib/endpoints/lib/catalyst-details.js +37 -0
- package/lib/endpoints/lib/client.js +15 -5
- package/lib/endpoints/lib/datastore.js +6 -2
- package/lib/endpoints/lib/ds-bulk.js +15 -5
- package/lib/endpoints/lib/env.js +3 -1
- package/lib/endpoints/lib/event-bus.js +3 -1
- package/lib/endpoints/lib/filestore.js +6 -2
- package/lib/endpoints/lib/functions.js +12 -4
- package/lib/endpoints/lib/project.js +9 -3
- package/lib/endpoints/lib/queue.js +9 -3
- package/lib/endpoints/lib/sdk.js +3 -1
- package/lib/endpoints/lib/zcql.js +3 -1
- package/lib/error.js +18 -0
- package/lib/errorOut.js +10 -7
- package/lib/event_generate/cache.js +9 -1
- package/lib/event_generate/custom.js +6 -1
- package/lib/event_generate/datastore.js +12 -2
- package/lib/event_generate/filestore.js +9 -1
- package/lib/event_generate/integration/cliq.js +10 -2
- package/lib/execute-script.js +35 -6
- package/lib/express_middlewares/unknownReqProxy.js +18 -7
- package/lib/fn-utils/index.js +1 -1
- package/lib/fn-utils/lib/common.js +95 -17
- package/lib/fn-utils/lib/integ.js +4 -3
- package/lib/fn-utils/lib/java.js +49 -13
- package/lib/fn-utils/lib/node.js +15 -6
- package/lib/fn-watcher.js +67 -0
- package/lib/index.js +13 -12
- package/lib/init/dependencies/package-json.js +3 -1
- package/lib/init/features/functions/index.js +41 -29
- package/lib/init/features/functions/languages/java.js +5 -4
- package/lib/init/features/functions/languages/node.js +6 -5
- package/lib/init/features/index.js +8 -4
- package/lib/init/index.js +10 -3
- package/lib/internal/api.js +9 -9
- package/lib/internal/command.js +19 -14
- package/lib/internal/config.js +15 -15
- package/lib/internal/credential.js +33 -7
- package/lib/internal/rc.js +18 -10
- package/lib/migration/global/1.4.0.js +4 -2
- package/lib/migration/global/1.6.2.js +4 -2
- package/lib/migration/index.js +1 -1
- package/lib/option-filter.js +79 -22
- package/lib/optional-import.js +1 -1
- package/lib/plugin-loader.js +1 -1
- package/lib/port-resolver.js +23 -3
- package/lib/prompt.js +1 -1
- package/lib/pull/features/functions/index.js +7 -7
- package/lib/pull/features/index.js +1 -1
- package/lib/pull/index.js +10 -3
- package/lib/repl-server.js +9 -5
- package/lib/serve/features/index.js +11 -2
- package/lib/serve/index.js +19 -9
- package/lib/serve/server/index.js +137 -60
- package/lib/serve/server/lib/client.js +1 -1
- package/lib/serve/server/lib/master.js +16 -3
- package/lib/serve/server/lib/node.js +1 -1
- package/lib/shell/dependencies/http-functions.js +120 -90
- package/lib/shell/dependencies/invoker/integ/node.js +1 -1
- package/lib/shell/dependencies/local-function.js +86 -119
- package/lib/shell/index.js +10 -10
- package/lib/shell/prepare/index.js +1 -4
- package/lib/shell/prepare/languages/index.js +15 -4
- package/lib/track.js +4 -1
- package/lib/util_modules/config/index.js +1 -1
- package/lib/util_modules/config/lib/apig.js +3 -3
- package/lib/util_modules/config/lib/client.js +3 -3
- package/lib/util_modules/config/lib/functions.js +5 -5
- package/lib/util_modules/constants/index.js +22 -20
- package/lib/util_modules/constants/lib/regex.js +3 -2
- package/lib/util_modules/constants/lib/runtime.js +9 -0
- package/lib/util_modules/contextHelp.js +63 -123
- package/lib/util_modules/fs/index.js +1 -1
- package/lib/util_modules/fs/lib/async.js +19 -2
- package/lib/util_modules/fs/lib/sync.js +13 -1
- package/lib/util_modules/logger.js +12 -20
- package/lib/util_modules/option.js +1 -13
- package/lib/util_modules/project.js +75 -26
- package/lib/util_modules/shell.js +8 -2
- package/package.json +45 -45
- package/scripts/postInstall.js +31 -0
- package/lib/cjson.js +0 -20
- package/lib/log-error.js +0 -18
- package/lib/util_modules/big-json.js +0 -16
- package/lib/util_modules/constants/lib/stack.js +0 -6
- package/templates/init/functions/.DS_Store +0 -0
- package/templates/init/functions/node/.DS_Store +0 -0
- package/templates/init/functions/node/integ/.DS_Store +0 -0
|
@@ -6,139 +6,79 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const runtime_store_1 = __importDefault(require("../runtime-store"));
|
|
8
8
|
const ansi_colors_1 = require("ansi-colors");
|
|
9
|
-
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
10
|
-
const constants_1 = require("./constants");
|
|
11
9
|
const fs_1 = require("./fs");
|
|
12
|
-
const js_1 = require("./js");
|
|
13
10
|
const logger_1 = require("./logger");
|
|
14
|
-
const option_1 = require("./option");
|
|
15
11
|
const toml_1 = __importDefault(require("./parser/toml"));
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
related: ['deploy', 'functions']
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
command: 'deploy',
|
|
24
|
-
related: ['serve', 'functions']
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
command: 'functions',
|
|
28
|
-
related: ['init', 'serve', 'deploy']
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
command: 'init',
|
|
32
|
-
related: ['functions', 'client', 'pull', 'deploy']
|
|
33
|
-
}
|
|
34
|
-
];
|
|
35
|
-
let lastMsg;
|
|
36
|
-
function contextualHelp(command) {
|
|
37
|
-
var _a;
|
|
38
|
-
if (!command) {
|
|
39
|
-
logger_1.debug('Unable to identify the command');
|
|
12
|
+
function help() {
|
|
13
|
+
const logs = runtime_store_1.default.get('log');
|
|
14
|
+
if (logs === undefined) {
|
|
15
|
+
logger_1.debug('NO ERRORS REGISTERED');
|
|
40
16
|
return;
|
|
41
17
|
}
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
18
|
+
const logKeys = Object.keys(logs);
|
|
19
|
+
const fillTemplate = (...arg) => {
|
|
20
|
+
const context = arg.shift();
|
|
21
|
+
const aid = arg.shift();
|
|
22
|
+
return {
|
|
23
|
+
context: eval('`' + context + '`'),
|
|
24
|
+
aid: eval('`' + aid + '`')
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
logKeys.forEach((key) => {
|
|
28
|
+
const errQueue = logs[key];
|
|
29
|
+
if (key === 'faultyError') {
|
|
30
|
+
errQueue.forEach((err) => {
|
|
31
|
+
outputError(err, errQueue);
|
|
32
|
+
return;
|
|
33
|
+
});
|
|
48
34
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
35
|
+
const docPath = key.replace(path_1.join(__dirname, '../../lib'), path_1.join(__dirname, '../../docs')) + '.toml';
|
|
36
|
+
const doc = fs_1.SYNC.readFile(docPath) || '';
|
|
37
|
+
const catHelp = toml_1.default(doc);
|
|
38
|
+
errQueue.forEach((err) => {
|
|
39
|
+
if (err.errorId === undefined || catHelp === undefined || catHelp === {}) {
|
|
40
|
+
outputError(err, errQueue);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const arg = err.arg || [];
|
|
44
|
+
const helpTemplate = catHelp[err.errorId];
|
|
45
|
+
if (helpTemplate === undefined || helpTemplate.context === undefined) {
|
|
46
|
+
logger_1.debug('Error when fetching the help');
|
|
47
|
+
logger_1.debug('No Help found for errorId: ' + err.errorId);
|
|
48
|
+
outputError(err, errQueue);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const help = fillTemplate(helpTemplate.context, helpTemplate.aid || '', ...arg);
|
|
52
|
+
logger_1.info();
|
|
53
|
+
logger_1.labeled(ansi_colors_1.bold('Error'), help.context).ERROR();
|
|
54
|
+
debugLog(err);
|
|
55
|
+
logger_1.log('error', help.aid);
|
|
56
|
+
if (helpTemplate.link && helpTemplate.link !== '') {
|
|
57
|
+
logger_1.log('error', ansi_colors_1.bold(ansi_colors_1.blue('REF: ') + ansi_colors_1.underline(helpTemplate.link)));
|
|
58
|
+
}
|
|
59
|
+
errQueue.shift();
|
|
60
|
+
});
|
|
71
61
|
});
|
|
72
|
-
if (!writeHelp(command, helpMsgArray)) {
|
|
73
|
-
logger_1.debug(`Unable to write to ${constants_1.FILENAME.command_log} file`);
|
|
74
|
-
}
|
|
75
|
-
if (lastMsg !== undefined) {
|
|
76
|
-
logger_1.info();
|
|
77
|
-
logger_1.info(ansi_colors_1.bold('HELP'));
|
|
78
|
-
logger_1.info(constructHelp(lastMsg));
|
|
79
|
-
}
|
|
80
|
-
logger_1.info(`Use the ${ansi_colors_1.bold('catalyst help -i')} command, to get help on the above errors/warnings.`);
|
|
81
62
|
}
|
|
82
|
-
exports.default =
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
63
|
+
exports.default = help;
|
|
64
|
+
function outputError(err, errQueue) {
|
|
65
|
+
logger_1.error(err.message);
|
|
66
|
+
debugLog(err);
|
|
67
|
+
errQueue.shift();
|
|
68
|
+
if (err.exit === 2) {
|
|
69
|
+
logger_1.info(`Kindly contact Catalyst support [${ansi_colors_1.bold.underline('support@zohocatalyst.com')}] if you need any further assistance`);
|
|
87
70
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
}
|
|
72
|
+
function debugLog(err) {
|
|
73
|
+
logger_1.debug('Error Stack: ' + err.stack);
|
|
74
|
+
if (err.original) {
|
|
75
|
+
logger_1.debug('Original Error: ' +
|
|
76
|
+
(typeof err.original === 'string' ? err.original : err.original.stack));
|
|
93
77
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
logger_1.debug('Unable to fetch the help informations');
|
|
97
|
-
return findHelp(command, logs, accu);
|
|
78
|
+
if (err.context) {
|
|
79
|
+
logger_1.debug('Error Context: ' + JSON.stringify(err.context, undefined, 2));
|
|
98
80
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const helpByLevel = help[log.level];
|
|
102
|
-
if (helpByLevel === undefined) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const filteredHelp = helpByLevel.find((hlp) => {
|
|
106
|
-
return hlp.message.some((message) => {
|
|
107
|
-
return stripMsg.match(new RegExp(message, 'i'));
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
if (filteredHelp !== undefined) {
|
|
111
|
-
const pushHelp = Object.assign({}, filteredHelp);
|
|
112
|
-
pushHelp.message = [log.message];
|
|
113
|
-
pushHelp.level = log.level;
|
|
114
|
-
accu.push(pushHelp);
|
|
115
|
-
if (idx === logs.length - 1) {
|
|
116
|
-
lastMsg = pushHelp;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
return findHelp(command, logs, accu);
|
|
121
|
-
}
|
|
122
|
-
function constructHelp(help) {
|
|
123
|
-
const msg = help.message[0] ? ansi_colors_1.bold.green('Message: ') + help.message[0] : '';
|
|
124
|
-
const reason = help.reason ? ansi_colors_1.bold.green('\nReason: ') + help.reason : '';
|
|
125
|
-
const solution = help.solution ? ansi_colors_1.bold.green('\nSolution: ') + help.solution : '';
|
|
126
|
-
return msg + reason + solution;
|
|
127
|
-
}
|
|
128
|
-
function writeHelp(command, help) {
|
|
129
|
-
const status = process.exitCode === 0
|
|
130
|
-
? help === undefined
|
|
131
|
-
? ansi_colors_1.bold.green('SUCCESS')
|
|
132
|
-
: ansi_colors_1.bold.blue('SUCCESS - WITH ERRORS / WARNINGS')
|
|
133
|
-
: ansi_colors_1.bold.red('FAILURE');
|
|
134
|
-
const pth = project_1.resolveProjectPath(constants_1.FILENAME.command_log);
|
|
135
|
-
if (fs_1.SYNC.fileExists(pth)) {
|
|
136
|
-
fs_1.SYNC.deleteFile(pth);
|
|
81
|
+
if (err.status) {
|
|
82
|
+
logger_1.debug('Error Status: ' + err.status);
|
|
137
83
|
}
|
|
138
|
-
fs_1.SYNC.writeFile(pth, JSON.stringify({
|
|
139
|
-
command,
|
|
140
|
-
status,
|
|
141
|
-
help
|
|
142
|
-
}));
|
|
143
|
-
return true;
|
|
144
84
|
}
|
|
@@ -14,7 +14,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
14
14
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
15
|
if (mod && mod.__esModule) return mod;
|
|
16
16
|
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.emptyDir = exports.findAndReplace = exports.rename = exports.copyDir = exports.copyFiles = exports.copyFile = exports.deleteDir = exports.deleteFile = exports.ensureDir = exports.ensureFile = exports.walk = exports.dirList = exports.writeFile = exports.tempFile = exports.readFile = exports.fileExists = exports.dirExists = void 0;
|
|
15
|
+
exports.writeJSONFile = exports.readJSONFile = exports.emptyDir = exports.findAndReplace = exports.rename = exports.copyDir = exports.copyFiles = exports.copyFile = exports.deleteDir = exports.deleteFile = exports.ensureDir = exports.ensureFile = exports.walk = exports.dirList = exports.writeFile = exports.tempFile = exports.readFile = exports.fileExists = exports.dirExists = void 0;
|
|
16
16
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
17
17
|
const minimatch_1 = __importDefault(require("minimatch"));
|
|
18
18
|
const os_1 = __importDefault(require("os"));
|
|
@@ -162,7 +162,7 @@ function rename(pth, modifier = (baseName) => baseName) {
|
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
exports.rename = rename;
|
|
165
|
-
|
|
165
|
+
const findAndReplace = (pth) => (templates, finalWords) => __awaiter(void 0, void 0, void 0, function* () {
|
|
166
166
|
if (Array.isArray(pth)) {
|
|
167
167
|
yield Promise.all(pth.map((el) => exports.findAndReplace(el)(templates, finalWords)));
|
|
168
168
|
return;
|
|
@@ -184,9 +184,26 @@ exports.findAndReplace = (pth) => (templates, finalWords) => __awaiter(void 0, v
|
|
|
184
184
|
return writeFile(file, content);
|
|
185
185
|
})));
|
|
186
186
|
});
|
|
187
|
+
exports.findAndReplace = findAndReplace;
|
|
187
188
|
function emptyDir(dir) {
|
|
188
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
189
190
|
return fs_extra_1.default.emptyDir(dir);
|
|
190
191
|
});
|
|
191
192
|
}
|
|
192
193
|
exports.emptyDir = emptyDir;
|
|
194
|
+
function readJSONFile(pth, opts) {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
if (opts && opts.checkpath && !(yield fileExists(pth))) {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
return fs_extra_1.default.readJson(pth, opts);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
exports.readJSONFile = readJSONFile;
|
|
203
|
+
function writeJSONFile(pth, object, opts) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
yield ensureFile(pth, true);
|
|
206
|
+
return fs_extra_1.default.writeJson(pth, object, opts);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
exports.writeJSONFile = writeJSONFile;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.emptyDir = exports.copyDir = exports.copyFiles = exports.copyFile = exports.deleteTempDir = exports.tempFile = exports.deleteDir = exports.isPathInside = exports.isPathOutside = exports.renameFile = exports.modifyFileName = exports.appendFile = exports.writeFile = exports.ensureFile = exports.ensureDir = exports.readFile = exports.deleteFile = exports.getAllFiles = exports.getAllDirs = exports.dirExists = exports.fileExists = exports.getReadStream = exports.getWriteStream = void 0;
|
|
6
|
+
exports.writeJSONFile = exports.readJSONFile = exports.emptyDir = exports.copyDir = exports.copyFiles = exports.copyFile = exports.deleteTempDir = exports.tempFile = exports.deleteDir = exports.isPathInside = exports.isPathOutside = exports.renameFile = exports.modifyFileName = exports.appendFile = exports.writeFile = exports.ensureFile = exports.ensureDir = exports.readFile = exports.deleteFile = exports.getAllFiles = exports.getAllDirs = exports.dirExists = exports.fileExists = exports.getReadStream = exports.getWriteStream = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -153,3 +153,15 @@ function emptyDir(dir) {
|
|
|
153
153
|
return fs_extra_1.default.emptyDirSync(dir);
|
|
154
154
|
}
|
|
155
155
|
exports.emptyDir = emptyDir;
|
|
156
|
+
function readJSONFile(pth, opts) {
|
|
157
|
+
if (opts && opts.checkpath && !fileExists(pth)) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
return fs_extra_1.default.readJsonSync(pth, opts);
|
|
161
|
+
}
|
|
162
|
+
exports.readJSONFile = readJSONFile;
|
|
163
|
+
function writeJSONFile(pth, object, opts) {
|
|
164
|
+
ensureFile(pth, true);
|
|
165
|
+
return fs_extra_1.default.writeJsonSync(pth, object, opts);
|
|
166
|
+
}
|
|
167
|
+
exports.writeJSONFile = writeJSONFile;
|
|
@@ -5,47 +5,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.labeled = exports.error = exports.warning = exports.message = exports.success = exports.debug = exports.info = exports.log = void 0;
|
|
7
7
|
const ansi_colors_1 = __importDefault(require("ansi-colors"));
|
|
8
|
-
const runtime_store_1 = __importDefault(require("../runtime-store"));
|
|
9
|
-
const winston_1 = __importDefault(require("../winston"));
|
|
10
8
|
const char_1 = require("./char");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
message: msg,
|
|
16
|
-
level: level
|
|
17
|
-
}
|
|
18
|
-
]));
|
|
19
|
-
}
|
|
20
|
-
winston_1.default.log(level, msg);
|
|
9
|
+
const winston_1 = __importDefault(require("../winston"));
|
|
10
|
+
const util_1 = require("util");
|
|
11
|
+
function log(level, message, ...meta) {
|
|
12
|
+
winston_1.default.log(level, message, meta);
|
|
21
13
|
}
|
|
22
14
|
exports.log = log;
|
|
23
|
-
function info(msg = '') {
|
|
24
|
-
winston_1.default.info(msg);
|
|
15
|
+
function info(msg = '', ...params) {
|
|
16
|
+
winston_1.default.info(util_1.format(msg, ...params));
|
|
25
17
|
}
|
|
26
18
|
exports.info = info;
|
|
27
|
-
function debug(msg = '') {
|
|
28
|
-
winston_1.default.debug(msg);
|
|
19
|
+
function debug(msg = '', ...params) {
|
|
20
|
+
winston_1.default.debug(util_1.format(msg, ...params));
|
|
29
21
|
}
|
|
30
22
|
exports.debug = debug;
|
|
31
23
|
function success(msg, level = 'info', label = '') {
|
|
32
24
|
const postChar = label === '' ? '' : label + ': ';
|
|
33
|
-
log(ansi_colors_1.default.green(char_1.CHAR.success + ' ' + postChar) + msg
|
|
25
|
+
winston_1.default.log(level, ansi_colors_1.default.green(char_1.CHAR.success + ' ' + postChar) + msg);
|
|
34
26
|
}
|
|
35
27
|
exports.success = success;
|
|
36
28
|
function message(msg, level = 'info', label = '') {
|
|
37
29
|
const postChar = label === '' ? '' : label + ': ';
|
|
38
|
-
log(ansi_colors_1.default.cyan(char_1.CHAR.info + ' ' + postChar) + msg
|
|
30
|
+
winston_1.default.log(level, ansi_colors_1.default.cyan(char_1.CHAR.info + ' ' + postChar) + msg);
|
|
39
31
|
}
|
|
40
32
|
exports.message = message;
|
|
41
33
|
function warning(msg, level = 'warn', label = '') {
|
|
42
34
|
const postChar = label === '' ? '' : label + ': ';
|
|
43
|
-
log(ansi_colors_1.default.yellow(char_1.CHAR.warning + ' ' + postChar) + msg
|
|
35
|
+
winston_1.default.log(level, ansi_colors_1.default.yellow(char_1.CHAR.warning + ' ' + postChar) + msg);
|
|
44
36
|
}
|
|
45
37
|
exports.warning = warning;
|
|
46
38
|
function error(msg, level = 'error', label = '') {
|
|
47
39
|
const postChar = label === '' ? '' : label + ': ';
|
|
48
|
-
log(ansi_colors_1.default.red(char_1.CHAR.error + ' ' + postChar) + msg
|
|
40
|
+
winston_1.default.log(level, ansi_colors_1.default.red(char_1.CHAR.error + ' ' + postChar) + msg);
|
|
49
41
|
}
|
|
50
42
|
exports.error = error;
|
|
51
43
|
function labeled(label, line) {
|
|
@@ -3,20 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getGlobalOptionValue = exports.setGlobalOption = exports.getOptionValue = exports.getCurrentCommand =
|
|
6
|
+
exports.getGlobalOptionValue = exports.setGlobalOption = exports.getOptionValue = exports.getCurrentCommand = void 0;
|
|
7
7
|
const runtime_store_1 = __importDefault(require("../runtime-store"));
|
|
8
|
-
const js_1 = require("./js");
|
|
9
|
-
function getInheritedOption(key, fallback) {
|
|
10
|
-
let target = runtime_store_1.default.get('opts');
|
|
11
|
-
while (target) {
|
|
12
|
-
if (js_1.JS.has(target, key)) {
|
|
13
|
-
return js_1.JS.get(target, key);
|
|
14
|
-
}
|
|
15
|
-
target = js_1.JS.get(target, 'parent');
|
|
16
|
-
}
|
|
17
|
-
return fallback;
|
|
18
|
-
}
|
|
19
|
-
exports.getInheritedOption = getInheritedOption;
|
|
20
8
|
function getCurrentCommand(fallback) {
|
|
21
9
|
return runtime_store_1.default.get('opts._name', fallback);
|
|
22
10
|
}
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.resolveProjectPath = exports.upsertProject = exports.upsertEnv = exports.removeProject = exports.transformEnv = exports.transformProject = exports.makeDefaultProjectActive = exports.getProjectRoot = exports.getDefaultEnvName = exports.getDefaultProjectName = exports.getDefaultProjectId = exports.getDomainKey = exports.getDomainPrefix = exports.getEnvName = exports.getProjectName = exports.getProjectId = void 0;
|
|
16
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
16
17
|
const path_1 = __importDefault(require("path"));
|
|
17
18
|
const error_1 = __importDefault(require("../error"));
|
|
18
19
|
const runtime_store_1 = __importDefault(require("../runtime-store"));
|
|
@@ -23,17 +24,39 @@ function getDefaultProject(throwError) {
|
|
|
23
24
|
const rc = runtime_store_1.default.get('rc', null);
|
|
24
25
|
if (rc === null) {
|
|
25
26
|
if (throwError) {
|
|
26
|
-
throw new error_1.default(constants_1.FILENAME.rc + ' file needed', {
|
|
27
|
+
throw new error_1.default(constants_1.FILENAME.rc + ' file needed', {
|
|
28
|
+
exit: 1,
|
|
29
|
+
errorId: 'PROJ-1',
|
|
30
|
+
arg: [constants_1.FILENAME.rc, ansi_colors_1.bold('catalyst init project')]
|
|
31
|
+
});
|
|
27
32
|
}
|
|
28
33
|
return;
|
|
29
34
|
}
|
|
30
35
|
return rc.defaultProject;
|
|
31
36
|
}
|
|
37
|
+
function getDefaultEnv(throwError) {
|
|
38
|
+
const rc = runtime_store_1.default.get('rc', null);
|
|
39
|
+
if (rc === null) {
|
|
40
|
+
if (throwError) {
|
|
41
|
+
throw new error_1.default(constants_1.FILENAME.rc + ' file needed', {
|
|
42
|
+
exit: 1,
|
|
43
|
+
errorId: 'PROJ-1',
|
|
44
|
+
arg: [constants_1.FILENAME.rc, ansi_colors_1.bold('catalyst init project')]
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
return rc.defaultEnv;
|
|
50
|
+
}
|
|
32
51
|
function getProjectId(fallback) {
|
|
33
52
|
const projectId = runtime_store_1.default.get('project.id', null);
|
|
34
53
|
if (projectId === null) {
|
|
35
54
|
if (fallback === undefined) {
|
|
36
|
-
throw new error_1.default('ProjectId is needed', {
|
|
55
|
+
throw new error_1.default('ProjectId is needed', {
|
|
56
|
+
exit: 1,
|
|
57
|
+
errorId: 'PROJ-2',
|
|
58
|
+
arg: ['Project ID', ansi_colors_1.bold('catalyst init project --force')]
|
|
59
|
+
});
|
|
37
60
|
}
|
|
38
61
|
return fallback;
|
|
39
62
|
}
|
|
@@ -44,7 +67,11 @@ function getProjectName(fallback) {
|
|
|
44
67
|
const projectName = runtime_store_1.default.get('project.name', null);
|
|
45
68
|
if (projectName === null) {
|
|
46
69
|
if (fallback === undefined) {
|
|
47
|
-
throw new error_1.default('ProjectName is needed', {
|
|
70
|
+
throw new error_1.default('ProjectName is needed', {
|
|
71
|
+
exit: 1,
|
|
72
|
+
errorId: 'PROJ-2',
|
|
73
|
+
arg: ['Project Name', ansi_colors_1.bold('catalyst init project --force')]
|
|
74
|
+
});
|
|
48
75
|
}
|
|
49
76
|
return fallback;
|
|
50
77
|
}
|
|
@@ -59,7 +86,11 @@ function getDomainPrefix(fallback) {
|
|
|
59
86
|
const domainName = runtime_store_1.default.get('project.domain.name', null);
|
|
60
87
|
if (domainName === null) {
|
|
61
88
|
if (fallback === undefined) {
|
|
62
|
-
throw new error_1.default('domainName is needed', {
|
|
89
|
+
throw new error_1.default('domainName is needed', {
|
|
90
|
+
exit: 1,
|
|
91
|
+
errorId: 'PROJ-2',
|
|
92
|
+
arg: ['Domain Name', ansi_colors_1.bold('catalyst init project --force')]
|
|
93
|
+
});
|
|
63
94
|
}
|
|
64
95
|
return fallback;
|
|
65
96
|
}
|
|
@@ -70,7 +101,11 @@ function getDomainKey(fallback) {
|
|
|
70
101
|
const domainId = runtime_store_1.default.get('project.domain.id', null);
|
|
71
102
|
if (domainId === null) {
|
|
72
103
|
if (fallback === undefined) {
|
|
73
|
-
throw new error_1.default('domainId is needed', {
|
|
104
|
+
throw new error_1.default('domainId is needed', {
|
|
105
|
+
exit: 1,
|
|
106
|
+
errorId: 'PROJ-2',
|
|
107
|
+
arg: ['Domain ID', ansi_colors_1.bold('catalyst init project --force')]
|
|
108
|
+
});
|
|
74
109
|
}
|
|
75
110
|
return fallback;
|
|
76
111
|
}
|
|
@@ -83,7 +118,9 @@ function getDefaultProjectId(fallback) {
|
|
|
83
118
|
return defaultProject.id + '';
|
|
84
119
|
}
|
|
85
120
|
if (fallback === undefined) {
|
|
86
|
-
throw new error_1.default('Default project id in rc file is not found', {
|
|
121
|
+
throw new error_1.default('Default project id in rc file is not found', {
|
|
122
|
+
exit: 2
|
|
123
|
+
});
|
|
87
124
|
}
|
|
88
125
|
return fallback;
|
|
89
126
|
}
|
|
@@ -94,25 +131,22 @@ function getDefaultProjectName(fallback) {
|
|
|
94
131
|
return defaultProject.name;
|
|
95
132
|
}
|
|
96
133
|
if (fallback === undefined) {
|
|
97
|
-
throw new error_1.default('Default project name in rc file is not found', {
|
|
134
|
+
throw new error_1.default('Default project name in rc file is not found', {
|
|
135
|
+
exit: 2
|
|
136
|
+
});
|
|
98
137
|
}
|
|
99
138
|
return fallback;
|
|
100
139
|
}
|
|
101
140
|
exports.getDefaultProjectName = getDefaultProjectName;
|
|
102
141
|
function getDefaultEnvName(fallback) {
|
|
103
|
-
const
|
|
104
|
-
if (rc === null) {
|
|
105
|
-
if (fallback === undefined) {
|
|
106
|
-
throw new error_1.default(constants_1.FILENAME.rc + ' file needed', { exit: 1 });
|
|
107
|
-
}
|
|
108
|
-
return fallback;
|
|
109
|
-
}
|
|
110
|
-
const defaultEnv = rc.defaultEnv;
|
|
142
|
+
const defaultEnv = getDefaultEnv(fallback === undefined);
|
|
111
143
|
if (defaultEnv !== undefined) {
|
|
112
144
|
return defaultEnv.name;
|
|
113
145
|
}
|
|
114
146
|
if (fallback === undefined) {
|
|
115
|
-
throw new error_1.default('Default Environment name in rc file is not found', {
|
|
147
|
+
throw new error_1.default('Default Environment name in rc file is not found', {
|
|
148
|
+
exit: 2
|
|
149
|
+
});
|
|
116
150
|
}
|
|
117
151
|
return fallback;
|
|
118
152
|
}
|
|
@@ -130,13 +164,22 @@ function getProjectRoot(fallback = process.cwd()) {
|
|
|
130
164
|
}
|
|
131
165
|
exports.getProjectRoot = getProjectRoot;
|
|
132
166
|
function makeDefaultProjectActive() {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
const defaultProject = getDefaultProject(false);
|
|
169
|
+
if (defaultProject === undefined) {
|
|
170
|
+
throw new error_1.default('Unable to set default project active since value is not defined', {
|
|
171
|
+
exit: 2
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const defaultEnv = getDefaultEnv(false);
|
|
175
|
+
if (defaultEnv === undefined) {
|
|
176
|
+
throw new error_1.default('Unable to set default env active since value is not defined', {
|
|
177
|
+
exit: 2
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
yield upsertProject(defaultProject, { active: true });
|
|
181
|
+
return upsertEnv(defaultProject.id, defaultEnv, { active: true });
|
|
182
|
+
});
|
|
140
183
|
}
|
|
141
184
|
exports.makeDefaultProjectActive = makeDefaultProjectActive;
|
|
142
185
|
function transformProject(projectObj) {
|
|
@@ -186,7 +229,9 @@ function removeProject(projectId) {
|
|
|
186
229
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
230
|
const rc = runtime_store_1.default.get('rc', null);
|
|
188
231
|
if (rc === null) {
|
|
189
|
-
throw new error_1.default(constants_1.FILENAME.rc + ' file needed to remove project', {
|
|
232
|
+
throw new error_1.default(constants_1.FILENAME.rc + ' file needed to remove project', {
|
|
233
|
+
exit: 2
|
|
234
|
+
});
|
|
190
235
|
}
|
|
191
236
|
return rc.removeProject(projectId);
|
|
192
237
|
});
|
|
@@ -197,7 +242,9 @@ function upsertEnv(projectId, envObj, { base = false, active = false }) {
|
|
|
197
242
|
const transformedEnv = transformEnv(envObj);
|
|
198
243
|
const rc = runtime_store_1.default.get('rc', null);
|
|
199
244
|
if (rc === null) {
|
|
200
|
-
throw new error_1.default(constants_1.FILENAME.rc + ' file needed to upsert environment', {
|
|
245
|
+
throw new error_1.default(constants_1.FILENAME.rc + ' file needed to upsert environment', {
|
|
246
|
+
exit: 2
|
|
247
|
+
});
|
|
201
248
|
}
|
|
202
249
|
return rc.associateEnv(projectId, transformedEnv, {
|
|
203
250
|
base,
|
|
@@ -211,7 +258,9 @@ function upsertProject(projectObj, { base = false, active = false }) {
|
|
|
211
258
|
const transformedProj = transformProject(projectObj);
|
|
212
259
|
const rc = runtime_store_1.default.get('rc', null);
|
|
213
260
|
if (rc === null) {
|
|
214
|
-
throw new error_1.default(constants_1.FILENAME.rc + ' file needed to upsert project', {
|
|
261
|
+
throw new error_1.default(constants_1.FILENAME.rc + ' file needed to upsert project', {
|
|
262
|
+
exit: 2
|
|
263
|
+
});
|
|
215
264
|
}
|
|
216
265
|
return rc.upsertProject(transformedProj, {
|
|
217
266
|
base,
|
|
@@ -45,7 +45,9 @@ function spawn(command, opts, _a = {}) {
|
|
|
45
45
|
return {
|
|
46
46
|
SYNC: () => cross_spawn_1.default.sync(command, opts, Object.assign({ cwd, stdio, shell }, otherOpts)),
|
|
47
47
|
ASYNC: () => {
|
|
48
|
-
const childProcess = cross_spawn_1.default(command, opts, Object.assign({ cwd,
|
|
48
|
+
const childProcess = cross_spawn_1.default(command, opts, Object.assign({ cwd,
|
|
49
|
+
stdio,
|
|
50
|
+
shell }, otherOpts));
|
|
49
51
|
return new Promise((res, rej) => {
|
|
50
52
|
let message = '';
|
|
51
53
|
childProcess.on('error', (err) => {
|
|
@@ -63,7 +65,11 @@ function spawn(command, opts, _a = {}) {
|
|
|
63
65
|
});
|
|
64
66
|
});
|
|
65
67
|
},
|
|
66
|
-
RAW: () =>
|
|
68
|
+
RAW: () => {
|
|
69
|
+
const child = cross_spawn_1.default(command, opts, Object.assign({ cwd, stdio, shell }, otherOpts));
|
|
70
|
+
child.on('error', (err) => logger_1.debug(err));
|
|
71
|
+
return child;
|
|
72
|
+
}
|
|
67
73
|
};
|
|
68
74
|
}
|
|
69
75
|
exports.spawn = spawn;
|