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
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ORIGIN = exports.TEMPLATE = exports.SCOPE = exports.REMOTE_REF = exports.REGEX = exports.REFERENCE = exports.PLACEHOLDER = exports.INTEG = exports.FOLDERNAME = exports.FN_TYPE = exports.DC_TYPE = exports.FILENAME = exports.EVENT_SOURCE = exports.EVENT_REF = exports.DEFAULT = exports.CLIQ = exports.AUTH = exports.APIG_RULES = void 0;
6
+ exports.IAC = exports.ORIGIN = exports.TEMPLATE = exports.SCOPE = exports.REMOTE_REF = exports.REGEX = exports.REFERENCE = exports.PLACEHOLDER = exports.INTEG = exports.FOLDERNAME = exports.FN_TYPE = exports.DC_TYPE = exports.FILENAME = exports.EVENT_SOURCE = exports.EVENT_REF = exports.DEFAULT = exports.CLIQ = exports.AUTH = exports.APIG_RULES = void 0;
7
7
  var apig_rules_1 = require("./lib/apig-rules");
8
8
  Object.defineProperty(exports, "APIG_RULES", { enumerable: true, get: function () { return __importDefault(apig_rules_1).default; } });
9
9
  var auth_1 = require("./lib/auth");
@@ -40,3 +40,5 @@ var template_1 = require("./lib/template");
40
40
  Object.defineProperty(exports, "TEMPLATE", { enumerable: true, get: function () { return __importDefault(template_1).default; } });
41
41
  var urls_1 = require("./lib/urls");
42
42
  Object.defineProperty(exports, "ORIGIN", { enumerable: true, get: function () { return __importDefault(urls_1).default; } });
