zcatalyst-cli 1.13.2 → 1.14.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.
Files changed (162) hide show
  1. package/docs/client-utils.toml +6 -1
  2. package/docs/commands/ds/import.toml +5 -0
  3. package/docs/fn-utils/lib/python.toml +4 -0
  4. package/docs/init/dependencies/python/ensure-python.toml +12 -0
  5. package/docs/init/dependencies/python/pip-install.toml +4 -0
  6. package/docs/serve/index.toml +5 -0
  7. package/lib/authentication/login.js +2 -1
  8. package/lib/cli_table/index.js +26 -2
  9. package/lib/cli_table/src/cell.js +359 -267
  10. package/lib/cli_table/src/layout-manager.js +231 -209
  11. package/lib/cli_table/src/table.js +76 -60
  12. package/lib/cli_table/src/utils.js +259 -224
  13. package/lib/client-utils.js +18 -4
  14. package/lib/command_needs/rc.js +57 -8
  15. package/lib/commands/config/delete.js +23 -0
  16. package/lib/commands/config/get.js +23 -0
  17. package/lib/commands/config/list.js +23 -0
  18. package/lib/commands/config/set.js +29 -0
  19. package/lib/commands/console/cache.js +31 -1
  20. package/lib/commands/console/queue.js +31 -1
  21. package/lib/commands/console/zcql.js +27 -1
  22. package/lib/commands/ds/export.js +2 -2
  23. package/lib/commands/ds/import.js +25 -5
  24. package/lib/commands/ds/status.js +2 -2
  25. package/lib/commands/iac/export.js +1 -1
  26. package/lib/commands/iac/import.js +1 -1
  27. package/lib/commands/iac/pack.js +16 -5
  28. package/lib/commands/iac/status.js +1 -1
  29. package/lib/commands/index.js +4 -0
  30. package/lib/commands/project/list.js +1 -1
  31. package/lib/commands/project/use.js +1 -1
  32. package/lib/deploy/features/client.js +2 -2
  33. package/lib/deploy/features/functions/index.js +13 -3
  34. package/lib/deploy/features/functions/languages/index.js +19 -2
  35. package/lib/endpoints/index.js +12 -5
  36. package/lib/endpoints/lib/env.js +5 -2
  37. package/lib/endpoints/lib/functions.js +30 -0
  38. package/lib/endpoints/lib/org.js +35 -0
  39. package/lib/endpoints/lib/project.js +7 -3
  40. package/lib/express_middlewares/unknownReqProxy.js +4 -1
  41. package/lib/fn-utils/index.js +2 -0
  42. package/lib/fn-utils/lib/common.js +68 -7
  43. package/lib/fn-utils/lib/integ.js +15 -11
  44. package/lib/fn-utils/lib/java.js +7 -3
  45. package/lib/fn-utils/lib/python.js +121 -0
  46. package/lib/fn-watcher.js +10 -2
  47. package/lib/index.js +2 -1
  48. package/lib/init/dependencies/python/ensure-python.js +151 -0
  49. package/lib/init/dependencies/python/pip-install.js +175 -0
  50. package/lib/init/features/functions/index.js +50 -29
  51. package/lib/init/features/functions/languages/index.js +3 -1
  52. package/lib/init/features/functions/languages/python.js +115 -0
  53. package/lib/init/features/index.js +2 -2
  54. package/lib/init/features/project.js +26 -6
  55. package/lib/init/util/project.js +2 -2
  56. package/lib/internal/api.js +2 -0
  57. package/lib/internal/command.js +1 -1
  58. package/lib/internal/rc.js +2 -0
  59. package/lib/port-resolver.js +4 -3
  60. package/lib/prompt/types/file-path.js +1 -1
  61. package/lib/pull/features/functions/index.js +35 -2
  62. package/lib/pull/features/functions/languages.js +8 -1
  63. package/lib/readLineUtils.js +37 -1
  64. package/lib/readline/features/cache.js +175 -1
  65. package/lib/readline/features/index.js +7 -1
  66. package/lib/readline/features/queue.js +209 -1
  67. package/lib/readline/features/zcql.js +237 -1
  68. package/lib/readline/index.js +30 -1
  69. package/lib/serve/index.js +48 -7
  70. package/lib/serve/server/index.js +118 -44
  71. package/lib/serve/server/lib/java/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  72. package/lib/serve/server/lib/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  73. package/lib/serve/server/lib/java/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  74. package/lib/serve/server/lib/master.js +18 -5
  75. package/lib/serve/server/lib/node.mjs +41 -0
  76. package/lib/serve/server/lib/web_client/index.js +7 -3
  77. package/lib/serve/server/lib/web_client/server.js +31 -15
  78. package/lib/shell/dependencies/http-functions.js +57 -21
  79. package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +1 -2
  80. package/lib/shell/dependencies/invoker/bio/node.mjs +127 -0
  81. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  82. package/lib/shell/dependencies/invoker/cron/node.mjs +87 -0
  83. package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +3 -3
  84. package/lib/shell/dependencies/invoker/event/node.mjs +84 -0
  85. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +1 -1
  86. package/lib/shell/dependencies/invoker/integ/node.mjs +88 -0
  87. package/lib/shell/dependencies/local-function.js +74 -22
  88. package/lib/shell/index.js +11 -2
  89. package/lib/shell/prepare/index.js +21 -0
  90. package/lib/shell/prepare/languages/index.js +8 -2
  91. package/lib/shell/prepare/languages/java.js +39 -2
  92. package/lib/shell/prepare/languages/node.js +21 -2
  93. package/lib/shell/prepare/languages/python.js +65 -0
  94. package/lib/throbber/index.js +3 -1
  95. package/lib/userConfig.js +48 -0
  96. package/lib/util_modules/constants/index.js +3 -1
  97. package/lib/util_modules/constants/lib/apig-rules.js +8 -0
  98. package/lib/util_modules/constants/lib/cliq-handlers.js +17 -1
  99. package/lib/util_modules/constants/lib/dc-type.js +8 -0
  100. package/lib/util_modules/constants/lib/default.js +2 -2
  101. package/lib/util_modules/constants/lib/env-path.js +12 -0
  102. package/lib/util_modules/constants/lib/file-names.js +4 -1
  103. package/lib/util_modules/constants/lib/folder-names.js +3 -1
  104. package/lib/util_modules/constants/lib/placeholders.js +6 -1
  105. package/lib/util_modules/constants/lib/runtime.js +2 -1
  106. package/lib/util_modules/constants/lib/scopes.js +1 -0
  107. package/lib/util_modules/constants/lib/template.js +9 -0
  108. package/lib/util_modules/constants/lib/urls.js +2 -6
  109. package/lib/util_modules/context-help.js +2 -0
  110. package/lib/util_modules/fs/lib/async.js +35 -11
  111. package/lib/util_modules/project.js +20 -1
  112. package/package.json +2 -1
  113. package/templates/init/functions/java/aio/catalyst-config.json +3 -2
  114. package/templates/init/functions/java/bio/catalyst-config.json +3 -2
  115. package/templates/init/functions/java/cron/catalyst-config.json +3 -2
  116. package/templates/init/functions/java/event/catalyst-config.json +3 -2
  117. package/templates/init/functions/java/integ/cliq/catalyst-config.json +1 -0
  118. package/templates/init/functions/node/aio/catalyst-config.json +3 -2
  119. package/templates/init/functions/node/bio/catalyst-config.json +3 -2
  120. package/templates/init/functions/node/cron/catalyst-config.json +3 -2
  121. package/templates/init/functions/node/event/catalyst-config.json +3 -2
  122. package/templates/init/functions/node/integ/cliq/catalyst-config.json +1 -0
  123. package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +2 -2
  124. package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +1 -2
  125. package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +1 -1
  126. package/templates/init/functions/node/integ/cliq/handlers/installation-handler.js +1 -1
  127. package/templates/init/functions/node/integ/cliq/handlers/installation-validator.js +1 -1
  128. package/templates/init/functions/node/integ/cliq/handlers/message-action-handler.js +1 -1
  129. package/templates/init/functions/node/integ/cliq/handlers/widget-handler.js +1 -1
  130. package/templates/init/functions/node/integ/cliq/sample.js +4 -4
  131. package/templates/init/functions/python/aio/catalyst-config.json +11 -0
  132. package/templates/init/functions/python/aio/requirements.txt +1 -0
  133. package/templates/init/functions/python/aio/sample.py +26 -0
  134. package/templates/init/functions/python/bio/catalyst-config.json +11 -0
  135. package/templates/init/functions/python/bio/requirements.txt +1 -0
  136. package/templates/init/functions/python/bio/sample.py +6 -0
  137. package/templates/init/functions/python/cron/catalyst-config.json +11 -0
  138. package/templates/init/functions/python/cron/requirements.txt +1 -0
  139. package/templates/init/functions/python/cron/sample.py +18 -0
  140. package/templates/init/functions/python/event/catalyst-config.json +11 -0
  141. package/templates/init/functions/python/event/requirements.txt +1 -0
  142. package/templates/init/functions/python/event/sample.py +21 -0
  143. package/templates/init/functions/python/integ/cliq/catalyst-config.json +11 -0
  144. package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +174 -0
  145. package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +102 -0
  146. package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +409 -0
  147. package/templates/init/functions/python/integ/cliq/handlers/installation_handler.py +12 -0
  148. package/templates/init/functions/python/integ/cliq/handlers/installation_validator.py +16 -0
  149. package/templates/init/functions/python/integ/cliq/handlers/message_action_handler.py +18 -0
  150. package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +269 -0
  151. package/templates/init/functions/python/integ/cliq/requirements.txt +1 -0
  152. package/templates/init/functions/python/integ/cliq/sample.py +21 -0
  153. package/lib/serve/server/lib/node.js +0 -62
  154. package/lib/shell/dependencies/invoker/bio/node.js +0 -80
  155. package/lib/shell/dependencies/invoker/cron/node.js +0 -54
  156. package/lib/shell/dependencies/invoker/event/node.js +0 -56
  157. package/lib/shell/dependencies/invoker/integ/node.js +0 -79
  158. package/templates/.DS_Store +0 -0
  159. package/templates/init/.DS_Store +0 -0
  160. package/templates/init/client/.DS_Store +0 -0
  161. package/templates/init/client/react/.DS_Store +0 -0
  162. package/templates/init/functions/node/integ/cliq/.DS_Store +0 -0
