zcatalyst-cli 1.8.0 → 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.
Files changed (113) hide show
  1. package/README.md +31 -10
  2. package/docs/command_needs/auth.toml +5 -0
  3. package/docs/commands/iac/export.toml +4 -0
  4. package/docs/commands/iac/import.toml +4 -0
  5. package/docs/commands/iac/status.toml +4 -0
  6. package/docs/commands/project/use.toml +6 -0
  7. package/docs/iac/status/bundle.toml +4 -0
  8. package/lib/api-timer.js +81 -0
  9. package/lib/apig-utils.js +16 -14
  10. package/lib/archiver.js +83 -45
  11. package/lib/authentication/login.js +4 -2
  12. package/lib/bin/catalyst.js +0 -1
  13. package/lib/client-utils.js +22 -22
  14. package/lib/client.js +0 -3
  15. package/lib/command_needs/auth.js +12 -3
  16. package/lib/command_needs/rc.js +12 -7
  17. package/lib/commands/apig/disable.js +1 -1
  18. package/lib/commands/apig/enable.js +1 -1
  19. package/lib/commands/apig/status.js +7 -5
  20. package/lib/commands/client/delete.js +3 -5
  21. package/lib/commands/client/setup.js +1 -1
  22. package/lib/commands/deploy.js +4 -2
  23. package/lib/commands/ds/export.js +4 -2
  24. package/lib/commands/ds/import.js +4 -2
  25. package/lib/commands/ds/status.js +146 -150
  26. package/lib/commands/event/generate/index.js +1 -1
  27. package/lib/commands/event/generate/integ.js +1 -1
  28. package/lib/commands/functions/add.js +1 -1
  29. package/lib/commands/functions/config.js +1 -1
  30. package/lib/commands/functions/delete.js +1 -1
  31. package/lib/commands/functions/setup.js +1 -1
  32. package/lib/commands/functions/shell.js +1 -1
  33. package/lib/commands/help.js +0 -22
  34. package/lib/commands/iac/export.js +85 -0
  35. package/lib/commands/iac/import.js +187 -0
  36. package/lib/commands/iac/pack.js +129 -0
  37. package/lib/commands/iac/status.js +63 -0
  38. package/lib/commands/index.js +4 -0
  39. package/lib/commands/init.js +34 -27
  40. package/lib/commands/login.js +1 -1
  41. package/lib/commands/logout.js +1 -1
  42. package/lib/commands/project/list.js +11 -7
  43. package/lib/commands/project/reset.js +1 -1
  44. package/lib/commands/project/use.js +42 -25
  45. package/lib/commands/pull.js +1 -1
  46. package/lib/commands/run.js +1 -1
  47. package/lib/commands/serve.js +6 -5
  48. package/lib/commands/token/generate.js +1 -1
  49. package/lib/commands/token/list.js +1 -1
  50. package/lib/commands/token/revoke.js +1 -1
  51. package/lib/commands/whoami.js +1 -1
  52. package/lib/deploy/features/functions/index.js +2 -1
  53. package/lib/deploy/index.js +3 -1
  54. package/lib/endpoints/lib/iac.js +134 -0
  55. package/lib/error.js +43 -9
  56. package/lib/errorOut.js +9 -2
  57. package/lib/express_middlewares/unknownReqProxy.js +18 -7
  58. package/lib/fn-utils/lib/common.js +32 -12
  59. package/lib/fn-utils/lib/java.js +8 -9
  60. package/lib/fn-utils/lib/node.js +7 -1
  61. package/lib/fn-watcher.js +67 -0
  62. package/lib/iac/status/bundle.js +82 -0
  63. package/lib/iac/status/deploy.js +74 -0
  64. package/lib/iac/status/util/index.js +26 -0
  65. package/lib/index.js +13 -19
  66. package/lib/init/features/client.js +2 -3
  67. package/lib/init/features/functions/languages/java.js +2 -5
  68. package/lib/init/features/functions/languages/node.js +2 -5
  69. package/lib/init/features/index.js +8 -3
  70. package/lib/init/features/project.js +70 -33
  71. package/lib/init/util/client.js +12 -0
  72. package/lib/init/util/functions.js +20 -0
  73. package/lib/init/util/project.js +35 -0
  74. package/lib/internal/api.js +6 -9
  75. package/lib/internal/command.js +3 -3
  76. package/lib/internal/config.js +6 -4
  77. package/lib/migration/index.js +10 -6
  78. package/lib/option-filter.js +4 -1
  79. package/lib/port-resolver.js +18 -16
  80. package/lib/prompt/index.js +92 -0
  81. package/lib/prompt/types/file-path.js +95 -0
  82. package/lib/pull/features/client.js +1 -1
  83. package/lib/pull/features/functions/index.js +5 -7
  84. package/lib/pull/index.js +4 -1
  85. package/lib/serve/features/index.js +3 -1
  86. package/lib/serve/index.js +8 -4
  87. package/lib/serve/server/index.js +134 -64
  88. package/lib/serve/server/lib/master.js +5 -4
  89. package/lib/shell/dependencies/http-functions.js +46 -21
  90. package/lib/shell/dependencies/local-function.js +17 -48
  91. package/lib/shell/index.js +9 -10
  92. package/lib/shell/prepare/index.js +1 -5
  93. package/lib/shell/prepare/languages/index.js +14 -3
  94. package/lib/track.js +3 -1
  95. package/lib/util_modules/constants/index.js +3 -1
  96. package/lib/util_modules/constants/lib/file-names.js +2 -1
  97. package/lib/util_modules/constants/lib/iac.js +8 -0
  98. package/lib/util_modules/constants/lib/regex.js +2 -1
  99. package/lib/util_modules/constants/lib/scopes.js +5 -0
  100. package/lib/util_modules/constants/project.js +6 -0
  101. package/lib/util_modules/contextHelp.js +25 -14
  102. package/lib/util_modules/env.js +2 -5
  103. package/lib/util_modules/fs/index.js +9 -1
  104. package/lib/util_modules/fs/lib/async.js +29 -22
  105. package/lib/util_modules/js.js +6 -0
  106. package/lib/util_modules/logger.js +11 -10
  107. package/lib/util_modules/parser/toml.js +5 -1
  108. package/lib/util_modules/project.js +34 -19
  109. package/lib/util_modules/shell.js +6 -5
  110. package/package.json +12 -7
  111. package/scripts/postInstall.js +31 -0
  112. package/templates/iacSuccess.html +391 -0
  113. package/lib/prompt.js +0 -49
