Repository navigation
feat(cli): create develop, qa and main branches on project creation #158
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6f954d0
feat(cli): create develop, qa and main branches on project creation
fernandatoledo b445779
fix(cli): address review feedback on repository initialization
fernandatoledo 2a82650
Merge branch 'master' of github.com:rootstrap/react-native-template i…
fernandatoledo 0d812c7
fix(cli): use consistent returns in execShellCommand callback
fernandatoledo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,9 +12,35 @@ const ProjectFilesManager = require('./project-files-manager.js'); | |
| */ | ||
| let projectFilesManager; | ||
|
|
||
| const DEFAULT_BRANCH = 'develop'; | ||
| const ADDITIONAL_BRANCHES = ['qa', 'main']; | ||
|
|
||
| const hasGitIdentity = async (options) => { | ||
| const name = await execShellCommand('git config user.name || true', options); | ||
| const email = await execShellCommand('git config user.email || true', options); | ||
| return Boolean(name.trim() && email.trim()); | ||
| }; | ||
|
|
||
| // Branches can only be created once a commit exists, so the initial commit | ||
| // happens before renaming the current branch and branching off it. | ||
| const initializeProjectRepository = async (projectName) => { | ||
| const escapedProjectName = escapeShellArg(projectName); | ||
| await execShellCommand(`cd ${escapedProjectName} && git init && cd ..`); | ||
| const options = { cwd: projectName }; | ||
|
|
||
| await execShellCommand('git init', options); | ||
| await execShellCommand('git add -A', options); | ||
|
|
||
| const identityFlags = (await hasGitIdentity(options)) | ||
| ? '' | ||
| : '-c user.name="Rootstrap Template" -c user.email="[email protected]"'; | ||
| await execShellCommand( | ||
| `git ${identityFlags} commit -m "chore: initial commit from Rootstrap React Native template"`, | ||
| options, | ||
| ); | ||
| await execShellCommand(`git branch -M ${DEFAULT_BRANCH}`, options); | ||
|
|
||
| for (const branch of ADDITIONAL_BRANCHES) { | ||
| await execShellCommand(`git branch ${branch}`, options); | ||
| } | ||
| }; | ||
|
|
||
| const installDependencies = async (projectName) => { | ||
|
|
@@ -54,7 +80,7 @@ const removeUnrelatedFiles = () => { | |
| }; | ||
|
|
||
| // Update package.json infos, name and set version to 0.0.1 + add initial version to rsMetadata | ||
| const updatePackageJson = async (projectName) => { | ||
| const updatePackageJson = (projectName) => { | ||
| const packageJsonPath = | ||
| projectFilesManager.getAbsoluteFilePath('package.json'); | ||
|
|
||
|
|
@@ -75,7 +101,7 @@ const updatePackageJson = async (projectName) => { | |
| fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 }); | ||
| }; | ||
|
|
||
| const updateProjectConfig = async (projectName) => { | ||
| const updateProjectConfig = (projectName) => { | ||
| projectFilesManager.replaceFilesContent([ | ||
| { | ||
| fileName: 'env.js', | ||
|
|
@@ -227,12 +253,13 @@ const setupProject = async (projectName) => { | |
|
|
||
| try { | ||
| removeUnrelatedFiles(); | ||
| await initializeProjectRepository(projectName); | ||
| updatePackageJson(projectName); | ||
| updateProjectConfig(projectName); | ||
| updateGitHubWorkflows(projectName); | ||
|
fernandatoledo marked this conversation as resolved.
|
||
| updateProjectReadme(projectName); | ||
| updateAgentDocs(projectName); | ||
| // Runs last so the initial commit contains the fully set up project | ||
| await initializeProjectRepository(projectName); | ||
| consola.success(`Clean up and setup your project 🧹`); | ||
| } catch (error) { | ||
| consola.error(`Failed to clean up project folder`, error); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.