@@ -12,9 +12,35 @@ const ProjectFilesManager = require('./project-files-manager.js');
1212 */
1313let projectFilesManager ;
1414
15+ const DEFAULT_BRANCH = 'develop' ;
16+ const ADDITIONAL_BRANCHES = [ 'qa' , 'main' ] ;
17+
18+ const hasGitIdentity = async ( options ) => {
19+ const name = await execShellCommand ( 'git config user.name || true' , options ) ;
20+ const email = await execShellCommand ( 'git config user.email || true' , options ) ;
21+ return Boolean ( name . trim ( ) && email . trim ( ) ) ;
22+ } ;
23+
24+ // Branches can only be created once a commit exists, so the initial commit
25+ // happens before renaming the current branch and branching off it.
1526const initializeProjectRepository = async ( projectName ) => {
16- const escapedProjectName = escapeShellArg ( projectName ) ;
17- await execShellCommand ( `cd ${ escapedProjectName } && git init && cd ..` ) ;
27+ const options = { cwd : projectName } ;
28+
29+ await execShellCommand ( 'git init' , options ) ;
30+ await execShellCommand ( 'git add -A' , options ) ;
31+
32+ const identityFlags = ( await hasGitIdentity ( options ) )
33+ ? ''
34+ : '-c user.name="Rootstrap Template" -c user.email="template@rootstrap.com"' ;
35+ await execShellCommand (
36+ `git ${ identityFlags } commit -m "chore: initial commit from Rootstrap React Native template"` ,
37+ options ,
38+ ) ;
39+ await execShellCommand ( `git branch -M ${ DEFAULT_BRANCH } ` , options ) ;
40+
41+ for ( const branch of ADDITIONAL_BRANCHES ) {
42+ await execShellCommand ( `git branch ${ branch } ` , options ) ;
43+ }
1844} ;
1945
2046const installDependencies = async ( projectName ) => {
@@ -54,7 +80,7 @@ const removeUnrelatedFiles = () => {
5480} ;
5581
5682// Update package.json infos, name and set version to 0.0.1 + add initial version to rsMetadata
57- const updatePackageJson = async ( projectName ) => {
83+ const updatePackageJson = ( projectName ) => {
5884 const packageJsonPath =
5985 projectFilesManager . getAbsoluteFilePath ( 'package.json' ) ;
6086
@@ -75,7 +101,7 @@ const updatePackageJson = async (projectName) => {
75101 fs . writeJsonSync ( packageJsonPath , packageJson , { spaces : 2 } ) ;
76102} ;
77103
78- const updateProjectConfig = async ( projectName ) => {
104+ const updateProjectConfig = ( projectName ) => {
79105 projectFilesManager . replaceFilesContent ( [
80106 {
81107 fileName : 'env.js' ,
@@ -227,12 +253,13 @@ const setupProject = async (projectName) => {
227253
228254 try {
229255 removeUnrelatedFiles ( ) ;
230- await initializeProjectRepository ( projectName ) ;
231256 updatePackageJson ( projectName ) ;
232257 updateProjectConfig ( projectName ) ;
233258 updateGitHubWorkflows ( projectName ) ;
234259 updateProjectReadme ( projectName ) ;
235260 updateAgentDocs ( projectName ) ;
261+ // Runs last so the initial commit contains the fully set up project
262+ await initializeProjectRepository ( projectName ) ;
236263 consola . success ( `Clean up and setup your project 🧹` ) ;
237264 } catch ( error ) {
238265 consola . error ( `Failed to clean up project folder` , error ) ;
0 commit comments