@@ -19,6 +19,7 @@ const error_1 = __importDefault(require("../../error"));
19
19
  const constants_1 = require("../../util_modules/constants");
20
20
  const fs_1 = require("../../util_modules/fs");
21
21
  const js_1 = require("../../util_modules/js");
22
+ const shell_1 = require("../../util_modules/shell");
22
23
  function validate(targets, idx) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
25
  if (targets.length < idx + 1) {
@@ -47,10 +48,15 @@ function validate(targets, idx) {
47
48
  ]
48
49
  });
49
50
  }
51
+ const nodeModuleExists = yield fs_1.ASYNC.dirExists(path_1.join(currentTarget.source, constants_1.FILENAME.node_modules));
52
+ if (!nodeModuleExists) {
53
+ yield shell_1.spawn('npm', ['install'], { cwd: currentTarget.source }).ASYNC();
54
+ }
50
55
  currentTarget.valid = true;
51
56
  return validate(targets, ++idx);
52
57
  }
53
- catch (err) {
58
+ catch (e) {
59
+ const err = error_1.default.getErrorInstance(e);
54
60
  currentTarget.valid = false;
55
61
  currentTarget.failure_reason = err.message;
56
62
  return validate(targets, ++idx);
@@ -0,0 +1,67 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const chokidar_1 = require("chokidar");
13
+ const languages_1 = require("./shell/prepare/languages");
14
+ const logger_1 = require("./util_modules/logger");
15
+ const shell_1 = require("./util_modules/shell");
16
+ exports.default = (target) => __awaiter(void 0, void 0, void 0, function* () {
17
+ return new Promise((res) => {
18
+ let paused = false;
19
+ let latestEvent;
20
+ const watcher = chokidar_1.watch(target.source, {
21
+ ignored: /(^|[\/\\])\../,
22
+ cwd: target.source,
23
+ ignoreInitial: true
24
+ });
25
+ watcher.on('next', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ if (latestEvent === undefined) {
27
+ paused = false;
28
+ return;
29
+ }
30
+ const currentLatestEvent = latestEvent;
31
+ shell_1.clearStdout(true);
32
+ logger_1.info(`\n${currentLatestEvent.evnt} of ${currentLatestEvent.pth} in ${target.name} detected. Preparing your function, please wait...`);
33
+ watcher.emit('preparing');
34
+ target.failure_reason = undefined;
35
+ target.valid = true;
36
+ yield languages_1.prepareFunctions([target]);
37
+ if (currentLatestEvent.at === latestEvent.at) {
38
+ latestEvent = undefined;
39
+ }
40
+ if (target.valid) {
41
+ watcher.emit('compiled');
42
+ return;
43
+ }
44
+ logger_1.warning('target [' + target.name + '] is not a valid one reason : ' + target.failure_reason);
45
+ logger_1.info('Waiting for correction..');
46
+ logger_1.info('\n(To exit, press ^C)');
47
+ watcher.emit('next');
48
+ }));
49
+ watcher.on('all', (evnt, pth) => {
50
+ latestEvent = { evnt, pth, at: Date.now() };
51
+ if (paused) {
52
+ return;
53
+ }
54
+ paused = true;
55
+ watcher.emit('next');
56
+ });
57
+ watcher.on('ready', () => {
58
+ target.watcher = watcher;
59
+ res();
60
+ });
61
+ watcher.on('error', (err) => {
62
+ logger_1.debug(err);
63
+ logger_1.warning(`Unable to start watcher for target [${target.name}]. Skipping watch mode.`);
64
+ res();
65
+ });
66
+ });
67
+ });
@@ -0,0 +1,82 @@
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 iac_1 = __importDefault(require("../../endpoints/lib/iac"));
16
+ const api_timer_1 = __importDefault(require("../../api-timer"));
17
+ const error_1 = __importDefault(require("../../error"));
18
+ const throbber_1 = __importDefault(require("../../throbber"));
19
+ const logger_1 = require("../../util_modules/logger");
20
+ const util_1 = require("./util");
21
+ const prompt_1 = __importDefault(require("../../prompt"));
22
+ const fs_1 = require("../../util_modules/fs");
23
+ const path_1 = require("path");
24
+ const option_1 = require("../../util_modules/option");
25
+ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const env = option_1.getOptionValue('production', false) ? 'Production' : 'Development';
27
+ const getSpinnerTxt = util_1.getSpinnerTxt('bundle');
28
+ const iacAPI = new iac_1.default(undefined, { env });
29
+ const bundleStatus = yield iacAPI.bundleStatus();
30
+ if (bundleStatus === undefined) {
31
+ throw new error_1.default('No export project available in server.', {
32
+ exit: 1,
33
+ errorId: 'B-1'
34
+ });
35
+ }
36
+ const throbber = throbber_1.default.getInstance();
37
+ const spinner = bundleStatus.id;
38
+ throbber.add(spinner, {
39
+ text: getSpinnerTxt(bundleStatus)
40
+ });
41
+ const timerAPI = new api_timer_1.default(iacAPI.bundleStatus.bind(iacAPI), 2000, 1);
42
+ timerAPI.on('data', (data) => __awaiter(void 0, void 0, void 0, function* () {
43
+ switch (data.status) {
44
+ case 'Scheduled':
45
+ case 'Processing':
46
+ throbber.update(spinner, {
47
+ text: getSpinnerTxt(data) + '\nPress CTRL + C to exit listening to the status'
48
+ });
49
+ break;
50
+ case 'Error_Processing':
51
+ throbber.fail(spinner, {
52
+ text: getSpinnerTxt(data, 'failed')
53
+ });
54
+ timerAPI.end();
55
+ break;
56
+ case 'Completed':
57
+ throbber.succeed(spinner, {
58
+ text: getSpinnerTxt(data)
59
+ });
60
+ timerAPI.end(undefined, true);
61
+ break;
62
+ default:
63
+ logger_1.debug('Unknown status received : ', data.status);
64
+ timerAPI.end();
65
+ }
66
+ }));
67
+ timerAPI.on('error', (e) => {
68
+ logger_1.debug('Error encounted :', e);
69
+ });
70
+ timerAPI.on('end', () => throbber.stopAll());
71
+ timerAPI.start();
72
+ const isCompleted = yield timerAPI.waitForEnd();
73
+ if (isCompleted) {
74
+ const ans = yield prompt_1.default.ask(prompt_1.default.question('download', 'Would you like to download the export zip of this job to your cmd execution directory?', { type: 'confirm', defaultAns: true }));
75
+ if (ans.download) {
76
+ const hrTime = process.hrtime();
77
+ const fileName = `export_${bundleStatus.id}_${hrTime[0] * 1000000000 + hrTime[1]}.zip`;
78
+ const bundlezip = yield iacAPI.bundleDownload();
79
+ return fs_1.ASYNC.writeFile(path_1.join(process.cwd(), fileName), bundlezip);
80
+ }
81
+ }
82
+ });
@@ -0,0 +1,74 @@
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 iac_1 = __importDefault(require("../../endpoints/lib/iac"));
16
+ const api_timer_1 = __importDefault(require("../../api-timer"));
17
+ const option_1 = require("../../util_modules/option");
18
+ const error_1 = __importDefault(require("../../error"));
19
+ const throbber_1 = __importDefault(require("../../throbber"));
20
+ const logger_1 = require("../../util_modules/logger");
21
+ const util_1 = require("./util");
22
+ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
23
+ const getSpinnerTxt = util_1.getSpinnerTxt('deploy');
24
+ const idOpt = option_1.getOptionValue('id', false);
25
+ const iacAPI = new iac_1.default();
26
+ const allDeploys = yield iacAPI.allDeploys();
27
+ if (allDeploys.length <= 0) {
28
+ throw new error_1.default('No import projects available in server.');
29
+ }
30
+ const neededDeploys = allDeploys.filter((deploy) => deploy.id === idOpt || deploy.status === 'Scheduled');
31
+ if (neededDeploys.length <= 0) {
32
+ throw new error_1.default(idOpt
33
+ ? 'No import projects with given id exists.'
34
+ : 'No import projects currently scheduled.');
35
+ }
36
+ const deployDetails = neededDeploys[0];
37
+ const throbber = throbber_1.default.getInstance();
38
+ const spinner = deployDetails.id;
39
+ throbber.add(spinner, {
40
+ text: getSpinnerTxt(deployDetails)
41
+ });
42
+ const timerAPI = new api_timer_1.default(iacAPI.deployStatus.bind(iacAPI, deployDetails.id), 2000, 1);
43
+ timerAPI.on('data', (data) => __awaiter(void 0, void 0, void 0, function* () {
44
+ switch (data.status) {
45
+ case 'Scheduled':
46
+ case 'Processing':
47
+ throbber.update(spinner, {
48
+ text: getSpinnerTxt(data) + '\nPress CTRL + C to exit listening to the status'
49
+ });
50
+ break;
51
+ case 'Error_Processing':
52
+ throbber.fail(spinner, {
53
+ text: getSpinnerTxt(data, 'failed')
54
+ });
55
+ timerAPI.end();
56
+ break;
57
+ case 'Completed':
58
+ throbber.succeed(spinner, {
59
+ text: getSpinnerTxt(data)
60
+ });
61
+ timerAPI.end(undefined, true);
62
+ break;
63
+ default:
64
+ logger_1.debug('Unknown status received : ', data.status);
65
+ timerAPI.end();
66
+ }
67
+ }));
68
+ timerAPI.on('error', (e) => {
69
+ logger_1.debug('Error encounted : ', e);
70
+ });
71
+ timerAPI.on('end', () => throbber.stopAll());
72
+ timerAPI.start();
73
+ yield timerAPI.waitForEnd();
74
+ });
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSpinnerTxt = void 0;
4
+ const getSpinnerTxt = (type) => (deployDetails, status) => {
5
+ var _a, _b;
6
+ const logs = [];
7
+ const processError = (_a = deployDetails.logs) === null || _a === void 0 ? void 0 : _a.processing_errors;
8
+ const validationError = (_b = deployDetails.logs) === null || _b === void 0 ? void 0 : _b.validation_errors;
9
+ if (processError) {
10
+ if (typeof processError === 'string') {
11
+ logs.push(`Error Message: ${processError}`);
12
+ }
13
+ else {
14
+ logs.push(`Error while processing "${processError.component}"`, `Error Message: ${processError.error_message}`);
15
+ }
16
+ }
17
+ if (validationError) {
18
+ logs.push('Error while validating : ');
19
+ logs.push(...validationError);
20
+ }
21
+ return [
22
+ `${type === 'bundle' ? 'Export' : 'Import'} Project "${deployDetails.project_details.project_name}" ${status ? status : deployDetails.status.toLowerCase()}`,
23
+ ...logs
24
+ ].join('\n' + ' '.repeat(status ? 2 : 4));
25
+ };
26
+ exports.getSpinnerTxt = getSpinnerTxt;
package/lib/index.js CHANGED
@@ -3,31 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ansi_colors_1 = require("ansi-colors");
7
6
  const commander_1 = require("commander");
