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: --yes #8870

Merged
merged 6 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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