1
1
'use strict' ;
2
2
3
+ var fs = require ( 'fs' ) ;
3
4
var path = require ( 'path' ) ;
5
+ var Enquirer = require ( 'enquirer' ) ;
6
+ var extend = require ( 'extend-shallow' ) ;
4
7
var utils = require ( './utils' ) ;
5
8
6
9
module . exports = function ( app , base ) {
7
10
if ( ! utils . isValid ( app , 'generate-git' ) ) return ;
8
11
9
12
/**
10
- * Load `base-task- prompts`
13
+ * Initialize prompts
11
14
*/
12
15
13
- var prompts = utils . prompts ( app ) ;
16
+ var enquirer = new Enquirer ( ) ;
17
+ enquirer . register ( 'confirm' , require ( 'prompt-confirm' ) ) ;
14
18
15
- /**
16
- * Generate a `.gitattributes` file. You can override the default template by adding
17
- * a custom template at the following path `~/templates/_gitattributes` (in user home).
18
- * See the [git documentation](https://git-scm.com/docs/gitattributes) for `.gitattributes` files.
19
- *
20
- * ```sh
21
- * $ gen git:gitattributes
22
- * ```
23
- * @name gitattributes
24
- * @api public
25
- */
26
-
27
- app . use ( require ( 'generate-gitattributes' ) ) ;
28
-
29
- /**
30
- * Generate a `.gitignore` file. You can override the default template by adding
31
- * a custom template at the following path: `~/templates/_gitignore` (in user home).
32
- *
33
- * ```sh
34
- * $ gen git:gitignore
35
- * ```
36
- * @name gitignore
37
- * @api public
38
- */
19
+ enquirer . question ( 'clone' , {
20
+ message : 'Which repo would you like to clone (owner/name)?' ,
21
+ } ) ;
39
22
40
- app . use ( require ( 'generate-gitignore' ) ) ;
23
+ enquirer . question ( 'first-commit' , {
24
+ message : 'Want to do first git commit?' ,
25
+ type : 'confirm'
26
+ } ) ;
41
27
42
28
/**
43
29
* Initialize a git repository, including `git add` and first commit.
@@ -62,34 +48,75 @@ module.exports = function(app, base) {
62
48
* @api public
63
49
*/
64
50
65
- app . task ( 'first-commit' , function ( next ) {
66
- if ( utils . exists ( path . resolve ( app . cwd , '.git' ) ) ) {
67
- app . log . warn ( ' .git exists, skipping' ) ;
68
- next ( ) ;
51
+ app . task ( 'first-commit' , function ( cb ) {
52
+ if ( fs . existsSync ( path . resolve ( app . cwd , '.git' ) ) ) {
53
+ app . log . warn ( ` .git exists, skipping ${ this . name } task` ) ;
54
+ cb ( ) ;
69
55
return ;
70
56
}
71
57
72
58
utils . firstCommit ( app . cwd , 'first commit' , function ( err ) {
73
59
if ( err && ! / C o m m a n d f a i l e d / . test ( err . message ) ) {
74
- next ( err ) ;
60
+ cb ( err ) ;
75
61
} else {
76
62
app . log . success ( 'first commit' ) ;
77
- next ( ) ;
63
+ cb ( ) ;
78
64
}
79
65
} ) ;
80
66
} ) ;
81
67
82
68
/**
83
- * Prompt the user to initialize a git repository and create a first commit,
84
- * runs the [first-commit](#first-commit) task if specified by the user.
69
+ * Alias for the default task, to provide a semantic task name when using this
70
+ * generator as a plugin or sub-generator.
71
+ *
72
+ * ```sh
73
+ * $ gen git:clone
74
+ * $ gen git:git-clone # aliased for API usage
75
+ * ```
76
+ * @name clone
77
+ * @api public
78
+ */
79
+
80
+ app . task ( 'clone' , [ 'prompt-clone' ] ) ;
81
+ app . task ( 'prompt-clone' , function ( cb ) {
82
+ var opts = extend ( { } , app . options ) ;
83
+ if ( opts . clone ) {
84
+ opts . repo = opts . clone ;
85
+ utils . clone ( opts , cb ) ;
86
+ return ;
87
+ }
88
+
89
+ return enquirer . ask ( 'clone' )
90
+ . then ( function ( answer ) {
91
+ if ( answer . clone ) {
92
+ opts . repo = answer . clone ;
93
+ app . log . info ( 'cloning' , opts . repo ) ;
94
+ utils . clone ( opts , cb ) ;
95
+ }
96
+ } ) ;
97
+
98
+ } ) ;
99
+
100
+ /**
101
+ * Prompts the user to confirm if they'd like to initialize a git repository with
102
+ * first [first-commit](#first-commit).
85
103
*
86
104
* ```sh
87
- * $ gen git :prompt-git
105
+ * $ gen updater :prompt-git
88
106
* ```
89
- * @name prompt-git
107
+ * @name updater: prompt-git
90
108
* @api public
91
109
*/
92
110
93
- app . confirm ( 'git' , 'Want to initialize a git repository?' ) ;
94
- app . task ( 'prompt-git' , { silent : true } , prompts . confirm ( 'git' , [ 'first-commit' ] ) ) ;
111
+ app . task ( 'prompt-first-commit' , function ( cb ) {
112
+ var name = this . name ;
113
+ return enquirer . ask ( name )
114
+ . then ( function ( answer ) {
115
+ if ( answer [ name ] ) {
116
+ return app . build ( name . replace ( 'prompt-' , '' ) , cb ) ;
117
+ }
118
+ } ) ;
119
+ } ) ;
120
+
95
121
} ;
122
+
0 commit comments