8
- const meant_1 = __importDefault(require("meant"));
9
7
  const client_1 = require("./client");
10
8
  const runtime_store_1 = __importDefault(require("./runtime-store"));
9
+ const fs_1 = require("./util_modules/fs");
10
+ const constants_1 = require("./util_modules/constants");
11
+ const ansi_colors_1 = require("ansi-colors");
11
12
  const packageJson = runtime_store_1.default.get('context.cli.package');
12
13
  const { description, version } = packageJson;
13
14
  const program = new commander_1.Command();
14
15
  program.description(description);
15
- program.version(version, '-v, --version');
16
- program.option('-p, --project <name|project_id>', 'the catalyst project to use for this command');
17
- program.option('--token <token>', 'supply an auth token for this command');
18
- program.option('--dc <us|eu|in>', 'supply a DC to use for this command');
19
- program.option('--verbose', 'changes the log level to verbose for debug purpose');
16
+ program.version(version, '-v, --version', 'Print the Catalyst CLI version number');
17
+ program.option('-p, --project <name|project_id>', 'Specify the Catalyst project to be used for a command');
18
+ program.option('--token <token>', 'Supply an authentication token for a command');
19
+ program.option('--dc <us|eu|in>', 'Supply a data center for a command');
20
+ program.option('--verbose', 'Change the log level to verbose for debugging purposes');
21
+ program.helpOption('-h, --help', 'Display help for a Catalyst command');
22
+ program.showSuggestionAfterError();
23
+ program.showHelpAfterError(`For more usage information use the ${ansi_colors_1.bold('catalyst help')} command`);
24
+ program.addHelpText('before', fs_1.SYNC.readFile(constants_1.TEMPLATE.banner, 'utf-8') || '');
25
+ program.addHelpText('afterAll', `\nFor detailed documentations please visit ${ansi_colors_1.underline('https://www.zoho.com/catalyst/help/cli-command-reference.html')}`);
20
26
  const cli = new client_1.Client(program);
