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
@@ -116,7 +116,8 @@ class API {
116
116
  body = JSON.parse(rawResponseData.toString());
117
117
  }
118
118
  catch (e) {
119
- logger_1.debug('API Parsing Error: ' + e.message);
119
+ const err = error_1.default.getErrorInstance(e);
120
+ logger_1.debug('API Parsing Error: ' + err.message);
120
121
  }
121
122
  }
122
123
  if (resp.statusCode >= 400 && !this.logOpts.skipRespBody) {
@@ -165,14 +166,10 @@ class API {
165
166
  try {
166
167
  resolve(yield this._retry(err));
167
168
  }
168
- catch (error) {
169
- if (error instanceof error_1.default) {
170
- reject(error);
171
- }
172
- reject(new error_1.default('API Error: ' + err.message, {
173
- original: error,
174
- exit: 2
175
- }));
169
+ catch (e) {
170
+ const error = error_1.default.getErrorInstance(e);
171
+ error.exit = 2;
172
+ reject(error);
176
173
  }
177
174
  break;
178
175
  }
@@ -33,7 +33,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  const ansi_colors_1 = require("ansi-colors");
35
35
  const strip_ansi_1 = __importDefault(require("strip-ansi"));
36
- const util_1 = require("util");
37
36
  const error_1 = __importDefault(require("../error"));
38
37
  const errorOut_1 = __importDefault(require("../errorOut"));
39
38
  const migration_1 = __importDefault(require("../migration"));
@@ -128,13 +127,14 @@ class Command {
128
127
  try {
129
128
  yield runner.apply(this, programArgs);
130
129
  const duration = Date.now() - start;
130
+ errorOut_1.default();
131
131
  yield track_1.default(this.cmdName, 'success', duration);
132
- process.exitCode = 0;
133
132
  }
134
133
  catch (err) {
135
134
  const duration = Date.now() - start;
136
135
  const errorEvent = err.exit === 1 ? 'Error (User)' : 'Error (Unexpected)';
137
136
  const preppedMessage = strip_ansi_1.default(err.message || '');
137
+ errorOut_1.default(err);
138
138
  yield track_1.default(errorEvent, preppedMessage, duration);
139
139
  }
140
140
  }));
@@ -173,7 +173,7 @@ class Command {
173
173
  yield migration_1.default(runtime_store_1.default.get('context.cli.package.version'));
174
174
  }
175
175
  catch (e) {
176
- logger_1.debug(util_1.inspect(e));
176
+ logger_1.debug(e);
177
177
  }
