zcatalyst-cli 1.18.0-beta.1 → 1.18.0-beta.3

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 (51) hide show
  1. package/docs/command_needs/rc.toml +8 -8
  2. package/docs/serve/server/lib/appsail/index.toml +22 -1
  3. package/lib/command_needs/rc.js +7 -7
  4. package/lib/commands/appsail/add.js +1 -1
  5. package/lib/commands/client/setup.js +1 -1
  6. package/lib/commands/codelib/install.js +5 -2
  7. package/lib/commands/event/generate/index.js +1 -2
  8. package/lib/commands/event/generate/integ.js +1 -2
  9. package/lib/commands/functions/add.js +1 -1
  10. package/lib/commands/functions/setup.js +1 -1
  11. package/lib/commands/index.js +1 -2
  12. package/lib/commands/init.js +8 -1
  13. package/lib/deploy/features/appsail/index.js +25 -10
  14. package/lib/endpoints/index.js +2 -2
  15. package/lib/endpoints/lib/tunnel.js +18 -0
  16. package/lib/init/features/appsail/index.js +34 -27
  17. package/lib/init/features/client/index.js +1 -2
  18. package/lib/init/features/project.js +5 -15
  19. package/lib/internal/api.js +13 -5
  20. package/lib/internal/command.js +1 -2
  21. package/lib/migration/index.js +2 -4
  22. package/lib/optional-import.js +2 -3
  23. package/lib/prompt/types/file-path.js +1 -1
  24. package/lib/prompt/types/tree.js +3 -3
  25. package/lib/serve/features/appsail.js +1 -1
  26. package/lib/serve/server/index.js +44 -14
  27. package/lib/serve/server/lib/appsail/index.js +73 -13
  28. package/lib/serve/server/lib/appsail/start.js +9 -1
  29. package/lib/serve/server/lib/master/unknown-req-proxy.js +3 -0
  30. package/lib/serve/server/lib/master/utils.js +6 -6
  31. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  32. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +14 -0
  33. package/lib/shell/dependencies/invoker/integ/node.mjs +13 -0
  34. package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +15 -1
  35. package/lib/shell/dependencies/local-function.js +24 -23
  36. package/lib/shell/dependencies/tunnel-server.js +52 -23
  37. package/lib/shell/index.js +22 -28
  38. package/lib/util_modules/config/lib/appsail.js +10 -8
  39. package/lib/util_modules/fs/lib/async.js +7 -2
  40. package/package.json +1 -1
  41. package/templates/init/functions/java/job/sample.java +1 -1
  42. package/templates/init/functions/node/aio/sample.js +7 -0
  43. package/templates/init/functions/node/bio/sample.js +5 -0
  44. package/templates/init/functions/node/bio/types/basicio.d.ts +57 -0
  45. package/templates/init/functions/node/cron/sample.js +5 -0
  46. package/templates/init/functions/node/cron/types/cron.d.ts +64 -0
  47. package/templates/init/functions/node/event/sample.js +11 -8
  48. package/templates/init/functions/node/event/types/event.d.ts +82 -0
  49. package/templates/init/functions/node/job/sample.js +0 -1
  50. package/templates/init/functions/node/job/types/job.d.ts +0 -4
  51. package/templates/init/functions/python/job/sample.py +0 -1
@@ -1,7 +1,7 @@
1
1
  [RC-1]
2
2
  context = '''The project(${arg[0]}) provided with the ${arg[1]} option is not available is not available in the ${arg[3]} org.'''
3
3
  aid = '''Please use one of the available projects with the ${arg[1]} option or specify the correct org \nThe available projects in the ${arg[3]} org are: \n${arg[2]}'''
4
- link = 'https://www.zoho.com/catalyst/help/cli-options.html#Project'
4
+ link = 'https://docs.catalyst.zoho.com/en/cli/v1/initialize-resources/initialize-new-project/'
5
5
 
6
6
  [RC-2]
7
7
  context = '''Unable to load the ${arg[0]} file.'''
@@ -10,18 +10,18 @@ link = ''
10
10
 
11
11
  [RC-3]
12
12
  context = '''Oops!!! It looks like you're not inside a Catalyst app directory because we are unable to locate the ${arg[0]} file.'''
13
- aid = '''Please run the ${arg[1]} command to initialise or specify a valid project with the ${arg[2]} option.'''
14
- link = 'https://www.zoho.com/catalyst/help/cli-init.html#Initialize_All'
13
+ aid = '''Please run the ${arg[1]} command to initialize or specify a valid project with the ${arg[2]} option.'''
14
+ link = 'https://docs.catalyst.zoho.com/en/cli/v1/initialize-resources/introduction/#Initialize_Alll'
15
15
 
16
16
  [RC-4]
17
17
  context = '''The ${arg[0]} file is corrupted.'''