21
- cli.onUnknownCommand((_OPTS, cmd) => {
22
- const commandNames = cli.getAllCommandNames();
23
- console.error();
24
- console.error('"' + ansi_colors_1.bold(cmd.args.join(' ')) + '" is not a catalyst command');
25
- let suggestion = meant_1.default(cmd.args.join(' '), commandNames);
26
- suggestion = suggestion || meant_1.default(cmd.args.join(':'), commandNames);
27
- if (suggestion && suggestion.length) {
28
- console.error('Did you mean ' + ansi_colors_1.bold(suggestion.join(', ')) + ' ?');
29
- }
30
- console.error();
31
- process.exit(1);
32
- });
33
27
  exports.default = cli;
@@ -14,11 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const ansi_colors_1 = require("ansi-colors");
16
16
  const prompt_1 = __importDefault(require("../../prompt"));
17
- const runtime_store_1 = __importDefault(require("../../runtime-store"));
18
17
  const constants_1 = require("../../util_modules/constants");
19
18
  const fs_1 = require("../../util_modules/fs");
20
19
  const logger_1 = require("../../util_modules/logger");
21
20
  const project_1 = require("../../util_modules/project");
21
+ const client_1 = require("../util/client");
22
22
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
23
23
  logger_1.message('A directory ' + ansi_colors_1.cyan.bold('client') + ' will be created with a webapp pre-configured.');