178
178
  yield Promise.all(js_1.JS.map(this.beforeRunners, (before) => __awaiter(this, void 0, void 0, function* () {
179
179
  const beforeModule = (yield Promise.resolve().then(() => __importStar(require('../command_needs/' + before.fn)))).default;
@@ -68,11 +68,13 @@ class Config {
68
68
  }
69
69
  }
70
70
  catch (e) {
71
- throw new error_1.default('There was an error loading a file', {
72
- exit: 1,
73
- errorId: 'CONFIG-1',
74
- arg: [ansi_colors_1.bold(constants_1.FILENAME.config), e.message]
71
+ const err = error_1.default.getErrorInstance(e, {
72
+ message: 'There was an error loading a file',
73
+ skipHelp: false
75
74
  });
75
+ err.errorId = 'CONFIG-1';
76
+ err.arg = [ansi_colors_1.bold(constants_1.FILENAME.config), err.message];
77
+ throw err;
76
78
  }
77
79
  if (canIgnore) {
78
80
  return new Config(path_1.join(pd, constants_1.FILENAME.config));
@@ -63,10 +63,12 @@ const runMigration = (rc, migFiles, idx = 0) => __awaiter(void 0, void 0, void 0
63
63
  completed: false
64
64
  });
65
65
  rc.syncSave();
66
- throw new error_1.default('Unable to run migration file ' + migFile, {
67
- original: e,
68
- exit: 2
66
+ const err = error_1.default.getErrorInstance(e, {
67
+ message: 'Unable to run migration file ' + migFile,
68
+ skipHelp: false
69
69
  });
70
+ err.exit = 2;
71
+ throw err;
70
72
  }
71
73
  rc.set(['migration', currentMigFileVersion], {
72
74
  completed: true
@@ -102,10 +104,12 @@ const runGlobalMigration = (migFiles) => __awaiter(void 0, void 0, void 0, funct
102
104
  error: util_1.inspect(e),
103
105
  completed: false
104
106
  });
105
- throw new error_1.default('Unable to run migration file ' + migFile, {
106
- original: e,
107
- exit: 2
107
+ const err = error_1.default.getErrorInstance(e, {
108
+ message: 'Unable to run migration file ' + migFile,
109
+ skipHelp: false
108
110
  });
111
+ err.exit = 2;
112
+ throw err;
109
113
  }
110
114
  config_store_1.default.set('migration.' + currentMigFileVersion.replace(new RegExp('\\.', 'g'), '\\.'), {
111
115
  completed: true
@@ -175,7 +175,7 @@ function filterPorts() {
175
175
  });
176
176
  }
177
177
  exports.filterPorts = filterPorts;
178
- function filterTargets() {
178
+ function filterTargets(pathSense = true) {
179
179
  const validTargetResultants = validateTargets();
180
180
  const config = runtime_store_1.default.get('config');
181
181
  let targets = validGlobalTargets.filter((t) => config.has(t));
@@ -185,6 +185,9 @@ function filterTargets() {
185
185
  if (target === 'apig' && option_1.getCurrentCommand() === 'serve') {
186
186
  return true;
187
187
  }
188
+ if (!pathSense) {
189
+ return true;
190
+ }
188
191
  const targetRoot = project_1.resolveProjectPath(CONFIG[(target + 'Config')].source());
189
192
  return (fs_1.SYNC.isPathInside(targetRoot, runtime_store_1.default.get('cwd')) ||
190
193
  runtime_store_1.default.get('cwd') === targetRoot);
@@ -68,25 +68,27 @@ class PortResolver {
68
68
  }
69
69
  catch (e) {
70
70
  if (searchSpan === 0) {
71
- throw new error_1.default(`Provided port '${port}' is not available`, {
72
- exit: 1,
73
- original: e,
74
- errorId: 'PORT-RESOLVER-1',
75
- arg: [
76
- ansi_colors_1.bold.red(port + ''),
77
- type === 'debug' ? 'debugging' : 'serving',
78
- ansi_colors_1.bold(feature),
79
- name,
80
- type
81
- ]
71
+ const err = error_1.default.getErrorInstance(e, {
72
+ message: `Provided port '${port}' is not available`,
73
+ skipHelp: false
82
74
  });
75
+ err.errorId = 'PORT-RESOLVER-1';
76
+ err.arg = [
77
+ ansi_colors_1.bold.red(port + ''),
78
+ type === 'debug' ? 'debugging' : 'serving',
79
+ ansi_colors_1.bold(feature),
80
+ name,
81
+ type
82
+ ];
83
+ throw err;
83
84
  }
84
- throw new error_1.default(`No ports from '${port}' to ${port + searchSpan} is free to use as a ${type} port.`, {
85
- exit: 1,
86
- original: e,
87
- errorId: 'PORT-RESOLVER-2',
88
- arg: [ansi_colors_1.bold(port + ''), ansi_colors_1.bold(port + searchSpan + ''), ansi_colors_1.bold('--' + type)]
85
+ const cerr = error_1.default.getErrorInstance(e, {
86
+ message: `No ports from '${port}' to ${port + searchSpan} is free to use as a ${type} port.`,
87
+ skipHelp: false
89
88
  });
89
+ cerr.errorId = 'PORT-RESOLVER-2';
90
+ cerr.arg = [ansi_colors_1.bold(port + ''), ansi_colors_1.bold(port + searchSpan + ''), ansi_colors_1.bold('--' + type)];
91
+ throw cerr;
90
92
  }
91
93
  if (finalPort !== port) {
92
94
  logger_1.debug(`${type} port : '${port}' is not available. Hence port '${finalPort}' will be used instead.`);
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __rest = (this && this.__rest) || function (s, e) {
31
+ var t = {};
32
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
33
+ t[p] = s[p];
34
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
35
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
36
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
37
+ t[p[i]] = s[p[i]];
38
+ }
39
+ return t;
40
+ };
41
+ var __importDefault = (this && this.__importDefault) || function (mod) {
42
+ return (mod && mod.__esModule) ? mod : { "default": mod };
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ const inquirer_1 = __importDefault(require("inquirer"));
46
+ const error_1 = __importDefault(require("../error"));
47
+ const choice = (name, _a = {}) => {
48
+ var { value = name, short = name, disabled = false, checked = false } = _a, otherOpts = __rest(_a, ["value", "short", "disabled", "checked"]);
49
+ return Object.assign({ name,
50
+ value,
51
+ short,
52
+ disabled,
53
+ checked }, otherOpts);
54
+ };
55
+ exports.default = {
56
+ register: (type) => __awaiter(void 0, void 0, void 0, function* () {
57
+ switch (type) {
58
+ case 'file-path':
59
+ const filePathExt = yield Promise.resolve().then(() => __importStar(require('./types/file-path')));
60
+ inquirer_1.default.registerPrompt('file-path', filePathExt.default);
61
+ break;
62
+ default:
63
+ throw new error_1.default('No such type registered', { exit: 2 });
64
+ }
65
+ }),
66
+ seperator: (line) => {
67
+ return new inquirer_1.default.Separator(line);
68
+ },
69
+ choice,
70
+ ask: (...questions) => {
71
+ return inquirer_1.default.prompt(questions);
72
+ },
73
+ question: (name, question, _a = {}) => {
74
+ var { type = 'input', defaultAns, choices = [], validate = () => {
75
+ return true;
76
+ }, filter = (ans) => {
77
+ return ans;
78
+ }, when = () => {
79
+ return true;
80
+ }, prefix = '', suffix = '' } = _a, otheropts = __rest(_a, ["type", "defaultAns", "choices", "validate", "filter", "when", "prefix", "suffix"]);
81
+ if (choices.length > 0 && typeof choices[0] === 'string') {
82
+ choices = choices.map((strChoice) => choice(strChoice));
83
+ }
84
+ return Object.assign({ type,
85
+ name, message: question, default: defaultAns, choices,
86
+ validate,
87
+ filter,
88
+ when,
89
+ prefix,
90
+ suffix }, otheropts);
91
+ }
92
+ };
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const choices_1 = __importDefault(require("inquirer/lib/objects/choices"));
16
+ const inquirer_autocomplete_prompt_1 = __importDefault(require("inquirer-autocomplete-prompt"));
17
+ const fuzzy_1 = __importDefault(require("fuzzy"));
18
+ const fs_1 = require("../../util_modules/fs");
19
+ const ansi_colors_1 = require("ansi-colors");
20
+ function getPaths(rootPath, pattern, exclude, defaultItem) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const nodeList = yield fs_1.ASYNC.walk(rootPath, { exclude, excludeDir: false });
23
+ const filteredNodes = fuzzy_1.default.filter(pattern || '', nodeList).map((e) => e.string);
24
+ if (!pattern && defaultItem) {
25
+ filteredNodes.unshift(defaultItem);
26
+ }
27
+ return filteredNodes;
28
+ });
29
+ }
30
+ class InquirerFilePath extends inquirer_autocomplete_prompt_1.default {
31
+ constructor(question, rl, answers) {
32
+ const { rootPath = '.', exclude = [] } = question;
33
+ const questionBase = Object.assign({
34
+ emptyText: 'No valid file inside current directory!. Try giving the entire path and press ' +
35
+ ansi_colors_1.cyan('<return> ') +
36
+ 'key'
37
+ }, question, {
38
+ source: (_, pattern) => getPaths(rootPath, pattern, exclude, question.default)
39
+ });
40
+ super(questionBase, rl, answers);
41
+ }
42
+ search(searchTerm) {
43
+ const _super = Object.create(null, {
44
+ search: { get: () => super.search }
45
+ });
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ yield _super.search.call(this, searchTerm);
48
+ this.currentChoices.getChoice = (choiceIndex) => {
49
+ const choice = choices_1.default.prototype.getChoice.call(this.currentChoices, choiceIndex);
50
+ return {
51
+ value: choice === null || choice === void 0 ? void 0 : choice.value,
52
+ name: choice === null || choice === void 0 ? void 0 : choice.name,
53
+ short: choice === null || choice === void 0 ? void 0 : choice.short
54
+ };
55
+ };
56
+ });
57
+ }
58
+ onSubmitAfterValidation(line) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const choice = this.currentChoices.getChoice(this.selected);
61
+ const value = (choice === null || choice === void 0 ? void 0 : choice.value) || line;
62
+ this.answerName = (choice === null || choice === void 0 ? void 0 : choice.name) || line;
63
+ this.shortAnswer = (choice === null || choice === void 0 ? void 0 : choice.short) || line;
64
+ this.answer = this.opt.filter ? this.opt.filter(value, this.answers) : value;
65
+ choice.value = this.answer;
66
+ this.status = 'answered';
67
+ this.render(undefined);
68
+ this.screen.done();
69
+ if (this.done) {
70
+ this.done(choice.value);
71
+ }
72
+ });
73
+ }
74
+ checkValidationResult(validationResult, lineOrRl) {
75
+ if (validationResult !== true) {
76
+ this.render(validationResult || 'try giving valid complete path..');
77
+ }
78
+ else {
79
+ this.onSubmitAfterValidation(lineOrRl);
80
+ }
81
+ }
82
+ onSubmit(line) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ const lineOrRl = line || this.rl.line;
85
+ if (typeof this.opt.validate !== 'function') {
86
+ return this.onSubmitAfterValidation(lineOrRl);
87
+ }
88
+ const choice = this.currentChoices.getChoice(this.selected);
89
+ choice.value = choice.value ? choice.value : lineOrRl;
90
+ const validationResult = yield this.opt.validate(choice, this.answers);
91
+ this.checkValidationResult(validationResult, lineOrRl);
92
+ });
93
+ }
94
+ }
95
+ exports.default = InquirerFilePath;
@@ -59,7 +59,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
59
59
  choices
60
60
  }));
61
61
  const clientZip = (yield webappAPI.download(historyAns.history));
62
- yield new archiver_1.default().load(clientZip).extract('/', clientDirPath, { isFolder: true }).finalize();
62
+ yield new archiver_1.default().load(clientZip).extract(clientDirPath).finalize();
63
63
  yield client_utils_1.clientUtils.validate();
64
64
  runtime_store_1.default.set('payload.client', runtime_store_1.default.get('context.client'));
65
65
  runtime_store_1.default.set('payload.client.source', project_1.resolveProjectPath(clientDirName));
@@ -26,6 +26,7 @@ const js_1 = require("../../../util_modules/js");
26
26
  const logger_1 = require("../../../util_modules/logger");
27
27
  const project_1 = require("../../../util_modules/project");
28
28
  const runtime_1 = __importDefault(require("../../../util_modules/constants/lib/runtime"));
29
+ const error_1 = __importDefault(require("../../../error"));
29
30
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
30
31
  const fnAPI = yield endpoints_1.functionsAPI();
31
32
  const fnDirName = config_1.functionsConfig.source();
@@ -108,10 +109,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
108
109
  var _a, _b;
109
110
  yield fs_1.ASYNC.ensureDir(fn.source);
110
111
  const buffer = (yield fnAPI.download(fn.id));
111
- yield new archiver_1.default()
112
- .load(buffer)
113
- .extract('/', path_1.join(fnDirPath, fn.name), { isFolder: true })
114
- .finalize();
112
+ yield new archiver_1.default().load(buffer).extract(path_1.join(fnDirPath, fn.name)).finalize();
115
113
  if ((_a = fn.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.nodejs)) {
116
114
  yield languages_1.node(fn);
117
115
  }
@@ -122,9 +120,9 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
122
120
  })));
