zcatalyst-cli 1.18.0-beta.11 → 1.18.0-beta.11-slate

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 (50) hide show
  1. package/docs/commands/slate/unlink.toml +9 -0
  2. package/docs/option-filter.toml +5 -0
  3. package/docs/serve/server/lib/slate/index.toml +14 -0
  4. package/docs/slate-utils.toml +4 -0
  5. package/lib/archiver.js +18 -9
  6. package/lib/command_needs/auth.js +1 -1
  7. package/lib/command_needs/rc.js +40 -3
  8. package/lib/commands/deploy/index.js +6 -1
  9. package/lib/commands/deploy/slate.js +58 -0
  10. package/lib/commands/index.js +3 -0
  11. package/lib/commands/init.js +4 -0
  12. package/lib/commands/slate/create.js +60 -0
  13. package/lib/commands/slate/link.js +60 -0
  14. package/lib/commands/slate/unlink.js +74 -0
  15. package/lib/deploy/features/index.js +3 -0
  16. package/lib/deploy/features/slate.js +123 -0
  17. package/lib/endpoints/index.js +8 -1
  18. package/lib/endpoints/lib/slate.js +91 -0
  19. package/lib/fn-utils/lib/common.js +1 -1
  20. package/lib/init/features/appsail/index.js +1 -1
  21. package/lib/init/features/index.js +15 -2
  22. package/lib/init/features/project.js +1 -1
  23. package/lib/init/features/slate/index.js +308 -0
  24. package/lib/internal/api.js +1 -1
  25. package/lib/internal/command.js +9 -5
  26. package/lib/option-filter.js +8 -2
  27. package/lib/port-resolver.js +7 -0
  28. package/lib/prompt/types/file-path.js +8 -5
  29. package/lib/serve/features/index.js +8 -1
  30. package/lib/serve/features/slate.js +47 -0
  31. package/lib/serve/index.js +19 -0
  32. package/lib/serve/server/index.js +61 -1
  33. package/lib/serve/server/lib/appsail/index.js +1 -1
  34. package/lib/serve/server/lib/master/index.js +25 -21
  35. package/lib/serve/server/lib/master/slate.js +45 -0
  36. package/lib/serve/server/lib/master/utils.js +2 -2
  37. package/lib/serve/server/lib/slate/index.js +144 -0
  38. package/lib/serve/server/lib/slate/static-server.js +193 -0
  39. package/lib/slate-utils.js +212 -0
  40. package/lib/util_modules/config/index.js +3 -1
  41. package/lib/util_modules/config/lib/slate.js +94 -0
  42. package/lib/util_modules/constants/lib/default.js +4 -0
  43. package/lib/util_modules/constants/lib/file-names.js +7 -1
  44. package/lib/util_modules/constants/lib/folder-names.js +1 -0
  45. package/lib/util_modules/constants/lib/scopes.js +3 -1
  46. package/lib/util_modules/context-help.js +2 -2
  47. package/lib/util_modules/fs/lib/async.js +8 -1
  48. package/lib/util_modules/fs/lib/sync.js +6 -1
  49. package/lib/util_modules/parser/toml.js +20 -5
  50. package/package.json +2 -2
@@ -0,0 +1,9 @@
1
+ [SLULK-1]
2
+ context = '''No app linked to the Catalyst Slate service.'''
3
+ aid = '''Please link your existing slate app by running the command ${arg[0]}.'''
4
+ link = ''
5
+
6
+ [SLULK-2]
7
+ context = '''No slate app linked with the given name.'''
8
+ aid = '''Please check the available slate apps by running the command ${arg[0]} without any options.'''
9
+ link = ''
@@ -43,3 +43,8 @@ link = ''
43
43
  context = '''The API Gateway cannot be served seperately in local.'''
44
44
  aid = '''Please include atleast one other component like functions or client along with the APIG to serve the APIG in local.'''
45
45
  link = ''
