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.
- package/README.md +1 -0
- package/lib/authentication/credential.d.ts +2 -1
- package/lib/authentication/credential.js +20 -3
- package/lib/authentication/crypt.d.ts +7 -3
- package/lib/authentication/crypt.js +87 -16
- package/lib/authentication/index.js +1 -0
- package/lib/authentication/key-manager.d.ts +7 -0
- package/lib/authentication/key-manager.js +62 -0
- package/lib/authentication/login.js +20 -20
- package/lib/bin/catalyst.js +1 -15
- package/lib/client.d.ts +3 -1
- package/lib/client.js +16 -5
- package/lib/command_needs/rc.js +13 -3
- package/lib/commands/appsail/add.js +10 -0
- package/lib/commands/client/delete.js +18 -6
- package/lib/commands/client/setup.js +7 -0
- package/lib/commands/deploy/index.js +3 -3
- package/lib/commands/deploy/slate.js +65 -4
- package/lib/commands/functions/add.js +7 -0
- package/lib/commands/functions/delete.js +22 -4
- package/lib/commands/functions/execute.js +39 -71
- package/lib/commands/functions/setup.js +13 -0
- package/lib/commands/functions/shell.js +15 -1
- package/lib/commands/iac/import.js +2 -2
- package/lib/commands/init.js +34 -20
- package/lib/commands/login.js +1 -0
- package/lib/commands/pull.js +22 -1
- package/lib/commands/serve.js +2 -1
- package/lib/commands/slate/create.js +7 -4
- package/lib/commands/slate/link.js +11 -5
- package/lib/commands/slate/unlink.js +7 -0
- package/lib/commands/zest/generate/index.js +28 -35
- package/lib/deploy/features/slate.d.ts +3 -1
- package/lib/deploy/features/slate.js +204 -5
- package/lib/docs/client-utils.toml +0 -5
- package/lib/docs/command_needs/rc.toml +9 -1
- package/lib/docs/commands/client/delete.toml +4 -0
- package/lib/docs/commands/deploy/slate.toml +3 -0
- package/lib/docs/commands/functions/delete.toml +10 -0
- package/lib/docs/commands/functions/execute.toml +1 -16
- package/lib/docs/commands/functions/setup.toml +3 -0
- package/lib/docs/commands/functions/shell.toml +8 -0
- package/lib/docs/commands/init.toml +3 -0
- package/lib/docs/commands/pull.toml +6 -0
- package/lib/docs/commands/slate/unlink.toml +6 -0
- package/lib/docs/execute/command-utils.toml +14 -0
- package/lib/docs/execute/execute-input-resolver.toml +37 -0
- package/lib/docs/init/features/project.toml +20 -0
- package/lib/docs/init/util/client.toml +4 -0
- package/lib/docs/prompt/index.toml +15 -0
- package/lib/docs/pull/features/apig.toml +6 -0
- package/lib/docs/pull/features/client.toml +20 -0
- package/lib/docs/pull/features/functions/index.toml +24 -0
- package/lib/endpoints/lib/slate.d.ts +14 -1
- package/lib/endpoints/lib/slate.js +35 -0
- package/lib/error/context-help.js +1 -1
- package/lib/error/index.js +9 -13
- package/lib/execute/command-utils.d.ts +5 -0
- package/lib/execute/command-utils.js +86 -0
- package/lib/execute/execute-input-resolver.d.ts +29 -0
- package/lib/execute/execute-input-resolver.js +207 -0
- package/lib/execute/index.d.ts +4 -1
- package/lib/execute/index.js +3 -2
- package/lib/fn-utils/lib/integ.js +22 -17
- package/lib/index.js +1 -0
- package/lib/init/dependencies/package-json.js +11 -7
- package/lib/init/features/appsail/index.js +75 -26
- package/lib/init/features/appsail/prompt-fields.d.ts +43 -0
- package/lib/init/features/appsail/prompt-fields.js +55 -0
- package/lib/init/features/appsail/utils/custom-runtime.d.ts +3 -0
- package/lib/init/features/appsail/utils/custom-runtime.js +161 -0
- package/lib/init/features/appsail/{utils.d.ts → utils/index.d.ts} +2 -2
- package/lib/init/features/appsail/utils/index.js +170 -0
- package/lib/init/features/client/index.js +4 -3
- package/lib/init/features/client/initializers/angular.js +3 -2
- package/lib/init/features/client/initializers/react.js +4 -3
- package/lib/init/features/client/prompt-fields.d.ts +37 -0
- package/lib/init/features/client/prompt-fields.js +48 -0
- package/lib/init/features/functions/index.js +37 -8
- package/lib/init/features/functions/languages/java.js +42 -7
- package/lib/init/features/functions/languages/node.js +42 -10
- package/lib/init/features/functions/languages/python.js +42 -7
- package/lib/init/features/functions/prompt-fields.d.ts +25 -0
- package/lib/init/features/functions/prompt-fields.js +34 -0
- package/lib/init/features/project.js +41 -6
- package/lib/init/features/slate/index.js +2 -0
- package/lib/init/features/slate/prompt-fields.d.ts +31 -0
- package/lib/init/features/slate/prompt-fields.js +41 -0
- package/lib/init/index.js +2 -1
- package/lib/init/util/client.js +11 -8
- package/lib/init/util/common.d.ts +2 -0
- package/lib/init/util/common.js +33 -3
- package/lib/init/util/prompt-fields.d.ts +7 -0
- package/lib/init/util/prompt-fields.js +13 -0
- package/lib/internal/command.d.ts +3 -0
- package/lib/internal/command.js +26 -3
- package/lib/migration/global/1.27.0.d.ts +2 -0
- package/lib/migration/global/1.27.0.js +39 -0
- package/lib/prompt/choice.d.ts +2 -0
- package/lib/prompt/choice.js +24 -0
- package/lib/prompt/cli-option-key.d.ts +1 -0
- package/lib/prompt/cli-option-key.js +10 -0
- package/lib/prompt/index.d.ts +6 -22
- package/lib/prompt/index.js +264 -67
- package/lib/prompt/overwrite-prompt.d.ts +11 -0
- package/lib/prompt/overwrite-prompt.js +16 -0
- package/lib/prompt/question-factory.d.ts +34 -0
- package/lib/prompt/question-factory.js +41 -0
- package/lib/prompt/register-fields.d.ts +24 -0
- package/lib/prompt/register-fields.js +37 -0
- package/lib/pull/features/apig.js +57 -6
- package/lib/pull/features/client.js +107 -24
- package/lib/pull/features/functions/index.js +100 -4
- package/lib/pull/index.js +1 -1
- package/lib/pull/utils.d.ts +13 -0
- package/lib/pull/utils.js +20 -0
- package/lib/repl-server.d.ts +4 -0
- package/lib/repl-server.js +9 -0
- package/lib/serve/server/lib/master/index.js +3 -3
- package/lib/serve/server/lib/slate/static-server.js +2 -2
- package/lib/serve/server/lib/web_client/server.js +2 -2
- package/lib/shell/format-functions.d.ts +4 -0
- package/lib/shell/format-functions.js +59 -0
- package/lib/shell/index.js +18 -0
- package/lib/util_modules/config/lib/appsail.d.ts +3 -2
- package/lib/util_modules/config/lib/appsail.js +6 -3
- package/lib/util_modules/config/lib/slate.d.ts +19 -0
- package/lib/util_modules/config-store.d.ts +1 -0
- package/lib/util_modules/config-store.js +29 -10
- package/lib/util_modules/constants/index.d.ts +0 -1
- package/lib/util_modules/constants/index.js +1 -3
- package/lib/util_modules/constants/lib/urls.d.ts +2 -0
- package/lib/util_modules/constants/lib/urls.js +4 -0
- package/lib/util_modules/dc.d.ts +6 -1
- package/lib/util_modules/dc.js +21 -8
- package/lib/util_modules/env.d.ts +3 -0
- package/lib/util_modules/env.js +41 -0
- package/lib/util_modules/fs/lib/sync.d.ts +1 -0
- package/lib/util_modules/fs/lib/sync.js +19 -0
- package/lib/util_modules/logger/utils.d.ts +1 -0
- package/lib/util_modules/logger/utils.js +5 -1
- package/lib/util_modules/option.d.ts +1 -0
- package/lib/util_modules/option.js +8 -0
- package/lib/util_modules/{server.js → server/index.js} +3 -3
- package/lib/util_modules/server/needed-scopes.d.ts +1 -0
- package/lib/util_modules/{constants/lib → server}/needed-scopes.js +7 -7
- package/package.json +3 -2
- package/lib/init/features/appsail/utils.js +0 -273
- package/lib/util_modules/constants/lib/needed-scopes.d.ts +0 -4
- /package/lib/docs/{dc.toml → util_modules/dc.toml} +0 -0
- /package/lib/util_modules/{server.d.ts → server/index.d.ts} +0 -0
package/lib/prompt/index.js
CHANGED
|
@@ -56,18 +56,184 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
56
56
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
57
57
|
};
|
|
58
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.PromptFieldsRegistry = exports.PromptFieldHandle = exports.definePromptFields = exports.overwritePromptQuestion = void 0;
|
|
59
60
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
61
|
+
const separator_1 = __importDefault(require("inquirer/lib/objects/separator"));
|
|
60
62
|
const error_1 = __importDefault(require("../error"));
|
|
63
|
+
const env_1 = require("../util_modules/env");
|
|
64
|
+
const utils_1 = require("../util_modules/logger/utils");
|
|
65
|
+
const option_1 = require("../util_modules/option");
|
|
66
|
+
const choice_1 = require("./choice");
|
|
67
|
+
const question_factory_1 = require("./question-factory");
|
|
61
68
|
const runtime_store_1 = __importDefault(require("../runtime-store"));
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
const register_fields_1 = require("./register-fields");
|
|
70
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
71
|
+
function isChoiceSeparator(c) {
|
|
72
|
+
return c instanceof separator_1.default;
|
|
73
|
+
}
|
|
74
|
+
function omitCliOptionKeyForInquirer(q) {
|
|
75
|
+
const { fieldOrName } = q, rest = __rest(q, ["fieldOrName"]);
|
|
76
|
+
void fieldOrName;
|
|
77
|
+
rest.name = (0, question_factory_1.getQuestionPromptName)(q);
|
|
78
|
+
return rest;
|
|
79
|
+
}
|
|
80
|
+
function questionWillBeAsked(question, answers) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
let shouldAsk = true;
|
|
83
|
+
const whenFn = question.when;
|
|
84
|
+
if (whenFn !== undefined) {
|
|
85
|
+
if (typeof whenFn === 'function') {
|
|
86
|
+
const result = whenFn(answers);
|
|
87
|
+
shouldAsk = !!(result instanceof Promise ? yield result : result);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
shouldAsk = !!whenFn;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return shouldAsk;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function ensureCustomPromptTypeRegistered(question) {
|
|
97
|
+
if (question.type && ['file-path', 'tree', 'search-box'].includes(question.type)) {
|
|
98
|
+
if (!registeredTypes.has(question.type)) {
|
|
99
|
+
throw new error_1.default(`Prompt type "${question.type}" is not registered.`, {
|
|
100
|
+
exit: 2
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function applyRawToAnswer(question, answers, raw) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
let value = mapRuntimeRawToAnswer(question, raw);
|
|
108
|
+
const filterFn = question.filter;
|
|
109
|
+
if (typeof filterFn === 'function') {
|
|
110
|
+
const filtered = yield Promise.resolve(filterFn(value, answers));
|
|
111
|
+
value = filtered;
|
|
112
|
+
}
|
|
113
|
+
const validateFn = question.validate;
|
|
114
|
+
if (typeof validateFn === 'function') {
|
|
115
|
+
const v = yield Promise.resolve(validateFn(value, answers));
|
|
116
|
+
if (v !== true) {
|
|
117
|
+
const qName = (0, question_factory_1.getQuestionPromptName)(question);
|
|
118
|
+
throw new error_1.default(typeof v === 'string' ? v : `Validation failed for prompt "${qName}".`, { exit: 2 });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const qName = (0, question_factory_1.getQuestionPromptName)(question);
|
|
122
|
+
answers[qName] = value;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function resolveRawInputForQuestion(question, answers, runtimePrompt) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const qName = (0, question_factory_1.getQuestionPromptName)(question);
|
|
128
|
+
let raw = runtimePrompt ? runtimePrompt[qName] : undefined;
|
|
129
|
+
if (raw === undefined && question.default !== undefined) {
|
|
130
|
+
const d = question.default;
|
|
131
|
+
if (typeof d === 'function') {
|
|
132
|
+
const r = d(answers);
|
|
133
|
+
raw = r instanceof Promise ? yield r : r;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
raw = d;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (raw === undefined && question.defaultAns !== undefined) {
|
|
140
|
+
raw = question.defaultAns;
|
|
141
|
+
}
|
|
142
|
+
return raw;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function resolveRuntimePromptAnswers(questions, runtimePrompt) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const answers = {};
|
|
148
|
+
for (const question of questions) {
|
|
149
|
+
const shouldAsk = yield questionWillBeAsked(question, answers);
|
|
150
|
+
if (shouldAsk) {
|
|
151
|
+
const raw = yield resolveRawInputForQuestion(question, answers, runtimePrompt);
|
|
152
|
+
if (raw === undefined) {
|
|
153
|
+
if ((0, env_1.isNonInteractiveMode)()) {
|
|
154
|
+
const qName = (0, question_factory_1.getQuestionPromptName)(question);
|
|
155
|
+
throw new error_1.default(`Missing runtime input for prompt "${qName}" (after defaults).`, { exit: 2 });
|
|
156
|
+
}
|
|
157
|
+
ensureCustomPromptTypeRegistered(question);
|
|
158
|
+
const qForPrompt = Object.assign(Object.assign({}, omitCliOptionKeyForInquirer(question)), { when: () => true });
|
|
159
|
+
const interactiveSlice = yield inquirer_1.default.prompt([qForPrompt], answers);
|
|
160
|
+
Object.assign(answers, interactiveSlice);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
yield applyRawToAnswer(question, answers, raw);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
const raw = yield resolveRawInputForQuestion(question, answers, runtimePrompt);
|
|
168
|
+
if (raw !== undefined) {
|
|
169
|
+
yield applyRawToAnswer(question, answers, raw);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return answers;
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function mapRuntimeRawToAnswer(question, raw) {
|
|
177
|
+
const qType = question.type;
|
|
178
|
+
const qName = (0, question_factory_1.getQuestionPromptName)(question);
|
|
179
|
+
switch (qType) {
|
|
180
|
+
case 'checkbox': {
|
|
181
|
+
let ids;
|
|
182
|
+
if (typeof raw === 'string') {
|
|
183
|
+
ids = raw
|
|
184
|
+
.split(',')
|
|
185
|
+
.map((s) => s.trim())
|
|
186
|
+
.filter(Boolean);
|
|
187
|
+
}
|
|
188
|
+
else if (Array.isArray(raw)) {
|
|
189
|
+
ids = raw;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
throw new error_1.default(`Runtime input for "${qName}" must be a comma-separated list or an array of choice ids for checkbox prompts.`, { exit: 2 });
|
|
193
|
+
}
|
|
194
|
+
const choices = (question.choices || []);
|
|
195
|
+
return choices
|
|
196
|
+
.filter((c) => !isChoiceSeparator(c))
|
|
197
|
+
.map((c) => c)
|
|
198
|
+
.filter((c) => !!c.id && ids.includes(c.id))
|
|
199
|
+
.map((c) => c.value);
|
|
200
|
+
}
|
|
201
|
+
case 'list': {
|
|
202
|
+
const choices = question.choices;
|
|
203
|
+
if (!(choices === null || choices === void 0 ? void 0 : choices.length)) {
|
|
204
|
+
return raw;
|
|
205
|
+
}
|
|
206
|
+
if (typeof choices[0] === 'string') {
|
|
207
|
+
return raw;
|
|
208
|
+
}
|
|
209
|
+
const id = String(raw);
|
|
210
|
+
const flat = choices.filter((c) => !isChoiceSeparator(c) && typeof c !== 'string');
|
|
211
|
+
let found = flat.find((c) => c.id === id);
|
|
212
|
+
if (found === undefined) {
|
|
213
|
+
found = flat.find((c) => String(c.value) === id || String(c.name) === id);
|
|
214
|
+
}
|
|
215
|
+
if (found === undefined) {
|
|
216
|
+
const idx = Number(id);
|
|
217
|
+
if (!isNaN(idx) && idx >= 0 && idx <= flat.length) {
|
|
218
|
+
found = flat[idx];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (found === undefined) {
|
|
222
|
+
const promptChoices = flat
|
|
223
|
+
.map((c) => '* ' + (typeof c.value === 'string' ? c.value : c.id))
|
|
224
|
+
.join('\n');
|
|
225
|
+
throw new error_1.default(`No list choice matches "${id}" for prompt "${qName}".`, {
|
|
226
|
+
exit: 1,
|
|
227
|
+
errorId: 'E_RUNTIME_PROMPT_NO_MATCH',
|
|
228
|
+
arg: [(0, ansi_colors_1.bold)(id), (0, ansi_colors_1.bold)(qName), promptChoices]
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return found.value;
|
|
232
|
+
}
|
|
233
|
+
default:
|
|
234
|
+
return raw;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
71
237
|
const registeredTypes = new Map();
|
|
72
238
|
exports.default = {
|
|
73
239
|
register: (type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -101,72 +267,103 @@ exports.default = {
|
|
|
101
267
|
separator: (line) => {
|
|
102
268
|
return new inquirer_1.default.Separator(line);
|
|
103
269
|
},
|
|
104
|
-
choice,
|
|
270
|
+
choice: choice_1.choice,
|
|
105
271
|
ask: (...questions) => {
|
|
106
|
-
const
|
|
107
|
-
|
|
272
|
+
const runInteractiveAsk = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
273
|
+
if (!(0, env_1.isNonInteractiveMode)()) {
|
|
274
|
+
return inquirer_1.default.prompt(questions.map(omitCliOptionKeyForInquirer));
|
|
275
|
+
}
|
|
276
|
+
const answers = {};
|
|
277
|
+
const askableQuestions = [];
|
|
108
278
|
for (const question of questions) {
|
|
109
|
-
if (question
|
|
110
|
-
question
|
|
111
|
-
|
|
112
|
-
if (!
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
279
|
+
if (yield questionWillBeAsked(question, answers)) {
|
|
280
|
+
askableQuestions.push(question);
|
|
281
|
+
const qName = (0, question_factory_1.getQuestionPromptName)(question);
|
|
282
|
+
if (!(qName in answers)) {
|
|
283
|
+
const raw = yield resolveRawInputForQuestion(question, answers);
|
|
284
|
+
if (raw !== undefined) {
|
|
285
|
+
yield applyRawToAnswer(question, answers, raw);
|
|
286
|
+
}
|
|
116
287
|
}
|
|
117
288
|
}
|
|
118
289
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
runtimeAns.includes(choice.id))
|
|
133
|
-
.map((filteredChoice) => filteredChoice.value);
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
case 'list': {
|
|
137
|
-
answers[question.name] = (_a = question.choices.find((choice) => choice.id === runtimeAns.toString())) === null || _a === void 0 ? void 0 : _a.value;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
default: {
|
|
141
|
-
answers[question.name] = runtimeAns;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
290
|
+
const missingAskableQuestions = askableQuestions.filter((q) => {
|
|
291
|
+
const qName = (0, question_factory_1.getQuestionPromptName)(q);
|
|
292
|
+
return !(qName in answers);
|
|
293
|
+
});
|
|
294
|
+
if (missingAskableQuestions.length > 0) {
|
|
295
|
+
const names = missingAskableQuestions
|
|
296
|
+
.map((q) => (0, question_factory_1.getQuestionPromptName)(q))
|
|
297
|
+
.join(', ');
|
|
298
|
+
const niSource = (0, env_1.getNonInteractiveModeSource)();
|
|
299
|
+
let hint;
|
|
300
|
+
if ((0, env_1.isCLIBin)()) {
|
|
301
|
+
if (niSource === 'env') {
|
|
302
|
+
hint = `Use command options to supply values, or unset ${(0, ansi_colors_1.italic)('ZCATALYST_NON_INTERACTIVE')}.`;
|
|
144
303
|
}
|
|
304
|
+
else if (niSource === 'option') {
|
|
305
|
+
hint = `Use command options to supply values, or run without ${(0, ansi_colors_1.italic)('--non-interactive, -ni')}.`;
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
hint =
|
|
309
|
+
'Use command options to supply values, or disable non-interactive mode.';
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
hint = `Use Catalyst.exec({ inputs: { ... } }) or matching options, or disable non-interactive mode (e.g. omit nonInteractive / ZCATALYST_NON_INTERACTIVE).`;
|
|
314
|
+
}
|
|
315
|
+
const _firstMissingQ = missingAskableQuestions[0];
|
|
316
|
+
if (_firstMissingQ.niInputMissingError) {
|
|
317
|
+
if (typeof _firstMissingQ.niInputMissingError === 'string') {
|
|
318
|
+
throw new error_1.default(_firstMissingQ.niInputMissingError, {
|
|
319
|
+
exit: 1,
|
|
320
|
+
errorId: 'E_NON_INTERACTIVE_MISSING_INPUTS_ANY',
|
|
321
|
+
arg: [(0, ansi_colors_1.bold)(_firstMissingQ.niInputMissingError)]
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
_firstMissingQ.niInputMissingError.skipHelp = false;
|
|
325
|
+
throw _firstMissingQ.niInputMissingError;
|
|
326
|
+
}
|
|
327
|
+
throw new error_1.default(`Non-interactive mode requires prepared inputs for: ${(0, ansi_colors_1.bold)(names)}`, {
|
|
328
|
+
exit: 1,
|
|
329
|
+
errorId: 'E_NON_INTERACTIVE_MISSING_INPUTS',
|
|
330
|
+
arg: [
|
|
331
|
+
(0, ansi_colors_1.bold)(names),
|
|
332
|
+
hint,
|
|
333
|
+
(0, utils_1.shellCommand)(`catalyst help ${(0, option_1.getCurrentCommand)()}`)
|
|
334
|
+
]
|
|
145
335
|
});
|
|
146
|
-
res(answers);
|
|
147
|
-
}
|
|
148
|
-
catch (err) {
|
|
149
|
-
rej(err);
|
|
150
336
|
}
|
|
337
|
+
return answers;
|
|
151
338
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
339
|
+
const stored = runtime_store_1.default.get('context.prompt', false);
|
|
340
|
+
const effective = typeof stored === 'object' && stored !== null ? Object.assign({}, stored) : {};
|
|
341
|
+
let filledFromCli = false;
|
|
342
|
+
for (const q of questions) {
|
|
343
|
+
const qName = (0, question_factory_1.getQuestionPromptName)(q);
|
|
344
|
+
if (effective[qName] === undefined) {
|
|
345
|
+
const optKey = q.fieldOrName instanceof register_fields_1.PromptFieldHandle
|
|
346
|
+
? q.fieldOrName.optKey
|
|
347
|
+
: q.fieldOrName;
|
|
348
|
+
const fromOpts = (0, option_1.getOptionValue)(optKey, undefined);
|
|
349
|
+
if (fromOpts !== undefined) {
|
|
350
|
+
effective[qName] = fromOpts;
|
|
351
|
+
filledFromCli = true;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
163
354
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
355
|
+
const fromExec = typeof stored === 'object' && stored !== null;
|
|
356
|
+
const useRuntimePath = fromExec || filledFromCli;
|
|
357
|
+
if (!useRuntimePath) {
|
|
358
|
+
return runInteractiveAsk();
|
|
359
|
+
}
|
|
360
|
+
return resolveRuntimePromptAnswers(questions, effective);
|
|
361
|
+
},
|
|
362
|
+
question: question_factory_1.buildQuestion
|
|
172
363
|
};
|
|
364
|
+
var overwrite_prompt_1 = require("./overwrite-prompt");
|
|
365
|
+
Object.defineProperty(exports, "overwritePromptQuestion", { enumerable: true, get: function () { return overwrite_prompt_1.overwritePromptQuestion; } });
|
|
366
|
+
var register_fields_2 = require("./register-fields");
|
|
367
|
+
Object.defineProperty(exports, "definePromptFields", { enumerable: true, get: function () { return register_fields_2.definePromptFields; } });
|
|
368
|
+
Object.defineProperty(exports, "PromptFieldHandle", { enumerable: true, get: function () { return register_fields_2.PromptFieldHandle; } });
|
|
369
|
+
Object.defineProperty(exports, "PromptFieldsRegistry", { enumerable: true, get: function () { return register_fields_2.PromptFieldsRegistry; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IQuestion, PromptFieldHandle } from './index';
|
|
2
|
+
type OverwriteResource = 'Directory' | 'File';
|
|
3
|
+
interface OverwritePromptOpts {
|
|
4
|
+
fieldOrName?: string | PromptFieldHandle;
|
|
5
|
+
resourceName: string;
|
|
6
|
+
resourceType?: OverwriteResource;
|
|
7
|
+
contextText?: string;
|
|
8
|
+
defaultAns?: boolean | null;
|
|
9
|
+
}
|
|
10
|
+
export declare const overwritePromptQuestion: ({ fieldOrName, resourceName, resourceType, contextText, defaultAns }: OverwritePromptOpts) => IQuestion;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.overwritePromptQuestion = void 0;
|
|
4
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
5
|
+
const question_factory_1 = require("./question-factory");
|
|
6
|
+
const overwritePromptQuestion = ({ fieldOrName = 'overwrite', resourceName, resourceType = 'Directory', contextText = '', defaultAns = false }) => {
|
|
7
|
+
const messageSuffix = contextText ? ` ${contextText}` : '';
|
|
8
|
+
const qOpts = {
|
|
9
|
+
type: 'confirm'
|
|
10
|
+
};
|
|
11
|
+
if (defaultAns !== null) {
|
|
12
|
+
qOpts['defaultAns'] = defaultAns;
|
|
13
|
+
}
|
|
14
|
+
return (0, question_factory_1.buildQuestion)(fieldOrName, `${resourceType} ${(0, ansi_colors_1.underline)(resourceName)} already exists${messageSuffix}. Overwrite ?`, qOpts);
|
|
15
|
+
};
|
|
16
|
+
exports.overwritePromptQuestion = overwritePromptQuestion;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import Separator from 'inquirer/lib/objects/separator';
|
|
3
|
+
import { PromptFieldHandle } from './register-fields';
|
|
4
|
+
import type { TreeData, TreeNode } from './types/tree';
|
|
5
|
+
import CatalystError from '../error';
|
|
6
|
+
export interface IChoice extends inquirer.ChoiceOptions, inquirer.ListChoiceOptions, inquirer.CheckboxChoiceOptions {
|
|
7
|
+
id?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IQuestion extends inquirer.Question, inquirer.ListQuestionOptions {
|
|
10
|
+
fieldOrName: string | PromptFieldHandle;
|
|
11
|
+
type?: inquirer.QuestionTypeName | 'file-path' | 'tree' | 'search-box' | 'with-desc';
|
|
12
|
+
defaultAns?: unknown;
|
|
13
|
+
choices?: Array<IChoice | TSeparator> | Array<string | TSeparator>;
|
|
14
|
+
treeChoices?: Array<TreeNode | TreeData>;
|
|
15
|
+
rootPath?: string;
|
|
16
|
+
exclude?: Array<string>;
|
|
17
|
+
excludeDir?: boolean;
|
|
18
|
+
ignoreFiles?: boolean;
|
|
19
|
+
depth?: number;
|
|
20
|
+
empTxt?: string;
|
|
21
|
+
validatingText?: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
searchable?: boolean;
|
|
24
|
+
pageSize?: number;
|
|
25
|
+
highlight?: boolean;
|
|
26
|
+
notFoundMsg?: string;
|
|
27
|
+
searchMsg?: string;
|
|
28
|
+
boxType?: string;
|
|
29
|
+
source?: (answersSoFar: unknown, input: string | undefined) => Promise<unknown> | unknown;
|
|
30
|
+
niInputMissingError?: CatalystError | string;
|
|
31
|
+
}
|
|
32
|
+
export type TSeparator = Separator;
|
|
33
|
+
export declare function getQuestionPromptName(question: IQuestion): string;
|
|
34
|
+
export declare function buildQuestion(fieldOrName: string | PromptFieldHandle, messageText: string, { type, defaultAns, choices, validate, filter, when, prefix, suffix, ...otheropts }?: Omit<IQuestion, 'name' | 'fieldOrName'>): IQuestion;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.getQuestionPromptName = getQuestionPromptName;
|
|
15
|
+
exports.buildQuestion = buildQuestion;
|
|
16
|
+
const choice_1 = require("./choice");
|
|
17
|
+
const register_fields_1 = require("./register-fields");
|
|
18
|
+
function getQuestionPromptName(question) {
|
|
19
|
+
return question.fieldOrName instanceof register_fields_1.PromptFieldHandle
|
|
20
|
+
? question.fieldOrName.promptName
|
|
21
|
+
: question.fieldOrName;
|
|
22
|
+
}
|
|
23
|
+
function buildQuestion(fieldOrName, messageText, _a = {}) {
|
|
24
|
+
var { type = 'input', defaultAns, choices = [], validate = () => {
|
|
25
|
+
return true;
|
|
26
|
+
}, filter = (ans) => {
|
|
27
|
+
return ans;
|
|
28
|
+
}, when = () => {
|
|
29
|
+
return true;
|
|
30
|
+
}, prefix = '', suffix = '' } = _a, otheropts = __rest(_a, ["type", "defaultAns", "choices", "validate", "filter", "when", "prefix", "suffix"]);
|
|
31
|
+
if (choices.length > 0 && typeof choices[0] === 'string') {
|
|
32
|
+
choices = choices.map((strChoice) => (0, choice_1.choice)(strChoice));
|
|
33
|
+
}
|
|
34
|
+
return Object.assign({ type,
|
|
35
|
+
fieldOrName, message: messageText, default: defaultAns, choices,
|
|
36
|
+
validate,
|
|
37
|
+
filter,
|
|
38
|
+
when,
|
|
39
|
+
prefix,
|
|
40
|
+
suffix }, otheropts);
|
|
41
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type PromptFieldDef = {
|
|
2
|
+
name: string;
|
|
3
|
+
cliOption: {
|
|
4
|
+
description: string;
|
|
5
|
+
option: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export type PromptFieldNames<T extends ReadonlyArray<PromptFieldDef>> = T[number]['name'];
|
|
9
|
+
export type DefinedPromptFields<T extends ReadonlyArray<PromptFieldDef>> = PromptFieldsRegistry<T>;
|
|
10
|
+
export declare class PromptFieldHandle<F extends PromptFieldDef = PromptFieldDef> extends Array<string> {
|
|
11
|
+
readonly def: F;
|
|
12
|
+
constructor(def: F);
|
|
13
|
+
get optKey(): string;
|
|
14
|
+
get promptName(): string;
|
|
15
|
+
toCliOpts(): [string, string];
|
|
16
|
+
}
|
|
17
|
+
export declare class PromptFieldsRegistry<T extends ReadonlyArray<PromptFieldDef>> {
|
|
18
|
+
readonly map: Map<string, PromptFieldHandle<PromptFieldDef>>;
|
|
19
|
+
constructor(fields: T);
|
|
20
|
+
get<K extends PromptFieldNames<T>>(name: K): PromptFieldHandle<Extract<T[number], {
|
|
21
|
+
name: K;
|
|
22
|
+
}>>;
|
|
23
|
+
}
|
|
24
|
+
export declare function definePromptFields<T extends ReadonlyArray<PromptFieldDef>>(fields: T): PromptFieldsRegistry<T>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromptFieldsRegistry = exports.PromptFieldHandle = void 0;
|
|
4
|
+
exports.definePromptFields = definePromptFields;
|
|
5
|
+
const cli_option_key_1 = require("./cli-option-key");
|
|
6
|
+
class PromptFieldHandle extends Array {
|
|
7
|
+
constructor(def) {
|
|
8
|
+
super();
|
|
9
|
+
this.def = def;
|
|
10
|
+
this.push(this.def.cliOption.option, this.def.cliOption.description);
|
|
11
|
+
}
|
|
12
|
+
get optKey() {
|
|
13
|
+
return (0, cli_option_key_1.commanderOptionKey)(this.def.cliOption.option);
|
|
14
|
+
}
|
|
15
|
+
get promptName() {
|
|
16
|
+
return this.def.name;
|
|
17
|
+
}
|
|
18
|
+
toCliOpts() {
|
|
19
|
+
return [this.def.cliOption.option, this.def.cliOption.description];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.PromptFieldHandle = PromptFieldHandle;
|
|
23
|
+
class PromptFieldsRegistry {
|
|
24
|
+
constructor(fields) {
|
|
25
|
+
this.map = new Map();
|
|
26
|
+
for (const f of fields) {
|
|
27
|
+
this.map.set(f.name, new PromptFieldHandle(f));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
get(name) {
|
|
31
|
+
return this.map.get(name);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.PromptFieldsRegistry = PromptFieldsRegistry;
|
|
35
|
+
function definePromptFields(fields) {
|
|
36
|
+
return new PromptFieldsRegistry(fields);
|
|
37
|
+
}
|
|
@@ -1,4 +1,37 @@
|
|
|
1
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -12,10 +45,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
46
|
};
|
|
14
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const ansi_colors_1 = require("ansi-colors");
|
|
16
48
|
const apig_utils_1 = require("../../apig-utils");
|
|
17
49
|
const endpoints_1 = require("../../endpoints");
|
|
18
|
-
const prompt_1 =
|
|
50
|
+
const prompt_1 = __importStar(require("../../prompt"));
|
|
19
51
|
const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
20
52
|
const config_1 = require("../../util_modules/config");
|
|
21
53
|
const fs_1 = require("../../util_modules/fs");
|
|
@@ -23,6 +55,10 @@ const sync_1 = require("../../util_modules/fs/lib/sync");
|
|
|
23
55
|
const index_1 = require("../../util_modules/logger/index");
|
|
24
56
|
const project_1 = require("../../util_modules/project");
|
|
25
57
|
const error_1 = __importDefault(require("../../error"));
|
|
58
|
+
const env_1 = require("../../util_modules/env");
|
|
59
|
+
const option_1 = require("../../util_modules/option");
|
|
60
|
+
const utils_1 = require("../utils");
|
|
61
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
26
62
|
exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
63
|
const apigName = config_1.apigConfig.rules();
|
|
28
64
|
const apigDirPath = (0, project_1.resolveProjectPath)(apigName);
|
|
@@ -37,7 +73,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
37
73
|
(0, index_1.info)();
|
|
38
74
|
const consent = yield prompt_1.default.ask(prompt_1.default.question('enable', 'The APIG is disable in catalyst console, Do you want to enable it and pull the APIG rules now ?', {
|
|
39
75
|
type: 'confirm',
|
|
40
|
-
defaultAns:
|
|
76
|
+
defaultAns: (0, env_1.isNonInteractiveMode)()
|
|
41
77
|
}));
|
|
42
78
|
if (!consent.enable) {
|
|
43
79
|
(0, index_1.info)('Skipping APIG pull. Since the APIG is disabled in catalyst console.');
|
|
@@ -47,12 +83,27 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
47
83
|
}
|
|
48
84
|
const fileExists = yield fs_1.ASYNC.fileExists(apigDirPath);
|
|
49
85
|
const overwriteAns = fileExists
|
|
50
|
-
? yield prompt_1.default.ask(
|
|
51
|
-
|
|
52
|
-
|
|
86
|
+
? yield prompt_1.default.ask((0, prompt_1.overwritePromptQuestion)({
|
|
87
|
+
resourceName: apigDirPath,
|
|
88
|
+
resourceType: 'File',
|
|
89
|
+
defaultAns: (0, env_1.isNonInteractiveMode)() &&
|
|
90
|
+
(0, option_1.getOptionValue)(utils_1.promptPullFields.get('overwrite').optKey, false)
|
|
91
|
+
? true
|
|
92
|
+
: false
|
|
53
93
|
}))
|
|
54
94
|
: { overwrite: true };
|
|
55
95
|
if (!overwriteAns.overwrite) {
|
|
96
|
+
if ((0, env_1.isNonInteractiveMode)()) {
|
|
97
|
+
throw new error_1.default('APIG pull failed as the APIG rules file already exists and the --overwrite option is not used to overwrite the file in local.', {
|
|
98
|
+
exit: 1,
|
|
99
|
+
errorId: 'E_NON_INTERACTIVE_APIG_PULL_OVERWRITE',
|
|
100
|
+
arg: [
|
|
101
|
+
ansi_colors_1.italic.red(apigDirPath),
|
|
102
|
+
(0, ansi_colors_1.italic)('--overwrite'),
|
|
103
|
+
(0, ansi_colors_1.italic)(`catalyst pull apig ${(0, ansi_colors_1.green)('--overwrite')}`)
|
|
104
|
+
]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
56
107
|
(0, index_1.info)('Skipping APIG pull');
|
|
57
108
|
return;
|
|
58
109
|
}
|