123
121
  targets = targets.filter((target) => {
124
122
  if (!target.valid) {
125
- logger_1.debug('Invalid target : ' + target + ' reason : ' + target.failure_reason);
126
- process.exitCode = 2;
127
- logger_1.warning('skipping pull of functions since the package is invalid. \nContact catalyst support with debug log');
123
+ logger_1.debug('Invalid target : ' + target.name + ' reason : ' + target.failure_reason);
124
+ logger_1.warning(`skipping pull of function(${target.name}) since the package is invalid. \nContact catalyst support with debug log.`);
125
+ new error_1.default('invalid package: ' + target.name, { exit: 2 });
128
126
  }
129
127
  return target.valid;
130
128
  });
package/lib/pull/index.js CHANGED
@@ -39,7 +39,10 @@ function pull() {
39
39
  }
40
40
  const MODULE = features_1.default[feature];
41
41
  logger_1.info(ansi_colors_1.bold('\n' + ansi_colors_1.white('===> ') + js_1.JS.capitalize(feature) + ' Setup'));
42
- yield MODULE();
42
+ yield MODULE().catch((err) => {
43
+ logger_1.info();
44
+ logger_1.warning(`Skipping pull of ${feature}. Since ${err.message}.\nContact Catalyst Support with catalyst-debug.log file.`);
45
+ });
43
46
  if (runtime_store_1.default.get('payload.' + feature, false)) {
44
47
  runtime_store_1.default.set('payload.features', runtime_store_1.default.get('payload.features', []).concat(feature));
45
48
  }
