Apply suffix/prefix for generated dirname

Signed-off-by: Min Kim <minkimcello@gmail.com>
This commit is contained in:
Min Kim
2024-12-11 02:35:33 -05:00
parent 565eaa6e98
commit 6d27973629
3 changed files with 33 additions and 14 deletions
+12 -8
View File
@@ -35,6 +35,7 @@ import {
verifyTemplate,
promptOptions,
populateOptions,
createDirName,
} from './util';
export default async () => {
@@ -60,6 +61,9 @@ export default async () => {
return dir;
}
const dirName = createDirName(template, options);
const targetDir = paths.resolveTargetRoot(options.targetPath, dirName);
let modified = false;
try {
await executePluginPackageTemplate(
@@ -74,23 +78,23 @@ export default async () => {
},
},
{
targetDir: options.targetDir,
targetDir,
templateDir: template.templatePath,
values: {
name: resolvePackageName({
baseName: options.id,
baseName: dirName, // convert to dirname
scope: options.scope,
plugin: template.plugin ?? true,
}),
pluginVersion: options.baseVersion,
moduleVar: '', // backend module
extension: '', // frontend plugin
pluginVar: '', // backend plugin
...options,
},
},
);
// create scope prompt
// double check default template paths
// create additional actions
// install to app
// install to backend
@@ -99,15 +103,15 @@ export default async () => {
if (options.install) {
// 🚨 temporary
if (options.owner) {
await addCodeownersEntry(options.targetDir, options.owner);
await addCodeownersEntry(targetDir, options.owner);
}
await Task.forCommand('yarn install', {
cwd: options.targetDir,
cwd: targetDir,
optional: true,
});
await Task.forCommand('yarn lint --fix', {
cwd: options.targetDir,
cwd: targetDir,
optional: true,
});
}
+3
View File
@@ -28,6 +28,9 @@ export interface Template {
template: string;
templatePath: string;
targetPath: string;
plugin?: boolean;
backendModulePrefix?: boolean;
suffix?: string;
prompts?: ConfigurablePrompt[];
additionalActions?: string[];
}
+18 -6
View File
@@ -168,7 +168,7 @@ interface Options extends Record<string, string | boolean> {
private: boolean;
baseVersion: string;
license: string;
targetDir: string;
targetPath: string;
owner: string;
scope: string;
}
@@ -192,16 +192,28 @@ export async function populateOptions(
template: Template,
): Promise<Options> {
return {
id: prompts.id,
id: prompts.id ?? '',
private: false,
baseVersion: await calculateBaseVersion(prompts.baseVersion),
owner: prompts.owner ?? '',
license: prompts.license ?? 'Apache-2.0',
targetDir: paths.resolveTargetRoot(
prompts.targetPath ?? template.targetPath,
prompts.id as string,
),
targetPath: prompts.targetPath ?? template.targetPath,
scope: prompts.scope ?? '',
...prompts,
};
}
export function createDirName(template: Template, options: Options) {
if (!options.id) {
throw new Error(`id prompt is mandatory for all cli templates`);
}
if (template.backendModulePrefix) {
if (!options.moduleId) {
throw new Error(`backendModulePrefix requires moduleId prompt`);
}
return `${options.id}-backend-module-${options.moduleId}`;
} else if (template.suffix) {
return `${options.id}-${template.suffix}`;
}
return options.id;
}