43
+ var iac_1 = require("./lib/iac");
44
+ Object.defineProperty(exports, "IAC", { enumerable: true, get: function () { return __importDefault(iac_1).default; } });
@@ -20,5 +20,6 @@ exports.default = Object.freeze({
20
20
  system_rules: 'catalyst-system-rules.json'
21
21
  },
22
22
  catalyst_config: 'catalyst-config.json',
23
- command_log: '.command.log'
23
+ command_log: '.command.log',
24
+ node_modules: 'node_modules'
24
25
  });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = Object.freeze({
4
+ template_format: {
5
+ json: 'JSON',
6
+ yml: 'YAML'
7
+ }
8
+ });
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const functionName = /(?!^\d+$)^(\w|-)+$/g;
4
4
  exports.default = Object.freeze({
5
5
  project: {
6
- name: /^[a-zA-Z0-9][a-zA-Z0-9-]*$/g
6
+ name: /^[a-zA-Z0-9][a-zA-Z0-9-]*$/g,
7
+ template: /project-template-\d{1,2}\.\d{1,2}\.\d{1,2}.(yml|json)/g
7
8
  },
8
9
  client: {
9
10
  package_name: /^[a-zA-Z0-9][a-zA-Z0-9-]*$/g
@@ -15,6 +15,11 @@ exports.default = Object.freeze({
15
15
  queue_data_read: 'ZohoCatalyst.queue.data.READ',
16
16
  queue_data_create: 'ZohoCatalyst.queue.data.CREATE',
17
17
  projects: 'ZohoCatalyst.projects.ALL',
18
+ project_export_read: 'ZohoCatalyst.project.export.READ',
19
+ project_export_create: 'ZohoCatalyst.project.export.CREATE',
20
+ project_import_read: 'ZohoCatalyst.project.import.READ',
21
+ project_import_create: 'ZohoCatalyst.project.import.CREATE',
22
+ project_import_delete: 'ZohoCatalyst.project.import.DELETE',
18
23
  cron: 'ZohoCatalyst.cron.ALL',
19
24
  zcql: 'ZohoCatalyst.zcql.CREATE',
20
25
  webapp: 'ZohoCatalyst.webapp.ALL',
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const PROJECT = Object.freeze({
4
+ accepted_types: ['Live', 'Demo']
5
+ });
6
+ exports.default = PROJECT;
@@ -10,10 +10,11 @@ const fs_1 = require("./fs");
10
10
  const logger_1 = require("./logger");
11
11
  const toml_1 = __importDefault(require("./parser/toml"));
12
12
  function help() {
13
+ let exitCode = 0;
13
14
  const logs = runtime_store_1.default.get('log');
14
15
  if (logs === undefined) {
15
16
  logger_1.debug('NO ERRORS REGISTERED');
16
- return;
17
+ return exitCode;
17
18
  }
18
19
  const logKeys = Object.keys(logs);
19
20
  const fillTemplate = (...arg) => {
@@ -26,42 +27,52 @@ function help() {
26
27
  };
27
28
  logKeys.forEach((key) => {
28
29
  const errQueue = logs[key];
30
+ if (key === 'faultyError') {
31
+ errQueue.forEach((err) => {
32
+ exitCode = err.exit > exitCode ? err.exit : exitCode;
33
+ outputError(err, errQueue);
34
+ return;
35
+ });
36
+ }
29
37
  const docPath = key.replace(path_1.join(__dirname, '../../lib'), path_1.join(__dirname, '../../docs')) + '.toml';
30
38
  const doc = fs_1.SYNC.readFile(docPath) || '';
31
39
  const catHelp = toml_1.default(doc);
32
40
  errQueue.forEach((err) => {
33
- if (err.errorId === undefined) {
34
- logger_1.error(err.message);
35
- debugLog(err);
36
- if (err.exit === 2) {
37
- logger_1.info(`Kindly contact Catalyst support [${ansi_colors_1.bold.underline('support@zohocatalyst.com')}] if you need any further assistance`);
38
- }
39
- errQueue.shift();
40
- return;
41
- }
42
- if (catHelp === {} || catHelp === undefined) {
41
+ exitCode = err.exit > exitCode ? err.exit : exitCode;
42
+ if (err.errorId === undefined || catHelp === undefined || catHelp === {}) {
43
+ outputError(err, errQueue);
43
44
  return;
44
45
  }
45
46
  const arg = err.arg || [];
46
47
  const helpTemplate = catHelp[err.errorId];
47
48
  if (helpTemplate === undefined || helpTemplate.context === undefined) {
48
- logger_1.info('Error when fetching the help');
49
+ logger_1.debug('Error when fetching the help');
49
50
  logger_1.debug('No Help found for errorId: ' + err.errorId);
51
+ outputError(err, errQueue);
50
52
  return;
51
53
  }
52
54
  const help = fillTemplate(helpTemplate.context, helpTemplate.aid || '', ...arg);
53
55
  logger_1.info();
54
56
  logger_1.labeled(ansi_colors_1.bold('Error'), help.context).ERROR();
55
57
  debugLog(err);
56
- logger_1.log(help.aid, 'error');
58
+ logger_1.log('error', help.aid);
57
59
  if (helpTemplate.link && helpTemplate.link !== '') {
58
- logger_1.log(ansi_colors_1.bold(ansi_colors_1.blue('REF: ') + ansi_colors_1.underline(helpTemplate.link)), 'error');
60
+ logger_1.log('error', ansi_colors_1.bold(ansi_colors_1.blue('REF: ') + ansi_colors_1.underline(helpTemplate.link)));
59
61
  }
60
62
  errQueue.shift();
61
63
  });
62
64
  });
65
+ return exitCode;
63
66
  }
64
67
  exports.default = help;
68
+ function outputError(err, errQueue) {
69
+ logger_1.error(err.message);
70
+ debugLog(err);
71
+ errQueue.shift();
72
+ if (err.exit === 2) {
73
+ logger_1.info(`Kindly contact Catalyst support [${ansi_colors_1.bold.underline('support@zohocatalyst.com')}] if you need any further assistance`);
74
+ }
75
+ }
65
76
  function debugLog(err) {
66
77
  logger_1.debug('Error Stack: ' + err.stack);
67
78
  if (err.original) {
@@ -12,13 +12,10 @@ function isWindows() {
12
12
  }
13
13
  exports.isWindows = isWindows;
14
14
  function isPrimaryShell() {
15
- if (!process) {
15
+ if (!process || process.env.CATALYST_SUB_PROCESS) {
16
16
  return false;
17
17
  }
18
- if (process.env.CATALYST_SUB_PROCESS) {
19
- return !process.env.CATALYST_SUB_PROCESS;
20
- }
21
- if (process.env.SHLVL) {
18
+ if (!isWindows() && process.env.SHLVL) {
22
19
  return parseInt(process.env.SHLVL) <= 1;
23
20
  }
24
21
  return false;
@@ -18,9 +18,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
21
24
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.ASYNC = exports.SYNC = void 0;
25
+ exports.ASYNC = exports.SYNC = exports.untildify = void 0;
26
+ const os_1 = __importDefault(require("os"));
23
27
  const ASYNC = __importStar(require("./lib/async"));
24
28
  exports.ASYNC = ASYNC;
25
29
  const SYNC = __importStar(require("./lib/sync"));
26
30
  exports.SYNC = SYNC;
31
+ const tildRegex = /^~(?=$|\/|\\)/;
32
+ const homeDirectory = os_1.default.homedir();
33
+ const untildify = (pth) => homeDirectory ? pth.replace(tildRegex, homeDirectory) : pth;
34
+ exports.untildify = untildify;
@@ -17,26 +17,31 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
17
17
  const minimatch_1 = __importDefault(require("minimatch"));
18
18
  const os_1 = __importDefault(require("os"));
19
19
  const path_1 = __importDefault(require("path"));
20
+ const __1 = require("..");
20
21
  function dirExists(pth) {
21
22
  return __awaiter(this, void 0, void 0, function* () {
22
- const stats = yield fs_extra_1.default.stat(pth).catch(() => false);
23
+ const stats = yield fs_extra_1.default.stat(__1.untildify(pth)).catch(() => false);
23
24
  return stats && stats.isDirectory();
24
25
  });
25
26
  }
26
27
  exports.dirExists = dirExists;
27
28
  function fileExists(pth) {
28
29
  return __awaiter(this, void 0, void 0, function* () {
29
- const stats = yield fs_extra_1.default.stat(pth).catch(() => false);
30
+ const stats = yield fs_extra_1.default.stat(__1.untildify(pth)).catch(() => false);
30
31
  return stats && stats.isFile();
31
32
  });
32
33
  }
33
34
  exports.fileExists = fileExists;
34
- function readFile(pth, encoding = 'utf8') {
35
+ function readFile(pth, type) {
35
36
  return __awaiter(this, void 0, void 0, function* () {
36
- if (yield fileExists(pth)) {
37
- return fs_extra_1.default.readFile(pth, encoding);
37
+ if (!(yield fileExists(pth))) {
38
+ return undefined;
38
39
  }
39
- return undefined;
40
+ return (type === 'buffer'
41
+ ? fs_extra_1.default.readFile(pth)
42
+ : type
43
+ ? fs_extra_1.default.readFile(pth, type)
44
+ : fs_extra_1.default.readFile(pth, 'utf8'));
40
45
  });
41
46
  }
42
47
  exports.readFile = readFile;
@@ -70,27 +75,29 @@ function dirList(dir) {
70
75
  });
71
76
  }
72
77
  exports.dirList = dirList;
73
- function walk(dir, exclude = []) {
78
+ function walk(dir, { exclude = [], excludeDir = true, depth = -1 } = {}) {
74
79
  return __awaiter(this, void 0, void 0, function* () {
80
+ if (depth === 0) {
81
+ return [];
82
+ }
75
83
  const isDir = yield fs_extra_1.default.stat(dir).then((stat) => stat.isDirectory());
76
84
  const files = isDir ? yield fs_extra_1.default.readdir(dir) : [path_1.default.basename(dir)];
77
- const folderContentPromise = files
78
- .map((entry) => {
79
- return isDir ? path_1.default.join(dir, entry) : dir;
80
- })
81
- .filter((entryPath) => {
82
- let match = false;
83
- for (const glob of exclude) {
84
- match = minimatch_1.default(entryPath, glob);
85
- if (match) {
86
- return false;
85
+ const folderContentPromise = files.map((entry) => __awaiter(this, void 0, void 0, function* () {
86
+ const entryPath = isDir ? path_1.default.join(dir, entry) : dir;
87
+ const stats = yield fs_extra_1.default.stat(entryPath);
88
+ const isEntryPthDir = stats.isDirectory();
89
+ let excludeMatch = false;
90
+ if (!(isEntryPthDir && !excludeDir)) {
91
+ for (const glob of exclude) {
92
+ excludeMatch = excludeMatch || minimatch_1.default(entryPath, glob);
87
93
  }
88
94
  }
89
- return true;
90
- })
91
- .map((entryPath) => __awaiter(this, void 0, void 0, function* () {
92
- const stats = yield fs_extra_1.default.stat(entryPath);
93
- return stats.isDirectory() ? walk(entryPath, exclude) : [entryPath];
95
+ if (excludeMatch) {
96
+ return [];
97
+ }
98
+ return isEntryPthDir
99
+ ? walk(entryPath, { exclude, excludeDir, depth: --depth })
100
+ : [entryPath];
94
101
  }));
95
102
  const folderContents = yield Promise.all(folderContentPromise);
96
103
  return folderContents.reduce((all, folderContent) => all.concat(folderContent), []);
@@ -42,5 +42,11 @@ exports.JS = lodash_1.default.mixin({
42
42
  exports.JS.removeNullAndUndefined(val)) ||
43
43
  ((val === null || val === undefined) && delete copy[key]));
44
44
  return copy;
45
+ },
46
+ parseJSON: (str) => {
47
+ try {
48
+ return JSON.parse(str);
49
+ }
50
+ catch (e) { }
45
51
  }
46
52
  });
@@ -7,36 +7,37 @@ exports.labeled = exports.error = exports.warning = exports.message = exports.su
7
7
  const ansi_colors_1 = __importDefault(require("ansi-colors"));
8
8
  const char_1 = require("./char");
9
9
  const winston_1 = __importDefault(require("../winston"));
10
- function log(msg = '', level = 'info') {
11
- winston_1.default.log(level, msg);
10
+ const util_1 = require("util");
11
+ function log(level, message, ...meta) {
12
+ winston_1.default.log(level, message, meta);
12
13
  }
13
14
  exports.log = log;
14
- function info(msg = '') {
15
- winston_1.default.info(msg);
15
+ function info(msg = '', ...params) {
16
+ winston_1.default.info(util_1.format(msg, ...params));
16
17
  }
17
18
  exports.info = info;
18
- function debug(msg = '') {
19
- winston_1.default.debug(msg);
19
+ function debug(msg = '', ...params) {
20
+ winston_1.default.debug(util_1.format(msg, ...params));
20
21
  }
21
22
  exports.debug = debug;
22
23
  function success(msg, level = 'info', label = '') {
23
24
  const postChar = label === '' ? '' : label + ': ';
24
- log(ansi_colors_1.default.green(char_1.CHAR.success + ' ' + postChar) + msg, level);
25
+ winston_1.default.log(level, ansi_colors_1.default.green(char_1.CHAR.success + ' ' + postChar) + msg);
25
26
  }
26
27
  exports.success = success;
27
28
  function message(msg, level = 'info', label = '') {
28
29
  const postChar = label === '' ? '' : label + ': ';
29
- log(ansi_colors_1.default.cyan(char_1.CHAR.info + ' ' + postChar) + msg, level);
30
+ winston_1.default.log(level, ansi_colors_1.default.cyan(char_1.CHAR.info + ' ' + postChar) + msg);
30
31
  }
31
32
  exports.message = message;
32
33
  function warning(msg, level = 'warn', label = '') {
33
34
  const postChar = label === '' ? '' : label + ': ';
34
- log(ansi_colors_1.default.yellow(char_1.CHAR.warning + ' ' + postChar) + msg, level);
35
+ winston_1.default.log(level, ansi_colors_1.default.yellow(char_1.CHAR.warning + ' ' + postChar) + msg);
35
36
  }
36
37
  exports.warning = warning;
37
38
  function error(msg, level = 'error', label = '') {
38
39
  const postChar = label === '' ? '' : label + ': ';
39
- log(ansi_colors_1.default.red(char_1.CHAR.error + ' ' + postChar) + msg, level);
40
+ winston_1.default.log(level, ansi_colors_1.default.red(char_1.CHAR.error + ' ' + postChar) + msg);
40
41
  }
41
42
  exports.error = error;
42
43
  function labeled(label, line) {
@@ -10,6 +10,10 @@ exports.default = (str) => {
10
10
  return toml_1.parse(str);
11
11
  }
12
12
  catch (e) {
13
- throw new error_1.default('TOML Parsing error on line ' + e.line + ', column ' + e.column + ': ' + e.message, { exit: 2 });
13
+ const err = error_1.default.getErrorInstance(e, {
14
+ message: 'TOML Parsing error'
15
+ });
16
+ err.exit = 2;
17
+ throw err;
14
18
  }
15
19
  };
@@ -34,6 +34,20 @@ function getDefaultProject(throwError) {
34
34
  }
35
35
  return rc.defaultProject;
36
36
  }
37
+ function getDefaultEnv(throwError) {
38
+ const rc = runtime_store_1.default.get('rc', null);
39
+ if (rc === null) {
40
+ if (throwError) {
41
+ throw new error_1.default(constants_1.FILENAME.rc + ' file needed', {
42
+ exit: 1,
43
+ errorId: 'PROJ-1',
44
+ arg: [constants_1.FILENAME.rc, ansi_colors_1.bold('catalyst init project')]
45
+ });
46
+ }
47
+ return;
48
+ }
49
+ return rc.defaultEnv;
50
+ }
37
51
  function getProjectId(fallback) {
38
52
  const projectId = runtime_store_1.default.get('project.id', null);
39
53
  if (projectId === null) {
@@ -125,18 +139,7 @@ function getDefaultProjectName(fallback) {
125
139
  }
126
140
  exports.getDefaultProjectName = getDefaultProjectName;
127
141
  function getDefaultEnvName(fallback) {
128
- const rc = runtime_store_1.default.get('rc', null);
129
- if (rc === null) {
130
- if (fallback === undefined) {
131
- throw new error_1.default(constants_1.FILENAME.rc + ' file needed', {
132
- exit: 1,
133
- errorId: 'PROJ-1',
134
- arg: [constants_1.FILENAME.rc, ansi_colors_1.bold('catalyst init project')]
135
- });
136
- }
137
- return fallback;
138
- }
139
- const defaultEnv = rc.defaultEnv;
142
+ const defaultEnv = getDefaultEnv(fallback === undefined);
140
143
  if (defaultEnv !== undefined) {
141
144
  return defaultEnv.name;
142
145
  }
@@ -161,13 +164,22 @@ function getProjectRoot(fallback = process.cwd()) {
161
164
  }
162
165
  exports.getProjectRoot = getProjectRoot;
163
166
  function makeDefaultProjectActive() {
164
- const defaultProject = getDefaultProject(false);
165
- if (defaultProject === undefined) {
166
- throw new error_1.default('Unable to set default project active since value is not defined', {
167
- exit: 2
168
- });
169
- }
170
- return upsertProject(defaultProject, { active: true });
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ const defaultProject = getDefaultProject(false);
169
+ if (defaultProject === undefined) {
170
+ throw new error_1.default('Unable to set default project active since value is not defined', {
171
+ exit: 2
172
+ });
173
+ }
174
+ const defaultEnv = getDefaultEnv(false);
175
+ if (defaultEnv === undefined) {
176
+ throw new error_1.default('Unable to set default env active since value is not defined', {
177
+ exit: 2
178
+ });
179
+ }
180
+ yield upsertProject(defaultProject, { active: true });
181
+ return upsertEnv(defaultProject.id, defaultEnv, { active: true });
182
+ });
171
183
  }
172
184
  exports.makeDefaultProjectActive = makeDefaultProjectActive;
173
185
  function transformProject(projectObj) {
@@ -187,6 +199,9 @@ function transformProject(projectObj) {
187
199
  name: value.project_domain_name
188
200
  };
189
201
  break;
202
+ case 'project_type':
203
+ key = 'type';
204
+ break;
190
205
  default:
191
206
  break;
192
207
  }
@@ -47,16 +47,14 @@ function spawn(command, opts, _a = {}) {
47
47
  ASYNC: () => {
48
48
  const childProcess = cross_spawn_1.default(command, opts, Object.assign({ cwd,
49
49
  stdio,
50
- shell }, otherOpts));
50
+ shell }, otherOpts)).on('error', logger_1.debug);
51
51
  return new Promise((res, rej) => {
52
52
  let message = '';
53
- childProcess.on('error', (err) => {
54
- rej(err);
55
- });
56
53
  childProcess.on('message', (msg) => {
57
54
  message += msg.toString();
58
55
  logger_1.debug(msg.toString());
59
56
  });
57
+ childProcess.on('error', rej);
60
58
  childProcess.on('exit', (code) => {
61
59
  if (code !== 0) {
62
60
  rej(code);
@@ -65,7 +63,10 @@ function spawn(command, opts, _a = {}) {
65
63
  });
66
64
  });
67
65
  },
68
- RAW: () => cross_spawn_1.default(command, opts, Object.assign({ cwd, stdio, shell }, otherOpts))
66
+ RAW: () => {
67
+ const child = cross_spawn_1.default(command, opts, Object.assign({ cwd, stdio, shell }, otherOpts)).on('error', logger_1.debug);
68
+ return child;
69
+ }
69
70
  };
70
71
  }
71
72
  exports.spawn = spawn;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "zcatalyst-cli",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "description": "Command Line Tool for CATALYST",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
7
7
  "catalyst": "./lib/bin/catalyst.js"
8
8
  },
9
9
  "engines": {
10
- "node": ">=10.0.0"
10
+ "node": ">=12.0.0"
11
11
  },
12
12
  "keywords": [
13
13
  "cli",
@@ -30,17 +30,18 @@
30
30
  "chokidar": "^3.5.2",
31
31
  "cli-cursor": "^3.1.0",
32
32
  "cli-table3": "^0.6.0",
33
- "commander": "^8.1.0",
33
+ "commander": "^8.2.0",
34
34
  "conf": "^10.0.2",
35
35
  "cross-spawn": "^7.0.3",
36
36
  "express": "^4.17.1",
37
37
  "fs-extra": "^10.0.0",
38
+ "fuzzy": "^0.1.3",
38
39
  "global-dirs": "^3.0.0",
39
40
  "http-proxy": "^1.18.1",
40
41
  "inquirer": "^8.1.2",
42
+ "inquirer-autocomplete-prompt": "^1.4.0",
41
43
  "jszip": "^3.7.1",
42
44
  "lodash": "^4.17.21",
43
- "meant": "^2.0.1",
44
45
  "minimatch": "^3.0.4",
45
46
  "moment": "^2.29.1",
46
47
  "open": "^8.2.1",
@@ -52,7 +53,8 @@
52
53
  "toml": "^3.0.0",
53
54
  "update-notifier": "^5.1.0",
54
55
  "winston": "^3.3.3",
55
- "xml2js": "^0.4.23"
56
+ "xml2js": "^0.4.23",
57
+ "yaml": "^1.10.2"
56
58
  },
57
59
  "devDependencies": {
58
60
  "@types/app-module-path": "^2.2.0",
@@ -62,6 +64,7 @@
62
64
  "@types/fs-extra": "^9.0.12",
63
65
  "@types/http-proxy": "^1.17.7",
64
66
  "@types/inquirer": "^7.3.3",
67
+ "@types/inquirer-autocomplete-prompt": "^1.3.3",
65
68
  "@types/jest": "^26.0.24",
66
69
  "@types/lodash": "^4.14.172",
67
70
  "@types/minimatch": "^3.0.5",
@@ -95,11 +98,13 @@
95
98
  "prepublishOnly": "npm test && npm run lint",
96
99
  "preversion": "npm run lint",
97
100
  "version": "git add -A src test templates",
98
- "postversion": "git push && git push --tags"
101
+ "postversion": "git push && git push --tags",
102
+ "postinstall": "node ./scripts/postInstall.js "
99
103
  },
100
104
  "files": [
101
105
  "lib/**/*",
102
106
  "templates/**/*",
103
- "docs/**/*"
107
+ "docs/**/*",
108
+ "scripts/**/*"
104
109
  ]
105
110
  }
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-console */
3
+ /* eslint-disable @typescript-eslint/no-var-requires */
4
+
5
+ 'use strict';
6
+
7
+ try {
8
+ const semver = require('semver');
9
+ const ansi = require('ansi-colors');
10
+ const cliTable = require('cli-table3');
11
+ const packageJson = require('../package.json');
12
+
13
+ if (semver.satisfies(process.version, packageJson.engines.node)) {
14
+ console.log(ansi.green.bold('Installation successful.'));
15
+ return;
16
+ }
17
+
18
+ const table = new cliTable({ style: { border: [], header: [] } });
19
+ table.push(
20
+ {
21
+ 'Current version: ': [ansi.red(semver.clean(process.version))]
22
+ },
23
+ {
24
+ 'Compatible version: ': [ansi.green(packageJson.engines.node)]
25
+ }
26
+ );
27
+ console.log(ansi.red('Node.js version is incompatible !!!'));
28
+ console.log(table.toString());
29
+ console.log('\n' + ansi.yellow.bold('Please update Node.js to a compatible version.'));
30
+ console.log(ansi.bold('Reference: ') + ansi.underline('https://nodejs.org/') + '\n');
31
+ } catch (err) {}