zcatalyst-cli 1.26.2 → 1.27.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 (151) hide show
  1. package/README.md +1 -0
  2. package/lib/authentication/credential.d.ts +2 -1
  3. package/lib/authentication/credential.js +20 -3
  4. package/lib/authentication/crypt.d.ts +7 -3
  5. package/lib/authentication/crypt.js +87 -16
  6. package/lib/authentication/index.js +1 -0
  7. package/lib/authentication/key-manager.d.ts +7 -0
  8. package/lib/authentication/key-manager.js +62 -0
  9. package/lib/authentication/login.js +20 -20
  10. package/lib/bin/catalyst.js +1 -15
  11. package/lib/client.d.ts +3 -1
  12. package/lib/client.js +16 -5
  13. package/lib/command_needs/rc.js +13 -3
  14. package/lib/commands/appsail/add.js +10 -0
  15. package/lib/commands/client/delete.js +18 -6
  16. package/lib/commands/client/setup.js +7 -0
  17. package/lib/commands/deploy/index.js +3 -3
  18. package/lib/commands/deploy/slate.js +65 -4
  19. package/lib/commands/functions/add.js +7 -0
  20. package/lib/commands/functions/delete.js +22 -4
  21. package/lib/commands/functions/execute.js +39 -71
  22. package/lib/commands/functions/setup.js +13 -0
  23. package/lib/commands/functions/shell.js +15 -1
  24. package/lib/commands/iac/import.js +2 -2
  25. package/lib/commands/init.js +34 -20
  26. package/lib/commands/login.js +1 -0
  27. package/lib/commands/pull.js +22 -1
  28. package/lib/commands/serve.js +2 -1
  29. package/lib/commands/slate/create.js +7 -4
  30. package/lib/commands/slate/link.js +11 -5
  31. package/lib/commands/slate/unlink.js +7 -0
  32. package/lib/commands/zest/generate/index.js +28 -35
  33. package/lib/deploy/features/slate.d.ts +3 -1
  34. package/lib/deploy/features/slate.js +204 -5
  35. package/lib/docs/client-utils.toml +0 -5
  36. package/lib/docs/command_needs/rc.toml +9 -1
  37. package/lib/docs/commands/client/delete.toml +4 -0
  38. package/lib/docs/commands/deploy/slate.toml +3 -0
  39. package/lib/docs/commands/functions/delete.toml +10 -0
  40. package/lib/docs/commands/functions/execute.toml +1 -16
  41. package/lib/docs/commands/functions/setup.toml +3 -0
  42. package/lib/docs/commands/functions/shell.toml +8 -0
  43. package/lib/docs/commands/init.toml +3 -0
  44. package/lib/docs/commands/pull.toml +6 -0
  45. package/lib/docs/commands/slate/unlink.toml +6 -0
  46. package/lib/docs/execute/command-utils.toml +14 -0
  47. package/lib/docs/execute/execute-input-resolver.toml +37 -0
  48. package/lib/docs/init/features/project.toml +20 -0
  49. package/lib/docs/init/util/client.toml +4 -0
  50. package/lib/docs/prompt/index.toml +15 -0
  51. package/lib/docs/pull/features/apig.toml +6 -0
  52. package/lib/docs/pull/features/client.toml +20 -0
  53. package/lib/docs/pull/features/functions/index.toml +24 -0
  54. package/lib/endpoints/lib/slate.d.ts +14 -1
  55. package/lib/endpoints/lib/slate.js +35 -0
  56. package/lib/error/context-help.js +1 -1
  57. package/lib/error/index.js +9 -13
  58. package/lib/execute/command-utils.d.ts +5 -0
  59. package/lib/execute/command-utils.js +86 -0
  60. package/lib/execute/execute-input-resolver.d.ts +29 -0
  61. package/lib/execute/execute-input-resolver.js +207 -0
  62. package/lib/execute/index.d.ts +4 -1
  63. package/lib/execute/index.js +3 -2
  64. package/lib/fn-utils/lib/integ.js +22 -17
  65. package/lib/index.js +1 -0
  66. package/lib/init/dependencies/package-json.js +11 -7
  67. package/lib/init/features/appsail/index.js +75 -26
  68. package/lib/init/features/appsail/prompt-fields.d.ts +43 -0
  69. package/lib/init/features/appsail/prompt-fields.js +55 -0
  70. package/lib/init/features/appsail/utils/custom-runtime.d.ts +3 -0
  71. package/lib/init/features/appsail/utils/custom-runtime.js +161 -0
  72. package/lib/init/features/appsail/{utils.d.ts → utils/index.d.ts} +2 -2
  73. package/lib/init/features/appsail/utils/index.js +170 -0
  74. package/lib/init/features/client/index.js +4 -3
  75. package/lib/init/features/client/initializers/angular.js +3 -2
  76. package/lib/init/features/client/initializers/react.js +4 -3
  77. package/lib/init/features/client/prompt-fields.d.ts +37 -0
  78. package/lib/init/features/client/prompt-fields.js +48 -0
  79. package/lib/init/features/functions/index.js +37 -8
  80. package/lib/init/features/functions/languages/java.js +42 -7
  81. package/lib/init/features/functions/languages/node.js +42 -10
  82. package/lib/init/features/functions/languages/python.js +42 -7
  83. package/lib/init/features/functions/prompt-fields.d.ts +25 -0
  84. package/lib/init/features/functions/prompt-fields.js +34 -0
  85. package/lib/init/features/project.js +41 -6
  86. package/lib/init/features/slate/index.js +2 -0
  87. package/lib/init/features/slate/prompt-fields.d.ts +31 -0
  88. package/lib/init/features/slate/prompt-fields.js +41 -0
  89. package/lib/init/index.js +2 -1
  90. package/lib/init/util/client.js +11 -8
  91. package/lib/init/util/common.d.ts +2 -0
  92. package/lib/init/util/common.js +33 -3
  93. package/lib/init/util/prompt-fields.d.ts +7 -0
  94. package/lib/init/util/prompt-fields.js +13 -0
  95. package/lib/internal/command.d.ts +3 -0
  96. package/lib/internal/command.js +26 -3
  97. package/lib/migration/global/1.27.0.d.ts +2 -0
  98. package/lib/migration/global/1.27.0.js +39 -0
  99. package/lib/prompt/choice.d.ts +2 -0
  100. package/lib/prompt/choice.js +24 -0
  101. package/lib/prompt/cli-option-key.d.ts +1 -0
  102. package/lib/prompt/cli-option-key.js +10 -0
  103. package/lib/prompt/index.d.ts +6 -22
  104. package/lib/prompt/index.js +264 -67
  105. package/lib/prompt/overwrite-prompt.d.ts +11 -0
  106. package/lib/prompt/overwrite-prompt.js +16 -0
  107. package/lib/prompt/question-factory.d.ts +34 -0
  108. package/lib/prompt/question-factory.js +41 -0
  109. package/lib/prompt/register-fields.d.ts +24 -0
  110. package/lib/prompt/register-fields.js +37 -0
  111. package/lib/pull/features/apig.js +57 -6
  112. package/lib/pull/features/client.js +107 -24
  113. package/lib/pull/features/functions/index.js +100 -4
  114. package/lib/pull/index.js +1 -1
  115. package/lib/pull/utils.d.ts +13 -0
  116. package/lib/pull/utils.js +20 -0
  117. package/lib/repl-server.d.ts +4 -0
  118. package/lib/repl-server.js +9 -0
  119. package/lib/serve/server/lib/master/index.js +3 -3
  120. package/lib/serve/server/lib/slate/static-server.js +2 -2
  121. package/lib/serve/server/lib/web_client/server.js +2 -2
  122. package/lib/shell/format-functions.d.ts +4 -0
  123. package/lib/shell/format-functions.js +59 -0
  124. package/lib/shell/index.js +18 -0
  125. package/lib/util_modules/config/lib/appsail.d.ts +3 -2
  126. package/lib/util_modules/config/lib/appsail.js +6 -3
  127. package/lib/util_modules/config/lib/slate.d.ts +19 -0
  128. package/lib/util_modules/config-store.d.ts +1 -0
  129. package/lib/util_modules/config-store.js +29 -10
  130. package/lib/util_modules/constants/index.d.ts +0 -1
  131. package/lib/util_modules/constants/index.js +1 -3
  132. package/lib/util_modules/constants/lib/urls.d.ts +2 -0
  133. package/lib/util_modules/constants/lib/urls.js +4 -0
  134. package/lib/util_modules/dc.d.ts +6 -1
  135. package/lib/util_modules/dc.js +21 -8
  136. package/lib/util_modules/env.d.ts +3 -0
  137. package/lib/util_modules/env.js +41 -0
  138. package/lib/util_modules/fs/lib/sync.d.ts +1 -0
  139. package/lib/util_modules/fs/lib/sync.js +19 -0
  140. package/lib/util_modules/logger/utils.d.ts +1 -0
  141. package/lib/util_modules/logger/utils.js +5 -1
  142. package/lib/util_modules/option.d.ts +1 -0
  143. package/lib/util_modules/option.js +8 -0
  144. package/lib/util_modules/{server.js → server/index.js} +3 -3
  145. package/lib/util_modules/server/needed-scopes.d.ts +1 -0
  146. package/lib/util_modules/{constants/lib → server}/needed-scopes.js +7 -7
  147. package/package.json +3 -2
  148. package/lib/init/features/appsail/utils.js +0 -273
  149. package/lib/util_modules/constants/lib/needed-scopes.d.ts +0 -4
  150. /package/lib/docs/{dc.toml → util_modules/dc.toml} +0 -0
  151. /package/lib/util_modules/{server.d.ts → server/index.d.ts} +0 -0
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const ansi_colors_1 = require("ansi-colors");
16
16
  const path_1 = require("path");
