1
1
import * as constants from "../constants" ;
2
2
import * as path from "path" ;
3
+ import simpleGit , { SimpleGit } from "simple-git" ;
3
4
import { exported } from "../common/decorators" ;
4
5
import { Hooks } from "../constants" ;
5
6
import { performanceLog } from "../common/decorators" ;
@@ -15,6 +16,7 @@ import {
15
16
} from "../definitions/project" ;
16
17
import {
17
18
INodePackageManager ,
19
+ IOptions ,
18
20
IProjectNameService ,
19
21
IStaticConfig ,
20
22
} from "../declarations" ;
@@ -32,6 +34,7 @@ import { ITempService } from "../definitions/temp-service";
32
34
33
35
export class ProjectService implements IProjectService {
34
36
constructor (
37
+ private $options : IOptions ,
35
38
private $hooksService : IHooksService ,
36
39
private $packageManager : INodePackageManager ,
37
40
private $errors : IErrors ,
@@ -106,24 +109,30 @@ export class ProjectService implements IProjectService {
106
109
projectName,
107
110
} ) ;
108
111
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
+ }
120
133
}
121
134
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.` ) ;
127
136
128
137
return projectCreationData ;
129
138
}
0 commit comments