18
- aid = '''Please delete the ${arg[0]} file in the Catalyst app directory and initialise the project with the ${arg[1]} command or \nSpecify a valid project with the ${arg[2]} option.'''
19
- link = 'https://www.zoho.com/catalyst/help/cli-init.html#Options'
18
+ aid = '''Please delete the ${arg[0]} file in the Catalyst app directory and initialize the project with the ${arg[1]} command or \nSpecify a valid project with the ${arg[2]} option.'''
19
+ link = 'https://docs.catalyst.zoho.com/en/cli/v1/initialize-resources/initialize-options/#--force'
20
20
 
21
21
  [RC-5]
22
- context = '''The project which is currently active doesn't seems to be present in Catalyst remote console.'''
23
- aid = '''Use the ${arg[0]} command in order to change the existing active project.'''
24
- link = 'https://www.zoho.com/catalyst/help/cli-projects.html#Use'
22
+ context = '''Oops!!! It looks like you don't have access to the currently initialized project ${arg[0]}.'''
23
+ aid = '''Please contact the owner or an administrator of the project.\nIf you would like to initialize a new project for this directory, please use the below command\n${arg[1]}'''
24
+ link = 'https://docs.catalyst.zoho.com/en/cli/v1/initialize-resources/initialize-options/#--force'
25
25
 
26
26
  [RC-6]
