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): Add git init option #6824

Closed
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/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ yarn create redwood-app <project directory> [option]
| `--overwrite` | Create the project even if the specified project directory isn't empty |
| `--no-telemetry` | Disable sending telemetry events for this create command and all Redwood CLI commands: https://telemetry.redwoodjs.com |
| `--yarn1` | Use yarn 1 instead of yarn 3 |
| `--git-init`, `--git` | Initialize a git repo during the install process, disabled by default |

If you run into trouble during the yarn install step, which may happen if you're developing on an external drive and in other miscellaneous scenarios, try the `--yarn1` flag:

Expand Down
44 changes: 43 additions & 1 deletion packages/create-redwood-app/src/create-redwood-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { name, version } from '../package'
overwrite,
telemetry: telemetry,
yarn1,
'git-init': gitInit,
} = yargs(hideBin(process.argv))
.scriptName(name)
.usage('Usage: $0 <project directory> [option]')
Expand Down Expand Up @@ -102,6 +103,12 @@ import { name, version } from '../package'
type: 'boolean',
describe: 'Use yarn 1. yarn 3 by default',
})
.option('git-init', {
alias: 'git',
default: null,
type: 'boolean',
describe: 'Initialize a git repository.',
})
.version(version)
.parse()

Expand Down Expand Up @@ -338,8 +345,30 @@ import { name, version } from '../package'
message: 'Select your preferred coding language',
initial: 'TypeScript',
})

task.output = ctx.language
// Error code and exit if someone has disabled yarn install but selected JavaScript
if (!yarnInstall && ctx.language === 'JavaScript') {
throw new Error(
'JavaScript transpilation requires running yarn install. Please rerun create-redwood-app without disabling yarn install.'
)
}
},
options: {
persistentOutput: true,
},
},
{
title: 'Git preference',
skip: () => gitInit !== null,
task: async (ctx, task) => {
ctx.gitInit = await task.prompt({
type: 'Toggle',
message: 'Do you want to initialize a git repo?',
enabled: 'Yes',
disabled: 'no',
initial: 'Yes',
})
task.output = ctx.gitInit ? 'Initialize a git repo' : 'Skip'
},
options: {
persistentOutput: true,
Expand Down Expand Up @@ -377,6 +406,19 @@ import { name, version } from '../package'
})
},
},
{
title: 'Initializing a git repo',
enabled: (ctx) => gitInit || ctx.gitInit,
task: () => {
return execa(
'git init && git add . && git commit -m "Initial commit"',
{
shell: true,
cwd: newAppDir,
}
)
},
},
],
{
rendererOptions: { collapse: false },
Expand Down
1 change: 1 addition & 0 deletions tasks/run-e2e
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const createRedwoodJSApp = ({ yarn1 }) => {
'--no-yarn-install',
'--typescript',
'--no-telemetry',
'--no-git',
yarn1 && '--yarn1',
].filter(Boolean),
{
Expand Down