@@ -0,0 +1,151 @@
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.ensurePythonWithPip = exports.ensurePython = void 0;
16
+ const error_1 = __importDefault(require("../../../error"));
17
+ const prompt_1 = __importDefault(require("../../../prompt"));
18
+ const env_1 = require("../../../util_modules/env");
19
+ const shell_1 = require("../../../util_modules/shell");
20
+ const userConfig_1 = __importDefault(require("../../../userConfig"));
21
+ const ansi_colors_1 = require("ansi-colors");
22
+ const console_1 = require("console");
23
+ function ensurePython(version, fallBackNeeded, skipHelp) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const configKey = `python${version.replace('.', '_')}.bin`;
26
+ const spawnCommand = userConfig_1.default.get(configKey);
27
+ try {
28
+ if (spawnCommand) {
29
+ yield validateCommand(version, spawnCommand, true);
30
+ return;
31
+ }
32
+ }
33
+ catch (_a) { }
34
+ return new Promise((resolve, reject) => {
35
+ const child = (0, shell_1.spawn)('python' + version, ['--version'], {
36
+ stdio: 'ignore'
37
+ }).RAW();
38
+ child.on('error', (error) => __awaiter(this, void 0, void 0, function* () {
39
+ if (env_1.isWindows) {
40
+ try {
41
+ yield (0, shell_1.spawn)('py -' + version, ['--version'], {
42
+ stdio: 'ignore'
43
+ }).ASYNC();
44
+ userConfig_1.default.set(configKey, 'py -' + version);
45
+ return resolve();
46
+ }
47
+ catch (_a) { }
48
+ }
49
+ if (fallBackNeeded) {
50
+ (0, console_1.info)(`unable to locate python${version} in your system`);
51
+ const ans = yield prompt_1.default.ask(prompt_1.default.question('binPath', `Please provide the binary path for python${version}:`, {
52
+ type: 'input'
53
+ }));
54
+ yield validateCommand(version, ans.binPath, skipHelp)
55
+ .then(() => {
56
+ userConfig_1.default.set(`python${version.replace('.', '_')}.bin`, ans.binPath);
57
+ resolve();
58
+ })
59
+ .catch((err) => {
60
+ reject(err);
61
+ });
62
+ }
63
+ else {
64
+ reject(new error_1.default(`unable to locate python${version} in your system`, {
65
+ original: error,
66
+ exit: 1,
67
+ errorId: 'PY-2',
68
+ arg: [
69
+ version,
70
+ (0, ansi_colors_1.italic)((0, ansi_colors_1.bold)(`catalyst config:set ${configKey}=<binary_path>`))
71
+ ],
72
+ skipHelp
73
+ }));
74
+ }
75
+ }));
76
+ child.on('exit', (code) => {
77
+ if (code == 0) {
78
+ userConfig_1.default.set(configKey, 'python' + version);
79
+ }
80
+ resolve();
81
+ });
82
+ });
83
+ });
84
+ }
85
+ exports.ensurePython = ensurePython;
86
+ function validateCommand(version, spawnCommand, skipHelp) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ const versionResponse = yield new Promise((resolve, reject) => {
89
+ var _a;
90
+ const child = (0, shell_1.spawn)(spawnCommand, ['--version'], {
91
+ stdio: 'pipe'
92
+ }).RAW();
93
+ const dataBuf = [];
94
+ (_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (chunk) => {
95
+ dataBuf.push(chunk);
96
+ });
97
+ child.on('exit', (code) => {
98
+ if (code == 0) {
99
+ const data = Buffer.concat(dataBuf).toString();
100
+ return resolve(data);
101
+ }
102
+ else {
103
+ reject(new error_1.default(`unable to locate python${version} with the given binary path`, {
104
+ exit: 1,
105
+ errorId: 'PY-1',
106
+ arg: [version, (0, ansi_colors_1.bold)(spawnCommand)],
107
+ skipHelp
108
+ }));
109
+ }
110
+ });
111
+ child.on('error', (err) => {
112
+ reject(new error_1.default(`unable to locate python${version} with the given binary path`, {
113
+ errorId: 'PY-1',
114
+ original: err,
115
+ exit: 1,
116
+ arg: [version, (0, ansi_colors_1.bold)(spawnCommand)],
117
+ skipHelp
118
+ }));
119
+ });
120
+ });
121
+ if (!versionResponse.split(' ')[1].startsWith(version)) {
122
+ throw new error_1.default(`unable to locate python${version} with the given binary path`, {
123
+ exit: 1,
124
+ errorId: 'PY-1',
125
+ arg: [version, (0, ansi_colors_1.bold)(spawnCommand)],
126
+ skipHelp
127
+ });
128
+ }
129
+ });
130
+ }
131
+ function ensurePythonWithPip(version, fallBackNeeded = false, skipHelp = false) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ yield ensurePython(version, fallBackNeeded, skipHelp);
134
+ return new Promise((resolve, reject) => {
135
+ const child = (0, shell_1.spawn)(userConfig_1.default.get(`python${version.replace('.', '_')}.bin`), ['-m', 'pip', '--version'], {
136
+ stdio: 'ignore'
137
+ }).RAW();
138
+ child.on('error', (err) => {
139
+ reject(new error_1.default(`unable to ensure pip for python${version}`, {
140
+ errorId: 'PIP',
141
+ original: err,
142
+ arg: [version],
143
+ exit: 1,
144
+ skipHelp
145
+ }));
146
+ });
147
+ child.on('exit', resolve);
148
+ });
149
+ });
150
+ }
151
+ exports.ensurePythonWithPip = ensurePythonWithPip;
@@ -0,0 +1,175 @@
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.installRequirements = exports.pypiRes = exports.ensurePyRuntime = void 0;
16
+ const error_1 = __importDefault(require("../../../error"));
17
+ const prompt_1 = __importDefault(require("../../../prompt"));
18
+ const shell_1 = require("../../../util_modules/shell");
19
+ const constants_1 = require("../../../util_modules/constants");
20
+ const path_1 = require("path");
21
+ const fs_1 = require("../../../util_modules/fs");
22
+ const https_1 = __importDefault(require("https"));
23
+ const runtime_1 = __importDefault(require("../../../util_modules/constants/lib/runtime"));
24
+ const env_1 = require("../../../util_modules/env");
25
+ const ensure_python_1 = require("./ensure-python");
26
+ const userConfig_1 = __importDefault(require("../../../userConfig"));
27
+ const sdkPipOpts = (0, env_1.envOverride)('CATALYST_SDK_PIP_OPTS', 'zcatalyst-sdk');
28
+ const cliqSdkPipOpts = (0, env_1.envOverride)('CATALYST_CLIQ_SDK_PIP_OPTS', 'zcatalyst-cliq');
29
+ exports.default = (pth, stack, isIntegFn = false, integService = false) => __awaiter(void 0, void 0, void 0, function* () {
30
+ const stackVersion = stack.replace('python_', '');
31
+ const ans = yield prompt_1.default.ask(prompt_1.default.question('pipInstall', 'Do you wish to install all dependency libraries now ? ', {
32
+ type: 'confirm',
33
+ defaultAns: true,
34
+ when: () => !isIntegFn
35
+ }));
36
+ if (ans.pipInstall && !isIntegFn) {
37
+ yield (0, ensure_python_1.ensurePythonWithPip)(stackVersion.replace('_', '.'), true);
38
+ const spawnOpts = ['-m', 'pip', 'install', ...sdkPipOpts.split(' '), '-t', '.'];
39
+ return (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), spawnOpts, {
40
+ cwd: pth
41
+ })
42
+ .ASYNC()
43
+ .catch((err) => {
44
+ throw new error_1.default('Failure while installing zcatalyst SDk', {
45
+ exit: 2,
46
+ original: err
47
+ });
48
+ });
49
+ }
50
+ else if ((isIntegFn || ans.pipInstall === undefined) &&
51
+ integService === constants_1.INTEG.services.cliq) {
52
+ yield (0, ensure_python_1.ensurePythonWithPip)(stackVersion.replace('_', '.'), true);
53
+ const spawnOpts = ['-m', 'pip', 'install', ...cliqSdkPipOpts.split(' '), '-t', '.'];
54
+ return (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), spawnOpts, { cwd: pth })
55
+ .ASYNC()
56
+ .catch((err) => {
57
+ throw error_1.default.getErrorInstance(err, {
58
+ message: 'Failure while installing zcatalyst cliq SDK.'
59
+ });
60
+ });
61
+ }
62
+ });
63
+ function ensurePyRuntime(pth, stack) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const stackVersion = stack.replace('python_', '');
66
+ const runtimePkgName = 'zcatalyst-runtime-' + stackVersion.replace('_', '');
67
+ yield fs_1.ASYNC.ensureDir(pth);
68
+ const runtimeDir = (0, path_1.join)(pth, runtime_1.default.language.python, `zcatalyst_runtime_${stackVersion.replace('_', '')}`);
69
+ const isInitializerExists = yield fs_1.ASYNC.fileExists((0, path_1.join)(runtimeDir, 'main.py'));
70
+ if (isInitializerExists) {
71
+ const runtimeMetaData = yield fs_1.ASYNC.readJSONFile((0, path_1.join)(runtimeDir, 'meta.json'));
72
+ const pyRespJson = yield (0, exports.pypiRes)(runtimePkgName);
73
+ if ((runtimeMetaData === null || runtimeMetaData === void 0 ? void 0 : runtimeMetaData.version) == pyRespJson.info.version) {
74
+ return;
75
+ }
76
+ }
77
+ yield new Promise((resolve, reject) => {
78
+ var _a;
79
+ const child = (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), ['-m', 'pip', 'install', runtimePkgName, '--upgrade', '-t', './python'], { cwd: pth, stdio: 'pipe' }).RAW();
80
+ const errData = [];
81
+ (_a = child.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (chunk) => {
82
+ errData.push(chunk);
83
+ });
84
+ child.on('error', (err) => {
85
+ reject(new error_1.default(`Error while installing python${stackVersion.replace('_', '.')} runtime`, {
86
+ original: err,
87
+ exit: 2
88
+ }));
89
+ });
90
+ child.on('exit', (code) => {
91
+ if (code != 0) {
92
+ process.stderr.write(Buffer.concat(errData).toString());
93
+ reject(new error_1.default(`Error while installing python${stackVersion.replace('_', '.')} runtime`, {
94
+ exit: 1
95
+ }));
96
+ }
97
+ resolve();
98
+ });
99
+ });
100
+ try {
101
+ const runtimeReqFile = (0, path_1.join)(runtimeDir, constants_1.FILENAME.functions.python_requirements);
102
+ if (yield fs_1.ASYNC.fileExists(runtimeReqFile)) {
103
+ yield installRequirements(runtimeReqFile, runtimeDir, stackVersion);
104
+ }
105
+ }
106
+ catch (err) {
107
+ fs_1.ASYNC.deleteDir(runtimeDir);
108
+ throw new error_1.default(`Error while installing python${stackVersion.replace('_', '.')} runtime dependencies`);
109
+ }
110
+ });
111
+ }
112
+ exports.ensurePyRuntime = ensurePyRuntime;
113
+ const pypiRes = (pkg) => __awaiter(void 0, void 0, void 0, function* () {
114
+ return new Promise((res) => {
115
+ https_1.default
116
+ .get(`https://pypi.org/pypi/${pkg}/json`, (resp) => {
117
+ const resBuffer = [];
118
+ resp.on('data', (chunk) => {
119
+ resBuffer.push(chunk);
120
+ });
121
+ resp.on('end', () => {
122
+ res(JSON.parse(Buffer.concat(resBuffer).toString()));
123
+ });
124
+ })
125
+ .on('error', (e) => {
126
+ throw new error_1.default('Error getting latest runtime version', {
127
+ original: e,
128
+ exit: 2
129
+ });
130
+ });
131
+ });
132
+ });
133
+ exports.pypiRes = pypiRes;
134
+ function installRequirements(reqFile, pth, stackVersion, linuxMode = false) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ const spawnOpts = ['-m', 'pip', 'install', '-r', reqFile, '-t', '.', '--upgrade'];
137
+ if (linuxMode) {
138
+ spawnOpts.push(...[
139
+ '--platform',
140
+ 'manylinux2014_x86_64',
141
+ '--implementation',
142
+ 'cp',
143
+ '--only-binary=:all:'
144
+ ]);
145
+ }
146
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
147
+ var _a;
148
+ const child = (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), spawnOpts, {
149
+ cwd: pth,
150
+ stdio: 'pipe'
151
+ }).RAW();
152
+ const errData = [];
153
+ (_a = child.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (chunk) => {
154
+ errData.push(chunk);
155
+ });
156
+ child.on('error', (err) => {
157
+ reject(new error_1.default('unable to process requirements.txt', {
158
+ exit: 2,
159
+ original: err
160
+ }));
161
+ });
162
+ child.on('exit', (code) => {
163
+ if (code != 0) {
164
+ process.stderr.write(Buffer.concat(errData).toString());
165
+ reject(new error_1.default('unable to process requirements.txt', {
166
+ exit: 1,
167
+ skipHelp: true
168
+ }));
169
+ }
170
+ resolve();
171
+ });
172
+ }));
173
+ });
174
+ }
175
+ exports.installRequirements = installRequirements;
@@ -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 dc_1 = require("../../../dc");
16
17
  const catalyst_details_1 = __importDefault(require("../../../endpoints/lib/catalyst-details"));