@@ -32,6 +32,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  exports.apig = exports.functions = exports.client = void 0;
35
+ const error_1 = __importDefault(require("../../error"));
35
36
  const port_resolver_1 = __importDefault(require("../../port-resolver"));
36
37
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
37
38
  const constants_1 = require("../../util_modules/constants");
@@ -42,7 +43,8 @@ function client() {
42
43
  try {
43
44
  yield clientModule.default();
44
45
  }
45
- catch (err) {
46
+ catch (e) {
47
+ const err = error_1.default.getErrorInstance(e);
46
48
  logger_1.info();
47
49
  logger_1.warning('Skipping the serve of Client because of the error: ' + err.message);
48
50
  logger_1.info();
@@ -35,12 +35,14 @@ const path_1 = require("path");
35
35
  const client_utils_1 = require("../client-utils");
36
36
  const error_1 = __importDefault(require("../error"));
37
37
  const fn_utils_1 = require("../fn-utils");
38
+ const fn_watcher_1 = __importDefault(require("../fn-watcher"));
38
39
  const port_resolver_1 = __importDefault(require("../port-resolver"));
39
40
  const runtime_store_1 = __importDefault(require("../runtime-store"));
40
41
  const http_functions_1 = __importDefault(require("../shell/dependencies/http-functions"));
41
42
  const constants_1 = require("../util_modules/constants");
42
43
  const fs_1 = require("../util_modules/fs");
43
44
  const logger_1 = require("../util_modules/logger");
45
+ const option_1 = require("../util_modules/option");
44
46
  const features = __importStar(require("./features"));
45
47
  const server_1 = __importDefault(require("./server"));
46
48
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -51,9 +53,11 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
51
53
  const masterPort = yield port_resolver_1.default.getPort('master', 'http', 'master', false);
52
54
  runtime_store_1.default.set('context.port.http.master', masterPort);
53
55
  yield Promise.all(serveTargets.map((target) => features[target]()));
54
- const funtionTargets = runtime_store_1.default
55
- .get('context.functions.targets', [])
56
- .filter((target) => {
56
+ const rawTargets = runtime_store_1.default.get('context.functions.targets', []);
57
+ if (option_1.getOptionValue('watch', false)) {
58
+ yield Promise.all(rawTargets.map((target) => __awaiter(void 0, void 0, void 0, function* () { return (target.valid ? fn_watcher_1.default(target) : undefined); })));
59
+ }
60
+ const funtionTargets = rawTargets.filter((target) => {
57
61
  if (!target.valid) {
58
62
  logger_1.warning('skipping serve of function [' +
59
63
  target.name +
@@ -87,13 +91,13 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
87
91
  (serveTargets.length === 1 && serveTargets[0] === 'apig')) {
88
92
  throw new error_1.default('No components to serve', { exit: 0, errorId: 'SERVE-1' });
89
93
  }
90
- yield advancedServer.start();
91
94
  const basicFn = runtime_store_1.default
92
95
  .get('context.functions.targets', [])
93
96
  .find((target) => target.type === constants_1.FN_TYPE.basic && target.valid);
94
97
  if (basicFn) {
95
98
  yield basicFnServer.start();
96
99
  }
100
+ yield advancedServer.start();
97
101
  yield advancedServer.wait();
98
102
  yield Promise.all([
99
103
  fs_1.ASYNC.deleteDir(path_1.join(runtime_store_1.default.get('cwd'), '.build')).catch(),