17
+ const error_1 = __importDefault(require("../../../error"));
17
18
  const prompt_1 = __importDefault(require("../../../prompt"));
18
19
  const runtime_store_1 = __importDefault(require("../../../runtime-store"));
19
20
  const constants_1 = require("../../../util_modules/constants");
@@ -23,9 +24,21 @@ const option_1 = require("../../../util_modules/option");
23
24
  const common_1 = require("../../util/common");
24
25
  const project_1 = require("../../../util_modules/project");
25
26
  const utils_1 = require("./utils");
27
+ const prompt_fields_1 = require("./prompt-fields");
28
+ const env_1 = require("../../../util_modules/env");
29
+ const custom_runtime_1 = require("./utils/custom-runtime");
30
+ const prompt_fields_2 = require("../../util/prompt-fields");
26
31
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
27
32
  (0, index_1.info)();
28
33
  (0, index_1.info)((0, ansi_colors_1.white)('=> ') + 'Configure AppSail');
34
+ const sourceFromOption = (0, option_1.getOptionValue)(prompt_fields_1.appsailAddPromptFields.get('source').optKey, undefined);
35
+ const sourceFromOptionTrimmed = typeof sourceFromOption === 'string' ? sourceFromOption.trim() : '';
36
+ if ((0, env_1.isNonInteractiveMode)() &&
37
+ (0, option_1.getCurrentCommand)() === 'appsail:add' &&
38
+ sourceFromOptionTrimmed === '') {
39
+ throw new error_1.default('Non-interactive mode requires --source. Pass an absolute path to the AppSail source directory, or a docker image/archive source (see catalyst appsail:add --help).', { exit: 2 });
40
+ }
41
+ const runtimeDetectedFromSource = (0, utils_1.detectRuntimeFromSourceOption)(sourceFromOption);
29
42
  const descArr = [
30
43
  '',
31
44
  ` Catalyst let's you choose the runtime of your choice for your AppSail. You can either select`,
@@ -35,9 +48,10 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
35
48
  ''
36
49
  ];