17
18
  const integ_1 = require("../../../fn-utils/lib/integ");
18
19
  const prompt_1 = __importDefault(require("../../../prompt"));
@@ -20,6 +21,7 @@ const runtime_store_1 = __importDefault(require("../../../runtime-store"));
20
21
  const char_1 = require("../../../util_modules/char");
21
22
  const constants_1 = require("../../../util_modules/constants");
22
23
  const fs_1 = require("../../../util_modules/fs");
24
+ const js_1 = require("../../../util_modules/js");
23
25
  const logger_1 = require("../../../util_modules/logger");
24
26
  const option_1 = require("../../../util_modules/option");
25
27
  const project_1 = require("../../../util_modules/project");
@@ -49,30 +51,33 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
49
51
  }
50
52
  const catalystDetailsAPI = new catalyst_details_1.default();
51
53
  const runtimeDetailsPromise = catalystDetailsAPI.getDetails('runtime');
54
+ const fnTypeChoices = [
55
+ prompt_1.default.choice('BasicIO', {
56
+ value: constants_1.FN_TYPE.basic,
57
+ short: 'basicIO'
58
+ }),
59
+ prompt_1.default.choice('AdvancedIO', {
60
+ value: constants_1.FN_TYPE.advanced,
61
+ short: 'advancedIO'
62
+ }),
63
+ prompt_1.default.choice('Event', {
64
+ value: constants_1.FN_TYPE.event,
65
+ short: 'event'
66
+ }),
67
+ prompt_1.default.choice('Cron', {
68
+ value: constants_1.FN_TYPE.cron,
69
+ short: 'cron'
70
+ })
71
+ ];
72
+ if ((0, dc_1.getActiveDC)() === constants_1.DC_TYPE.us.value) {
73
+ fnTypeChoices.push(prompt_1.default.choice('Integration', {
74
+ value: constants_1.FN_TYPE.integration,
75
+ short: 'integration'
76
+ }));
77
+ }
52
78
  const fnTypeAns = yield prompt_1.default.ask(prompt_1.default.question('type', 'Which type of function do you like to create?', {
53
79
  type: 'list',
54
- choices: [
55
- prompt_1.default.choice('BasicIO', {
56
- value: constants_1.FN_TYPE.basic,
57
- short: 'basicIO'
58
- }),
59
- prompt_1.default.choice('AdvancedIO', {
60
- value: constants_1.FN_TYPE.advanced,
61
- short: 'advancedIO'
62
- }),
63
- prompt_1.default.choice('Event', {
64
- value: constants_1.FN_TYPE.event,
65
- short: 'event'
66
- }),
67
- prompt_1.default.choice('Cron', {
68
- value: constants_1.FN_TYPE.cron,
69
- short: 'cron'
70
- }),
71
- prompt_1.default.choice('Integration', {
72
- value: constants_1.FN_TYPE.integration,
73
- short: 'integration'
74
- })
75
- ]
80
+ choices: fnTypeChoices
76
81
  }));
