speedrun-cli 2.7.6 → 2.7.7
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/package.json +1 -1
- package/src/moduleGenerator.js +87 -23
package/package.json
CHANGED
package/src/moduleGenerator.js
CHANGED
|
@@ -199,6 +199,7 @@ async function promptForModuleOptions(providedModuleName) {
|
|
|
199
199
|
selectedOperations = customOps;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
// Interactive Field Builder Loop
|
|
202
203
|
// Interactive Field Builder Loop
|
|
203
204
|
const { addCustomFields } = await inquirer.prompt([{
|
|
204
205
|
type: 'confirm',
|
|
@@ -210,13 +211,16 @@ async function promptForModuleOptions(providedModuleName) {
|
|
|
210
211
|
const fields = [];
|
|
211
212
|
|
|
212
213
|
if (addCustomFields) {
|
|
213
|
-
let
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
let building = true;
|
|
215
|
+
|
|
216
|
+
// Helper untuk input field baru / edit
|
|
217
|
+
const promptSingleField = async (initialValues = {}) => {
|
|
218
|
+
return await inquirer.prompt([
|
|
216
219
|
{
|
|
217
220
|
type: 'input',
|
|
218
221
|
name: 'fieldName',
|
|
219
222
|
message: 'Enter field name (e.g., totalAmount, title):',
|
|
223
|
+
default: initialValues.name,
|
|
220
224
|
validate: (input) => {
|
|
221
225
|
if (!input || !input.trim()) return 'Field name is required';
|
|
222
226
|
if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(input.trim())) {
|
|
@@ -230,30 +234,96 @@ async function promptForModuleOptions(providedModuleName) {
|
|
|
230
234
|
name: 'fieldType',
|
|
231
235
|
message: (answers) => `Select field type for '${answers.fieldName}':`,
|
|
232
236
|
choices: ['String', 'Number', 'Boolean', 'Date'],
|
|
233
|
-
default: 'String',
|
|
237
|
+
default: initialValues.type || 'String',
|
|
234
238
|
},
|
|
235
239
|
{
|
|
236
240
|
type: 'confirm',
|
|
237
241
|
name: 'isOptional',
|
|
238
242
|
message: (answers) => `Is '${answers.fieldName}' optional?`,
|
|
239
|
-
default: false,
|
|
243
|
+
default: initialValues.isOptional !== undefined ? initialValues.isOptional : false,
|
|
240
244
|
},
|
|
241
245
|
]);
|
|
246
|
+
};
|
|
242
247
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
248
|
+
// Tambah field pertama
|
|
249
|
+
console.log(chalk.cyan('\n--- Add Field 1 ---'));
|
|
250
|
+
const firstField = await promptSingleField();
|
|
251
|
+
fields.push({
|
|
252
|
+
name: firstField.fieldName.trim(),
|
|
253
|
+
type: firstField.fieldType,
|
|
254
|
+
isOptional: firstField.isOptional,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// Menu Navigasi (Add, Edit, Delete, Finish)
|
|
258
|
+
while (building) {
|
|
259
|
+
console.log(chalk.gray(`\nCurrent Fields (${fields.length}): `) + fields.map(f => chalk.yellow(`${f.name} (${f.type}${f.isOptional ? '?' : ''})`)).join(', '));
|
|
260
|
+
|
|
261
|
+
const { action } = await inquirer.prompt([{
|
|
262
|
+
type: 'list',
|
|
263
|
+
name: 'action',
|
|
264
|
+
message: 'What do you want to do next?',
|
|
265
|
+
choices: [
|
|
266
|
+
{ name: '➕ Add another field', value: 'add' },
|
|
267
|
+
{ name: '✏️ Edit an existing field', value: 'edit' },
|
|
268
|
+
{ name: '🗑️ Delete a field', value: 'delete' },
|
|
269
|
+
{ name: '✅ Finish and generate module', value: 'done' },
|
|
270
|
+
],
|
|
254
271
|
}]);
|
|
255
272
|
|
|
256
|
-
|
|
273
|
+
if (action === 'add') {
|
|
274
|
+
console.log(chalk.cyan(`\n--- Add Field ${fields.length + 1} ---`));
|
|
275
|
+
const newField = await promptSingleField();
|
|
276
|
+
fields.push({
|
|
277
|
+
name: newField.fieldName.trim(),
|
|
278
|
+
type: newField.fieldType,
|
|
279
|
+
isOptional: newField.isOptional,
|
|
280
|
+
});
|
|
281
|
+
} else if (action === 'edit') {
|
|
282
|
+
if (fields.length === 0) {
|
|
283
|
+
console.log(chalk.yellow('⚠️ No fields available to edit.'));
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const { fieldToEditIndex } = await inquirer.prompt([{
|
|
288
|
+
type: 'list',
|
|
289
|
+
name: 'fieldToEditIndex',
|
|
290
|
+
message: 'Select field to edit:',
|
|
291
|
+
choices: fields.map((f, index) => ({
|
|
292
|
+
name: `${f.name} (${f.type}${f.isOptional ? '?' : ''})`,
|
|
293
|
+
value: index,
|
|
294
|
+
})),
|
|
295
|
+
}]);
|
|
296
|
+
|
|
297
|
+
console.log(chalk.cyan(`\n--- Editing Field '${fields[fieldToEditIndex].name}' ---`));
|
|
298
|
+
const editedField = await promptSingleField(fields[fieldToEditIndex]);
|
|
299
|
+
fields[fieldToEditIndex] = {
|
|
300
|
+
name: editedField.fieldName.trim(),
|
|
301
|
+
type: editedField.fieldType,
|
|
302
|
+
isOptional: editedField.isOptional,
|
|
303
|
+
};
|
|
304
|
+
console.log(chalk.green(`✓ Field '${fields[fieldToEditIndex].name}' updated successfully.`));
|
|
305
|
+
} else if (action === 'delete') {
|
|
306
|
+
if (fields.length === 0) {
|
|
307
|
+
console.log(chalk.yellow('⚠️ No fields available to delete.'));
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const { fieldToDeleteIndex } = await inquirer.prompt([{
|
|
312
|
+
type: 'list',
|
|
313
|
+
name: 'fieldToDeleteIndex',
|
|
314
|
+
message: 'Select field to delete:',
|
|
315
|
+
choices: fields.map((f, index) => ({
|
|
316
|
+
name: `${f.name} (${f.type}${f.isOptional ? '?' : ''})`,
|
|
317
|
+
value: index,
|
|
318
|
+
})),
|
|
319
|
+
}]);
|
|
320
|
+
|
|
321
|
+
const deletedName = fields[fieldToDeleteIndex].name;
|
|
322
|
+
fields.splice(fieldToDeleteIndex, 1);
|
|
323
|
+
console.log(chalk.red(`🗑️ Field '${deletedName}' removed.`));
|
|
324
|
+
} else if (action === 'done') {
|
|
325
|
+
building = false;
|
|
326
|
+
}
|
|
257
327
|
}
|
|
258
328
|
}
|
|
259
329
|
|
|
@@ -261,12 +331,6 @@ async function promptForModuleOptions(providedModuleName) {
|
|
|
261
331
|
if (fields.length === 0) {
|
|
262
332
|
fields.push({ name: 'name', type: 'String', isOptional: false });
|
|
263
333
|
}
|
|
264
|
-
|
|
265
|
-
return {
|
|
266
|
-
moduleName,
|
|
267
|
-
operations: selectedOperations,
|
|
268
|
-
fields,
|
|
269
|
-
};
|
|
270
334
|
}
|
|
271
335
|
|
|
272
336
|
function getFieldExampleValue(field, pascalName) {
|