zcatalyst-cli 1.15.0-beta.4 → 1.15.0-beta.6
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/lib/archiver.js +8 -3
- package/lib/client-utils.js +5 -1
- package/lib/commands/iac/pack.js +9 -8
- package/lib/deploy/features/appsail/index.js +15 -5
- package/lib/deploy/features/client.js +1 -1
- package/lib/deploy/features/functions/index.js +7 -4
- package/lib/endpoints/lib/applogic.js +14 -2
- package/lib/endpoints/lib/appsail.js +11 -2
- package/lib/endpoints/lib/client.js +11 -2
- package/lib/endpoints/lib/functions.js +14 -2
- package/lib/endpoints/lib/sdk.js +8 -5
- package/lib/express_middlewares/logger.js +6 -2
- package/lib/fn-utils/lib/common.js +78 -48
- package/lib/fn-utils/lib/integ.js +23 -13
- package/lib/fn-utils/lib/java.js +28 -29
- package/lib/fn-utils/lib/node.js +17 -1
- package/lib/fn-utils/lib/python.js +1 -1
- package/lib/init/features/appsail/index.js +2 -2
- package/lib/init/features/functions/index.js +10 -4
- package/lib/init/features/functions/languages/java.js +2 -17
- package/lib/init/features/functions/languages/node.js +2 -17
- package/lib/init/features/project.js +1 -1
- package/lib/internal/api.js +33 -8
- package/lib/option-filter.js +4 -4
- package/lib/port-resolver.js +24 -11
- package/lib/progress.js +3 -2
- package/lib/prompt/types/file-path.js +3 -1
- package/lib/serve/features/appsail.js +14 -3
- package/lib/serve/features/index.js +1 -1
- package/lib/serve/index.js +7 -2
- package/lib/serve/server/index.js +252 -92
- package/lib/serve/server/lib/appsail/index.js +19 -9
- package/lib/serve/server/lib/appsail/start.js +4 -15
- package/lib/serve/server/lib/master.js +10 -10
- package/lib/serve/server/lib/web_client/index.js +5 -5
- package/lib/shell/dependencies/http-functions.js +11 -15
- package/lib/shell/prepare/languages/java.js +9 -4
- package/lib/util_modules/constants/lib/default.js +4 -1
- package/lib/util_modules/constants/lib/integ.js +4 -2
- package/lib/util_modules/constants/lib/scopes.js +1 -0
- package/lib/util_modules/constants/lib/template.js +23 -20
- package/lib/util_modules/fs/lib/async.js +10 -9
- package/lib/util_modules/fs/lib/sync.js +5 -1
- package/package.json +1 -1
- package/templates/init/functions/java/aio/sample.java +14 -4
- package/templates/init/functions/java/integ/convokraft/.classpath +6 -0
- package/templates/init/functions/java/integ/convokraft/.project +17 -0
- package/templates/init/functions/java/integ/convokraft/ExecuteHandler.java +20 -0
- package/templates/init/functions/java/integ/convokraft/FailureHandler.java +20 -0
- package/templates/init/functions/java/integ/convokraft/FallbackHandler.java +13 -0
- package/templates/init/functions/java/integ/convokraft/PromptHandler.java +17 -0
- package/templates/init/functions/java/integ/convokraft/Sample.java +62 -0
- package/templates/init/functions/java/integ/convokraft/WelcomeHandler.java +22 -0
- package/templates/init/functions/java/integ/convokraft/catalyst-config.json +12 -0
- package/templates/init/functions/node/integ/convokraft/catalyst-config.json +12 -0
- package/templates/init/functions/node/integ/convokraft/execute.js +16 -0
- package/templates/init/functions/node/integ/convokraft/failure.js +10 -0
- package/templates/init/functions/node/integ/convokraft/fallback.js +11 -0
- package/templates/init/functions/node/integ/convokraft/integ-response.js +13 -0
- package/templates/init/functions/node/integ/convokraft/logger.js +9 -0
- package/templates/init/functions/node/integ/convokraft/package.json +10 -0
- package/templates/init/functions/node/integ/convokraft/prompt.js +19 -0
- package/templates/init/functions/node/integ/convokraft/sample.js +46 -0
- package/templates/init/functions/node/integ/convokraft/welcome.js +12 -0
- package/templates/init/functions/python/integ/cliq/catalyst-config.json +2 -1
- package/templates/init/functions/python/integ/convokraft/catalyst-config.json +12 -0
- package/templates/init/functions/python/integ/convokraft/execute_handler.py +17 -0
- package/templates/init/functions/python/integ/convokraft/failure_handler.py +15 -0
- package/templates/init/functions/python/integ/convokraft/fallback_handler.py +16 -0
- package/templates/init/functions/python/integ/convokraft/prompt_handler.py +18 -0
- package/templates/init/functions/python/integ/convokraft/requirements.txt +1 -0
- package/templates/init/functions/python/integ/convokraft/sample.py +36 -0
- package/templates/init/functions/python/integ/convokraft/welcome_handler.py +19 -0
package/lib/fn-utils/lib/java.js
CHANGED
|
@@ -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.validate = exports.projectFileValidation = exports.ensureJavaInvoker = exports.compileTarget = exports.normaliseClasspath = exports.rewriteClasspath = exports.isValidClassName = exports.containsKeyWord = exports.classPathSep = void 0;
|
|
15
|
+
exports.getTemplatePath = exports.validate = exports.projectFileValidation = exports.ensureJavaInvoker = exports.compileTarget = exports.normaliseClasspath = exports.rewriteClasspath = exports.isValidClassName = exports.containsKeyWord = exports.classPathSep = void 0;
|
|
16
16
|
const ansi_colors_1 = require("ansi-colors");
|
|
17
17
|
const path_1 = require("path");
|
|
18
18
|
const semver_1 = require("semver");
|
|
@@ -120,14 +120,14 @@ function rewriteClasspath(pth, libPth) {
|
|
|
120
120
|
});
|
|
121
121
|
const result = yield xml2js_1.default.parseStringPromise(content);
|
|
122
122
|
const classPathEntries = js_1.JS.chain(files)
|
|
123
|
-
.filter((
|
|
124
|
-
.map((
|
|
123
|
+
.filter((jar) => (0, path_1.extname)(jar.path) === '.jar')
|
|
124
|
+
.map((jar) => {
|
|
125
125
|
return {
|
|
126
126
|
$: {
|
|
127
127
|
kind: 'lib',
|
|
128
|
-
path: (0, path_1.basename)((0, path_1.dirname)(
|
|
129
|
-
? 'lib/' + (0, path_1.basename)(
|
|
130
|
-
: (0, path_1.basename)(
|
|
128
|
+
path: (0, path_1.basename)((0, path_1.dirname)(jar.path)) === 'lib'
|
|
129
|
+
? 'lib/' + (0, path_1.basename)(jar.path)
|
|
130
|
+
: (0, path_1.basename)(jar.path)
|
|
131
131
|
}
|
|
132
132
|
};
|
|
133
133
|
})
|
|
@@ -203,9 +203,10 @@ function compileTarget(target) {
|
|
|
203
203
|
if (integ && integ.length > 0) {
|
|
204
204
|
integ.forEach((integConf) => {
|
|
205
205
|
const handlers = integConf.handlers;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
handlers &&
|
|
207
|
+
Object.keys(handlers).forEach((handler) => {
|
|
208
|
+
entries.push((0, path_1.join)(targetSource, handlers[handler].replace(/\./g, path_1.sep) + '.java'));
|
|
209
|
+
});
|
|
209
210
|
});
|
|
210
211
|
}
|
|
211
212
|
yield fs_1.ASYNC.ensureDir(outputFolder);
|
|
@@ -214,14 +215,14 @@ function compileTarget(target) {
|
|
|
214
215
|
const allFiles = yield fs_1.ASYNC.walk(targetSource, {
|
|
215
216
|
filter: { exclude: ['**/.output', ...ignore], excludeDir: true }
|
|
216
217
|
});
|
|
217
|
-
const cleanUpFiles =
|
|
218
|
+
const cleanUpFiles = allFiles.map((file) => file.path);
|
|
218
219
|
while (allFiles.length > 0) {
|
|
219
220
|
const limit = allFiles.length < 20 ? allFiles.length : 20;
|
|
220
221
|
yield Promise.all(allFiles.splice(0, limit).map((file) => {
|
|
221
|
-
const targetPth = file.includes(path_1.sep + 'lib' + path_1.sep)
|
|
222
|
-
? file.replace(targetSource + path_1.sep + 'lib', '')
|
|
223
|
-
: file.replace(targetSource, '');
|
|
224
|
-
return fs_1.ASYNC.copyFile(file, (0, path_1.join)(outputFolder, targetPth));
|
|
222
|
+
const targetPth = file.path.includes(path_1.sep + 'lib' + path_1.sep)
|
|
223
|
+
? file.path.replace(targetSource + path_1.sep + 'lib', '')
|
|
224
|
+
: file.path.replace(targetSource, '');
|
|
225
|
+
return fs_1.ASYNC.copyFile(file.path, (0, path_1.join)(outputFolder, targetPth));
|
|
225
226
|
}));
|
|
226
227
|
}
|
|
227
228
|
yield Promise.all(entries.map((file) => {
|
|
@@ -274,10 +275,11 @@ function ensureJavaInvoker(pth, invoker) {
|
|
|
274
275
|
}
|
|
275
276
|
exports.ensureJavaInvoker = ensureJavaInvoker;
|
|
276
277
|
function projectFileValidation(pth, target) {
|
|
278
|
+
var _a, _b;
|
|
277
279
|
return __awaiter(this, void 0, void 0, function* () {
|
|
278
280
|
const fileExists = yield fs_1.ASYNC.fileExists(pth);
|
|
279
281
|
if (!fileExists) {
|
|
280
|
-
const templatePath = getTemplatePath(target);
|
|
282
|
+
const templatePath = getTemplatePath(target.type, (_b = (_a = target.integ_config) === null || _a === void 0 ? void 0 : _a.at(0)) === null || _b === void 0 ? void 0 : _b.service);
|
|
281
283
|
yield fs_1.ASYNC.copyFile((0, path_1.join)(templatePath, constants_1.FILENAME.functions.java_project), (0, path_1.join)(target.source, constants_1.FILENAME.functions.java_project));
|
|
282
284
|
yield fs_1.ASYNC.findAndReplace(pth)(constants_1.PLACEHOLDER.functions.java_name, target.name);
|
|
283
285
|
}
|
|
@@ -369,7 +371,7 @@ function validate(targets, idx) {
|
|
|
369
371
|
});
|
|
370
372
|
}
|
|
371
373
|
if (!classPathExists) {
|
|
372
|
-
const templatePath = getTemplatePath(currentTarget);
|
|
374
|
+
const templatePath = getTemplatePath(currentTarget.type);
|
|
373
375
|
yield fs_1.ASYNC.copyFile((0, path_1.join)(templatePath, constants_1.FILENAME.functions.java_classpath), (0, path_1.join)(targetSource, constants_1.FILENAME.functions.java_classpath));
|
|
374
376
|
yield rewriteClasspath(classpath, libFolder);
|
|
375
377
|
}
|
|
@@ -429,23 +431,20 @@ function cleanUp(files) {
|
|
|
429
431
|
return Promise.all([...deleteArr.map((file) => fs_1.ASYNC.deleteFile(file)), ...promiseArr]);
|
|
430
432
|
});
|
|
431
433
|
}
|
|
432
|
-
function getTemplatePath(
|
|
433
|
-
|
|
434
|
-
|
|
434
|
+
function getTemplatePath(fnType, add) {
|
|
435
|
+
switch (fnType) {
|
|
436
|
+
case constants_1.FN_TYPE.browserLogic:
|
|
437
|
+
return constants_1.TEMPLATE.functions.java.browserlogic.selenium;
|
|
435
438
|
case constants_1.FN_TYPE.integration: {
|
|
436
|
-
if (!
|
|
437
|
-
throw new error_1.default('Invalid
|
|
439
|
+
if (!add) {
|
|
440
|
+
throw new error_1.default('Invalid additional parameter', { exit: 2 });
|
|
438
441
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
case constants_1.FN_TYPE.browserLogic: {
|
|
442
|
-
return constants_1.TEMPLATE.functions.java.browserlogic.selenium;
|
|
442
|
+
const temp = constants_1.TEMPLATE.functions.java[fnType];
|
|
443
|
+
return temp[add];
|
|
443
444
|
}
|
|
444
445
|
default: {
|
|
445
|
-
|
|
446
|
-
throw new error_1.default('Invalid target type', { exit: 2 });
|
|
447
|
-
}
|
|
448
|
-
return constants_1.TEMPLATE.functions.java[targetType];
|
|
446
|
+
return constants_1.TEMPLATE.functions.java[fnType];
|
|
449
447
|
}
|
|
450
448
|
}
|
|
451
449
|
}
|
|
450
|
+
exports.getTemplatePath = getTemplatePath;
|
package/lib/fn-utils/lib/node.js
CHANGED
|
@@ -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.validate = void 0;
|
|
15
|
+
exports.getTemplatePath = exports.validate = void 0;
|
|
16
16
|
const ansi_colors_1 = require("ansi-colors");
|
|
17
17
|
const path_1 = require("path");
|
|
18
18
|
const error_1 = __importDefault(require("../../error"));
|
|
@@ -64,3 +64,19 @@ function validate(targets, idx) {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
exports.validate = validate;
|
|
67
|
+
function getTemplatePath(fnType, add) {
|
|
68
|
+
switch (fnType) {
|
|
69
|
+
case constants_1.FN_TYPE.browserLogic:
|
|
70
|
+
case constants_1.FN_TYPE.integration: {
|
|
71
|
+
if (!add) {
|
|
72
|
+
throw new error_1.default('Invalid additional parameter', { exit: 2 });
|
|
73
|
+
}
|
|
74
|
+
const fnTemplate = constants_1.TEMPLATE.functions.node[fnType];
|
|
75
|
+
return fnTemplate[add];
|
|
76
|
+
}
|
|
77
|
+
default: {
|
|
78
|
+
return constants_1.TEMPLATE.functions.node[fnType];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.getTemplatePath = getTemplatePath;
|
|
@@ -114,7 +114,7 @@ function removeRequirements(reqFile, target) {
|
|
|
114
114
|
yield (0, pip_install_1.installRequirements)(reqFile, tmpDir, (_a = target.stack) === null || _a === void 0 ? void 0 : _a.replace('python_', ''), true);
|
|
115
115
|
const files = yield fs_1.ASYNC.walk(tmpDir, { depth: 1, includeDirPaths: true });
|
|
116
116
|
yield Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
yield fs_1.ASYNC.deleteFile((0, path_1.join)(target.source, path_1.default.basename(file)));
|
|
117
|
+
yield fs_1.ASYNC.deleteFile((0, path_1.join)(target.source, path_1.default.basename(file.path)));
|
|
118
118
|
})));
|
|
119
119
|
});
|
|
120
120
|
}
|
|
@@ -79,8 +79,8 @@ function getAppSailZip() {
|
|
|
79
79
|
lang: 'python'
|
|
80
80
|
},
|
|
81
81
|
scripts: {
|
|
82
|
-
preserve: 'python3 -m pip install -r ./requirements.txt -t ./',
|
|
83
|
-
predeploy: 'python3 -m pip install -r ./requirements.txt -t ./'
|
|
82
|
+
preserve: 'python3 -m pip install -r ./requirements.txt -t ./ --upgrade',
|
|
83
|
+
predeploy: 'python3 -m pip install -r ./requirements.txt -t ./ --upgrade'
|
|
84
84
|
},
|
|
85
85
|
memory: 256
|
|
86
86
|
},
|
|
@@ -13,7 +13,6 @@ 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 dc_1 = require("../../../dc");
|
|
17
16
|
const integ_1 = require("../../../fn-utils/lib/integ");
|
|
18
17
|
const prompt_1 = __importDefault(require("../../../prompt"));
|
|
19
18
|
const runtime_store_1 = __importDefault(require("../../../runtime-store"));
|
|
@@ -24,10 +23,15 @@ const option_1 = require("../../../util_modules/option");
|
|
|
24
23
|
const project_1 = require("../../../util_modules/project");
|
|
25
24
|
const common_1 = require("../../util/common");
|
|
26
25
|
const languages_1 = __importDefault(require("./languages"));
|
|
26
|
+
const catalyst_details_1 = __importDefault(require("../../../endpoints/lib/catalyst-details"));
|
|
27
27
|
exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
28
|
const currentCmd = (0, option_1.getCurrentCommand)();
|
|
29
29
|
const config = runtime_store_1.default.get('config');
|
|
30
30
|
const functionsDirPath = (0, project_1.resolveProjectPath)(config.get('functions.source') || constants_1.FOLDERNAME.functions);
|
|
31
|
+
const catalystDetailsAPI = new catalyst_details_1.default();
|
|
32
|
+
const integServicesPromise = catalystDetailsAPI
|
|
33
|
+
.getDetails('integration_services')
|
|
34
|
+
.catch((err) => (0, logger_1.debug)('Error feting integ services: ', err));
|
|
31
35
|
runtime_store_1.default.set('context.functions.dir_path', functionsDirPath);
|
|
32
36
|
if (currentCmd === 'init' || currentCmd === 'functions:setup') {
|
|
33
37
|
(0, logger_1.message)('A directory ' +
|
|
@@ -70,7 +74,9 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
70
74
|
short: 'browser logic'
|
|
71
75
|
})
|
|
72
76
|
];
|
|
73
|
-
|
|
77
|
+
const integServicesRes = yield integServicesPromise;
|
|
78
|
+
const integServices = integServicesRes === null || integServicesRes === void 0 ? void 0 : integServicesRes.integration_services;
|
|
79
|
+
if (integServices && integServices.length > 0) {
|
|
74
80
|
fnTypeChoices.push(prompt_1.default.choice('Integration', {
|
|
75
81
|
value: constants_1.FN_TYPE.integration,
|
|
76
82
|
short: 'integration'
|
|
@@ -81,8 +87,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
81
87
|
choices: fnTypeChoices
|
|
82
88
|
}));
|
|
83
89
|
runtime_store_1.default.set('context.functions.type', fnTypeAns.type);
|
|
84
|
-
if (fnTypeAns.type === constants_1.FN_TYPE.integration) {
|
|
85
|
-
yield (0, integ_1.integHelper)();
|
|
90
|
+
if (fnTypeAns.type === constants_1.FN_TYPE.integration && integServices) {
|
|
91
|
+
yield (0, integ_1.integHelper)(integServices);
|
|
86
92
|
}
|
|
87
93
|
const runtimeAns = yield (0, common_1.getRuntimePromptAnswer)('Which runtime do you prefer to write your function?', fnTypeAns.type);
|
|
88
94
|
return languages_1.default[runtimeAns.lang](runtimeAns.runtime)();
|
|
@@ -26,22 +26,7 @@ const runtime_1 = __importDefault(require("../../../../util_modules/constants/li
|
|
|
26
26
|
const functions_1 = require("../../../util/functions");
|
|
27
27
|
const browserLogic_1 = require("../../../../fn-utils/lib/browserLogic");
|
|
28
28
|
const browserLogic_2 = __importDefault(require("../../../../util_modules/constants/lib/browserLogic"));
|
|
29
|
-
const
|
|
30
|
-
function getTemplatePath(fnType, add) {
|
|
31
|
-
switch (fnType) {
|
|
32
|
-
case constants_1.FN_TYPE.browserLogic:
|
|
33
|
-
case constants_1.FN_TYPE.integration: {
|
|
34
|
-
if (!add) {
|
|
35
|
-
throw new error_1.default('Invalid additional parameter', { exit: 2 });
|
|
36
|
-
}
|
|
37
|
-
const temp = constants_1.TEMPLATE.functions.java[fnType];
|
|
38
|
-
return temp[add.toLowerCase()];
|
|
39
|
-
}
|
|
40
|
-
default: {
|
|
41
|
-
return constants_1.TEMPLATE.functions.java[fnType];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
29
|
+
const java_1 = require("../../../../fn-utils/lib/java");
|
|
45
30
|
exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
31
|
const fnType = runtime_store_1.default.get('context.functions.type');
|
|
47
32
|
const fnDirPath = (0, path_1.join)(runtime_store_1.default.get('context.functions.dir_path'));
|
|
@@ -81,7 +66,7 @@ exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
81
66
|
}
|
|
82
67
|
yield fs_1.ASYNC.deleteDir(targetPath).catch();
|
|
83
68
|
const service = runtime_store_1.default.get('context.functions.integration.service', '');
|
|
84
|
-
const templatePath = getTemplatePath(fnType, service || framework || '');
|
|
69
|
+
const templatePath = (0, java_1.getTemplatePath)(fnType, service || framework || '');
|
|
85
70
|
if (fnType === constants_1.FN_TYPE.integration) {
|
|
86
71
|
yield (0, integ_1.copyIntegHandlers)(templatePath, targetPath, runtime_1.default.language.java.value);
|
|
87
72
|
}
|
|
@@ -27,22 +27,7 @@ const runtime_1 = __importDefault(require("../../../../util_modules/constants/li
|
|
|
27
27
|
const functions_1 = require("../../../util/functions");
|
|
28
28
|
const browserLogic_1 = require("../../../../fn-utils/lib/browserLogic");
|
|
29
29
|
const browserLogic_2 = __importDefault(require("../../../../util_modules/constants/lib/browserLogic"));
|
|
30
|
-
const
|
|
31
|
-
function getTemplatePath(fnType, add) {
|
|
32
|
-
switch (fnType) {
|
|
33
|
-
case constants_1.FN_TYPE.browserLogic:
|
|
34
|
-
case constants_1.FN_TYPE.integration: {
|
|
35
|
-
if (!add) {
|
|
36
|
-
throw new error_1.default('Invalid additional parameter', { exit: 2 });
|
|
37
|
-
}
|
|
38
|
-
const fnTemplate = constants_1.TEMPLATE.functions.node[fnType];
|
|
39
|
-
return fnTemplate[add.toLowerCase()];
|
|
40
|
-
}
|
|
41
|
-
default: {
|
|
42
|
-
return constants_1.TEMPLATE.functions.node[fnType];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
30
|
+
const node_1 = require("../../../../fn-utils/lib/node");
|
|
46
31
|
exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
32
|
const fnType = runtime_store_1.default.get('context.functions.type');
|
|
48
33
|
const service = runtime_store_1.default.get('context.functions.integration.service', '');
|
|
@@ -50,7 +35,7 @@ exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
50
35
|
yield fs_1.ASYNC.ensureDir(functionsDirPath);
|
|
51
36
|
const framework = fnType === constants_1.FN_TYPE.browserLogic ? yield (0, browserLogic_1.getBrowserLogicFramework)('nodejs') : '';
|
|
52
37
|
const finalJson = Object.assign(Object.assign({}, (yield (0, package_json_1.default)(['name', 'main', 'author']))), { framework: framework.toLowerCase(), dependencies: JSON.stringify(browserLogic_2.default.nodejs[framework] || {}, null, '\t').replace(new RegExp('\n', 'g'), '\n\t'), stack });
|
|
53
|
-
const templatePath = getTemplatePath(fnType, service || framework || '');
|
|
38
|
+
const templatePath = (0, node_1.getTemplatePath)(fnType, service || framework || '');
|
|
54
39
|
const targetPath = (0, path_1.join)(functionsDirPath, finalJson.name);
|
|
55
40
|
const dirExists = yield fs_1.ASYNC.dirExists(targetPath);
|
|
56
41
|
const overwriteAns = dirExists
|
|
@@ -68,7 +68,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
68
68
|
const orgAns = yield prompt_1.default.ask(prompt_1.default.question('org', 'Select a default Catalyst portal for this directory: ', {
|
|
69
69
|
type: 'list',
|
|
70
70
|
choices: js_1.JS.reverse(orgChoice),
|
|
71
|
-
when: orgChoice.length >
|
|
71
|
+
when: orgChoice.length > 1
|
|
72
72
|
}));
|
|
73
73
|
const selectedOrg = orgAns.org || orgList[0];
|
|
74
74
|
(0, logger_1.message)('Setting up a new default project for this folder\n');
|
package/lib/internal/api.js
CHANGED
|
@@ -44,6 +44,8 @@ const constants_1 = require("../util_modules/constants");
|
|
|
44
44
|
const js_1 = require("../util_modules/js");
|
|
45
45
|
const logger_1 = require("../util_modules/logger");
|
|
46
46
|
const project_1 = require("../util_modules/project");
|
|
47
|
+
const fs_1 = require("fs");
|
|
48
|
+
const throbber_1 = __importDefault(require("../throbber"));
|
|
47
49
|
class API {
|
|
48
50
|
constructor({ authNeeded = true, resolveOnError = false, maxRetry = 3, env = constants_1.DEFAULT.env_name, log = {}, headers = {}, isExternal = false, origin = constants_1.ORIGIN.admin, showWarning = true, envId = (0, project_1.getEnvId)() } = {}) {
|
|
49
51
|
this.requestOpts = {
|
|
@@ -63,7 +65,6 @@ class API {
|
|
|
63
65
|
this.logOpts = log;
|
|
64
66
|
this.maxRetryCount = maxRetry;
|
|
65
67
|
this.retryCount = 0;
|
|
66
|
-
this.progress = null;
|
|
67
68
|
this.showWarning = showWarning;
|
|
68
69
|
}
|
|
69
70
|
_logReq() {
|
|
@@ -100,12 +101,21 @@ class API {
|
|
|
100
101
|
}
|
|
101
102
|
if (this.logOpts.progress !== undefined) {
|
|
102
103
|
js_1.JS.set(this.logOpts, 'progress.total', resp.headers['content-length']);
|
|
103
|
-
this.
|
|
104
|
+
this.downloadProgress = new progress_1.default(this.logOpts.progress);
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
|
-
|
|
107
|
-
if (this.
|
|
108
|
-
!chunk || error
|
|
107
|
+
_logUploadProgress({ chunk, error } = {}) {
|
|
108
|
+
if (this.uploadProgress) {
|
|
109
|
+
!chunk || error
|
|
110
|
+
? this.uploadProgress.error(error)
|
|
111
|
+
: this.uploadProgress.tick(chunk.length);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
_logDownloadProgress({ chunk, error } = {}) {
|
|
115
|
+
if (this.downloadProgress) {
|
|
116
|
+
!chunk || error
|
|
117
|
+
? this.downloadProgress.error(error)
|
|
118
|
+
: this.downloadProgress.tick(chunk.length);
|
|
109
119
|
}
|
|
110
120
|
}
|
|
111
121
|
_addAuthHeader() {
|
|
@@ -130,10 +140,10 @@ class API {
|
|
|
130
140
|
(0, logger_1.debug)('Response Body : ' + JSON.stringify(resp.body) + '\n');
|
|
131
141
|
if (!this.resolveOnHTTPError) {
|
|
132
142
|
const errRes = (0, errorResponse_1.default)(resp, body);
|
|
133
|
-
this.
|
|
143
|
+
this._logDownloadProgress({ error: errRes });
|
|
134
144
|
throw errRes;
|
|
135
145
|
}
|
|
136
|
-
this.
|
|
146
|
+
this._logDownloadProgress({ error: (0, errorResponse_1.default)(resp, body, true) });
|
|
137
147
|
}
|
|
138
148
|
return {
|
|
139
149
|
status: resp.statusCode,
|
|
@@ -164,7 +174,22 @@ class API {
|
|
|
164
174
|
return new Promise((resolve, reject) => {
|
|
165
175
|
const responseBuffer = [];
|
|
166
176
|
let isJSONResponse = false;
|
|
177
|
+
const throbber = throbber_1.default.getInstance();
|
|
178
|
+
if (this.logOpts.uploadProgress !== undefined &&
|
|
179
|
+
this.logOpts.stream instanceof fs_1.ReadStream) {
|
|
180
|
+
const _stream = this.logOpts.stream;
|
|
181
|
+
this.uploadProgress = new progress_1.default(this.logOpts.uploadProgress);
|
|
182
|
+
_stream.on('data', (chunk) => {
|
|
183
|
+
this._logUploadProgress({ chunk });
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (this.logOpts.awaitingSpinner) {
|
|
187
|
+
this.logOpts.stream
|
|
188
|
+
? this.logOpts.stream.on('end', () => throbber.add('response_await', { text: this.logOpts.awaitingSpinner }))
|
|
189
|
+
: throbber.add('response_await', { text: this.logOpts.awaitingSpinner });
|
|
190
|
+
}
|
|
167
191
|
(0, request_1.default)(this.requestOpts, (err) => __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
this.logOpts.awaitingSpinner && throbber.remove('response_await');
|
|
168
193
|
if (err) {
|
|
169
194
|
switch (err.code) {
|
|
170
195
|
case 'ETIMEDOUT':
|
|
@@ -205,7 +230,7 @@ class API {
|
|
|
205
230
|
if (isJSONResponse) {
|
|
206
231
|
responseBuffer.push(data);
|
|
207
232
|
}
|
|
208
|
-
this.
|
|
233
|
+
this._logDownloadProgress({ chunk: data });
|
|
209
234
|
});
|
|
210
235
|
});
|
|
211
236
|
});
|
package/lib/option-filter.js
CHANGED
|
@@ -141,7 +141,7 @@ function validateTargets() {
|
|
|
141
141
|
return [];
|
|
142
142
|
}
|
|
143
143
|
function validatePorts() {
|
|
144
|
-
const customHttpPort =
|
|
144
|
+
const customHttpPort = (0, option_1.getOptionValue)('http', undefined);
|
|
145
145
|
const enrichedDebugOpts = enrichOptsData('debug', (0, option_1.getOptionValue)('debug'), portTargets);
|
|
146
146
|
if (enrichedDebugOpts.some((opt) => {
|
|
147
147
|
const noFilter = !opt.hasFilter;
|
|
@@ -185,11 +185,11 @@ function filterPorts() {
|
|
|
185
185
|
]
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
|
-
else if (res.target.target === constants_1.REMOTE_REF.functions.type
|
|
189
|
-
runtime_store_1.default.set(`context.port.debug.${
|
|
188
|
+
else if (res.target.target === constants_1.REMOTE_REF.functions.type.bio) {
|
|
189
|
+
runtime_store_1.default.set(`context.port.debug.${constants_1.REMOTE_REF.functions.type.bio}`, res.filter);
|
|
190
190
|
}
|
|
191
191
|
else {
|
|
192
|
-
runtime_store_1.default.set(`context.port.debug.${res.target}.${res.filter}`, res.specific);
|
|
192
|
+
runtime_store_1.default.set(`context.port.debug.${res.target.target}.${res.filter}`, res.specific);
|
|
193
193
|
}
|
|
194
194
|
});
|
|
195
195
|
}
|
package/lib/port-resolver.js
CHANGED
|
@@ -8,9 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
14
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
+
};
|
|
11
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
18
|
};
|
|
19
|
+
var _a, _PortResolver_takenPorts, _PortResolver_isPortTaken;
|
|
14
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
21
|
const ansi_colors_1 = require("ansi-colors");
|
|
16
22
|
const portfinder_1 = require("portfinder");
|
|
@@ -19,9 +25,6 @@ const runtime_store_1 = __importDefault(require("./runtime-store"));
|
|
|
19
25
|
const constants_1 = require("./util_modules/constants");
|
|
20
26
|
const logger_1 = require("./util_modules/logger");
|
|
21
27
|
class PortResolver {
|
|
22
|
-
static isPortTaken(port) {
|
|
23
|
-
return PortResolver.takenPorts.includes(port);
|
|
24
|
-
}
|
|
25
28
|
static getFreePort(startPort, searchSpan, dupCheck) {
|
|
26
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
30
|
if (searchSpan < 0) {
|
|
@@ -31,20 +34,19 @@ class PortResolver {
|
|
|
31
34
|
port: startPort,
|
|
32
35
|
stopPort: startPort + searchSpan
|
|
33
36
|
});
|
|
34
|
-
if (PortResolver.
|
|
37
|
+
if (__classPrivateFieldGet(PortResolver, _a, "m", _PortResolver_isPortTaken).call(PortResolver, port)) {
|
|
35
38
|
if (dupCheck) {
|
|
36
39
|
return PortResolver.getFreePort(port + 1, searchSpan - (port - startPort), dupCheck);
|
|
37
40
|
}
|
|
38
41
|
return port;
|
|
39
42
|
}
|
|
40
|
-
PortResolver.
|
|
43
|
+
__classPrivateFieldGet(PortResolver, _a, "f", _PortResolver_takenPorts).add(port);
|
|
41
44
|
return port;
|
|
42
45
|
});
|
|
43
46
|
}
|
|
44
|
-
static getPort(feature, type, name = '', duplicateCheck = true,
|
|
47
|
+
static getPort(feature, type, { name = '', duplicateCheck = true, searchSpan = 20, fallbackNeeded = true, server } = {}) {
|
|
45
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
49
|
let port = parseInt(runtime_store_1.default.get(`context.port.${type}.${feature}.${name}`), 10);
|
|
47
|
-
feature = pythonBio ? 'advancedio' : feature;
|
|
48
50
|
port = isNaN(port) ? parseInt(runtime_store_1.default.get(`context.port.${type}.${feature}`), 10) : port;
|
|
49
51
|
if (isNaN(port)) {
|
|
50
52
|
if (type === 'debug' && feature === 'client') {
|
|
@@ -53,7 +55,15 @@ class PortResolver {
|
|
|
53
55
|
if (!fallbackNeeded) {
|
|
54
56
|
return -1;
|
|
55
57
|
}
|
|
56
|
-
|
|
58
|
+
if (feature === 'appsail') {
|
|
59
|
+
if (!server || type !== 'http') {
|
|
60
|
+
throw new error_1.default('Invalid appsail details', { exit: 2 });
|
|
61
|
+
}
|
|
62
|
+
port = constants_1.DEFAULT.serve_port['http']['appsail'][server];
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
port = constants_1.DEFAULT.serve_port[type][feature];
|
|
66
|
+
}
|
|
57
67
|
}
|
|
58
68
|
else {
|
|
59
69
|
searchSpan = 0;
|
|
@@ -65,7 +75,7 @@ class PortResolver {
|
|
|
65
75
|
}
|
|
66
76
|
let finalPort = port;
|
|
67
77
|
try {
|
|
68
|
-
finalPort = yield PortResolver.getFreePort(port, searchSpan, duplicateCheck
|
|
78
|
+
finalPort = yield PortResolver.getFreePort(port, searchSpan, duplicateCheck);
|
|
69
79
|
}
|
|
70
80
|
catch (e) {
|
|
71
81
|
if (searchSpan === 0) {
|
|
@@ -86,7 +96,7 @@ class PortResolver {
|
|
|
86
96
|
}
|
|
87
97
|
const cerr = error_1.default.getErrorInstance(e, {
|
|
88
98
|
message: `No ports from '${port}' to ${port + searchSpan} is free to use as a ${type} port.`,
|
|
89
|
-
skipHelp: false,
|
|
99
|
+
skipHelp: server ? true : false,
|
|
90
100
|
fileName: __filename
|
|
91
101
|
});
|
|
92
102
|
cerr.errorId = 'PORT-RESOLVER-2';
|
|
@@ -101,4 +111,7 @@ class PortResolver {
|
|
|
101
111
|
}
|
|
102
112
|
}
|
|
103
113
|
exports.default = PortResolver;
|
|
104
|
-
PortResolver
|
|
114
|
+
_a = PortResolver, _PortResolver_isPortTaken = function _PortResolver_isPortTaken(port) {
|
|
115
|
+
return __classPrivateFieldGet(PortResolver, _a, "f", _PortResolver_takenPorts).has(port);
|
|
116
|
+
};
|
|
117
|
+
_PortResolver_takenPorts = { value: new Set() };
|
package/lib/progress.js
CHANGED
|
@@ -7,7 +7,7 @@ const ansi_colors_1 = require("ansi-colors");
|
|
|
7
7
|
const pretty_ms_1 = __importDefault(require("pretty-ms"));
|
|
8
8
|
const throbber_1 = __importDefault(require("./throbber"));
|
|
9
9
|
class Progress {
|
|
10
|
-
constructor({ title = '', fillChar = '·', bgChar = ' ', startingChar = '[', endingChar = ']', total = 10, failure } = {}) {
|
|
10
|
+
constructor({ title = '', fillChar = '·', bgChar = ' ', startingChar = '[', endingChar = ']', total = 10, failure, progressType = 'download' } = {}) {
|
|
11
11
|
this.title = title;
|
|
12
12
|
this.fillChar = fillChar;
|
|
13
13
|
this.bgChar = bgChar;
|
|
@@ -19,6 +19,7 @@ class Progress {
|
|
|
19
19
|
this.currentProgress = 0;
|
|
20
20
|
this.currentProgressFrame = '';
|
|
21
21
|
this.failure = failure;
|
|
22
|
+
this.progressType = progressType;
|
|
22
23
|
}
|
|
23
24
|
get MAX_SCREEN_LENGTH() {
|
|
24
25
|
return 35;
|
|
@@ -57,7 +58,7 @@ class Progress {
|
|
|
57
58
|
if (this.throbber.hasActiveSpinners()) {
|
|
58
59
|
const [totalSec] = process.hrtime(this.startTime);
|
|
59
60
|
this.throbber.succeed(this.title, {
|
|
60
|
-
text: `${this.title}
|
|
61
|
+
text: `${this.title} ${this.progressType}ed in ${totalSec} seconds`
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
return;
|
|
@@ -23,7 +23,9 @@ function getPaths(rootPath, pattern, exclude, defaultItem) {
|
|
|
23
23
|
filter: { exclude, excludeDir: false },
|
|
24
24
|
includeDirPaths: true
|
|
25
25
|
});
|
|
26
|
-
const filteredNodes = fuzzy_1.default
|
|
26
|
+
const filteredNodes = fuzzy_1.default
|
|
27
|
+
.filter(pattern || '', nodeList, { extract: (node) => node.path })
|
|
28
|
+
.map((e) => e.string);
|
|
27
29
|
if (!pattern && defaultItem) {
|
|
28
30
|
filteredNodes.unshift(defaultItem);
|
|
29
31
|
}
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const appsail_utils_1 = require("../../appsail-utils");
|
|
16
|
+
const error_1 = __importDefault(require("../../error"));
|
|
16
17
|
const port_resolver_1 = __importDefault(require("../../port-resolver"));
|
|
17
18
|
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
18
19
|
const config_1 = require("../../util_modules/config");
|
|
@@ -26,12 +27,22 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
26
27
|
}
|
|
27
28
|
const validated = (0, appsail_utils_1.validateAppSail)(optionTargets);
|
|
28
29
|
const filledTargets = yield Promise.all(validated.map((targ) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
-
var _a;
|
|
30
|
+
var _a, _b;
|
|
30
31
|
if (!targ.validity.valid) {
|
|
31
32
|
return targ;
|
|
32
33
|
}
|
|
33
|
-
const
|
|
34
|
-
|
|
34
|
+
const proxyPort = yield port_resolver_1.default.getPort('appsail', 'http', {
|
|
35
|
+
name: ((_a = targ.appSail) === null || _a === void 0 ? void 0 : _a.name) + '_proxy',
|
|
36
|
+
searchSpan: 10,
|
|
37
|
+
server: 'master'
|
|
38
|
+
}).catch((err) => {
|
|
39
|
+
throw new error_1.default('No free ports between 3000 and 3010. AppSail needs the ports within this range to function properly', { original: err });
|
|
40
|
+
});
|
|
41
|
+
const appsailPort = yield port_resolver_1.default.getPort('appsail', 'http', {
|
|
42
|
+
name: ((_b = targ.appSail) === null || _b === void 0 ? void 0 : _b.name) + '_proxy',
|
|
43
|
+
server: 'service'
|
|
44
|
+
});
|
|
45
|
+
return Object.assign(Object.assign({}, targ), { port: { appsail: appsailPort, proxy: proxyPort } });
|
|
35
46
|
})));
|
|
36
47
|
runtime_store_1.default.set('context.appsail.targets', filledTargets);
|
|
37
48
|
});
|
|
@@ -55,7 +55,7 @@ function client() {
|
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
const clientName = runtime_store_1.default.get('context.client.name');
|
|
58
|
-
const finalPort = yield port_resolver_1.default.getPort('client', 'http', clientName);
|
|
58
|
+
const finalPort = yield port_resolver_1.default.getPort('client', 'http', { name: clientName });
|
|
59
59
|
runtime_store_1.default.set('context.port.http.client.' + clientName, finalPort);
|
|
60
60
|
});
|
|
61
61
|
}
|
package/lib/serve/index.js
CHANGED
|
@@ -59,7 +59,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
59
59
|
const buildFolder = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build);
|
|
60
60
|
if (yield fs_1.ASYNC.isPathExists(buildFolder)) {
|
|
61
61
|
try {
|
|
62
|
-
(0, logger_1.debug)('Build folder already exists,
|
|
62
|
+
(0, logger_1.debug)('Build folder already exists, starting cleanup');
|
|
63
63
|
yield fs_1.ASYNC.chmod((0, path_1.join)(buildFolder, constants_1.FOLDERNAME.functions), '755', {
|
|
64
64
|
recursive: true
|
|
65
65
|
});
|
|
@@ -75,7 +75,11 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
try {
|
|
78
|
-
const masterPort = yield port_resolver_1.default.getPort('master', 'http',
|
|
78
|
+
const masterPort = yield port_resolver_1.default.getPort('master', 'http', {
|
|
79
|
+
name: 'master',
|
|
80
|
+
duplicateCheck: false,
|
|
81
|
+
searchSpan: 10
|
|
82
|
+
});
|
|
79
83
|
runtime_store_1.default.set('context.port.http.master', masterPort);
|
|
80
84
|
yield Promise.all(serveTargets.map((target) => features[target]()));
|
|
81
85
|
const rawTargets = runtime_store_1.default.get('context.functions.targets', []);
|
|
@@ -165,6 +169,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
165
169
|
checkPath: false,
|
|
166
170
|
recursive: true
|
|
167
171
|
}).catch((err) => (0, logger_1.debug)('Error modifying the permissions: ', err)));
|
|
172
|
+
(0, logger_1.info)('Shutting down server');
|
|
168
173
|
yield Promise.all([
|
|
169
174
|
fs_1.ASYNC.deleteDir(buildFolder).catch(),
|
|
170
175
|
advancedServer ? advancedServer.stop() : undefined,
|