11import * as constants from "../constants" ;
22import * as path from "path" ;
3+ import simpleGit , { SimpleGit } from "simple-git" ;
34import { exported } from "../common/decorators" ;
45import { Hooks } from "../constants" ;
56import { performanceLog } from "../common/decorators" ;
@@ -15,6 +16,7 @@ import {
1516} from "../definitions/project" ;
1617import {
1718 INodePackageManager ,
19+ IOptions ,
1820 IProjectNameService ,
1921 IStaticConfig ,
2022} from "../declarations" ;
@@ -32,6 +34,7 @@ import { ITempService } from "../definitions/temp-service";
3234
3335export class ProjectService implements IProjectService {
3436 constructor (
37+ private $options : IOptions ,
3538 private $hooksService : IHooksService ,
3639 private $packageManager : INodePackageManager ,
3740 private $errors : IErrors ,
@@ -106,24 +109,30 @@ export class ProjectService implements IProjectService {
106109 projectName,
107110 } ) ;
108111
109- try {
110- await this . $childProcess . exec ( `git init ${ projectDir } ` ) ;
111- await this . $childProcess . exec ( `git -C ${ projectDir } add --all` ) ;
112- await this . $childProcess . exec (
113- `git -C ${ projectDir } commit --no-verify -m "init"`
114- ) ;
115- } catch ( err ) {
116- this . $logger . trace (
117- "Unable to initialize git repository. Error is: " ,
118- err
119- ) ;
112+ // can pass --no-git to skip creating a git repo
113+ // useful in monorepos where we're creating
114+ // sub projects in an existing git repo.
115+ if ( this . $options . git ) {
116+ try {
117+ const git : SimpleGit = simpleGit ( projectDir ) ;
118+ if ( await git . checkIsRepo ( ) ) {
119+ // throwing here since we're catching below.
120+ throw new Error ( "Already part of a git repository." ) ;
121+ }
122+ await this . $childProcess . exec ( `git init ${ projectDir } ` ) ;
123+ await this . $childProcess . exec ( `git -C ${ projectDir } add --all` ) ;
124+ await this . $childProcess . exec (
125+ `git -C ${ projectDir } commit --no-verify -m "init"`
126+ ) ;
127+ } catch ( err ) {
128+ this . $logger . trace (
129+ "Unable to initialize git repository. Error is: " ,
130+ err
131+ ) ;
132+ }
120133 }
121134
122- this . $logger . info ( ) ;
123- this . $logger . printMarkdown (
124- "__Project `%s` was successfully created.__" ,
125- projectName
126- ) ;
135+ this . $logger . trace ( `Project ${ projectName } was successfully created.` ) ;
127136
128137 return projectCreationData ;
129138 }
0 commit comments