46
+
47
+ [OPT-FILTER-10]
48
+ context = '''Slate does not have a serve support.'''
49
+ aid = '''Please start your Slate apps using the framework-specific commands.'''
50
+ link = ''
@@ -0,0 +1,14 @@
1
+ [SERVE-SLATE-1]
2
+ context = '''The given app is not configured with catalyst project.'''
3
+ aid = '''Please run the command ${arg[1]} to link your app with catalyst project.'''
4
+ link = ''
5
+
6
+ [SERVE-SLATE-2]
7
+ context = '''Not able to start the server using the given development command ${arg[1]}.'''
8
+ aid = '''Please provide a valid development command'''
9
+ link = ''
10
+
11
+ [SERVE-SLATE-3]
12
+ context = '''Error when installing the dependencies.'''
13
+ aid = '''Please install the necessary packages before running the command ${arg[1]}'''
14
+ link = ''
@@ -0,0 +1,4 @@
1
+ [SLATE-UTILS-1]
2
+ context = '''The slate source directory ${arg[0]} does not exist.'''
3
+ aid = '''Please specify a valid source directory for the slate.'''
4
+ link = 'https://www.zoho.com/catalyst/help/slate-client.html'
package/lib/archiver.js CHANGED
@@ -55,25 +55,34 @@ class Archiver {
55
55
  this.jszip = (0, jszip_1.loadAsync)(content, { createFolders });
56
56
  return this;
57
57
  }