24
24
  const clientDirPath = project_1.resolveProjectPath(constants_1.FOLDERNAME.client);
@@ -46,6 +46,5 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
46
46
  }
47
47
  }));
48
48
  yield fs_1.ASYNC.findAndReplace(clientDirPath)(constants_1.PLACEHOLDER.client.package.name, clientNameAns.clientName);
49
- runtime_store_1.default.set('payload.client.source', project_1.resolveProjectPath(constants_1.FOLDERNAME.client));
50
- runtime_store_1.default.set('payload.client.name', clientNameAns.clientName);
49
+ return client_1.fillClientInitPayload(project_1.resolveProjectPath(constants_1.FOLDERNAME.client), clientNameAns.clientName);
51
50
  });
@@ -24,6 +24,7 @@ const js_1 = require("../../../../util_modules/js");
24
24
  const integ_1 = require("../../../../fn-utils/lib/integ");
25
25
  const common_1 = require("../../../../fn-utils/lib/common");
26
26
  const runtime_1 = __importDefault(require("../../../../util_modules/constants/lib/runtime"));
27
+ const functions_1 = require("../../../util/functions");
27
28
  exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* () {
28
29
  const fnType = runtime_store_1.default.get('context.functions.type');
29
30
  const fnDirPath = path_1.join(runtime_store_1.default.get('context.functions.dir_path'));
@@ -85,9 +86,5 @@ exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* (
85
86
  const userFnClassPath = path_1.join(fnDirPath, functionAns.name, constants_1.FILENAME.functions.java_classpath);
86
87
  const userFnLibPath = path_1.join(fnDirPath, functionAns.name, constants_1.FOLDERNAME.java_fn_lib);
87
88
  yield fn_utils_1.fnUtils.java.rewriteClasspath(userFnClassPath, userFnLibPath);
88
- runtime_store_1.default.set('payload.functions.source', targetPath);
89
- runtime_store_1.default.set('payload.functions.stack', stack);
90
- runtime_store_1.default.set('payload.functions.name', functionAns.name);
91
- runtime_store_1.default.set('payload.functions.class', functionAns.class);
92
- runtime_store_1.default.set('payload.functions.type', fnType);
89
+ return functions_1.fillFunctionsInitPayload(targetPath, functionAns.name, stack, fnType);
93
90
  });
