From 4f1c30c1766263e7dd1276445933db00464771b0 Mon Sep 17 00:00:00 2001 From: Colton Padden Date: Mon, 4 Oct 2021 15:36:50 -0400 Subject: [PATCH] Support optional [path] argument in create-app command-line utility When this is specified, then copy the newly created application to the specified directory, otherwise, copy the application to a folder based on the name specified name. Signed-off-by: Colton Padden --- .changeset/neat-rings-protect.md | 5 +++++ packages/create-app/src/createApp.ts | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .changeset/neat-rings-protect.md diff --git a/.changeset/neat-rings-protect.md b/.changeset/neat-rings-protect.md new file mode 100644 index 0000000000..16b0a5fe82 --- /dev/null +++ b/.changeset/neat-rings-protect.md @@ -0,0 +1,5 @@ +--- +'@backstage/create-app': minor +--- + +Support optional path argument when generating a project using `create-app` diff --git a/packages/create-app/src/createApp.ts b/packages/create-app/src/createApp.ts index 1da3139f41..0c1cd09d5b 100644 --- a/packages/create-app/src/createApp.ts +++ b/packages/create-app/src/createApp.ts @@ -77,7 +77,7 @@ async function buildApp(appDir: string) { async function moveApp(tempDir: string, destination: string, id: string) { await Task.forItem('moving', id, async () => { - await fs.move(tempDir, destination).catch(error => { + await fs.move(tempDir, destination, { overwrite: true }).catch(error => { throw new Error( `Failed to move app from ${tempDir} to ${destination}: ${error.message}`, ); @@ -119,14 +119,24 @@ export default async (cmd: Command): Promise => { const templateDir = paths.resolveOwn('templates/default-app'); const tempDir = resolvePath(os.tmpdir(), answers.name); - const appDir = resolvePath(paths.targetDir, answers.name); + + // Use `[path]` argument as applicaiton directory when specified, otherwise + // create a directory using `answers.name` + const appDir = + cmd.args.length > 0 + ? resolvePath(cmd.args[0]) + : resolvePath(paths.targetDir, answers.name); Task.log(); Task.log('Creating the app...'); try { - Task.section('Checking if the directory is available'); - await checkExists(paths.targetDir, answers.name); + // Directory must not already exist when using consructed path from + // `answers.name` + if (cmd.args.length === 0) { + Task.section('Checking if the directory is available'); + await checkExists(paths.targetDir, answers.name); + } Task.section('Creating a temporary app directory'); await createTemporaryAppFolder(tempDir);