From 4d5974495d1ac8c75d113c25e3e0098e8e7ab609 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Mon, 24 Jul 2023 01:59:50 +0200 Subject: [PATCH 1/4] CRWA: Prompt for installation dir --- .../src/create-redwood-app.js | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index d74f390e5345..d7970686764f 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -3,7 +3,6 @@ import path from 'path' import { trace, SpanStatusCode } from '@opentelemetry/api' -import chalk from 'chalk' import checkNodeVersionCb from 'check-node-version' import execa from 'execa' import fs from 'fs-extra' @@ -404,6 +403,28 @@ async function initializeGit(newAppDir, commitMessage) { tui.stopReactive() } +async function handleTargetDirPreference(targetDir) { + if (targetDir) { + return targetDir + } + + // Prompt user for preference + try { + const response = await tui.prompt({ + type: 'input', + name: 'targetDir', + message: 'Where would you like to create your Redwood app?', + initial: 'my-redwood-app', + }) + + return response.targetDir + } catch { + recordErrorViaTelemetry('User cancelled install at target dir prompt') + await shutdownTelemetry() + process.exit(1) + } +} + async function handleTypescriptPreference(typescriptFlag) { // Handle case where flag is set if (typescriptFlag !== null) { @@ -603,35 +624,15 @@ async function createRedwoodApp() { trace.getActiveSpan()?.setAttribute('overwrite', overwrite) // Get the directory for installation from the args - const targetDir = String(args).replace(/,/g, '-') - - // Throw an error if there is no target directory specified - if (!targetDir) { - tui.displayError( - 'No target directory specified', - [ - 'Please specify the project directory', - ` ${chalk.cyan('yarn create redwood-app')} ${chalk.green( - '' - )}`, - '', - 'For example:', - ` ${chalk.cyan('yarn create redwood-app')} ${chalk.green( - 'my-redwood-app' - )}`, - ].join('\n') - ) - recordErrorViaTelemetry('No target directory specified') - await shutdownTelemetry() - process.exit(1) - } + let targetDir = String(args).replace(/,/g, '-') - const newAppDir = path.resolve(process.cwd(), targetDir) const templatesDir = path.resolve(__dirname, '../templates') // Engine check await executeCompatibilityCheck(path.join(templatesDir, 'ts')) + targetDir = await handleTargetDirPreference(targetDir) + // Determine ts/js preference const useTypescript = await handleTypescriptPreference(typescriptFlag) trace.getActiveSpan()?.setAttribute('typescript', useTypescript) @@ -654,6 +655,8 @@ async function createRedwoodApp() { yarnInstall = await handleYarnInstallPreference(yarnInstallFlag) } + const newAppDir = path.resolve(process.cwd(), targetDir) + // Create project files await createProjectFiles(newAppDir, { templateDir, overwrite }) From 74de2143c175f16cb753522f899df289f3b0ae6d Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Mon, 24 Jul 2023 02:16:30 +0200 Subject: [PATCH 2/4] Add message with selected targetdir --- packages/create-redwood-app/src/create-redwood-app.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index d7970686764f..3fe1b5cfcd9e 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -405,6 +405,12 @@ async function initializeGit(newAppDir, commitMessage) { async function handleTargetDirPreference(targetDir) { if (targetDir) { + tui.drawText( + `${RedwoodStyling.green( + '✔' + )} Creating your Redwood app in ${targetDir} based on command line argument` + ) + return targetDir } From 700fe7cea0d57986a005d131d2f20aea58a42d9c Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Mon, 24 Jul 2023 02:53:26 +0200 Subject: [PATCH 3/4] Untildify --- packages/create-redwood-app/package.json | 1 + packages/create-redwood-app/src/create-redwood-app.js | 3 ++- yarn.lock | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/create-redwood-app/package.json b/packages/create-redwood-app/package.json index 87254a5cf3bd..b3f359a04137 100644 --- a/packages/create-redwood-app/package.json +++ b/packages/create-redwood-app/package.json @@ -35,6 +35,7 @@ "semver": "7.5.3", "systeminformation": "5.18.5", "terminal-link": "2.1.1", + "untildify": "4.0.0", "uuid": "9.0.0", "yargs": "17.7.2" }, diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index 3fe1b5cfcd9e..5c6e0c5eaad8 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -8,6 +8,7 @@ import execa from 'execa' import fs from 'fs-extra' import semver from 'semver' import terminalLink from 'terminal-link' +import untildify from 'untildify' import { hideBin, Parser } from 'yargs/helpers' import yargs from 'yargs/yargs' @@ -423,7 +424,7 @@ async function handleTargetDirPreference(targetDir) { initial: 'my-redwood-app', }) - return response.targetDir + return untildify(response.targetDir) } catch { recordErrorViaTelemetry('User cancelled install at target dir prompt') await shutdownTelemetry() diff --git a/yarn.lock b/yarn.lock index 55c3b38dcb78..be2237252f5e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14997,6 +14997,7 @@ __metadata: semver: 7.5.3 systeminformation: 5.18.5 terminal-link: 2.1.1 + untildify: 4.0.0 uuid: 9.0.0 yargs: 17.7.2 bin: @@ -30767,7 +30768,7 @@ __metadata: languageName: node linkType: hard -"untildify@npm:^4.0.0": +"untildify@npm:4.0.0, untildify@npm:^4.0.0": version: 4.0.0 resolution: "untildify@npm:4.0.0" checksum: d758e624c707d49f76f7511d75d09a8eda7f2020d231ec52b67ff4896bcf7013be3f9522d8375f57e586e9a2e827f5641c7e06ee46ab9c435fc2b2b2e9de517a From ecee8171d581234d680de57c12e27a5f3c752653 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Mon, 24 Jul 2023 03:05:22 +0200 Subject: [PATCH 4/4] Error on ~username --- .../create-redwood-app/src/create-redwood-app.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index 5c6e0c5eaad8..f60dc9a05f24 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -424,6 +424,18 @@ async function handleTargetDirPreference(targetDir) { initial: 'my-redwood-app', }) + if (/^~\w/.test(response.targetDir)) { + tui.stopReactive(true) + tui.displayError( + 'The `~username` syntax is not supported here', + 'Please use the full path or specify the target directory on the command line.' + ) + + recordErrorViaTelemetry('Target dir prompt path syntax not supported') + await shutdownTelemetry() + process.exit(1) + } + return untildify(response.targetDir) } catch { recordErrorViaTelemetry('User cancelled install at target dir prompt')