37
50
  yield prompt_1.default.register('with-desc');
38
- const runtimeQuestion = yield prompt_1.default.ask(prompt_1.default.question('runtime', 'Please select the runtime for your AppSail to continue:', {
51
+ const runtimeQuestion = yield prompt_1.default.ask(prompt_1.default.question('runtimeType', 'Please select the runtime type for your AppSail to continue:', {
39
52
  type: 'with-desc',
40
53
  description: (0, ansi_colors_1.italic)(descArr.join('\n')),
54
+ when: !(0, env_1.isNonInteractiveMode)() && runtimeDetectedFromSource === undefined,
41
55
  choices: [
42
56
  prompt_1.default.choice('Catalyst-Managed Runtime', {
43
57
  value: 'catalyst',
@@ -49,11 +63,32 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
49
63
  })
50
64
  ]
51
65
  }));
52
- if (runtimeQuestion.runtime === 'custom') {
66
+ const effectiveRuntime = runtimeDetectedFromSource !== null && runtimeDetectedFromSource !== void 0 ? runtimeDetectedFromSource : runtimeQuestion.runtimeType;
67
+ if (effectiveRuntime === 'custom') {
68
+ const portOpt = (0, option_1.getOptionValue)(prompt_fields_1.appsailAddPromptFields.get('port').optKey, undefined);
69
+ const commandOpt = (0, option_1.getOptionValue)(prompt_fields_1.appsailAddPromptFields.get('command').optKey, undefined);
70
+ (0, common_1.niIgnorableOptsTest)([
71
+ prompt_fields_2.initCommonPromptFields.get('stack').optKey,
72
+ prompt_fields_1.appsailAddPromptFields.get('overwrite').optKey,
73
+ prompt_fields_1.appsailAddPromptFields.get('buildPath').optKey,
74
+ prompt_fields_1.appsailAddPromptFields.get('platform').optKey
75
+ ], 'The following options are not applicable for the custom runtime in non-interactive mode and will be ignored.');
53
76
  const payload = {
54
- source: yield (0, utils_1.getCustomAppSailSource)(),
77
+ source: yield (0, custom_runtime_1.getCustomAppSailSource)(sourceFromOption),
55
78
  name: yield (0, utils_1.getAppSailName)()
56
79
  };
80
+ if (commandOpt) {
81
+ payload.command = commandOpt;
82
+ }
83
+ if (portOpt) {
84
+ const _port = parseInt(portOpt);
85
+ if (isNaN(_port) || _port < 1 || _port > 65535) {
86
+ throw new error_1.default(`Invalid port number provided: ${portOpt}. Please provide a valid port number between 1 and 65535.`, { exit: 1 });
87
+ }
88
+ payload.port = {
89
+ http: _port
90
+ };
91
+ }
57
92
  runtime_store_1.default.set('context.payload.appsail.targets', [payload]);
58
93
  return;
59
94
  }
@@ -67,22 +102,25 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
67
102
  const sourcePath = yield prompt_1.default.ask(prompt_1.default.question('currentDir', 'Do you want to initialize an AppSail in this directory?', {
68
103
  type: 'confirm',
69
104
  default: true,
70
- when: !pulledSource
105
+ when: !pulledSource && !(0, env_1.isNonInteractiveMode)() && sourceFromOption === undefined
71
106
  }));
72
107
  const _appSailConfig = sourcePath.currentDir
73
108
  ? { source: runtime_store_1.default.get('cwd') }
74
- : pulledSource || {
75
- source: (yield prompt_1.default.ask(prompt_1.default.question('source', "Please provide the exact path to your AppSail's source directory:", {
76
- type: 'input',
77
- validate: (pth) => __awaiter(void 0, void 0, void 0, function* () {
78
- return (0, path_1.isAbsolute)(pth)
79
- ? (yield fs_1.ASYNC.dirExists(pth))
80
- ? true
81
- : 'Provided path does not exists'
82
- : 'Please provide an absolute path';
83
- })
84
- }))).source
85
- };
109
+ : pulledSource ||
110
+ (sourceFromOption !== undefined
111
+ ? { source: yield (0, utils_1.resolveCatalystSourceFromOption)(sourceFromOption) }
112
+ : {
113
+ source: (yield prompt_1.default.ask(prompt_1.default.question(prompt_fields_1.appsailAddPromptFields.get('source'), "Please provide the exact path to your AppSail's source directory:", {
114
+ type: 'input',
115
+ validate: (pth) => __awaiter(void 0, void 0, void 0, function* () {
116
+ return (0, path_1.isAbsolute)(pth)
117
+ ? (yield fs_1.ASYNC.dirExists(pth))
118
+ ? true
119
+ : 'Provided path does not exists'
120
+ : 'Please provide an absolute path';
121
+ })
122
+ }))).source
123
+ });
86
124
  const payload = {
87
125
  source: (0, path_1.relative)((0, project_1.getProjectRoot)(), _appSailConfig.source) || '.',
88
126
  name: yield (0, utils_1.getAppSailName)()
@@ -93,37 +131,48 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
93
131
  (0, index_1.info)();
94
132
  (0, index_1.warning)(`The ${(0, ansi_colors_1.bold)(constants_1.FILENAME.app_config)} file is already present in the appsail directory`);
95
133
  }
96
- const overWrite = yield prompt_1.default.ask(prompt_1.default.question('appConfig', 'Do you wish to overwrite the ' + constants_1.FILENAME.app_config + '?', {
134
+ const overwriteOpt = prompt_fields_1.appsailAddPromptFields.get('overwrite');
135
+ const overWrite = yield prompt_1.default.ask(prompt_1.default.question(overwriteOpt, 'Do you wish to overwrite the ' + constants_1.FILENAME.app_config + '?', {
97
136
  type: 'confirm',
98
137
  default: false,
99
138
  when: isAppConfig
100
139
  }));
101
- const activeWrite = overWrite.appConfig !== false;
140
+ const activeWrite = overWrite[overwriteOpt.promptName] !== false;
102
141
  if (!activeWrite) {
103
142
  runtime_store_1.default.set('context.payload.appsail.targets', [payload]);
143
+ (0, index_1.info)();
144
+ (0, index_1.info)((0, ansi_colors_1.bold)(`${constants_1.FILENAME.app_config} will not be overwritten. Keeping the existing configuration file.`));
145
+ if ((0, env_1.isNonInteractiveMode)()) {
146
+ (0, index_1.info)();
147
+ (0, index_1.info)(`To overwrite the existing configuration file, use the ${(0, ansi_colors_1.bold)('--overwrite-config')} option.`);
148
+ }
149
+ (0, index_1.info)();
104
150
  return;
105
151
  }
106
- const buildPath = yield prompt_1.default.ask(prompt_1.default.question('path', 'Please provide the build path of your AppSail:', {
152
+ const buildPath = yield prompt_1.default.ask(prompt_1.default.question(prompt_fields_1.appsailAddPromptFields.get('buildPath'), 'Please provide the build path of your AppSail:', {
107
153
  type: 'input',
108
154
  rootPath: _appSailConfig.source,
109
- when: !_appSailConfig.build && activeWrite
155
+ when: !_appSailConfig.build && activeWrite,
156
+ defaultAns: './'
110
157
  }));
158
+ const appCmdFromOpt = (0, option_1.getOptionValue)(prompt_fields_1.appsailAddPromptFields.get('command').optKey, 'echo Please specify the start-up command in the app-config.json file under the key command for AppSail $X_ZC_RESOURCE_NAME');
111
159
  const appSailStack = _appSailConfig.stack ||
112
160
  (yield (0, common_1.getRuntimePromptAnswer)('Please choose a stack for your AppSail: '));
161
+ const _buildPath = buildPath[prompt_fields_1.appsailAddPromptFields.get('buildPath').promptName];
162
+ (0, common_1.niIgnorableOptsTest)(prompt_fields_1.appsailAddPromptFields.get('port').optKey, 'The following option is not applicable for the Catalyst-Managed runtime in non-interactive mode and will be ignored.');
113
163
  const appConfig = {
114
- command: _appSailConfig.command ||
115
- 'echo Please specify the start-up command in the app-config.json file under the key command for AppSail $X_ZC_RESOURCE_NAME',
164
+ command: _appSailConfig.command || appCmdFromOpt,
116
165
  build_path: _appSailConfig.build ||
117
- ((0, path_1.isAbsolute)(buildPath.path)
118
- ? (0, path_1.relative)(_appSailConfig.source, buildPath.path) || '.'
119
- : buildPath.path),
166
+ ((0, path_1.isAbsolute)(_buildPath)
167
+ ? (0, path_1.relative)(_appSailConfig.source, _buildPath) || '.'
168
+ : _buildPath),
120
169
  stack: appSailStack.runtime,
121
170
  env_variables: {},
122
171
  memory: _appSailConfig.memory || 256,
123
172
  scripts: _appSailConfig.scripts || {}
124
173
  };
125
174
  if (appSailStack.lang === 'java') {
126
- const platformQ = yield prompt_1.default.ask(prompt_1.default.question('platform', 'Please choose a platform for your AppSail: ', {
175
+ const platformQ = yield prompt_1.default.ask(prompt_1.default.question(prompt_fields_1.appsailAddPromptFields.get('platform'), 'Please choose a platform for your AppSail: ', {
127
176
  type: 'list',
128
177
  choices: [
129
178
  prompt_1.default.choice('JavaSE', {
@@ -0,0 +1,43 @@
1
+ export declare const appsailAddPromptFields: import("../../../prompt/register-fields").PromptFieldsRegistry<readonly [{
2
+ readonly name: "name";
3
+ readonly cliOption: {
4
+ readonly option: "--name <name>";
5
+ readonly description: "appsail service name";
6
+ };
7
+ }, {
8
+ readonly name: "source";
9
+ readonly cliOption: {
10
+ readonly option: "--source <source>";
11
+ readonly description: "absolute path to appsail source directory or docker image url or docker archive url";
12
+ };
13
+ }, {
14
+ readonly name: "overwrite";
15
+ readonly cliOption: {
16
+ readonly option: "--overwrite-config";
17
+ readonly description: "overwrite existing app-config.json when present, applicable for catalyst runtime";
18
+ };
19
+ }, {
20
+ readonly name: "buildPath";
21
+ readonly cliOption: {
22
+ readonly option: "--build <path>";
23
+ readonly description: "appsail build path relative to source, applicable for catalyst runtime";
24
+ };
25
+ }, {
26
+ readonly name: "platform";
27
+ readonly cliOption: {
28
+ readonly option: "--platform <platform>";
29
+ readonly description: "appsail java platform <javase|war>";
30
+ };
31
+ }, {
32
+ readonly name: "command";
33
+ readonly cliOption: {
34
+ readonly option: "--command <command>";
35
+ readonly description: "startup command for appsail";
36
+ };
37
+ }, {
38
+ readonly name: "port";
39
+ readonly cliOption: {
40
+ readonly option: "--port <httpPort>";
41
+ readonly description: "http port for appsail, applicable only for custom runtime";
42
+ };
43
+ }]>;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appsailAddPromptFields = void 0;
4
+ const register_fields_1 = require("../../../prompt/register-fields");
5
+ exports.appsailAddPromptFields = (0, register_fields_1.definePromptFields)([
6
+ {
7
+ name: 'name',
8
+ cliOption: {
9
+ option: '--name <name>',
10
+ description: 'appsail service name'
11
+ }
12
+ },
13
+ {
14
+ name: 'source',
15
+ cliOption: {
16
+ option: '--source <source>',
17
+ description: 'absolute path to appsail source directory or docker image url or docker archive url'
18
+ }
19
+ },
20
+ {
21
+ name: 'overwrite',
22
+ cliOption: {
23
+ option: '--overwrite-config',
24
+ description: 'overwrite existing app-config.json when present, applicable for catalyst runtime'
25
+ }
26
+ },
27
+ {
28
+ name: 'buildPath',
29
+ cliOption: {
30
+ option: '--build <path>',
31
+ description: 'appsail build path relative to source, applicable for catalyst runtime'
32
+ }
33
+ },
34
+ {
35
+ name: 'platform',
36
+ cliOption: {
37
+ option: '--platform <platform>',
38
+ description: 'appsail java platform <javase|war>'
39
+ }
40
+ },
41
+ {
42
+ name: 'command',
43
+ cliOption: {
44
+ option: '--command <command>',
45
+ description: 'startup command for appsail'
46
+ }
47
+ },
48
+ {
49
+ name: 'port',
50
+ cliOption: {
51
+ option: '--port <httpPort>',
52
+ description: 'http port for appsail, applicable only for custom runtime'
53
+ }
54
+ }
55
+ ]);
@@ -0,0 +1,3 @@
1
+ export declare function getContainerImageTag(): Promise<string>;
2
+ export declare function resolveCustomAppSailSourceFromOption(sourceInput: string): Promise<string>;
3
+ export declare function getCustomAppSailSource(sourceInput?: string): Promise<string>;
@@ -0,0 +1,161 @@
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.getContainerImageTag = getContainerImageTag;
16
+ exports.resolveCustomAppSailSourceFromOption = resolveCustomAppSailSourceFromOption;
17
+ exports.getCustomAppSailSource = getCustomAppSailSource;
18
+ const image_1 = require("@zcatalyst/container-plugin/out/endpoints/image");
19
+ const container_1 = require("../../../../util_modules/container");
20
+ const js_1 = require("../../../../util_modules/js");
21
+ const ansi_colors_1 = require("ansi-colors");
22
+ const prompt_1 = __importDefault(require("../../../../prompt"));
23
+ const error_1 = __importDefault(require("../../../../error"));
24
+ const project_1 = require("../../../../util_modules/project");
25
+ const path_1 = require("path");
26
+ const fs_1 = require("../../../../util_modules/fs");
27
+ function getContainerImageTag() {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ yield (0, container_1.isSocketAccessible)();
30
+ const images = (yield (0, image_1.getAllLocalImages)()).reduce((_images, img) => {
31
+ var _a;
32
+ (_a = img.RepoTags) === null || _a === void 0 ? void 0 : _a.forEach((tag) => _images.push({ imgName: tag, id: img.Id }));
33
+ return _images;
34
+ }, []);
35
+ const searchImages = (filter) => {
36
+ const filteredImages = [];
37
+ images.forEach((img) => {
38
+ var _a;
39
+ if (filter === '' ||
40
+ img.id.includes(filter) ||
41
+ ((_a = img.imgName) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(filter.toLowerCase()))) {
42
+ filteredImages.push({
43
+ name: `${img.imgName} ${(0, ansi_colors_1.dim)(img.id.substring(7, 17))}`,
44
+ value: img.imgName || img.id
45
+ });
46
+ return;
47
+ }
48
+ });
49
+ return filteredImages;
50
+ };
51
+ yield prompt_1.default.register('search-box');
52
+ const image = yield prompt_1.default.ask(prompt_1.default.question('name', 'Please search and select the image to link:', {
53
+ type: 'search-box',
54
+ boxType: 'list',
55
+ searchable: true,
56
+ pageSize: 10,
57
+ highlight: true,
58
+ notFoundMsg: 'No Images found!',
59
+ searchMsg: 'Searching images...',
60
+ source(_answersSoFar, input) {
61
+ input || (input = '');
62
+ return Promise.resolve(searchImages(input));
63
+ },
64
+ validate: (ansArr) => {
65
+ if (js_1.JS.isEmpty(ansArr)) {
66
+ return 'Must select an Image';
67
+ }
68
+ return true;
69
+ }
70
+ }));
71
+ return `docker://${image.name}`;
72
+ });
73
+ }
74
+ function resolveCustomAppSailSourceFromOption(sourceInput) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const source = sourceInput.trim();
77
+ if (!source) {
78
+ throw new error_1.default('AppSail source cannot be empty for custom runtime.', {
79
+ exit: 2
80
+ });
81
+ }
82
+ const isDockerArchiveProtocol = source.startsWith('docker-archive://');
83
+ const isDockerImageProtocol = source.startsWith('docker://');
84
+ if (isDockerImageProtocol) {
85
+ const imageName = source.slice('docker://'.length).trim();
86
+ if (!imageName) {
87
+ throw new error_1.default('Invalid docker image source. Use format docker://<image[:tag]>.', { exit: 2 });
88
+ }
89
+ return source;
90
+ }
91
+ const archivePathOrImage = isDockerArchiveProtocol
92
+ ? source.slice('docker-archive://'.length)
93
+ : source;
94
+ const archivePathCandidate = (0, path_1.isAbsolute)(archivePathOrImage)
95
+ ? archivePathOrImage
96
+ : (0, project_1.resolveProjectPath)(archivePathOrImage);
97
+ const isArchiveLike = archivePathOrImage.endsWith('.tar');
98
+ if (isDockerArchiveProtocol || isArchiveLike) {
99
+ if (!(yield fs_1.ASYNC.fileExists(archivePathCandidate))) {
100
+ throw new error_1.default('Provided docker archive path does not exist.', {
101
+ exit: 2
102
+ });
103
+ }
104
+ if (!archivePathCandidate.endsWith('.tar')) {
105
+ throw new error_1.default('Provided file is not a valid docker archive. Please provide a .tar file.', { exit: 2 });
106
+ }
107
+ const normalized = (0, path_1.relative)((0, project_1.getProjectRoot)(), archivePathCandidate);
108
+ return `docker-archive://${normalized}`;
109
+ }
110
+ return `docker://${source}`;
111
+ });
112
+ }
113
+ function getCustomAppSailSource(sourceInput) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ if (sourceInput !== undefined) {
116
+ return resolveCustomAppSailSourceFromOption(sourceInput);
117
+ }
118
+ const dockerProtocol = yield prompt_1.default.ask(prompt_1.default.question('type', 'Please choose one of the supported protocols:', {
119
+ type: 'list',
120
+ choices: [
121
+ prompt_1.default.choice(`Docker image ${(0, ansi_colors_1.italic)('(docker://)')}`, {
122
+ value: 'image',
123
+ short: 'Docker image'
124
+ }),
125
+ prompt_1.default.choice(`Docker archive ${(0, ansi_colors_1.italic)('(docker-archive://)')}`, {
126
+ value: 'docker-archive',
127
+ short: 'Docker archive'
128
+ })
129
+ ]
130
+ }));
131
+ switch (dockerProtocol.type) {
132
+ case 'image': {
133
+ return getContainerImageTag();
134
+ }
135
+ case 'docker-archive': {
136
+ const archivePath = yield prompt_1.default.ask(prompt_1.default.question('archive', 'Please provide the path to the docker archive file: ', {
137
+ type: 'input',
138
+ validate: (pth) => __awaiter(this, void 0, void 0, function* () {
139
+ if (!(0, path_1.isAbsolute)(pth)) {
140
+ return 'Please provide an absolute path';
141
+ }
142
+ if (!(yield fs_1.ASYNC.fileExists(pth))) {
143
+ return 'Provided path does not exists';
144
+ }
145
+ if (!pth.endsWith('.tar')) {
146
+ return 'Provided file is not a valid docker archive. Please provide a .tar file';
147
+ }
148
+ return true;
149
+ })
150
+ }));
151
+ const path = (0, path_1.relative)((0, project_1.getProjectRoot)(), archivePath.archive);
152
+ return `docker-archive://${path}`;
153
+ }
154
+ default: {
155
+ throw new error_1.default('Unsupported protocol selected for AppSail source', {
156
+ exit: 2
157
+ });
158
+ }
159
+ }
160
+ });
161
+ }
@@ -12,5 +12,5 @@ export type _TAppSailInitConfig = {
12
12
  };
13
13
  export declare function getAppSailZip(): Promise<_TAppSailInitConfig>;
14
14
  export declare function getAppSailName(): Promise<string>;
15
- export declare function getContainerImageTag(): Promise<string>;
16
- export declare function getCustomAppSailSource(): Promise<string>;
15
+ export declare function detectRuntimeFromSourceOption(sourceInput?: string): 'custom' | 'catalyst' | undefined;
16
+ export declare function resolveCatalystSourceFromOption(sourceInput: string): Promise<string>;
@@ -0,0 +1,170 @@
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.getAppSailZip = getAppSailZip;
16
+ exports.getAppSailName = getAppSailName;
17
+ exports.detectRuntimeFromSourceOption = detectRuntimeFromSourceOption;
18
+ exports.resolveCatalystSourceFromOption = resolveCatalystSourceFromOption;
19
+ const ansi_colors_1 = require("ansi-colors");
20
+ const path_1 = require("path");
21
+ const archiver_1 = __importDefault(require("../../../../archiver"));
22
+ const endpoints_1 = require("../../../../endpoints");
23
+ const error_1 = __importDefault(require("../../../../error"));
24
+ const prompt_1 = __importDefault(require("../../../../prompt"));
25
+ const config_1 = require("../../../../util_modules/config");
26
+ const appsail_1 = require("../../../../util_modules/config/lib/appsail");
27
+ const constants_1 = require("../../../../util_modules/constants");
28
+ const fs_1 = require("../../../../util_modules/fs");
29
+ const logger_1 = require("../../../../util_modules/logger");
30
+ const project_1 = require("../../../../util_modules/project");
31
+ const prompt_fields_1 = require("../prompt-fields");
32
+ function getAppSailZip() {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const _gitHubAPI = yield (0, endpoints_1.gitHubAPI)();
35
+ const gitRepo = yield prompt_1.default.ask(prompt_1.default.question('repo', 'Please choose from the list of recommended projects to get started', {
36
+ type: 'list',
37
+ choices: [
38
+ prompt_1.default.choice(`appsail-nodejs - ${(0, ansi_colors_1.underline)('https://github.com/catalystbyzoho/appsail-nodejs')}`, {
39
+ value: {
40
+ api: _gitHubAPI.appsailNodejs.bind(_gitHubAPI),
41
+ command: 'node index.js',
42
+ source: (0, project_1.resolveProjectPath)('appsail-nodejs'),
43
+ build: './',
44
+ stack: {
45
+ runtime: 'node16',
46
+ lang: 'node'
47
+ },
48
+ scripts: {
49
+ preserve: 'npm install',
50
+ predeploy: 'npm install'
51
+ },
52
+ memory: 256
53
+ },
54
+ short: 'appsail-nodejs'
55
+ }),
56
+ prompt_1.default.choice(`appsail-java - ${(0, ansi_colors_1.underline)('https://github.com/catalystbyzoho/appsail-java')}`, {
57
+ value: {
58
+ api: _gitHubAPI.appsailJava.bind(_gitHubAPI),
59
+ command: 'java -jar demo-0.0.1-SNAPSHOT.jar',
60
+ source: (0, project_1.resolveProjectPath)('appsail-java'),
61
+ build: (0, path_1.join)('target', 'demo-0.0.1-SNAPSHOT.jar'),
62
+ stack: {
63
+ runtime: 'java8',
64
+ lang: 'java'
65
+ },
66
+ scripts: {
67
+ preserve: './mvnw clean install',
68
+ predeploy: './mvnw clean install'
69
+ },
70
+ memory: 512,
71
+ platform: 'javase'
72
+ },
73
+ short: 'appsail-java'
74
+ }),
75
+ prompt_1.default.choice(`appsail-python - ${(0, ansi_colors_1.underline)('https://github.com/catalystbyzoho/appsail-python')}`, {
76
+ value: {
77
+ api: _gitHubAPI.appsailPython.bind(_gitHubAPI),
78
+ command: 'python3 app.py',
79
+ source: (0, project_1.resolveProjectPath)('appsail-python'),
80
+ build: './',
81
+ stack: {
82
+ runtime: 'python_3_9',
83
+ lang: 'python'
84
+ },
85
+ scripts: {
86
+ preserve: 'python3 -m pip install -r ./requirements.txt -t ./ --upgrade',
87
+ predeploy: 'python3 -m pip install -r ./requirements.txt -t ./ --upgrade'
88
+ },
89
+ memory: 256
90
+ },
91
+ short: 'appsail-python'
92
+ })
93
+ ]
94
+ }));
95
+ (0, logger_1.info)();
96
+ (0, logger_1.info)((0, ansi_colors_1.white)('=>') + ' Downloading code');
97
+ const code = (yield gitRepo.repo.api());
98
+ const repoDir = gitRepo.repo.source;
99
+ yield fs_1.ASYNC.ensureDir(repoDir);
100
+ const zip = new archiver_1.default();
101
+ zip.load(code);
102
+ zip.extract(repoDir, '/', {
103
+ isFolder: true,
104
+ ignoreLevel: 1
105
+ });
106
+ yield zip.finalize();
107
+ (0, logger_1.success)(`Successfully downloaded the code to ${ansi_colors_1.bold.green(gitRepo.repo.source)}`);
108
+ return {
109
+ source: gitRepo.repo.source,
110
+ build: gitRepo.repo.build,
111
+ stack: gitRepo.repo.stack,
112
+ command: gitRepo.repo.command,
113
+ scripts: gitRepo.repo.scripts,
114
+ memory: gitRepo.repo.memory,
115
+ platform: gitRepo.repo.platform
116
+ };
117
+ });
118
+ }
119
+ function getAppSailName() {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ const existingSails = config_1.appSailConfig.raw() || [];
122
+ const appName = yield prompt_1.default.ask(prompt_1.default.question(prompt_fields_1.appsailAddPromptFields.get('name'), 'Please provide the name for your AppSail: ', {
123
+ type: 'input',
124
+ default: 'AppSail',
125
+ validate: (name) => {
126
+ const exists = existingSails.findIndex((appSail) => appSail.name === name) !== -1
127
+ ? 'AppSail already exists'
128
+ : true;
129
+ const match = name.match(constants_1.REGEX.appsail.name)
130
+ ? true
131
+ : 'Invalid AppSail name: Name must contain only alphanumeric and hyphen';
132
+ return typeof exists === 'string'
133
+ ? exists
134
+ : typeof match === 'string'
135
+ ? match
136
+ : true;
137
+ }
138
+ }));
139
+ return appName.name;
140
+ });
141
+ }
142
+ function detectRuntimeFromSourceOption(sourceInput) {
143
+ if (sourceInput === undefined) {
144
+ return undefined;
145
+ }
146
+ const source = sourceInput.trim();
147
+ if (!source) {
148
+ return undefined;
149
+ }
150
+ if ((0, appsail_1.isCustomAppSailSource)(source)) {
151
+ return 'custom';
152
+ }
153
+ return 'catalyst';
154
+ }
155
+ function resolveCatalystSourceFromOption(sourceInput) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ const source = sourceInput.trim();
158
+ if (!(0, path_1.isAbsolute)(source)) {
159
+ throw new error_1.default('Please provide an absolute path for AppSail source directory.', {
160
+ exit: 2
161
+ });
162
+ }
163
+ if (!(yield fs_1.ASYNC.dirExists(source))) {
164
+ throw new error_1.default('Provided AppSail source directory does not exist.', {
165
+ exit: 2
166
+ });
167
+ }
168
+ return source;
169
+ });
170
+ }
@@ -47,16 +47,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
48
  const index_js_1 = __importDefault(require("../../../prompt/index.js"));
49
49
  const index_js_2 = require("../../../util_modules/constants/index.js");
50
+ const prompt_fields_js_1 = require("./prompt-fields.js");
50
51
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
51
- const clientInitAnswer = yield index_js_1.default.ask(index_js_1.default.question('clientFlavour', 'Choose the type of client to initialise: ', {
52
+ const clientInitAnswer = yield index_js_1.default.ask(index_js_1.default.question(prompt_fields_js_1.clientPromptFields.get('clientType'), 'Choose the type of client to initialise: ', {
52
53
  type: 'list',
53
54
  choices: index_js_2.PLUGIN.client.map((plugin) => {
54
55
  return index_js_1.default.choice(plugin + ' web app', {
55
- id: plugin.toUpperCase(),
56
+ id: plugin.toLowerCase(),
56
57
  value: plugin.toLowerCase(),
57
58
  short: plugin.toUpperCase()
58
59
  });
59
60
  })
60
61
  }));
61
- return (yield Promise.resolve(`${'./initializers/' + clientInitAnswer.clientFlavour}`).then(s => __importStar(require(s)))).default();
62
+ return (yield Promise.resolve(`${'./initializers/' + clientInitAnswer.clientType}`).then(s => __importStar(require(s)))).default();
62
63
  });