Skip to content

Commit 816d02d

Browse files
committed
feat: enhance CRUD injection logging and improve component file naming with optional additional name
1 parent 20ce34c commit 816d02d

File tree

5 files changed

+56
-24
lines changed

5 files changed

+56
-24
lines changed

adminforth/commands/createCustomComponent/configUpdater.js

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ export async function updateResourceConfig(resourceId, columnName, fieldType, co
202202
const outputCode = recast.print(ast).code;
203203

204204
await fs.writeFile(filePath, outputCode, 'utf-8');
205-
console.log(chalk.dim(`Successfully updated resource configuration file (preserving formatting): ${filePath}:${injectionLine}`));
205+
console.log(
206+
chalk.green(
207+
`✅ Successfully updated CRUD injection in resource file: ${filePath}` +
208+
(injectionLine !== null ? `:${injectionLine}` : '')
209+
)
210+
);
206211

207212
} catch (error) {
208213
console.error(chalk.red(`❌ Error processing resource file: ${filePath}`));
@@ -309,7 +314,12 @@ export async function injectLoginComponent(indexFilePath, componentPath) {
309314

310315
const outputCode = recast.print(ast).code;
311316
await fs.writeFile(indexFilePath, outputCode, 'utf-8');
312-
console.log(chalk.green(`✅ Successfully updated login injection in: ${indexFilePath}:${injectionLine}`));
317+
console.log(
318+
chalk.green(
319+
`✅ Successfully updated CRUD injection in resource file: ${indexFilePath}` +
320+
(injectionLine !== null ? `:${injectionLine}` : '')
321+
)
322+
);
313323
}
314324

315325

@@ -402,7 +412,12 @@ export async function injectGlobalComponent(indexFilePath, injectionType, compon
402412

403413
const outputCode = recast.print(ast).code;
404414
await fs.writeFile(indexFilePath, outputCode, 'utf-8');
405-
console.log(chalk.green(`✅ Successfully updated global injection '${injectionType}' in: ${indexFilePath}:${injectionLine}`));
415+
console.log(
416+
chalk.green(
417+
`✅ Successfully updated CRUD injection in resource file: ${indexFilePath}` +
418+
(injectionLine !== null ? `:${injectionLine}` : '')
419+
)
420+
);
406421
}
407422

408423
export async function updateCrudInjectionConfig(resourceId, crudType, injectionPosition, componentPathForConfig, isThin) {
@@ -487,11 +502,23 @@ export async function updateCrudInjectionConfig(resourceId, crudType, injectionP
487502
]);
488503

489504
if (injectionProp) {
490-
injectionProp.value = newInjectionObject;
491-
console.log(chalk.dim(`Updated '${injectionPosition}' injection for '${crudType}'.`));
505+
if (n.ArrayExpression.check(injectionProp.value)) {
506+
injectionProp.value.elements.push(newInjectionObject);
507+
console.log(chalk.dim(`Appended new injection to array at '${injectionPosition}' for '${crudType}'.`));
508+
}
509+
else if (n.ObjectExpression.check(injectionProp.value)) {
510+
injectionProp.value = b.arrayExpression([injectionProp.value, newInjectionObject]);
511+
console.log(chalk.dim(`Converted to array and added new injection at '${injectionPosition}' for '${crudType}'.`));
512+
}
513+
else {
514+
injectionProp.value = b.arrayExpression([newInjectionObject]);
515+
console.log(chalk.yellow(`⚠️ Replaced invalid injection at '${injectionPosition}' with array.`));
516+
}
492517
} else {
493-
crudValue.properties.push(b.objectProperty(b.identifier(injectionPosition), newInjectionObject));
494-
console.log(chalk.dim(`Added '${injectionPosition}' injection for '${crudType}'.`));
518+
crudValue.properties.push(
519+
b.objectProperty(b.identifier(injectionPosition), b.arrayExpression([newInjectionObject]))
520+
);
521+
console.log(chalk.dim(`Added new array of injections at '${injectionPosition}' for '${crudType}'.`));
495522
}
496523

497524
updateApplied = true;
@@ -506,7 +533,12 @@ export async function updateCrudInjectionConfig(resourceId, crudType, injectionP
506533

507534
const outputCode = recast.print(ast).code;
508535
await fs.writeFile(filePath, outputCode, 'utf-8');
509-
console.log(chalk.dim(`✅ Successfully updated CRUD injection in resource file: ${filePath}:${injectionLine}`));
536+
console.log(
537+
chalk.green(
538+
`✅ Successfully updated CRUD injection in resource file: ${filePath}` +
539+
(injectionLine !== null ? `:${injectionLine}` : '')
540+
)
541+
);
510542

511543
} catch (error) {
512544
console.error(chalk.red(`❌ Error processing resource file: ${filePath}`));

adminforth/commands/createCustomComponent/main.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,26 @@ async function handleCrudPageInjectionCreation(config, resources) {
170170
});
171171
if (injectionPosition === '__BACK__') return handleCrudPageInjectionCreation(config, resources);
172172

173+
const additionalName = await input({
174+
message: 'Enter additional name (optional, e.g., "CustomExport"):',
175+
validate: (value) => {
176+
if (!value) return true;
177+
return /^[A-Za-z0-9_-]+$/.test(value) || 'Only alphanumeric characters, hyphens or underscores are allowed.';
178+
},
179+
});
180+
173181
const isThin = await select({
174182
message: 'Will this component be thin enough to fit on the same page with list (so list will still shrink)?',
175183
choices: [
176184
{ name: 'Yes', value: true },
177185
{ name: 'No', value: false },
178186
],
179187
});
180-
188+
const formattedAdditionalName = additionalName
189+
? additionalName[0].toUpperCase() + additionalName.slice(1)
190+
: '';
181191
const safeResourceLabel = sanitizeLabel(selectedResource.label)
182-
const componentFileName = `${safeResourceLabel}${crudType.charAt(0).toUpperCase() + crudType.slice(1)}${injectionPosition.charAt(0).toUpperCase() + injectionPosition.slice(1)}.vue`;
192+
const componentFileName = `${safeResourceLabel}${crudType.charAt(0).toUpperCase() + crudType.slice(1)}${injectionPosition.charAt(0).toUpperCase() + injectionPosition.slice(1) + formattedAdditionalName}.vue`;
183193
const componentPathForConfig = `@@/${componentFileName}`;
184194

185195
try {

adminforth/commands/createCustomComponent/templates/customCrud/afterBreadcrumbs.vue.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@click="handleClick"
66
class="text-white bg-blue-600 hover:bg-blue-700 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-500 dark:hover:bg-blue-600 dark:focus:ring-blue-800"
77
>
8-
{{ {{ $t('Example') }} }}
8+
\{{ $t('Example') }}
99
</button>
1010
</div>
1111
</template>

adminforth/commands/createCustomComponent/templates/customCrud/beforeBreadcrumbs.vue.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@click="handleClick"
66
class="text-white bg-blue-600 hover:bg-blue-700 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-500 dark:hover:bg-blue-600 dark:focus:ring-blue-800"
77
>
8-
{{ $t('Example') }}
8+
\{{ $t('Example') }}
99
</button>
1010
</div>
1111
</template>

adminforth/commands/createCustomComponent/templates/customCrud/threeDotsDropdownItems.vue.hbs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
v-for="item in menuItems"
55
:key="item.label"
66
@click="item.action"
7-
class="w-full text-left text-sm px-4 py-2 rounded hover:bg-gray-100 dark:hover:bg-gray-700 dark:text-white"
87
>
9-
{{ item.label }}
8+
\{{ item.label }}
109
</button>
1110
</div>
1211
</template>
@@ -35,16 +34,7 @@ const menuItems = [
3534
variant: 'success',
3635
});
3736
},
38-
},
39-
{
40-
label: 'Show Error Alert',
41-
action: () => {
42-
adminforth.alert({
43-
message: t('Error Alert'),
44-
variant: 'danger',
45-
});
46-
},
47-
},
37+
}
4838
];
4939
5040
onMounted(() => {

0 commit comments

Comments
 (0)