77
82
  runtime_store_1.default.set('context.functions.type', fnTypeAns.type);
78
83
  if (fnTypeAns.type === constants_1.FN_TYPE.integration) {
@@ -80,14 +85,21 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
80
85
  }
81
86
  const runtimeDetails = (yield runtimeDetailsPromise);
82
87
  const runtimeChoices = runtimeDetails.runtimes.reduce((acc, value) => {
83
- const langArr = value.match(/[a-zA-Z]+/g);
84
- if (langArr === null || languages_1.default[langArr[0]] === undefined) {
88
+ const langArr = value.match(/^([a-zA-Z]+)([0-9_]+)$/);
89
+ if (langArr === null ||
90
+ languages_1.default[langArr[1]] === undefined) {
85
91
  (0, logger_1.debug)('Language cannot be identified hence skipping');
86
92
  return acc;
87
93
  }
88
- const runtimeLang = langArr[0];
94
+ const runtimeLang = langArr[1];
89
95
  const langFn = languages_1.default[runtimeLang];
90
96
  let displayValue = value;
97
+ if (displayValue.startsWith('python')) {
98
+ displayValue = 'Python ' + displayValue.replace('python_', '').replace('_', '.');
99
+ }
100
+ else {
101
+ displayValue = js_1.JS.startCase(langArr[1]) + ' ' + langArr[2];
102
+ }
91
103
  let disabled = false;
92
104
  if (runtimeDetails.eol_runtimes && runtimeDetails.eol_runtimes[value]) {
93
105
  switch (runtimeDetails.eol_runtimes[value]) {
@@ -110,14 +122,23 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
110
122
  if (acc[runtimeLang].length === 0) {
111
123
  const sep = {
112
124
  node: '---NodeJS---',
113
- java: '----Java----'
125
+ java: '----Java----',
126
+ python: '----Python----'
114
127
  };
115
128
  acc[runtimeLang].push(prompt_1.default.separator(sep[runtimeLang]));
116
129
  }
117
- acc[runtimeLang].push(prompt_1.default.choice(displayValue, { value: langFn(value), short: value, disabled }));
130
+ acc[runtimeLang].push(prompt_1.default.choice(displayValue, { value: langFn(value), short: displayValue, disabled }));
118
131
  return acc;
119
- }, { node: [], java: [] });
120
- const runtimeChoicesArr = [...runtimeChoices.java, ...runtimeChoices.node];
132
+ }, {
133
+ node: [],
134
+ java: [],
135
+ python: []
136
+ });
137
+ const runtimeChoicesArr = [
138
+ ...runtimeChoices.python,
139
+ ...runtimeChoices.java,
140
+ ...runtimeChoices.node
141
+ ];
121
142
  const runtimeAns = yield prompt_1.default.ask(prompt_1.default.question('runtime', 'Which runtime do you prefer to write your function?', {
122
143
  type: 'list',
123
144
  choices: runtimeChoicesArr,
@@ -5,7 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const java_1 = __importDefault(require("./java"));
7
7
  const node_1 = __importDefault(require("./node"));
8
+ const python_1 = __importDefault(require("./python"));
8
9
  exports.default = {
9
10
  node: node_1.default,
10
- java: java_1.default
11
+ java: java_1.default,
12
+ python: python_1.default
11
13
  };
@@ -0,0 +1,115 @@
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 ansi_colors_1 = require("ansi-colors");
16
+ const path_1 = require("path");
17
+ const prompt_1 = __importDefault(require("../../../../prompt"));
18
+ const fn_utils_1 = require("../../../../fn-utils");
19
+ const runtime_store_1 = __importDefault(require("../../../../runtime-store"));
20
+ const constants_1 = require("../../../../util_modules/constants");
21
+ const fs_1 = require("../../../../util_modules/fs");
22
+ const logger_1 = require("../../../../util_modules/logger");
23
+ const js_1 = require("../../../../util_modules/js");
24
+ const integ_1 = require("../../../../fn-utils/lib/integ");
25
+ const runtime_1 = __importDefault(require("../../../../util_modules/constants/lib/runtime"));
26
+ const functions_1 = require("../../../util/functions");
27
+ const project_1 = require("../../../../util_modules/project");
28
+ const ensure_python_1 = require("../../../dependencies/python/ensure-python");
29
+ const error_1 = __importDefault(require("../../../../error"));
30
+ const pip_install_1 = require("../../../dependencies/python/pip-install");
31
+ const cli_table_1 = require("../../../../cli_table");
32
+ const char_1 = require("../../../../util_modules/char");
33
+ exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* () {
34
+ const fnType = runtime_store_1.default.get('context.functions.type');
35
+ const fnDirPath = runtime_store_1.default.get('context.functions.dir_path');
36
+ yield fs_1.ASYNC.ensureDir(fnDirPath);
37
+ const service = runtime_store_1.default.get('context.functions.integration.service', '');
38
+ const templatePath = fnType === constants_1.FN_TYPE.integration
39
+ ? js_1.JS.get(constants_1.TEMPLATE.functions.python[fnType], service)
40
+ : constants_1.TEMPLATE.functions.python[fnType];
41
+ const functionAns = yield prompt_1.default.ask(prompt_1.default.question('name', 'package name: ', {
42
+ defaultAns: js_1.JS.snakeCase((0, project_1.getProjectName)('sample') + '_function'),
43
+ validate: (ans) => {
44
+ if (ans.match(constants_1.REGEX.folder_name)) {
45
+ return true;
46
+ }
47
+ return 'Invalid package name';
48
+ }
49
+ }), prompt_1.default.question('main', 'entry point: ', {
50
+ defaultAns: 'main.py',
51
+ validate: (ans) => {
52
+ if (js_1.JS.endsWith(ans, '.py')) {
53
+ return true;
54
+ }
55
+ return 'Invalid entry point';
56
+ }
57
+ }));
58
+ const targetPath = (0, path_1.join)(fnDirPath, functionAns.name);
59
+ const dirExists = yield fs_1.ASYNC.dirExists(targetPath);
60
+ const overwriteAns = dirExists
61
+ ? yield prompt_1.default.ask(prompt_1.default.question('overwrite', 'Directory ' +
62
+ (0, ansi_colors_1.underline)(functionAns.name) +
63
+ ' already exists inside functions directory. Overwrite ?', {
64
+ type: 'confirm',
65
+ defaultAns: false
66
+ }))
67
+ : { overwrite: true };
68
+ if (!overwriteAns.overwrite) {
69
+ (0, logger_1.warning)('Skipping functions python setup...');
70
+ return;
71
+ }
72
+ yield fs_1.ASYNC.deleteDir(targetPath).catch();
73
+ if (fnType === constants_1.FN_TYPE.integration) {
74
+ yield (0, integ_1.copyIntegHandlers)(templatePath, targetPath, runtime_1.default.language.python);
75
+ }
76
+ else {
77
+ yield fs_1.ASYNC.copyDir(templatePath, targetPath);
78
+ }
79
+ const pyRespJson = fnType === constants_1.FN_TYPE.integration
80
+ ? yield (0, pip_install_1.pypiRes)('zcatalyst-cliq')
81
+ : yield (0, pip_install_1.pypiRes)('zcatalyst-sdk');
82
+ yield fs_1.ASYNC.findAndReplace(targetPath)([
83
+ constants_1.PLACEHOLDER.functions.python_package.name,
84
+ constants_1.PLACEHOLDER.functions.python_package.main,
85
+ constants_1.PLACEHOLDER.functions.python_package.sdkVersion
86
+ ], [
87
+ functionAns.name,
88
+ functionAns.main,
89
+ pyRespJson.info.version
90
+ ]);
91
+ yield fs_1.ASYNC.rename((0, path_1.join)(targetPath, constants_1.FILENAME.functions.python_main), () => functionAns.main);
92
+ const integ_config = runtime_store_1.default.get('context.functions.integration.config', '');
93
+ yield fn_utils_1.fnUtils.common.findAndReplaceConfigProps(targetPath, {
94
+ stack,
95
+ type: fnType,
96
+ integ_config
97
+ });
98
+ const stackVersion = stack.replace('python_', '');
99
+ try {
100
+ yield (0, ensure_python_1.ensurePython)(stackVersion.replace('_', '.'), false, true);
101
+ }
102
+ catch (err) {
103
+ const error = error_1.default.getErrorInstance(err);
104
+ const table = (0, cli_table_1.getCustomColourTable)(ansi_colors_1.yellow);
105
+ table.push([
106
+ (0, ansi_colors_1.yellow)(char_1.CHAR.warning + ' ') +
107
+ error.message +
108
+ '\n' +
109
+ `you can set it later with the command ` +
110
+ `"${(0, ansi_colors_1.italic)((0, ansi_colors_1.bold)(`catalyst config:set python${stackVersion}.bin=<binary_path>`))}"`
111
+ ]);
112
+ (0, logger_1.info)(table.toString());
113
+ }
114
+ return (0, functions_1.fillFunctionsInitPayload)(targetPath, functionAns.name, stack, fnType);
115
+ });
@@ -85,7 +85,7 @@ function setFnConfig(featureName, add) {
85
85
  case 'functions':
86
86
  if (!add) {
87
87
  config.set(featureName + '.targets', [context.name]);
88
- config.set(featureName + '.ignore', ((_a = context.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) ? ['.output'] : []);
88
+ config.set(featureName + '.ignore', ((_a = context.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.java)) ? [constants_1.FOLDERNAME.output] : []);
89
89
  config.set(featureName + '.source', targetSource);
90
90
  return;
91
91
  }
@@ -93,7 +93,7 @@ function setFnConfig(featureName, add) {
93
93
  config.set(featureName + '.targets', js_1.JS.uniq(targetArr.concat([context.name])));
94
94
  const ignoreArr = config.get(featureName + '.ignore', []);
95
95
  config.set(featureName + '.ignore', ((_b = context.stack) === null || _b === void 0 ? void 0 : _b.startsWith(runtime_1.default.language.java))
96
- ? js_1.JS.uniq(ignoreArr.concat(['.output']))
96
+ ? js_1.JS.uniq(ignoreArr.concat([constants_1.FOLDERNAME.output]))
97
97
  : ignoreArr);
98
98
  if (config.get(featureName + '.source') !== targetSource) {
99
99
  (0, logger_1.warning)(featureName + ' source has been modified');