58
- _writeFolder(folder, to, recursive = false, ignoreInitial = false) {
58
+ _writeFolder(folder, to, recursive = false, ignoreLevel = 1) {
59
59
  return __awaiter(this, void 0, void 0, function* () {
60
- return this._writeAllFile(folder.filter((_relPath, file) => !file.dir), to, recursive, ignoreInitial);
60
+ return this._writeAllFile(folder.filter((_relPath, file) => !file.dir), to, recursive, ignoreLevel);
61
61
  });
62
62
  }
63
- _writeAllFile(files, to, recursive = false, ignoreInitial = false) {
63
+ _writeAllFile(files, to, recursive = false, ignoreLevel = 0) {
64
64
  return __awaiter(this, void 0, void 0, function* () {
65
65
  while (files.length > 0) {
66
66
  const limit = files.length < Archiver.maxWriteLimit ? files.length : Archiver.maxWriteLimit;
67
67
  yield Promise.all(files.splice(0, limit).map((file) => __awaiter(this, void 0, void 0, function* () {
68
- const filePath = (0, path_1.join)(to, (0, path_1.dirname)(ignoreInitial ? file.name.substr(file.name.indexOf('/') + 1) : file.name));
68
+ const findIgnoreIndex = () => {
69
+ let index = 0, level = ignoreLevel;
70
+ while (level > 0) {
71
+ index = file.name.indexOf('/', index + 1);
72
+ level--;
73
+ }
74
+ return index;
75
+ };
76
+ const filePath = (0, path_1.join)(to, (0, path_1.dirname)(ignoreLevel !== 0
77
+ ? file.name.substring(findIgnoreIndex() + 1)
78
+ : file.name));
69
79
  yield fs_1.ASYNC.ensureDir(filePath);
70
80
  if (file.name.endsWith('.zip') && recursive) {
71
81
  const zipContent = yield file.async('nodebuffer');
72
82
  return new Archiver()
73
83
  .load(zipContent)
74
84
  .extract((0, path_1.join)(filePath, (0, path_1.basename)(file.name).replace('.zip', '')), '/', {
75
- recursive,
76
- ignoreInitial
85
+ recursive
77
86
  })
78
87
  .finalize();
79
88
  }
@@ -127,7 +136,7 @@ class Archiver {
127
136
  return fileObjArr[0].async('string');
128
137
  });
129
138
  }
130
- extract(to, from = '/', { isFolder = true, recursive = false, ignoreInitial = false } = {}) {
139
+ extract(to, from = '/', { isFolder = true, recursive = false, ignoreLevel = 0 } = {}) {
131
140
  const extractPromise = this.jszip.then((zip) => __awaiter(this, void 0, void 0, function* () {
132
141
  if (isFolder) {
133
142
  let folder = null;
@@ -152,7 +161,7 @@ class Archiver {
152
161
  exit: 2
153
162
  });
154
163
  }
155
- yield this._writeFolder(folder, to, recursive, ignoreInitial);
164
+ yield this._writeFolder(folder, to, recursive, ignoreLevel);
156
165
  return true;
157
166
  }
158
167
  const fromFileObj = [];
@@ -170,7 +179,7 @@ class Archiver {
170
179
  exit: 2
171
180
  });
172
181
  }
173
- yield this._writeAllFile(fromFileObj, to, recursive, ignoreInitial);
182
+ yield this._writeAllFile(fromFileObj, to, recursive, ignoreLevel);
174
183
  return true;
175
184
  }));
176
185
  this.promiseArr.push(extractPromise);
@@ -23,7 +23,7 @@ exports.default = (inScopes = []) => {
23
23
  },
24
24
  {
25
25
  option: 'CATALYST_TOKEN env',
26
- token: (0, env_1.getEnvVariable)('CATALYST_TOKEN'),
26
+ token: (0, env_1.getEnvVariable)('CATALYST_TOKEN', (0, env_1.getEnvVariable)('ZC_TOKEN')),
27
27
  temp: true
28
28
  },
29
29
  {
@@ -27,13 +27,26 @@ const project_2 = require("../util_modules/project");
27
27
  const config_store_1 = __importDefault(require("../config-store"));
28
28
  const dc_1 = require("../dc");
29
29
  const env_1 = require("../util_modules/env");
30
- exports.default = ({ optional = false, resolveOnNotFound = false, skipOrgCheck = true } = {}) => __awaiter(void 0, void 0, void 0, function* () {
30
+ const features_1 = require("../init/features");
31
+ exports.default = ({ optional = false, resolveOnNotFound = false, skipOrgCheck = true, skipProjectCheck = true, generateRc = false } = {}) => __awaiter(void 0, void 0, void 0, function* () {
31
32
  const globOrgOpt = (0, option_1.getGlobalOptionValue)('org', null);
32
- const orgOpt = globOrgOpt ? globOrgOpt : (0, env_1.getEnvVariable)('CATALYST_ORG', null);
33
+ const orgOpt = globOrgOpt
34
+ ? globOrgOpt
35
+ : (0, env_1.getEnvVariable)('CATALYST_ORG', (0, env_1.getEnvVariable)('ZC_ORG_ID', null));
33
36
  const globProjectOpt = (0, option_1.getGlobalOptionValue)('project', null);
34
37
  const projectOpt = globProjectOpt
35
38
  ? globProjectOpt
36
- : (0, env_1.getEnvVariable)('CATALYST_PROJECT_ID', (0, env_1.getEnvVariable)('CATALYST_PROJECT', null));
39
+ : (0, env_1.getEnvVariable)('CATALYST_PROJECT_ID', (0, env_1.getEnvVariable)('CATALYST_PROJECT', (0, env_1.getEnvVariable)('ZC_PROJECT_ID', null)));
40
+ if (env_1.isCI) {
41
+ if (orgOpt && projectOpt) {
42
+ runtime_store_1.default.set('project.id', projectOpt);
43
+ runtime_store_1.default.set('project.env.id', orgOpt + '');
44
+ return;
45
+ }
46
+ throw new error_1.default('Org and Project Id cannot be empty.', {
47
+ exit: 1
48
+ });
49
+ }
37
50
  const orgApi = yield (0, endpoints_1.orgAPI)();
38
51
  if (orgOpt !== null) {
39
52
  const orgList = yield orgApi.getAllOrgs();
@@ -139,6 +152,30 @@ exports.default = ({ optional = false, resolveOnNotFound = false, skipOrgCheck =
139
152
  const selectedOrg = orgAns.org || orgList[0];
140
153
  runtime_store_1.default.set('project.env.id', selectedOrg.id);
141
154
  }
155
+ if (!skipProjectCheck) {
156
+ const projectList = yield (yield (0, endpoints_1.projectAPI)()).getAllProjects();
157
+ const projectChoice = projectList.map((project) => prompt_1.default.choice(project.project_name + ' (' + project.id + ')', {
158
+ value: project,
159
+ short: project.project_name
160
+ }));
161
+ const projectAns = yield prompt_1.default.ask(prompt_1.default.question('project', 'Select a Catalyst Project to continue: ', {
162
+ type: 'list',
163
+ choices: js_1.JS.reverse(projectChoice),
164
+ when: projectChoice.length > 0
165
+ }));
166
+ const selectedProject = projectAns.project || projectList[0];
167
+ runtime_store_1.default.set('project.id', selectedProject.id);
168
+ }
169
+ if (generateRc) {
170
+ (0, logger_1.warning)('Not in Catalyst app directory!!!');
171
+ const stagedAns = yield prompt_1.default.ask(prompt_1.default.question('consent', 'Do you wish to initialize the catalyst project in this directory?', {
172
+ type: 'confirm',
173
+ defaultAns: true
174
+ }));
175
+ if (stagedAns.consent) {
176
+ yield (0, features_1.project)();
177
+ }
178
+ }
142
179
  if (optional || ignoreRC) {
143
180
  return;
144
181
  }
@@ -36,11 +36,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const utils_1 = require("../../deploy/features/appsail/utils");
39
+ const slate_1 = require("../../deploy/features/slate");
39
40
  const command_1 = __importDefault(require("../../internal/command"));
40
41
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
41
42
  const constants_1 = require("../../util_modules/constants");
42
43
  const logger_1 = require("../../util_modules/logger");
43
44
  const appsail_1 = __importDefault(require("./appsail"));
45
+ const slate_2 = __importDefault(require("./slate"));
44
46
  exports.default = new command_1.default('deploy')
45
47
  .description('Deploy the Catalyst project and project resources to the Catalyst development environment from the local directory')
46
48
  .option('--only <targets>', 'only deploy specified, comma-separated targets (e.g. "functions,client,appsail").' +
@@ -51,7 +53,7 @@ exports.default = new command_1.default('deploy')
51
53
  .needs('auth', [constants_1.SCOPE.functions, constants_1.SCOPE.webapp, constants_1.SCOPE.appsail_update])
52
54
  .needs('config')
53
55
  .needs('rc', { optional: true })
54
- .addSubCommand(appsail_1.default)
56
+ .addSubCommand(appsail_1.default, slate_2.default)
55
57
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
56
58
  const optionFilter = yield Promise.resolve().then(() => __importStar(require('../../option-filter')));
57
59
  optionFilter.filterTargets();
@@ -74,6 +76,9 @@ exports.default = new command_1.default('deploy')
74
76
  (0, logger_1.labeled)(deploytarget, 'URL => ' + runtime_store_1.default.get('payload.client.url')).MESSAGE();
75
77
  (0, logger_1.info)();
76
78
  break;
79
+ case 'slate':
80
+ (0, slate_1.slateLogger)();
81
+ break;
77
82
  case 'apig':
78
83
  (0, logger_1.labeled)(deploytarget, 'deploy scheduled successfully').SUCCESS();
79
84
  (0, logger_1.info)();
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const slate_1 = require("../../deploy/features/slate");
39
+ const command_1 = __importDefault(require("../../internal/command"));
40
+ const logger_1 = require("../../util_modules/logger");
41
+ exports.default = new command_1.default('slate')
42
+ .description('Deploy your Catalyst Slate service to Catalyst Development environment')
43
+ .option('-m <msg>', 'Please provide the description for your app deployment.')
44
+ .option('--production', 'Deploy the slate app to production environment.')
45
+ .needs('auth')
46
+ .needs('config', { optional: true })
47
+ .needs('rc', { optional: true })
48
+ .action(() => __awaiter(void 0, void 0, void 0, function* () {
49
+ yield (yield Promise.resolve().then(() => __importStar(require('../../deploy')))).default('slate');
50
+ (0, logger_1.info)();
51
+ const deployTargets = (0, slate_1.slateLogger)();
52
+ if (deployTargets.length === 0) {
53
+ (0, logger_1.error)('Slate Deploy failed');
54
+ }
55
+ else {
56
+ (0, logger_1.success)('Catalyst Slate Deploy completed successfully');
57
+ }
58
+ }));
@@ -77,6 +77,9 @@ exports.default = (client) => {
77
77
  loadCommand('functions:shell'),
78
78
  loadCommand('functions:config'),
79
79
  loadCommand('appsail:add'),
80
+ loadCommand('slate:link'),
81
+ loadCommand('slate:create'),
82
+ loadCommand('slate:unlink'),
80
83
  loadCommand('codelib:install'),
81
84
  loadCommand('event:generate'),
82
85
  loadCommand('event:generate:integ'),
@@ -125,6 +125,10 @@ exports.default = new command_1.default('init [feature]')
125
125
  prompt_1.default.choice('AppSail: Configure and deploy AppSail services', {
126
126
  value: 'appsail',
127
127
  short: 'AppSail'
128
+ }),
129
+ prompt_1.default.choice('Slate: Configure and deploy slate apps', {
130
+ value: 'slate',
131
+ short: 'Slate'
128
132
  })
129
133
  ],
130
134
  when: !runtime_store_1.default.get('payload.project.import', false) &&
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const ansi_colors_1 = require("ansi-colors");
39
+ const command_1 = __importDefault(require("../../internal/command"));
40
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
41
+ const constants_1 = require("../../util_modules/constants");
42
+ const logger_1 = require("../../util_modules/logger");
43
+ exports.default = new command_1.default('slate:create')
44
+ .description('Configure a new slate service in catalyst')
45
+ .option('--name <app_name>', 'Please provide name for your slate')
46
+ .option('--framework <framework_name>', 'Specify frame work name for your slate')
47
+ .option('--template <template_url>', 'Provide template url for your slate')
48
+ .option('--default', 'Set default app configurations')
49
+ .option('--production', 'Set production app configurations')
50
+ .needs('auth')
51
+ .needs('config', { optional: true })
52
+ .needs('rc', { optional: true, generateRc: true })
53
+ .action(() => __awaiter(void 0, void 0, void 0, function* () {
54
+ const config = runtime_store_1.default.get('config');
55
+ yield (yield Promise.resolve().then(() => __importStar(require('../../init/features')))).slate();
56
+ yield config.save();
57
+ (0, logger_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) + ' file has been successfully updated with slate details.');
58
+ (0, logger_1.info)();
59
+ (0, logger_1.success)('Slate created successfully');
60
+ }));
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const ansi_colors_1 = require("ansi-colors");
39
+ const command_1 = __importDefault(require("../../internal/command"));
40
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
41
+ const constants_1 = require("../../util_modules/constants");
42
+ const logger_1 = require("../../util_modules/logger");
43
+ exports.default = new command_1.default('slate:link')
44
+ .description('Configure your existing app in slate service')
45
+ .option('--name <app_name>', 'Please provide name for your slate')
46
+ .option('--framework <framework_name>', 'Specify frame work name for your slate')
47
+ .option('--template <template_url>', 'Provide template url for your slate')
48
+ .option('--default', 'Set default app configurations')
49
+ .option('--production', 'Create a app with production configurations')
50
+ .needs('auth')
51
+ .needs('config', { optional: true })
52
+ .needs('rc', { optional: true, generateRc: true })
53
+ .action(() => __awaiter(void 0, void 0, void 0, function* () {
54
+ const config = runtime_store_1.default.get('config');
55
+ yield (yield Promise.resolve().then(() => __importStar(require('../../init/features')))).slate(true);
56
+ yield config.save();
57
+ (0, logger_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) + ' file has been successfully updated with slate details.');
58
+ (0, logger_1.info)();
59
+ (0, logger_1.success)('Slate linked successfully');
60
+ }));
@@ -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 ansi_colors_1 = require("ansi-colors");
16
+ const command_1 = __importDefault(require("../../internal/command"));
17
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
18
+ const constants_1 = require("../../util_modules/constants");
19
+ const logger_1 = require("../../util_modules/logger");
20
+ const option_1 = require("../../util_modules/option");
21
+ const prompt_1 = __importDefault(require("../../prompt"));
22
+ const config_1 = require("../../util_modules/config");
23
+ const fs_1 = require("../../util_modules/fs");
24
+ const error_1 = __importDefault(require("../../error"));
25
+ const path_1 = require("path");
26
+ exports.default = new command_1.default('slate:unlink')
27
+ .description('Unlink your existing slate app')
28
+ .option('--name <app_name>', 'Please provide name for your slate app')
29
+ .needs('auth')
30
+ .needs('config')
31
+ .needs('rc')
32
+ .action(() => __awaiter(void 0, void 0, void 0, function* () {
33
+ const config = runtime_store_1.default.get('config');
34
+ let appName = (0, option_1.getOptionValue)('name', false);
35
+ const slateServices = config_1.slateConfig.raw();
36
+ if ((slateServices === null || slateServices === void 0 ? void 0 : slateServices.length) === 0 || !slateServices) {
37
+ throw new error_1.default('No slates found.', {
38
+ exit: 1,
39
+ errorId: 'SLULK-1',
40
+ arg: [(0, ansi_colors_1.bold)('catalyst slate:link')]
41
+ });
42
+ }
43
+ if (!appName) {
44
+ const { name } = yield prompt_1.default.ask(prompt_1.default.question('name', 'Please select the slate app you want to delete', {
45
+ type: 'list',
46
+ choices: slateServices
47
+ }));
48
+ appName = name;
49
+ }
50
+ const slateDetails = slateServices.find((slate) => slate.name === appName);
51
+ if (!slateDetails) {
52
+ throw new error_1.default(`No slates match the given name ${appName}.`, {
53
+ exit: 1,
54
+ errorId: 'SLULK-2',
55
+ arg: [(0, ansi_colors_1.bold)('catalyst slate:unlink')]
56
+ });
57
+ }
58
+ const { removeSource } = yield prompt_1.default.ask(prompt_1.default.question('removeSource', `Do you want to delete the source?`, {
59
+ type: 'confirm',
60
+ default: false
61
+ }));
62
+ if (removeSource) {
63
+ fs_1.ASYNC.deleteDir(slateDetails.source);
64
+ }
65
+ else {
66
+ fs_1.ASYNC.deleteDir((0, path_1.join)(slateDetails.source, '.catalyst'));
67
+ }
68
+ config.unset('slate');
69
+ config.set('slate', slateServices.filter((slateCon) => slateCon.name !== appName));
70
+ yield config.save();
71
+ (0, logger_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) + ' file has been updated.');
72
+ (0, logger_1.info)();
73
+ (0, logger_1.success)('Slate unlinked successfully');
74
+ }));
@@ -39,6 +39,9 @@ exports.default = {
39
39
  client: () => __awaiter(void 0, void 0, void 0, function* () {
40
40
  return (yield Promise.resolve().then(() => __importStar(require('./client')))).default();
41
41
  }),
42
+ slate: () => __awaiter(void 0, void 0, void 0, function* () {
43
+ return (yield Promise.resolve().then(() => __importStar(require('./slate')))).default();
44
+ }),
42
45
  apig: () => __awaiter(void 0, void 0, void 0, function* () {
43
46
  return (yield Promise.resolve().then(() => __importStar(require('./apig')))).default();
44
47
  }),
@@ -0,0 +1,123 @@
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.slateLogger = exports.getEnvironmentType = void 0;
16
+ const slate_utils_1 = require("../../slate-utils");
17
+ const endpoints_1 = require("../../endpoints");
18
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
19
+ const error_1 = __importDefault(require("../../error"));
20
+ const config_1 = require("../../util_modules/config");
21
+ const throbber_1 = __importDefault(require("../../throbber"));
22
+ const logger_1 = require("../../util_modules/logger");
23
+ const ansi_colors_1 = require("ansi-colors");
24
+ const option_1 = require("../../util_modules/option");
25
+ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const dId = process.env.ZC_APP_DEPLOYMENT_BUILD_ID;
27
+ const env = getEnvironmentType();
28
+ if (!dId) {
29
+ const targets = yield config_1.slateConfig.getAllTargetDetails(false);
30
+ if (!targets || targets.length === 0) {
31
+ throw new error_1.default('No targets found');
32
+ }
33
+ const filtered = slate_utils_1.slateUtils.filterTargets(targets);
34
+ const validTargets = filtered.filter((targ) => {
35
+ var _a, _b;
36
+ if ((_a = targ.validity) === null || _a === void 0 ? void 0 : _a.valid) {
37
+ return targ;
38
+ }
39
+ (0, logger_1.labeled)('Slate: ', 'Invalid Slate service ' + (0, ansi_colors_1.bold)(targ.name || 'Unknown')).ERROR();
40
+ (0, logger_1.error)('Reason: ' + ((_b = targ.validity) === null || _b === void 0 ? void 0 : _b.reason));
41
+ (0, logger_1.info)();
42
+ return false;
43
+ });
44
+ if (validTargets.length === 0) {
45
+ throw new error_1.default('No valid Slate services found to deploy', {
46
+ skipHelp: true
47
+ });
48
+ }
49
+ const slateAppConfigs = yield (yield (0, endpoints_1.slateAPI)({ env })).getAllApps();
50
+ const throbber = throbber_1.default.getInstance();
51
+ const deployRes = yield validTargets.reduce((result, _targ) => __awaiter(void 0, void 0, void 0, function* () {
52
+ var _a;
53
+ const targ = _targ;
54
+ const prevRes = yield result;
55
+ try {
56
+ const throbberName = `prepare_slate_${targ.name}`;
57
+ throbber.add(throbberName, {
58
+ text: `Preparing Slate[${targ.name}]`
59
+ });
60
+ const isAppExists = slateAppConfigs.find((app) => app.name === targ.name);
61
+ const configDetails = !isAppExists
62
+ ? (_a = (yield config_1.slateConfig.getTargetDetails(targ))) === null || _a === void 0 ? void 0 : _a.config
63
+ : undefined;
64
+ const readStream = yield slate_utils_1.slateUtils.pack(targ.source);
65
+ throbber.remove(throbberName);
66
+ yield (yield (0, endpoints_1.slateAPI)({ env })).deploy(readStream.stream, readStream.length, targ.name, '', isAppExists === null || isAppExists === void 0 ? void 0 : isAppExists.id, configDetails ? JSON.stringify(configDetails) : '', (0, option_1.getOptionValue)('m') || '');
67
+ }
68
+ catch (err) {
69
+ (0, logger_1.debug)(err);
70
+ _targ.validity = {
71
+ valid: false,
72
+ reason: error_1.default.getErrorInstance(err).message
73
+ };
74
+ }
75
+ prevRes.push(_targ);
76
+ return Promise.resolve(prevRes);
77
+ }), Promise.resolve([]));
78
+ const deployedValidTargets = deployRes.filter((targ) => {
79
+ var _a, _b, _c;
80
+ if (!((_a = targ.validity) === null || _a === void 0 ? void 0 : _a.valid)) {
81
+ (0, logger_1.warning)('Deploy of Slate [' +
82
+ targ.name +
83
+ '] was unsuccessful since ' +
84
+ ((_b = targ.validity) === null || _b === void 0 ? void 0 : _b.reason));
85
+ }
86
+ return (_c = targ.validity) === null || _c === void 0 ? void 0 : _c.valid;
87
+ });
88
+ runtime_store_1.default.set('payload.slate.targets', deployedValidTargets);
89
+ if (deployedValidTargets.length > 0) {
90
+ runtime_store_1.default.set('payload.slate.deploy', true);
91
+ }
92
+ }
93
+ else {
94
+ const source = runtime_store_1.default.get('cwd');
95
+ yield slate_utils_1.slateUtils.validate(source);
96
+ const readStream = yield slate_utils_1.slateUtils.pack();
97
+ try {
98
+ const deployRes = yield (yield (0, endpoints_1.slateAPI)({ env })).deploy(readStream.stream, readStream.length, process.env.ZC_APP_NAME, dId);
99
+ deployRes.name = process.env.ZC_APP_NAME;
100
+ runtime_store_1.default.set('payload.slate.targets', [deployRes]);
101
+ runtime_store_1.default.set('payload.slate.deploy', true);
102
+ }
103
+ catch (err) {
104
+ throw err;
105
+ }
106
+ }
107
+ });
108
+ function getEnvironmentType() {
109
+ var _a;
110
+ const isProduction = (0, option_1.getOptionValue)('production', false) ||
111
+ ((_a = process.env.ZC_ENVIRONMENT) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'production';
112
+ return isProduction ? 'Production' : 'Development';
113
+ }
114
+ exports.getEnvironmentType = getEnvironmentType;
115
+ function slateLogger() {
116
+ const deployTargets = runtime_store_1.default.get('payload.slate.targets', []);
117
+ deployTargets.forEach((slate) => {
118
+ (0, logger_1.labeled)(`Slate(${slate.name})`, 'deploy successful').SUCCESS();
119
+ (0, logger_1.info)();
120
+ });
121
+ return deployTargets;
122
+ }
123
+ exports.slateLogger = slateLogger;