@@ -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
- runtime_store_1.default.set('payload.functions.source', targetPath);
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) : path_1.basename(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 === null) {
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
- logger_1.warning('skipping project setup. since project directory contains a default project. To overwrite use --force option');
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') === 404) {
45
- logger_1.error('default project not found');
48
+ if (js_1.JS.get(err, 'context.response.statusCode') !== 404) {
49
+ throw err;
46
50
  }
47
- throw err;
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: null,
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', 'Note: This process cannot be undone!\n ' +
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 === null) {
76
- const projectNameAns = yield prompt_1.default.ask(prompt_1.default.question('projectName', 'Provide a name for your new project?', {
77
- validate: (ans) => {
78
- if (ans.match(constants_1.REGEX.project.name)) {
79
- return true;
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
- runtime_store_1.default.set('payload.project.new', true);
93
+ return project_2.fillProjectPayload(selectedProject, true);
86
94
  }
87
- runtime_store_1.default.set('payload.project', selectedProject);
88
- runtime_store_1.default.set('project', project_1.transformProject(selectedProject));
89
- const envAPI = yield endpoints_1.envAPI();
90
- const envArr = (yield envAPI.getEnvs(project_1.getProjectId()));
91
- const envObj = js_1.JS.find(envArr, { env_name: constants_1.DEFAULT.env_name });
92
- if (envObj === undefined) {
93
- throw new error_1.default('There is no development environment found for this project. kindly contact support.');
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
- runtime_store_1.default.set('payload.env', envArr);
96
- runtime_store_1.default.set('project.env', project_1.transformEnv(envObj));
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;