From 7d24167afcdcebac7ac08519b8b12ede093d11e4 Mon Sep 17 00:00:00 2001 From: Min Kim Date: Wed, 11 Dec 2024 02:49:39 -0500 Subject: [PATCH] Add template-specific variables for execution Signed-off-by: Min Kim --- packages/cli/src/commands/new/new.ts | 13 +++++++++---- packages/cli/src/commands/new/util.ts | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/commands/new/new.ts b/packages/cli/src/commands/new/new.ts index aa1520ff6c..827352232d 100644 --- a/packages/cli/src/commands/new/new.ts +++ b/packages/cli/src/commands/new/new.ts @@ -17,6 +17,8 @@ import os from 'os'; import fs from 'fs-extra'; import { join as joinPath } from 'path'; +import camelCase from 'lodash/camelCase'; +import upperFirst from 'lodash/upperFirst'; import { isMonoRepo } from '@backstage/cli-node'; import { paths } from '../../lib/paths'; import { assertError } from '@backstage/errors'; @@ -82,19 +84,22 @@ export default async () => { templateDir: template.templatePath, values: { name: resolvePackageName({ - baseName: dirName, // convert to dirname + baseName: dirName, scope: options.scope, plugin: template.plugin ?? true, }), pluginVersion: options.baseVersion, - moduleVar: '', // backend module - extension: '', // frontend plugin - pluginVar: '', // backend plugin + moduleVar: `${camelCase(options.id)}Module${camelCase( + options.moduleId, + )[0].toUpperCase()}${camelCase(options.moduleId).slice(1)}`, // used in default-backend-module template + extension: `${upperFirst(camelCase(options.id))}Page`, // used in default-plugin template + pluginVar: `${camelCase(options.id)}Plugin`, // used in default-backend-plugin and default-plugin template ...options, }, }, ); + // update default templates // create additional actions // install to app // install to backend diff --git a/packages/cli/src/commands/new/util.ts b/packages/cli/src/commands/new/util.ts index 6e18cea949..d2e5849a37 100644 --- a/packages/cli/src/commands/new/util.ts +++ b/packages/cli/src/commands/new/util.ts @@ -171,6 +171,7 @@ interface Options extends Record { targetPath: string; owner: string; scope: string; + moduleId: string; } async function calculateBaseVersion(baseVersion: string) { @@ -199,6 +200,7 @@ export async function populateOptions( license: prompts.license ?? 'Apache-2.0', targetPath: prompts.targetPath ?? template.targetPath, scope: prompts.scope ?? '', + moduleId: prompts.moduleId ?? '', ...prompts, }; }