zcatalyst-cli 1.9.1 → 1.10.0
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 +3 -3
- package/docs/command_needs/auth.toml +5 -0
- package/docs/commands/iac/export.toml +4 -0
- package/docs/commands/iac/import.toml +4 -0
- package/docs/commands/iac/status.toml +4 -0
- package/docs/commands/project/use.toml +6 -0
- package/docs/iac/status/bundle.toml +4 -0
- package/lib/api-timer.js +81 -0
- package/lib/apig-utils.js +16 -14
- package/lib/archiver.js +83 -45
- package/lib/authentication/login.js +4 -2
- package/lib/bin/catalyst.js +0 -1
- package/lib/client-utils.js +22 -22
- package/lib/client.js +0 -3
- package/lib/command_needs/auth.js +12 -3
- package/lib/command_needs/rc.js +12 -7
- package/lib/commands/apig/status.js +6 -4
- package/lib/commands/client/delete.js +2 -4
- package/lib/commands/client/setup.js +1 -1
- package/lib/commands/deploy.js +3 -1
- package/lib/commands/ds/export.js +3 -1
- package/lib/commands/ds/import.js +3 -1
- package/lib/commands/ds/status.js +145 -149
- package/lib/commands/functions/config.js +1 -1
- package/lib/commands/functions/setup.js +1 -1
- package/lib/commands/help.js +1 -23
- package/lib/commands/iac/export.js +85 -0
- package/lib/commands/iac/import.js +187 -0
- package/lib/commands/iac/pack.js +129 -0
- package/lib/commands/iac/status.js +63 -0
- package/lib/commands/index.js +4 -0
- package/lib/commands/init.js +33 -26
- package/lib/commands/project/list.js +10 -6
- package/lib/commands/project/use.js +42 -25
- package/lib/deploy/features/functions/index.js +2 -1
- package/lib/deploy/index.js +3 -1
- package/lib/endpoints/lib/iac.js +134 -0
- package/lib/error.js +29 -0
- package/lib/errorOut.js +3 -2
- package/lib/fn-utils/lib/common.js +32 -12
- package/lib/fn-utils/lib/java.js +6 -8
- package/lib/fn-utils/lib/node.js +7 -1
- package/lib/iac/status/bundle.js +82 -0
- package/lib/iac/status/deploy.js +74 -0
- package/lib/iac/status/util/index.js +26 -0
- package/lib/index.js +8 -14
- package/lib/init/features/client.js +2 -3
- package/lib/init/features/functions/languages/java.js +2 -5
- package/lib/init/features/functions/languages/node.js +2 -5
- package/lib/init/features/index.js +8 -3
- package/lib/init/features/project.js +70 -33
- package/lib/init/util/client.js +12 -0
- package/lib/init/util/functions.js +20 -0
- package/lib/init/util/project.js +35 -0
- package/lib/internal/api.js +6 -9
- package/lib/internal/command.js +2 -2
- package/lib/internal/config.js +6 -4
- package/lib/migration/index.js +10 -6
- package/lib/option-filter.js +4 -1
- package/lib/port-resolver.js +18 -16
- package/lib/prompt/index.js +92 -0
- package/lib/prompt/types/file-path.js +95 -0
- package/lib/pull/features/client.js +1 -1
- package/lib/pull/features/functions/index.js +5 -7
- package/lib/pull/index.js +4 -1
- package/lib/serve/features/index.js +3 -1
- package/lib/shell/dependencies/http-functions.js +1 -1
- package/lib/shell/index.js +3 -1
- package/lib/track.js +3 -1
- package/lib/util_modules/constants/index.js +3 -1
- package/lib/util_modules/constants/lib/file-names.js +2 -1
- package/lib/util_modules/constants/lib/iac.js +8 -0
- package/lib/util_modules/constants/lib/regex.js +2 -1
- package/lib/util_modules/constants/lib/scopes.js +5 -0
- package/lib/util_modules/constants/project.js +6 -0
- package/lib/util_modules/contextHelp.js +5 -1
- package/lib/util_modules/env.js +2 -5
- package/lib/util_modules/fs/index.js +9 -1
- package/lib/util_modules/fs/lib/async.js +29 -22
- package/lib/util_modules/js.js +6 -0
- package/lib/util_modules/parser/toml.js +5 -1
- package/lib/util_modules/project.js +3 -0
- package/lib/util_modules/shell.js +3 -6
- package/package.json +7 -4
- package/templates/iacSuccess.html +391 -0
- package/lib/prompt.js +0 -49
|
@@ -25,6 +25,7 @@ const logger_1 = require("../../../../util_modules/logger");
|
|
|
25
25
|
const js_1 = require("../../../../util_modules/js");
|
|
26
26
|
const integ_1 = require("../../../../fn-utils/lib/integ");
|
|
27
27
|
const runtime_1 = __importDefault(require("../../../../util_modules/constants/lib/runtime"));
|
|
28
|
+
const functions_1 = require("../../../util/functions");
|
|
28
29
|
exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
30
|
const fnType = runtime_store_1.default.get('context.functions.type');
|
|
30
31
|
const service = runtime_store_1.default.get('context.functions.integration.service', '');
|
|
@@ -70,9 +71,5 @@ exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
70
71
|
integ_config
|
|
71
72
|
});
|
|
72
73
|
yield npm_install_1.default(targetPath);
|
|
73
|
-
|
|
74
|
-
runtime_store_1.default.set('payload.functions.stack', stack);
|
|
75
|
-
runtime_store_1.default.set('payload.functions.name', finalJson.name);
|
|
76
|
-
runtime_store_1.default.set('payload.functions.main', finalJson.main);
|
|
77
|
-
runtime_store_1.default.set('payload.functions.type', fnType);
|
|
74
|
+
return functions_1.fillFunctionsInitPayload(targetPath, finalJson.name, stack, fnType);
|
|
78
75
|
});
|
|
@@ -75,7 +75,7 @@ function setFnConfig(featureName, add) {
|
|
|
75
75
|
const config = runtime_store_1.default.get('config');
|
|
76
76
|
featureContextArr.forEach((context) => {
|
|
77
77
|
var _a, _b;
|
|
78
|
-
const targetSourceDir = featureName === 'functions' ? path_1.dirname(context.source) :
|
|
78
|
+
const targetSourceDir = featureName === 'functions' ? path_1.dirname(context.source) : context.source;
|
|
79
79
|
const targetSource = path_1.relative(project_1.getProjectRoot(), targetSourceDir);
|
|
80
80
|
switch (featureName) {
|
|
81
81
|
case 'functions':
|
|
@@ -125,7 +125,7 @@ function project() {
|
|
|
125
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
126
|
yield (yield Promise.resolve().then(() => __importStar(require('./project')))).default();
|
|
127
127
|
const projectPayload = runtime_store_1.default.get('payload.project', null);
|
|
128
|
-
if (projectPayload
|
|
128
|
+
if (!projectPayload) {
|
|
129
129
|
return;
|
|
130
130
|
}
|
|
131
131
|
yield project_1.upsertProject(projectPayload, {
|
|
@@ -133,10 +133,15 @@ function project() {
|
|
|
133
133
|
active: true
|
|
134
134
|
});
|
|
135
135
|
yield upsertEnvArr(runtime_store_1.default.get('payload.env', null));
|
|
136
|
-
if (runtime_store_1.default.get('project.new', false)) {
|
|
136
|
+
if (runtime_store_1.default.get('payload.project.new', false)) {
|
|
137
137
|
logger_1.message('New Project has been successfully created and associated with this directory.');
|
|
138
138
|
}
|
|
139
139
|
logger_1.message(ansi_colors_1.bold(constants_1.FILENAME.rc) + ' file has be successfully created with project details.');
|
|
140
|
+
const isImport = runtime_store_1.default.get('payload.project.import', false);
|
|
141
|
+
if (isImport) {
|
|
142
|
+
setFnConfig('functions', true);
|
|
143
|
+
setFnConfig('client', false);
|
|
144
|
+
}
|
|
140
145
|
});
|
|
141
146
|
}
|
|
142
147
|
exports.project = project;
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const ansi_colors_1 = require("ansi-colors");
|
|
16
|
+
const import_1 = require("../../commands/iac/import");
|
|
16
17
|
const endpoints_1 = require("../../endpoints");
|
|
17
18
|
const error_1 = __importDefault(require("../../error"));
|
|
18
19
|
const prompt_1 = __importDefault(require("../../prompt"));
|
|
@@ -21,33 +22,39 @@ const constants_1 = require("../../util_modules/constants");
|
|
|
21
22
|
const js_1 = require("../../util_modules/js");
|
|
22
23
|
const logger_1 = require("../../util_modules/logger");
|
|
23
24
|
const option_1 = require("../../util_modules/option");
|
|
25
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
24
26
|
const project_1 = require("../../util_modules/project");
|
|
27
|
+
const path_1 = require("path");
|
|
28
|
+
const functions_1 = require("../util/functions");
|
|
29
|
+
const project_2 = require("../util/project");
|
|
30
|
+
const client_1 = require("../util/client");
|
|
31
|
+
const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
|
|
32
|
+
const fn_utils_1 = require("../../fn-utils");
|
|
33
|
+
const client_utils_1 = require("../../client-utils");
|
|
25
34
|
exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
var _a, _b;
|
|
26
36
|
const projectAPI = yield endpoints_1.projectAPI();
|
|
27
37
|
const defaultRCProjectName = project_1.getDefaultProjectName(null);
|
|
28
38
|
const defaultRCProjectId = project_1.getDefaultProjectId(null);
|
|
29
39
|
if (defaultRCProjectName !== null &&
|
|
30
40
|
defaultRCProjectId !== null &&
|
|
31
41
|
!option_1.getOptionValue('force', false)) {
|
|
32
|
-
logger_1.message(constants_1.FILENAME.rc +
|
|
33
|
-
' already has ' +
|
|
34
|
-
ansi_colors_1.bold(defaultRCProjectName) +
|
|
35
|
-
' as a default project. To overwrite use ' +
|
|
36
|
-
ansi_colors_1.bold('--force') +
|
|
37
|
-
' option');
|
|
42
|
+
logger_1.message(constants_1.FILENAME.rc + ' already has ' + ansi_colors_1.bold(defaultRCProjectName) + ' as a default project.');
|
|
38
43
|
try {
|
|
39
44
|
yield projectAPI.getProject(defaultRCProjectId);
|
|
40
|
-
|
|
41
|
-
return;
|
|
45
|
+
throw new error_1.default('Skipping project setup, since project directory contains a default project. To overwrite use --force option');
|
|
42
46
|
}
|
|
43
47
|
catch (err) {
|
|
44
|
-
if (js_1.JS.get(err, 'context.response.statusCode')
|
|
45
|
-
|
|
48
|
+
if (js_1.JS.get(err, 'context.response.statusCode') !== 404) {
|
|
49
|
+
throw err;
|
|
46
50
|
}
|
|
47
|
-
|
|
51
|
+
logger_1.warning('cleaning up ' +
|
|
52
|
+
constants_1.FILENAME.rc +
|
|
53
|
+
' since the current default project for this folder is not found in remote');
|
|
54
|
+
yield project_1.removeProject(defaultRCProjectId + '');
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
|
-
logger_1.message('Setting up a default project for this folder\n');
|
|
57
|
+
logger_1.message('Setting up a new default project for this folder\n');
|
|
51
58
|
const allProjects = (yield projectAPI.getAllProjects());
|
|
52
59
|
if (allProjects.length === 0) {
|
|
53
60
|
throw new error_1.default('Visit ' +
|
|
@@ -56,8 +63,12 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
56
63
|
}
|
|
57
64
|
const projectChoices = [
|
|
58
65
|
prompt_1.default.choice('[create a new project]', {
|
|
59
|
-
value:
|
|
66
|
+
value: 0,
|
|
60
67
|
short: 'New-Project'
|
|
68
|
+
}),
|
|
69
|
+
prompt_1.default.choice('[import a existing project]', {
|
|
70
|
+
value: 1,
|
|
71
|
+
short: 'Import-project'
|
|
61
72
|
})
|
|
62
73
|
];
|
|
63
74
|
allProjects.forEach((project) => {
|
|
@@ -66,32 +77,58 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
66
77
|
short: project.project_name
|
|
67
78
|
}));
|
|
68
79
|
});
|
|
69
|
-
const projectAns = yield prompt_1.default.ask(prompt_1.default.question('project', '
|
|
70
|
-
'Select a default Catalyst project for this directory: ', {
|
|
80
|
+
const projectAns = yield prompt_1.default.ask(prompt_1.default.question('project', 'Select a default Catalyst project for this directory: ', {
|
|
71
81
|
type: 'list',
|
|
72
82
|
choices: js_1.JS.reverse(projectChoices)
|
|
73
83
|
}));
|
|
74
84
|
let selectedProject = projectAns.project;
|
|
75
|
-
if (selectedProject
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return 'Invalid project name';
|
|
82
|
-
}
|
|
85
|
+
if (typeof selectedProject !== 'number') {
|
|
86
|
+
return project_2.fillProjectPayload(selectedProject);
|
|
87
|
+
}
|
|
88
|
+
if (selectedProject === 0) {
|
|
89
|
+
const projectNameAns = yield prompt_1.default.ask(prompt_1.default.question('projectName', 'Provide a name for your new project:', {
|
|
90
|
+
validate: (ans) => (ans.match(constants_1.REGEX.project.name) ? true : 'Invalid project name')
|
|
83
91
|
}));
|
|
84
92
|
selectedProject = yield projectAPI.createProject(projectNameAns.projectName);
|
|
85
|
-
|
|
93
|
+
return project_2.fillProjectPayload(selectedProject, true);
|
|
86
94
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
const [zipArchive, template, importRes] = yield import_1.iacImport();
|
|
96
|
+
yield zipArchive
|
|
97
|
+
.extract(runtime_store_1.default.get('cwd'), '/', { recursive: true, ignoreInitial: false })
|
|
98
|
+
.finalize();
|
|
99
|
+
const parsedJSON = js_1.JS.parseJSON(template);
|
|
100
|
+
const templateJson = parsedJSON ? parsedJSON : yaml_1.default.parse(template);
|
|
101
|
+
const functions = ((_a = templateJson.components) === null || _a === void 0 ? void 0 : _a.Functions) || [];
|
|
102
|
+
const client = ((_b = templateJson.components) === null || _b === void 0 ? void 0 : _b.WebClient) || [];
|
|
103
|
+
yield Promise.all(functions.map(({ properties }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
const source = properties.code.path.replace('/', path_1.sep).replace('.zip', '');
|
|
105
|
+
const stack = properties.stack.toLowerCase();
|
|
106
|
+
const refinedTargets = yield fn_utils_1.fnUtils.common.refineTargets([source], false);
|
|
107
|
+
const fnUtil = stack.startsWith(runtime_1.default.language.nodejs)
|
|
108
|
+
? fn_utils_1.fnUtils.node
|
|
109
|
+
: stack.startsWith(runtime_1.default.language.java)
|
|
110
|
+
? fn_utils_1.fnUtils.java
|
|
111
|
+
: null;
|
|
112
|
+
if (fnUtil === null) {
|
|
113
|
+
logger_1.warning(`skipping setup of function(${refinedTargets[0].name}) since provided stack ${stack} is not supported.`);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!refinedTargets[0].valid) {
|
|
117
|
+
logger_1.debug('Invalid target : ' +
|
|
118
|
+
refinedTargets[0].name +
|
|
119
|
+
' reason : ' +
|
|
120
|
+
refinedTargets[0].failure_reason);
|
|
121
|
+
logger_1.warning(`skipping setup of function(${refinedTargets[0].name}) since the package is invalid. \nContact catalyst support with debug log.`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
functions_1.fillFunctionsInitPayload(source, properties.name, properties.stack, properties.type);
|
|
125
|
+
})));
|
|
126
|
+
if (client.length > 0) {
|
|
127
|
+
const { properties } = client[0];
|
|
128
|
+
const source = properties.code.path.replace('/', path_1.sep).replace('.zip', '');
|
|
129
|
+
yield client_utils_1.clientUtils.validate(source);
|
|
130
|
+
client_1.fillClientInitPayload(source, properties.app_name);
|
|
94
131
|
}
|
|
95
|
-
|
|
96
|
-
|
|
132
|
+
const projectDetails = yield projectAPI.getProject(importRes.project_details.id);
|
|
133
|
+
return project_2.fillProjectPayload(projectDetails, true, true);
|
|
97
134
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
exports.fillClientInitPayload = void 0;
|
|
7
|
+
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
8
|
+
const fillClientInitPayload = (source, name) => {
|
|
9
|
+
runtime_store_1.default.set('payload.client.source', source);
|
|
10
|
+
runtime_store_1.default.set('payload.client.name', name);
|
|
11
|
+
};
|
|
12
|
+
exports.fillClientInitPayload = fillClientInitPayload;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
exports.fillFunctionsInitPayload = void 0;
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
9
|
+
const fillFunctionsInitPayload = (source, name, stack, type) => {
|
|
10
|
+
const existingFns = runtime_store_1.default.get('payload.functions.targets', []);
|
|
11
|
+
existingFns.push({
|
|
12
|
+
source,
|
|
13
|
+
name,
|
|
14
|
+
stack,
|
|
15
|
+
type
|
|
16
|
+
});
|
|
17
|
+
runtime_store_1.default.set('payload.functions.targets', existingFns);
|
|
18
|
+
runtime_store_1.default.set('payload.functions.source', path_1.dirname(source));
|
|
19
|
+
};
|
|
20
|
+
exports.fillFunctionsInitPayload = fillFunctionsInitPayload;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.fillProjectPayload = void 0;
|
|
16
|
+
const endpoints_1 = require("../../endpoints");
|
|
17
|
+
const error_1 = __importDefault(require("../../error"));
|
|
18
|
+
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
19
|
+
const constants_1 = require("../../util_modules/constants");
|
|
20
|
+
const project_1 = require("../../util_modules/project");
|
|
21
|
+
const fillProjectPayload = (selectedProject, isNew = false, isImport = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
runtime_store_1.default.set('payload.project', selectedProject);
|
|
23
|
+
runtime_store_1.default.set('project', project_1.transformProject(selectedProject));
|
|
24
|
+
const envAPI = yield endpoints_1.envAPI();
|
|
25
|
+
const envArr = (yield envAPI.getEnvs(project_1.getProjectId()));
|
|
26
|
+
const envObj = envArr.find((env) => env.env_name === constants_1.DEFAULT.env_name);
|
|
27
|
+
if (envObj === undefined) {
|
|
28
|
+
throw new error_1.default('There is no development environment found for this project. Kindly contact support.', { exit: 2 });
|
|
29
|
+
}
|
|
30
|
+
runtime_store_1.default.set('payload.env', envArr);
|
|
31
|
+
runtime_store_1.default.set('project.env', project_1.transformEnv(envObj));
|
|
32
|
+
runtime_store_1.default.set('payload.project.new', isNew);
|
|
33
|
+
runtime_store_1.default.set('payload.project.import', isImport);
|
|
34
|
+
});
|
|
35
|
+
exports.fillProjectPayload = fillProjectPayload;
|
package/lib/internal/api.js
CHANGED
|
@@ -116,7 +116,8 @@ class API {
|
|
|
116
116
|
body = JSON.parse(rawResponseData.toString());
|
|
117
117
|
}
|
|
118
118
|
catch (e) {
|
|
119
|
-
|
|
119
|
+
const err = error_1.default.getErrorInstance(e);
|
|
120
|
+
logger_1.debug('API Parsing Error: ' + err.message);
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
if (resp.statusCode >= 400 && !this.logOpts.skipRespBody) {
|
|
@@ -165,14 +166,10 @@ class API {
|
|
|
165
166
|
try {
|
|
166
167
|
resolve(yield this._retry(err));
|
|
167
168
|
}
|
|
168
|
-
catch (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
reject(new error_1.default('API Error: ' + err.message, {
|
|
173
|
-
original: error,
|
|
174
|
-
exit: 2
|
|
175
|
-
}));
|
|
169
|
+
catch (e) {
|
|
170
|
+
const error = error_1.default.getErrorInstance(e);
|
|
171
|
+
error.exit = 2;
|
|
172
|
+
reject(error);
|
|
176
173
|
}
|
|
177
174
|
break;
|
|
178
175
|
}
|
package/lib/internal/command.js
CHANGED
|
@@ -127,15 +127,15 @@ class Command {
|
|
|
127
127
|
try {
|
|
128
128
|
yield runner.apply(this, programArgs);
|
|
129
129
|
const duration = Date.now() - start;
|
|
130
|
+
errorOut_1.default();
|
|
130
131
|
yield track_1.default(this.cmdName, 'success', duration);
|
|
131
|
-
process.exitCode = 0;
|
|
132
132
|
}
|
|
133
133
|
catch (err) {
|
|
134
134
|
const duration = Date.now() - start;
|
|
135
135
|
const errorEvent = err.exit === 1 ? 'Error (User)' : 'Error (Unexpected)';
|
|
136
136
|
const preppedMessage = strip_ansi_1.default(err.message || '');
|
|
137
|
+
errorOut_1.default(err);
|
|
137
138
|
yield track_1.default(errorEvent, preppedMessage, duration);
|
|
138
|
-
return errorOut_1.default(err);
|
|
139
139
|
}
|
|
140
140
|
}));
|
|
141
141
|
return cmd;
|
package/lib/internal/config.js
CHANGED
|
@@ -68,11 +68,13 @@ class Config {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
catch (e) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
arg: [ansi_colors_1.bold(constants_1.FILENAME.config), e.message]
|
|
71
|
+
const err = error_1.default.getErrorInstance(e, {
|
|
72
|
+
message: 'There was an error loading a file',
|
|
73
|
+
skipHelp: false
|
|
75
74
|
});
|
|
75
|
+
err.errorId = 'CONFIG-1';
|
|
76
|
+
err.arg = [ansi_colors_1.bold(constants_1.FILENAME.config), err.message];
|
|
77
|
+
throw err;
|
|
76
78
|
}
|
|
77
79
|
if (canIgnore) {
|
|
78
80
|
return new Config(path_1.join(pd, constants_1.FILENAME.config));
|
package/lib/migration/index.js
CHANGED
|
@@ -63,10 +63,12 @@ const runMigration = (rc, migFiles, idx = 0) => __awaiter(void 0, void 0, void 0
|
|
|
63
63
|
completed: false
|
|
64
64
|
});
|
|
65
65
|
rc.syncSave();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
const err = error_1.default.getErrorInstance(e, {
|
|
67
|
+
message: 'Unable to run migration file ' + migFile,
|
|
68
|
+
skipHelp: false
|
|
69
69
|
});
|
|
70
|
+
err.exit = 2;
|
|
71
|
+
throw err;
|
|
70
72
|
}
|
|
71
73
|
rc.set(['migration', currentMigFileVersion], {
|
|
72
74
|
completed: true
|
|
@@ -102,10 +104,12 @@ const runGlobalMigration = (migFiles) => __awaiter(void 0, void 0, void 0, funct
|
|
|
102
104
|
error: util_1.inspect(e),
|
|
103
105
|
completed: false
|
|
104
106
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
const err = error_1.default.getErrorInstance(e, {
|
|
108
|
+
message: 'Unable to run migration file ' + migFile,
|
|
109
|
+
skipHelp: false
|
|
108
110
|
});
|
|
111
|
+
err.exit = 2;
|
|
112
|
+
throw err;
|
|
109
113
|
}
|
|
110
114
|
config_store_1.default.set('migration.' + currentMigFileVersion.replace(new RegExp('\\.', 'g'), '\\.'), {
|
|
111
115
|
completed: true
|
package/lib/option-filter.js
CHANGED
|
@@ -175,7 +175,7 @@ function filterPorts() {
|
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
177
|
exports.filterPorts = filterPorts;
|
|
178
|
-
function filterTargets() {
|
|
178
|
+
function filterTargets(pathSense = true) {
|
|
179
179
|
const validTargetResultants = validateTargets();
|
|
180
180
|
const config = runtime_store_1.default.get('config');
|
|
181
181
|
let targets = validGlobalTargets.filter((t) => config.has(t));
|
|
@@ -185,6 +185,9 @@ function filterTargets() {
|
|
|
185
185
|
if (target === 'apig' && option_1.getCurrentCommand() === 'serve') {
|
|
186
186
|
return true;
|
|
187
187
|
}
|
|
188
|
+
if (!pathSense) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
188
191
|
const targetRoot = project_1.resolveProjectPath(CONFIG[(target + 'Config')].source());
|
|
189
192
|
return (fs_1.SYNC.isPathInside(targetRoot, runtime_store_1.default.get('cwd')) ||
|
|
190
193
|
runtime_store_1.default.get('cwd') === targetRoot);
|
package/lib/port-resolver.js
CHANGED
|
@@ -68,25 +68,27 @@ class PortResolver {
|
|
|
68
68
|
}
|
|
69
69
|
catch (e) {
|
|
70
70
|
if (searchSpan === 0) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
errorId: 'PORT-RESOLVER-1',
|
|
75
|
-
arg: [
|
|
76
|
-
ansi_colors_1.bold.red(port + ''),
|
|
77
|
-
type === 'debug' ? 'debugging' : 'serving',
|
|
78
|
-
ansi_colors_1.bold(feature),
|
|
79
|
-
name,
|
|
80
|
-
type
|
|
81
|
-
]
|
|
71
|
+
const err = error_1.default.getErrorInstance(e, {
|
|
72
|
+
message: `Provided port '${port}' is not available`,
|
|
73
|
+
skipHelp: false
|
|
82
74
|
});
|
|
75
|
+
err.errorId = 'PORT-RESOLVER-1';
|
|
76
|
+
err.arg = [
|
|
77
|
+
ansi_colors_1.bold.red(port + ''),
|
|
78
|
+
type === 'debug' ? 'debugging' : 'serving',
|
|
79
|
+
ansi_colors_1.bold(feature),
|
|
80
|
+
name,
|
|
81
|
+
type
|
|
82
|
+
];
|
|
83
|
+
throw err;
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
errorId: 'PORT-RESOLVER-2',
|
|
88
|
-
arg: [ansi_colors_1.bold(port + ''), ansi_colors_1.bold(port + searchSpan + ''), ansi_colors_1.bold('--' + type)]
|
|
85
|
+
const cerr = error_1.default.getErrorInstance(e, {
|
|
86
|
+
message: `No ports from '${port}' to ${port + searchSpan} is free to use as a ${type} port.`,
|
|
87
|
+
skipHelp: false
|
|
89
88
|
});
|
|
89
|
+
cerr.errorId = 'PORT-RESOLVER-2';
|
|
90
|
+
cerr.arg = [ansi_colors_1.bold(port + ''), ansi_colors_1.bold(port + searchSpan + ''), ansi_colors_1.bold('--' + type)];
|
|
91
|
+
throw cerr;
|
|
90
92
|
}
|
|
91
93
|
if (finalPort !== port) {
|
|
92
94
|
logger_1.debug(`${type} port : '${port}' is not available. Hence port '${finalPort}' will be used instead.`);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
31
|
+
var t = {};
|
|
32
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
33
|
+
t[p] = s[p];
|
|
34
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
35
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
36
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
37
|
+
t[p[i]] = s[p[i]];
|
|
38
|
+
}
|
|
39
|
+
return t;
|
|
40
|
+
};
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
46
|
+
const error_1 = __importDefault(require("../error"));
|
|
47
|
+
const choice = (name, _a = {}) => {
|
|
48
|
+
var { value = name, short = name, disabled = false, checked = false } = _a, otherOpts = __rest(_a, ["value", "short", "disabled", "checked"]);
|
|
49
|
+
return Object.assign({ name,
|
|
50
|
+
value,
|
|
51
|
+
short,
|
|
52
|
+
disabled,
|
|
53
|
+
checked }, otherOpts);
|
|
54
|
+
};
|
|
55
|
+
exports.default = {
|
|
56
|
+
register: (type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
switch (type) {
|
|
58
|
+
case 'file-path':
|
|
59
|
+
const filePathExt = yield Promise.resolve().then(() => __importStar(require('./types/file-path')));
|
|
60
|
+
inquirer_1.default.registerPrompt('file-path', filePathExt.default);
|
|
61
|
+
break;
|
|
62
|
+
default:
|
|
63
|
+
throw new error_1.default('No such type registered', { exit: 2 });
|
|
64
|
+
}
|
|
65
|
+
}),
|
|
66
|
+
seperator: (line) => {
|
|
67
|
+
return new inquirer_1.default.Separator(line);
|
|
68
|
+
},
|
|
69
|
+
choice,
|
|
70
|
+
ask: (...questions) => {
|
|
71
|
+
return inquirer_1.default.prompt(questions);
|
|
72
|
+
},
|
|
73
|
+
question: (name, question, _a = {}) => {
|
|
74
|
+
var { type = 'input', defaultAns, choices = [], validate = () => {
|
|
75
|
+
return true;
|
|
76
|
+
}, filter = (ans) => {
|
|
77
|
+
return ans;
|
|
78
|
+
}, when = () => {
|
|
79
|
+
return true;
|
|
80
|
+
}, prefix = '', suffix = '' } = _a, otheropts = __rest(_a, ["type", "defaultAns", "choices", "validate", "filter", "when", "prefix", "suffix"]);
|
|
81
|
+
if (choices.length > 0 && typeof choices[0] === 'string') {
|
|
82
|
+
choices = choices.map((strChoice) => choice(strChoice));
|
|
83
|
+
}
|
|
84
|
+
return Object.assign({ type,
|
|
85
|
+
name, message: question, default: defaultAns, choices,
|
|
86
|
+
validate,
|
|
87
|
+
filter,
|
|
88
|
+
when,
|
|
89
|
+
prefix,
|
|
90
|
+
suffix }, otheropts);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const choices_1 = __importDefault(require("inquirer/lib/objects/choices"));
|
|
16
|
+
const inquirer_autocomplete_prompt_1 = __importDefault(require("inquirer-autocomplete-prompt"));
|
|
17
|
+
const fuzzy_1 = __importDefault(require("fuzzy"));
|
|
18
|
+
const fs_1 = require("../../util_modules/fs");
|
|
19
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
20
|
+
function getPaths(rootPath, pattern, exclude, defaultItem) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const nodeList = yield fs_1.ASYNC.walk(rootPath, { exclude, excludeDir: false });
|
|
23
|
+
const filteredNodes = fuzzy_1.default.filter(pattern || '', nodeList).map((e) => e.string);
|
|
24
|
+
if (!pattern && defaultItem) {
|
|
25
|
+
filteredNodes.unshift(defaultItem);
|
|
26
|
+
}
|
|
27
|
+
return filteredNodes;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
class InquirerFilePath extends inquirer_autocomplete_prompt_1.default {
|
|
31
|
+
constructor(question, rl, answers) {
|
|
32
|
+
const { rootPath = '.', exclude = [] } = question;
|
|
33
|
+
const questionBase = Object.assign({
|
|
34
|
+
emptyText: 'No valid file inside current directory!. Try giving the entire path and press ' +
|
|
35
|
+
ansi_colors_1.cyan('<return> ') +
|
|
36
|
+
'key'
|
|
37
|
+
}, question, {
|
|
38
|
+
source: (_, pattern) => getPaths(rootPath, pattern, exclude, question.default)
|
|
39
|
+
});
|
|
40
|
+
super(questionBase, rl, answers);
|
|
41
|
+
}
|
|
42
|
+
search(searchTerm) {
|
|
43
|
+
const _super = Object.create(null, {
|
|
44
|
+
search: { get: () => super.search }
|
|
45
|
+
});
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
yield _super.search.call(this, searchTerm);
|
|
48
|
+
this.currentChoices.getChoice = (choiceIndex) => {
|
|
49
|
+
const choice = choices_1.default.prototype.getChoice.call(this.currentChoices, choiceIndex);
|
|
50
|
+
return {
|
|
51
|
+
value: choice === null || choice === void 0 ? void 0 : choice.value,
|
|
52
|
+
name: choice === null || choice === void 0 ? void 0 : choice.name,
|
|
53
|
+
short: choice === null || choice === void 0 ? void 0 : choice.short
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
onSubmitAfterValidation(line) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const choice = this.currentChoices.getChoice(this.selected);
|
|
61
|
+
const value = (choice === null || choice === void 0 ? void 0 : choice.value) || line;
|
|
62
|
+
this.answerName = (choice === null || choice === void 0 ? void 0 : choice.name) || line;
|
|
63
|
+
this.shortAnswer = (choice === null || choice === void 0 ? void 0 : choice.short) || line;
|
|
64
|
+
this.answer = this.opt.filter ? this.opt.filter(value, this.answers) : value;
|
|
65
|
+
choice.value = this.answer;
|
|
66
|
+
this.status = 'answered';
|
|
67
|
+
this.render(undefined);
|
|
68
|
+
this.screen.done();
|
|
69
|
+
if (this.done) {
|
|
70
|
+
this.done(choice.value);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
checkValidationResult(validationResult, lineOrRl) {
|
|
75
|
+
if (validationResult !== true) {
|
|
76
|
+
this.render(validationResult || 'try giving valid complete path..');
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.onSubmitAfterValidation(lineOrRl);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
onSubmit(line) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const lineOrRl = line || this.rl.line;
|
|
85
|
+
if (typeof this.opt.validate !== 'function') {
|
|
86
|
+
return this.onSubmitAfterValidation(lineOrRl);
|
|
87
|
+
}
|
|
88
|
+
const choice = this.currentChoices.getChoice(this.selected);
|
|
89
|
+
choice.value = choice.value ? choice.value : lineOrRl;
|
|
90
|
+
const validationResult = yield this.opt.validate(choice, this.answers);
|
|
91
|
+
this.checkValidationResult(validationResult, lineOrRl);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.default = InquirerFilePath;
|
|
@@ -59,7 +59,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
59
59
|
choices
|
|
60
60
|
}));
|
|
61
61
|
const clientZip = (yield webappAPI.download(historyAns.history));
|
|
62
|
-
yield new archiver_1.default().load(clientZip).extract(
|
|
62
|
+
yield new archiver_1.default().load(clientZip).extract(clientDirPath).finalize();
|
|
63
63
|
yield client_utils_1.clientUtils.validate();
|
|
64
64
|
runtime_store_1.default.set('payload.client', runtime_store_1.default.get('context.client'));
|
|
65
65
|
runtime_store_1.default.set('payload.client.source', project_1.resolveProjectPath(clientDirName));
|