27
27
  context = '''The Catalyst portal initialized in the current project directory is not accessible with the currently logged in user.\n
@@ -1,4 +1,25 @@
1
1
  [SERVE-APPSAIL-1]
2
- context = '''The provided build path (${arg[0]}) for the AppSail ${arg[1]} does not exists.'''
2
+ context = '''The provided build path ${arg[0]} for the AppSail ${arg[1]} does not exists.'''
3
3
  aid = '''Please provide a valid build path'''
4
4
  link = ''
5
+
6
+ [SERVE-APPSAIL-2]
7
+ context = '''The build path resolved from the provided relative path "${arg[0]}" does not exists.
8
+ Source path : ${arg[1]}
9
+ Build path : ${arg[2]}
10
+ Resolved Path : ${arg[3]}'''
11
+ aid = '''Please provide a valid relative path as build path'''
12
+ link = ''
13
+
14
+ [SERVE-APPSAIL-3]
15
+ context = '''Unable to start the ${arg[0]} AppSail server with the below parameters.
16
+ Command : ${arg[1]}
17
+ Build path : ${arg[2]}
18
+ Runtime : ${arg[3]}'''
19
+ aid = '''Please fix the errors if any'''
20
+ link = ''
21
+
22
+ [SERVE-APPSAIL-4]
23
+ context = '''Invalid AppSail Stack/Runtime for AppSail ${arg[0]}: ${arg[1]}'''
24
+ aid = '''Please use a supported Stack/Runtime from the below list: \n${arg[2]}'''
25
+ link = ''
@@ -192,7 +192,7 @@ exports.default = ({ optional = false, resolveOnNotFound = false, skipOrgCheck =
192
192
  });
193
193
  }
194
194
  if (typeof finalEnvObj !== 'undefined') {
195
- projectApi = yield (0, endpoints_1.projectAPI)({ auth: true, org: finalEnvObj.id });
195
+ projectApi = yield (0, endpoints_1.projectAPI)({ auth: true, org: finalEnvObj.id, printError: false });
196
196
  envApi = yield (0, endpoints_1.envAPI)({ auth: true, org: finalEnvObj.id });
197
197
  }
198
198
  const projectDetails = yield projectApi
@@ -200,19 +200,19 @@ exports.default = ({ optional = false, resolveOnNotFound = false, skipOrgCheck =
200
200
  .catch((err) => __awaiter(void 0, void 0, void 0, function* () {
201
201
  if (js_1.JS.hasIn(err, 'context.response.statusCode')) {
202
202
  switch (err.context.response.statusCode) {
203
+ case 401:
203
204
  case 404: {
204
- (0, logger_1.message)('cleaning up ' +
205
- constants_1.FILENAME.rc +
206
- ' since the current active project for this folder is not found in remote');
207
- yield (0, project_2.removeProject)(finalProjectObj.id + '');
208
205
  if (resolveOnNotFound) {
209
206
  finalProjectObj = undefined;
210
207
  return;
211
208
  }
212
- throw new error_1.default('active project not found in remote', {
209
+ throw new error_1.default('no access to project: ' + (finalProjectObj === null || finalProjectObj === void 0 ? void 0 : finalProjectObj.id), {
213
210
  exit: 1,
214
211
  errorId: 'RC-5',
215
- arg: [(0, ansi_colors_1.bold)('catalyst project:use')]
212
+ arg: [
213
+ (0, ansi_colors_1.bold)(`${finalProjectObj === null || finalProjectObj === void 0 ? void 0 : finalProjectObj.name}(${finalProjectObj === null || finalProjectObj === void 0 ? void 0 : finalProjectObj.id})`),
214
+ (0, ansi_colors_1.bold)((0, ansi_colors_1.cyan)('command: ') + 'catalyst init --force')
215
+ ]
216
216
  });
217
217
  }
218
218
  case 403: {
@@ -43,7 +43,7 @@ const logger_1 = require("../../util_modules/logger");
43
43
  exports.default = new command_1.default('appsail:add')
44
44
  .description('Link an already existing AppSail service to Catalyst Project')
45
45
  .needs('auth', [constants_1.SCOPE.functions])
46
- .needs('config')
46
+ .needs('config', { optional: true })
47
47
  .needs('rc')
48
48
  .ci(false)
49
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -43,7 +43,7 @@ const logger_1 = require("../../util_modules/logger");
43
43
  exports.default = new command_1.default('client:setup')
44
44
  .description('Set up and configure the client directory in your project directory')
45
45
  .needs('auth', [constants_1.SCOPE.webapp])
46
- .needs('config')
46
+ .needs('config', { optional: true })
47
47
  .needs('rc')
48
48
  .ci(false)
49
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -32,7 +32,7 @@ exports.default = new command_1.default('codelib:install [git-url]')
32
32
  .description('Install the code library functionalities into your project')
33
33
  .option('-c, --continue <install-id>', 'Continue CodeLib install')
34
34
  .needs('auth', [constants_1.SCOPE.project_import_create])
35
- .needs('config')
35
+ .needs('config', { optional: true })
36
36
  .needs('rc')
37
37
  .action((gitUrl) => __awaiter(void 0, void 0, void 0, function* () {
38
38
  var _a;
@@ -72,7 +72,10 @@ exports.default = new command_1.default('codelib:install [git-url]')
72
72
  if (!gitUrl) {
73
73
  throw new error_1.default('Invalid code lib', { exit: 2 });
74
74
  }
75
- return;
75
+ throw new error_1.default(`Error while downloading codelib.`, {
76
+ exit: 2,
77
+ original: `Occurred while processing ${gitUrl}`
78
+ });
76
79
  }
77
80
  const templateFile = yield (0, code_deck_1.getTemplateFile)(deckZip);
78
81
  const templateJson = JSON.parse(templateFile || '');
@@ -54,7 +54,6 @@ exports.default = new command_1.default('event:generate <source> <action>')
54
54
  .needs('auth')
55
55
  .action(function generate(source, action) {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
- var _a;
58
57
  const unknownArgs = (0, option_1.getUnknownOpts)([]);
59
58
  if (unknownArgs.length % 2 !== 0) {
60
59
  throw new error_1.default('Unknown options are not provided as key value pairs', {
@@ -176,7 +175,7 @@ exports.default = new command_1.default('event:generate <source> <action>')
176
175
  break;
177
176
  }
178
177
  });
179
- const sourceModule = (yield (_a = '../../../event_generate/' + source, Promise.resolve().then(() => __importStar(require(_a))))).default;
178
+ const sourceModule = (yield Promise.resolve().then(() => __importStar(require('../../../event_generate/' + source)))).default;
180
179
  eventJsonContent = yield sourceModule(eventJsonContent, optionMap, action);
181
180
  const jsonContent = JSON.parse(eventJsonContent);
182
181
  Object.keys(jsonContent).forEach((key) => {
@@ -46,7 +46,6 @@ exports.default = new command_1.default('event:generate:integ <service>')
46
46
  .needs('rc')
47
47
  .needs('auth')
48
48
  .action((service) => __awaiter(void 0, void 0, void 0, function* () {
49
- var _a;
50
49
  const availableServices = Object.keys(constants_1.INTEG.service_map);
51
50
  if (!availableServices.includes(service)) {
52
51
  throw new error_1.default('Unknown service requested', {
@@ -57,7 +56,7 @@ exports.default = new command_1.default('event:generate:integ <service>')
57
56
  }
58
57
  const inputs = (0, option_1.getOptionValue)('inputs', '');
59
58
  const serviceValue = constants_1.INTEG.service_map[service];
60
- const serviceModule = (yield (_a = `../../../event_generate/integration/${serviceValue}`, Promise.resolve().then(() => __importStar(require(_a)))))
59
+ const serviceModule = (yield Promise.resolve().then(() => __importStar(require(`../../../event_generate/integration/${serviceValue}`))))
61
60
  .default;
62
61
  const payload = yield serviceModule(inputs);
63
62
  process.stdout.write(payload + '\n');
@@ -43,7 +43,7 @@ const logger_1 = require("../../util_modules/logger");
43
43
  exports.default = new command_1.default('functions:add')
44
44
  .description('Add a function of the required stack to the function directory')
45
45
  .needs('auth', [constants_1.SCOPE.functions])
46
- .needs('config')
46
+ .needs('config', { optional: true })
47
47
  .needs('rc')
48
48
  .ci(false)
49
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -43,7 +43,7 @@ const logger_1 = require("../../util_modules/logger");
43
43
  exports.default = new command_1.default('functions:setup')
44
44
  .description('Set up and configure the function directory in your project directory')
45
45
  .needs('auth', [constants_1.SCOPE.functions])
46
- .needs('config')
46
+ .needs('config', { optional: true })
47
47
  .needs('rc')
48
48
  .ci(false)
49
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -36,8 +36,7 @@ exports.default = (client) => {
36
36
  function loadCommand(name) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
38
  return new Promise((resolve, reject) => setTimeout(() => __awaiter(this, void 0, void 0, function* () {
39
- var _a;
40
- const cmd = (yield (_a = './' + name.split(':').join('/'), Promise.resolve().then(() => __importStar(require(_a))))).default;
39
+ const cmd = (yield Promise.resolve().then(() => __importStar(require('./' + name.split(':').join('/'))))).default;
41
40
  try {
42
41
  cmd.register(client);
43
42
  resolve();
@@ -100,8 +100,15 @@ exports.default = new command_1.default('init [feature]')
100
100
  return;
101
101
  }
102
102
  if (feature !== 'project') {
103
- yield (0, features_1.project)();
103
+ try {
104
+ yield (0, features_1.project)();
105
+ }
106
+ catch (er) {
107
+ (0, logger_1.debug)(er);
108
+ return;
109
+ }
104
110
  }
111
+ (0, logger_1.info)();
105
112
  const featureAns = yield prompt_1.default.ask(prompt_1.default.question('features', 'Which are the features you want to setup for this folder?\n This step is optional! Press ' +
106
113
  (0, ansi_colors_1.cyan)('<return> ') +
107
114
  'to proceed.\n', {
@@ -31,6 +31,7 @@ const option_1 = require("../../../util_modules/option");
31
31
  const project_1 = require("../../../util_modules/project");
32
32
  const utils_1 = require("./utils");
33
33
  const throbber_1 = __importDefault(require("../../../throbber"));
34
+ const minimatch_1 = __importDefault(require("minimatch"));
34
35
  function executeHook(script, name, moduleSource) {
35
36
  if ((0, option_1.getOptionValue)('ignoreScripts', false)) {
36
37
  (0, logger_1.debug)(`skipping ${name} hook`);
@@ -183,29 +184,42 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
183
184
  var _a, _b;
184
185
  const targ = _targ.config;
185
186
  const prevRes = yield result;
187
+ const throbberName = `prepare_appsail_${_targ.name}`;
186
188
  try {
187
189
  if ((_a = targ.scripts) === null || _a === void 0 ? void 0 : _a.predeploy) {
188
190
  executeHook(targ.scripts.predeploy, 'predeploy', _targ.source);
189
191
  }
190
- const throbberName = `prepare_appsail_${_targ.name}`;
191
192
  throbber.add(throbberName, {
192
193
  text: `Preparing AppSail[${_targ.name}]`
193
194
  });
194
- const zip = new archiver_1.default();
195
- const ignoreFile = yield fs_1.ASYNC.readFile((0, path_1.join)(_targ.source, constants_1.FILENAME.catalyst_ignore));
196
195
  const folderPath = targ.build_path;
196
+ const isBuildPath = yield fs_1.ASYNC.isPathExists(folderPath);
197
+ if (!isBuildPath) {
198
+ throw new error_1.default(`the build path doesn't exists: ${folderPath}`, {
199
+ exit: 1,
200
+ skipHelp: true
201
+ });
202
+ }
203
+ const ignoreFile = yield fs_1.ASYNC.readFile((0, path_1.join)(_targ.source, constants_1.FILENAME.catalyst_ignore));
204
+ const excludePatterns = [
205
+ '**/.DS_Store',
206
+ '**/.vscode/**/*',
207
+ `**/${constants_1.FILENAME.log}`,
208
+ `**/${constants_1.FILENAME.config}`,
209
+ `**/${constants_1.FILENAME.rc}`,
210
+ `**/${constants_1.FILENAME.app_config}`,
211
+ `**/${constants_1.FILENAME.catalyst_ignore}`,
212
+ ...((ignoreFile === null || ignoreFile === void 0 ? void 0 : ignoreFile.split('\n')) || [])
213
+ ];
197
214
  const folderContents = yield fs_1.ASYNC.walk(folderPath, {
198
215
  filter: {
199
- exclude: [
200
- '**/.DS_Store',
201
- '**/.vscode/**/*',
202
- `**/${constants_1.FILENAME.app_config}`,
203
- `**/${constants_1.FILENAME.catalyst_ignore}`,
204
- ...((ignoreFile === null || ignoreFile === void 0 ? void 0 : ignoreFile.split('\n')) || [])
205
- ],
216
+ exclude: (path) => __awaiter(void 0, void 0, void 0, function* () {
217
+ return !!excludePatterns.find((glob) => (0, minimatch_1.default)(path.replace(folderPath + path_1.sep, ''), glob, { dot: true }));
218
+ }),
206
219
  excludeDir: true
207
220
  }
208
221
  });
222
+ const zip = new archiver_1.default();
209
223
  folderContents.forEach((content) => {
210
224
  zip.add(content.path === folderPath
211
225
  ? (0, path_1.basename)(content.path)
@@ -234,6 +248,7 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
234
248
  }
235
249
  }
236
250
  catch (err) {
251
+ throbber.remove(throbberName);
237
252
  (0, logger_1.debug)(err);
238
253
  _targ.validity = {
239
254
  valid: false,
@@ -41,10 +41,10 @@ function orgAPI({ auth = true } = {}) {
41
41
  });
42
42
  }
43
43
  exports.orgAPI = orgAPI;
44
- function projectAPI({ auth = true, org = (0, project_1.getEnvId)() } = {}) {
44
+ function projectAPI({ auth = true, org = (0, project_1.getEnvId)(), printError = true } = {}) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
46
  const project = (yield Promise.resolve().then(() => __importStar(require('./lib/project')))).default;
47
- return new project({ authNeeded: auth }, org);
47
+ return new project({ authNeeded: auth, printError }, org);
48
48
  });
49
49
  }
50
50
  exports.projectAPI = projectAPI;
@@ -62,5 +62,23 @@ class TunnelAPI {
62
62
  });
63
63
  });
64
64
  }
65
+ tunnelCallback(status, details, data) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const res = yield new api_1.default(this.opts).post(`/baas/v1/project/${this.projectId}/tunneling/callback`, {
68
+ body: {
69
+ status,
70
+ content: Object.assign({}, details),
71
+ data
72
+ }
73
+ });
74
+ if (res.status >= 200 && res.status <= 299) {
75
+ return;
76
+ }
77
+ (0, logger_1.debug)(`tunnel callback response from server ::: status=${res.status} ::: body=${res.body}`);
78
+ throw new error_1.default('Server Error: Unexpected Response from server.', {
79
+ exit: 2
80
+ });
81
+ });
82
+ }
65
83
  }
66
84
  exports.default = TunnelAPI;
@@ -141,21 +141,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
141
141
  })
142
142
  }))).source
143
143
  };
144
- const appConfigPth = (0, path_1.join)(_appSailConfig.source, constants_1.FILENAME.app_config);
145
- const isAppConfig = yield fs_1.ASYNC.fileExists(appConfigPth);
146
144
  const existingSails = config_1.appSailConfig.raw() || [];
147
- yield prompt_1.default.register('file-path');
148
- const appSail = yield prompt_1.default.ask(prompt_1.default.question('buildPath', 'Please provide the build path of your AppSail service: ', {
149
- type: 'file-path',
150
- validate: (pth) => __awaiter(void 0, void 0, void 0, function* () {
151
- const buildPath = (0, path_1.resolve)(runtime_store_1.default.get('cwd'), pth.value);
152
- if ((yield fs_1.ASYNC.dirExists(buildPath)) || (yield fs_1.ASYNC.fileExists(buildPath))) {
153
- return true;
154
- }
155
- return 'Path does not exists';
156
- }),
157
- when: !_appSailConfig.build
158
- }), prompt_1.default.question('name', 'Please provide the name for your AppSail: ', {
145
+ const appName = yield prompt_1.default.ask(prompt_1.default.question('name', 'Please provide the name for your AppSail: ', {
159
146
  type: 'input',
160
147
  default: 'AppSail',
161
148
  validate: (name) => {
@@ -172,20 +159,45 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
172
159
  : true;
173
160
  }
174
161
  }));
175
- const appSailStack = _appSailConfig.stack ||
176
- (yield (0, common_1.getRuntimePromptAnswer)('Please choose a stack for your AppSail: '));
177
162
  const payload = {
178
- source: _appSailConfig.source,
179
- name: appSail.name
163
+ source: (0, path_1.relative)((0, project_1.getProjectRoot)(), _appSailConfig.source) || '.',
164
+ name: appName.name
180
165
  };
166
+ const appConfigPth = (0, path_1.join)(_appSailConfig.source, constants_1.FILENAME.app_config);
167
+ const isAppConfig = yield fs_1.ASYNC.fileExists(appConfigPth);
168
+ if (isAppConfig) {
169
+ (0, logger_1.info)();
170
+ (0, logger_1.warning)(`The ${(0, ansi_colors_1.bold)(constants_1.FILENAME.app_config)} file is already present in the appsail directory`);
171
+ }
172
+ const overWrite = yield prompt_1.default.ask(prompt_1.default.question('appConfig', 'Do you wish to overwrite the ' + constants_1.FILENAME.app_config, {
173
+ type: 'confirm',
174
+ default: false,
175
+ when: isAppConfig
176
+ }));
177
+ const activeWrite = overWrite.appConfig !== false;
178
+ if (!activeWrite) {
179
+ runtime_store_1.default.set('payload.appsail.targets', [payload]);
180
+ return;
181
+ }
182
+ const buildPath = yield prompt_1.default.ask(prompt_1.default.question('path', 'Please provide the build path of your AppSail service: ', {
183
+ type: 'input',
184
+ rootPath: _appSailConfig.source,
185
+ when: !_appSailConfig.build && activeWrite
186
+ }));
187
+ const appSailStack = _appSailConfig.stack ||
188
+ (yield (0, common_1.getRuntimePromptAnswer)('Please choose a stack for your AppSail: '));
181
189
  const appConfig = {
182
190
  command: _appSailConfig.command ||
183
- 'echo Please specify the start-up command in the app-config.json file under the key command',
184
- build_path: _appSailConfig.build || './' + (0, path_1.relative)(_appSailConfig.source, appSail.buildPath),
191
+ 'echo Please specify the start-up command in the app-config.json file under the key command for AppSail $X_ZC_RESOURCE_NAME',
192
+ build_path: _appSailConfig.build ||
193
+ ((0, path_1.isAbsolute)(buildPath.path)
194
+ ? (0, path_1.relative)(_appSailConfig.source, buildPath.path) || '.'
195
+ : buildPath.path),
185
196
  stack: appSailStack.runtime,
186
197
  env_variables: {},
187
198
  memory: _appSailConfig.memory || 256,
188
- scripts: _appSailConfig.scripts || {}
199
+ scripts: _appSailConfig.scripts || {},
200
+ raw: {}
189
201
  };
190
202
  if (appSailStack.lang === 'java') {
191
203
  const platform = yield prompt_1.default.ask(prompt_1.default.question('value', 'Please choose a platform for your AppSail: ', {
@@ -208,10 +220,5 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
208
220
  }
209
221
  }
210
222
  runtime_store_1.default.set('payload.appsail.targets', [payload]);
211
- if (isAppConfig) {
212
- (0, logger_1.message)((0, ansi_colors_1.bold)(`app-config.json`) + ` file already exist in ${(0, ansi_colors_1.underline)(_appSailConfig.source)}`);
213
- }
214
- else {
215
- yield fs_1.ASYNC.writeJSONFile(appConfigPth, appConfig);
216
- }
223
+ activeWrite && (yield fs_1.ASYNC.writeJSONFile(appConfigPth, appConfig));
217
224
  });
@@ -38,7 +38,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const index_js_1 = __importDefault(require("../../../prompt/index.js"));
39
39
  const index_js_2 = require("../../../util_modules/constants/index.js");
40
40
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
41
- var _a;
42
41
  const clientInitAnswer = yield index_js_1.default.ask(index_js_1.default.question('clientFlavour', 'Choose the type of client to initialise: ', {
43
42
  type: 'list',
44
43
  choices: index_js_2.PLUGIN.client.map((plugin) => {
@@ -48,5 +47,5 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
48
47
  });
49
48
  })
50
49
  }));
51
- return (yield (_a = './initializers/' + clientInitAnswer.clientFlavour, Promise.resolve().then(() => __importStar(require(_a))))).default();
50
+ return (yield Promise.resolve().then(() => __importStar(require('./initializers/' + clientInitAnswer.clientFlavour)))).default();
52
51
  });
@@ -34,26 +34,16 @@ const client_utils_1 = require("../../client-utils");
34
34
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
35
35
  var _a, _b;
36
36
  const orgAPI = yield (0, endpoints_1.orgAPI)();
37
- const projectAPIWithoutOrg = yield (0, endpoints_1.projectAPI)();
38
37
  const defaultRCProjectName = (0, project_1.getDefaultProjectName)(null);
39
38
  const defaultRCProjectId = (0, project_1.getDefaultProjectId)(null);
40
39
  if (defaultRCProjectName !== null &&
41
40
  defaultRCProjectId !== null &&
42
41
  !(0, option_1.getOptionValue)('force', false)) {
43
- (0, logger_1.message)(constants_1.FILENAME.rc + ' already has ' + (0, ansi_colors_1.bold)(defaultRCProjectName) + ' as a default project.');
44
- try {
45
- yield projectAPIWithoutOrg.getProject(defaultRCProjectId);
46
- throw new error_1.default('Skipping project setup, since project directory contains a default project. To overwrite use --force option');
47
- }
48
- catch (err) {
49
- if (js_1.JS.get(err, 'context.response.statusCode') !== 404) {
50
- throw err;
51
- }
52
- (0, logger_1.warning)('cleaning up ' +
53
- constants_1.FILENAME.rc +
54
- ' since the current default project for this folder is not found in remote');
55
- yield (0, project_1.removeProject)(defaultRCProjectId + '');
56
- }
42
+ (0, logger_1.message)(constants_1.FILENAME.rc +
43
+ ' already has ' +
44
+ (0, ansi_colors_1.bold)(defaultRCProjectName) +
45
+ ' as a default project. To overwrite use --force option');
46
+ throw new error_1.default('Skipping project setup, since project directory contains a default project. To overwrite use --force option', { skipHelp: true, exit: 0 });
57
47
  }
58
48
  const orgList = yield orgAPI.getAllOrgs();
59
49
  if (orgList.length === 0) {
@@ -47,7 +47,7 @@ const project_1 = require("../util_modules/project");
47
47
  const fs_1 = require("fs");
48
48
  const throbber_1 = __importDefault(require("../throbber"));
49
49
  class API {
50
- constructor({ authNeeded = true, resolveOnError = false, maxRetry = 3, env = constants_1.DEFAULT.env_name, log = {}, headers = {}, isExternal = false, origin = constants_1.ORIGIN.admin, showWarning = true, envId = (0, project_1.getEnvId)() } = {}) {
50
+ constructor({ authNeeded = true, resolveOnError = false, maxRetry = 3, env = constants_1.DEFAULT.env_name, log = {}, headers = {}, isExternal = false, origin = constants_1.ORIGIN.admin, showWarning = true, envId = (0, project_1.getEnvId)(), printError = true } = {}) {
51
51
  this.requestOpts = {
52
52
  url: origin,
53
53
  method: 'GET',
@@ -73,6 +73,7 @@ class API {
73
73
  this.maxRetryCount = maxRetry;
74
74
  this.retryCount = 0;
75
75
  this.showWarning = showWarning;
76
+ this.printError = printError;
76
77
  }
77
78
  _logReq() {
78
79
  let qs = this.requestOpts.qs
@@ -113,7 +114,9 @@ class API {
113
114
  (0, logger_1.debug)('TOTAL TIME TAKEN : ' + Number(resp.timings.end.toFixed(3)) + ' ms\n');
114
115
  (0, logger_1.debug)('REQUEST PHASES : ' + resp.timingPhases);
115
116
  }
116
- if (this.logOpts.progress !== undefined) {
117
+ if (resp.statusCode >= 200 &&
118
+ resp.statusCode < 300 &&
119
+ this.logOpts.progress !== undefined) {
117
120
  js_1.JS.set(this.logOpts, 'progress.total', resp.headers['content-length']);
118
121
  this.downloadProgress = new progress_1.default(this.logOpts.progress);
119
122
  }
@@ -153,11 +156,11 @@ class API {
153
156
  if (resp.statusCode >= 400 && !this.logOpts.skipRespBody) {
154
157
  (0, logger_1.debug)('Response Body : ' + JSON.stringify(resp.body) + '\n');
155
158
  if (!this.resolveOnHTTPError) {
156
- const errRes = (0, errorResponse_1.default)(resp, body);
159
+ const errRes = (0, errorResponse_1.default)(resp, body, !this.printError);
157
160
  this._logDownloadProgress({ error: errRes });
158
161
  throw errRes;
159
162
  }
160
- this._logDownloadProgress({ error: (0, errorResponse_1.default)(resp, body, true) });
163
+ this._logDownloadProgress({ error: (0, errorResponse_1.default)(resp, body, !this.printError) });
161
164
  }
162
165
  return {
163
166
  status: resp.statusCode,
@@ -188,6 +191,7 @@ class API {
188
191
  return new Promise((resolve, reject) => {
189
192
  const responseBuffer = [];
190
193
  let isJSONResponse = false;
194
+ let isErrorPage = false;
191
195
  const throbber = throbber_1.default.getInstance();
192
196
  if (this.logOpts.uploadProgress !== undefined &&
193
197
  this.logOpts.stream instanceof fs_1.ReadStream) {
@@ -230,6 +234,7 @@ class API {
230
234
  }))
231
235
  .on('response', (resp) => {
232
236
  isJSONResponse = js_1.JS.includes(resp.headers['content-type'], 'json');
237
+ isErrorPage = !(resp.statusCode >= 200 && resp.statusCode < 300);
233
238
  this._logResp(resp);
234
239
  })
235
240
  .on('complete', (resp, body) => __awaiter(this, void 0, void 0, function* () {
@@ -244,7 +249,9 @@ class API {
244
249
  if (isJSONResponse) {
245
250
  responseBuffer.push(data);
246
251
  }
247
- this._logDownloadProgress({ chunk: data });
252
+ if (!isErrorPage) {
253
+ this._logDownloadProgress({ chunk: data });
254
+ }
248
255
  });
249
256
  });
250
257
  });
@@ -252,6 +259,7 @@ class API {
252
259
  fire(method, path, options) {
253
260
  return __awaiter(this, void 0, void 0, function* () {
254
261
  this.resolveOnHTTPError = js_1.JS.get(options, 'resolveOnError', this.resolveOnHTTPError);
262
+ this.printError = (options === null || options === void 0 ? void 0 : options.printError) || this.printError;
255
263
  this.maxRetryCount = js_1.JS.get(options, 'maxRetry', this.maxRetryCount);
256
264
  this.authNeeded = js_1.JS.get(options, 'authNeeded', this.authNeeded);
257
265
  this.logOpts = js_1.JS.get(options, 'log', this.logOpts);
@@ -229,8 +229,7 @@ class Command {
229
229
  (0, logger_1.debug)(e);
230
230
  }
231
231
  yield Promise.all(js_1.JS.map(this.beforeRunners, (before) => __awaiter(this, void 0, void 0, function* () {
232
- var _a;
233
- const beforeModule = (yield (_a = '../command_needs/' + before.fn, Promise.resolve().then(() => __importStar(require(_a))))).default;
232
+ const beforeModule = (yield Promise.resolve().then(() => __importStar(require('../command_needs/' + before.fn)))).default;
234
233
  return beforeModule.call(this, before.args);
235
234
  })));
236
235
  return this.cmdAction.call(this, ...args);
@@ -44,7 +44,6 @@ const rc_1 = __importDefault(require("../internal/rc"));
44
44
  const fs_1 = require("../util_modules/fs");
45
45
  const logger_1 = require("../util_modules/logger");
46
46
  const runMigration = (rc, migFiles, idx = 0) => __awaiter(void 0, void 0, void 0, function* () {
47
- var _a;
48
47
  if (migFiles.length <= idx) {
49
48
  return Promise.resolve();
50
49
  }
@@ -55,7 +54,7 @@ const runMigration = (rc, migFiles, idx = 0) => __awaiter(void 0, void 0, void 0
55
54
  return runMigration(rc, migFiles, ++idx);
56
55
  }
57
56
  try {
58
- const migModule = yield (_a = migFile, Promise.resolve().then(() => __importStar(require(_a))));
57
+ const migModule = yield Promise.resolve().then(() => __importStar(require(migFile)));
59
58
  if (migModule.isRequire()) {
60
59
  (0, logger_1.debug)('migration started for v' + currentMigFileVersion);
61
60
  migModule.migrate();
@@ -84,7 +83,6 @@ const runMigration = (rc, migFiles, idx = 0) => __awaiter(void 0, void 0, void 0
84
83
  return runMigration(rc, migFiles, ++idx);
85
84
  });
86
85
  const runGlobalMigration = (migFiles) => __awaiter(void 0, void 0, void 0, function* () {
87
- var _b;
88
86
  if (migFiles.length === 0) {
89
87
  return;
90
88
  }
@@ -98,7 +96,7 @@ const runGlobalMigration = (migFiles) => __awaiter(void 0, void 0, void 0, funct
98
96
  return runGlobalMigration(migFiles);
99
97
  }
100
98
  try {
101
- const migModule = yield (_b = migFile, Promise.resolve().then(() => __importStar(require(_b))));
99
+ const migModule = yield Promise.resolve().then(() => __importStar(require(migFile)));
102
100
  if (migModule.isRequire()) {
103
101
  (0, logger_1.debug)('migration started for v' + currentMigFileVersion);
104
102
  migModule.migrate();
@@ -42,7 +42,6 @@ const async_js_1 = require("./util_modules/fs/lib/async.js");
42
42
  const error_js_1 = __importDefault(require("./error.js"));
43
43
  const ansi_colors_1 = require("ansi-colors");
44
44
  exports.default = (name, source) => __awaiter(void 0, void 0, void 0, function* () {
45
- var _a, _b;
46
45
  if (name === (0, path_1.basename)(name)) {
47
46
  const projectModulePath = (0, project_js_1.resolveProjectPath)((0, path_1.join)(source, 'node_modules', name));
48
47
  const projectModulePathExists = yield (0, async_js_1.dirExists)(projectModulePath);
@@ -54,7 +53,7 @@ exports.default = (name, source) => __awaiter(void 0, void 0, void 0, function*
54
53
  });
55
54
  }
56
55
  app_module_path_1.default.addPath(projectModulePath);
57
- return _a = projectModulePath, Promise.resolve().then(() => __importStar(require(_a)));
56
+ return Promise.resolve().then(() => __importStar(require(projectModulePath)));
58
57
  }
59
58
  const projectModulePath = (0, project_js_1.resolveProjectPath)(name);
60
59
  const projectModulePathExists = yield (0, async_js_1.dirExists)(projectModulePath);
@@ -66,5 +65,5 @@ exports.default = (name, source) => __awaiter(void 0, void 0, void 0, function*
66
65
  });
67
66
  }
68
67
  app_module_path_1.default.addPath(projectModulePath);
69
- return _b = projectModulePath, Promise.resolve().then(() => __importStar(require(_b)));
68
+ return Promise.resolve().then(() => __importStar(require(projectModulePath)));
70
69
  });
@@ -36,7 +36,7 @@ class InquirerFilePath extends inquirer_autocomplete_prompt_1.default {
36
36
  constructor(question, rl, answers) {
37
37
  const { rootPath = '.', exclude = [] } = question;
38
38
  const questionBase = Object.assign({
39
- emptyText: 'No valid file inside current directory!. Try giving the entire path and press ' +
39
+ emptyText: 'No valid file path inside current directory!. Try giving the entire path and press ' +
40
40
  (0, ansi_colors_1.cyan)('<return> ') +
41
41
  'key'
42
42
  }, question, {