Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRWA: Prompt for installation dir #8955

Merged
merged 5 commits into from
Jul 25, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 33 additions & 24 deletions packages/create-redwood-app/src/create-redwood-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -404,6 +403,34 @@ async function initializeGit(newAppDir, commitMessage) {
tui.stopReactive()
}

async function handleTargetDirPreference(targetDir) {
if (targetDir) {
tui.drawText(
`${RedwoodStyling.green(
'✔'
)} Creating your Redwood app in ${targetDir} based on command line argument`
)

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) {
Expand Down Expand Up @@ -603,35 +630,15 @@ async function createRedwoodApp() {
trace.getActiveSpan()?.setAttribute('overwrite', overwrite)

// Get the directory for installation from the args
const targetDir = String(args).replace(/,/g, '-')
let 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(
'<project-directory>'
)}`,
'',
'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)
}

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)
Expand All @@ -654,6 +661,8 @@ async function createRedwoodApp() {
yarnInstall = await handleYarnInstallPreference(yarnInstallFlag)
}

const newAppDir = path.resolve(process.cwd(), targetDir)

// Create project files
await createProjectFiles(newAppDir, { templateDir, overwrite })

Expand Down