Skip to content

Commit

Permalink
CRWA: --yes (#8870)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Jul 13, 2023
1 parent 9c967cc commit 2a92ac3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/docs/create-redwood-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ You can by pass these prompts by using the following flags:
| `--overwrite` | | Overwrites the existing directory, if it has the same name |
| `--git-init` | `git` | Initializes a git repository |
| `--commit-message "Initial commit"` | `m` | Specifies the initial git commit message |
| `--yes` | `y` | Automatically select all defaults |

For example, here's the project with all flags enabled:

Expand Down
33 changes: 22 additions & 11 deletions packages/create-redwood-app/src/create-redwood-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
recordErrorViaTelemetry,
} from './telemetry'

const INITIAL_COMMIT_MESSAGE = 'Initial commit'

// Telemetry
const { telemetry } = Parser(hideBin(process.argv))

Expand Down Expand Up @@ -380,7 +382,7 @@ async function initializeGit(newAppDir, commitMessage) {
"Couldn't initialize a git repo",
[
`We could not initialize a git repo using ${RedwoodStyling.info(
'git init && git add . && git commit -m "Initial commit"'
`git init && git add . && git commit -m "${commitMessage}"`
)}. Please see below for the full error message.`,
'',
error,
Expand Down Expand Up @@ -474,7 +476,7 @@ async function handleCommitMessagePreference(commitMessageFlag) {
type: 'input',
name: 'commitMessage',
message: 'Enter a commit message',
initial: 'Initial commit',
initial: INITIAL_COMMIT_MESSAGE,
})
return response.commitMessage
} catch (_error) {
Expand Down Expand Up @@ -562,6 +564,12 @@ async function createRedwoodApp() {
type: 'string',
describe: 'Commit message for the initial commit.',
})
.option('yes', {
alias: 'y',
default: null,
type: 'boolean',
describe: 'Skip prompts and use defaults.',
})
.version(version)

const _isYarnBerryOrNewer = isYarnBerryOrNewer()
Expand All @@ -575,17 +583,20 @@ async function createRedwoodApp() {
})
}

const parsedFlags = cli.parse()

// Extract the args as provided by the user in the command line
// TODO: Make all flags have the 'flag' suffix
const {
_: args,
'yarn-install': yarnInstallFlag,
typescript: typescriptFlag,
overwrite,
// telemetry, // Extracted above to check if telemetry is disabled before we even reach this point
'git-init': gitInitFlag,
'commit-message': commitMessageFlag,
} = cli.parse()
const args = parsedFlags._
const yarnInstallFlag =
parsedFlags['yarn-install'] ?? !_isYarnBerryOrNewer ? parsedFlags.yes : null
const typescriptFlag = parsedFlags.typescript ?? parsedFlags.yes
const overwrite = parsedFlags.overwrite
// telemetry, // Extracted above to check if telemetry is disabled before we even reach this point
const gitInitFlag = parsedFlags['git-init'] ?? parsedFlags.yes
const commitMessageFlag =
parsedFlags['commit-message'] ??
(parsedFlags.yes ? INITIAL_COMMIT_MESSAGE : null)

// Record some of the arguments for telemetry
trace.getActiveSpan()?.setAttribute('yarn-install', yarnInstallFlag)
Expand Down

0 comments on commit 2a92ac3

Please sign in to comment.