@@ -23,7 +23,7 @@ const { mv, rm, which, exec } = require('shelljs');
23
23
// Note: These should all be relative to the project root directory
24
24
const rmDirs = [ '.git' , 'tools' ] ;
25
25
const rmFiles = [ '.all-contributorsrc' , '.gitattributes' ] ;
26
- const modifyFiles = [ 'LICENSE' , 'package.json' , 'example/package.json' ] ;
26
+ const modifyFiles = [ 'LICENSE' , 'package.json' ] ;
27
27
const renameFiles : Array < string > = [ ] ;
28
28
29
29
/**
@@ -60,7 +60,7 @@ function modifyContents(
60
60
61
61
const files = modifyFiles . map ( f => resolve ( __dirname , '..' , f ) ) ;
62
62
try {
63
- replace ( {
63
+ replace . sync ( {
64
64
files,
65
65
from : [
66
66
/ - - l i b r a r y n a m e - - / g,
@@ -74,13 +74,12 @@ function modifyContents(
74
74
} catch ( error ) {
75
75
console . error ( 'An error occurred modifying the file: ' , error ) ;
76
76
}
77
-
78
77
console . log ( '\n' ) ;
79
78
}
80
79
81
80
function modifyGitignoreFile ( ) : void {
82
81
const files = [ '.gitignore' ] . map ( f => resolve ( __dirname , '..' , f ) ) ;
83
- replace ( {
82
+ replace . sync ( {
84
83
files,
85
84
from : [ 'dist/' , 'docs/' ] ,
86
85
to : '' ,
@@ -109,29 +108,6 @@ function renameItems(libraryName: string) {
109
108
console . log ( '\n' ) ;
110
109
}
111
110
112
- const _promptInstallExampleApp = {
113
- properties : {
114
- installExampleApp : {
115
- description : cyan (
116
- 'Would you like to generate an example react app to test your library/component?'
117
- ) ,
118
- pattern : / ^ ( y ( e s ) ? | n ( o ) ? ) $ / i,
119
- type : 'string' ,
120
- required : true ,
121
- message : 'You need to type "Yes" or "No" to continue...' ,
122
- } ,
123
- } ,
124
- } ;
125
- function installExampleApp ( ) {
126
- _prompt . get ( _promptInstallExampleApp , ( err : any , res : any ) => {
127
- if ( err ) return ;
128
- if ( res . installExampleApp . toLowerCase ( ) . charAt ( 0 ) === 'y' ) {
129
- exec ( 'npx create-react-app example' ) ;
130
- exec ( 'echo "SKIP_PREFLIGHT_CHECK=true" >> example/.env' ) ;
131
- }
132
- } ) ;
133
- }
134
-
135
111
/**
136
112
* Calls any external programs to finish setting up the library
137
113
*/
@@ -162,14 +138,16 @@ function finalize() {
162
138
console . log ( yellow ( 'Removing yarn.lock and performing a clean install...' ) ) ;
163
139
rm ( 'yarn.lock' ) ;
164
140
exec ( 'yarn install' ) ;
141
+ exec ( 'yarn build' ) ;
142
+ exec ( "git add . && git commit -am 'chore: init' --no-verify" ) ;
165
143
console . log ( '\n' ) ;
166
144
}
167
145
/**
168
146
* Calls all of the functions needed to setup the library
169
147
*
170
148
* @param libraryName
171
149
*/
172
- function setupLibrary ( libraryName : string ) {
150
+ function setupLibrary ( libraryName : string , generateExample = false ) {
173
151
console . log (
174
152
cyan (
175
153
'\nThanks for the info. The last few changes are being made... hang tight!\n\n'
@@ -180,13 +158,24 @@ function setupLibrary(libraryName: string) {
180
158
const username = exec ( 'git config user.name' ) . stdout . trim ( ) ;
181
159
const usermail = exec ( 'git config user.email' ) . stdout . trim ( ) ;
182
160
161
+ if ( generateExample ) {
162
+ yellow ( 'Installing the test application into example/ directory...' ) ;
163
+ exec ( 'npx create-react-app example' ) ;
164
+ exec ( 'echo "SKIP_PREFLIGHT_CHECK=true" >> example/.env' ) ;
165
+ }
183
166
removeItems ( ) ;
184
167
185
168
modifyGitignoreFile ( ) ;
186
- installExampleApp ( ) ;
187
169
modifyContents ( libraryName , username , usermail ) ;
188
170
// renameItems(libraryName);
189
171
172
+ if ( generateExample ) {
173
+ console . log ( yellow ( 'Linking packages to the example app...' ) ) ;
174
+ exec (
175
+ 'cd example && yarn add link:.. link:../node_modules/react link:../node_modules/react-dom && cd ..'
176
+ ) ;
177
+ }
178
+
190
179
finalize ( ) ;
191
180
192
181
console . log ( cyan ( "OK, you're all set. Happy coding!! ;)\n" ) ) ;
@@ -237,6 +226,21 @@ const _promptSchemaLibrarySuggest = {
237
226
} ,
238
227
} ,
239
228
} ;
229
+
230
+ const _promptInstallExampleApp = {
231
+ properties : {
232
+ installExampleApp : {
233
+ description : yellow (
234
+ 'Would you like to generate an example react app to test your library/component? [Yes/No]'
235
+ ) ,
236
+ pattern : / ^ ( y ( e s ) ? | n ( o ) ? ) $ / i,
237
+ type : 'string' ,
238
+ required : true ,
239
+ message : 'You need to type "Yes" or "No" to continue...' ,
240
+ } ,
241
+ } ,
242
+ } ;
243
+
240
244
/**
241
245
* Asks the user for the name of the library if it has been cloned into the
242
246
* default directory, or if they want a different name to the one suggested
@@ -249,8 +253,14 @@ function libraryNameCreate() {
249
253
process . exit ( 1 ) ;
250
254
return ;
251
255
}
252
-
253
- setupLibrary ( res . library ) ;
256
+ _prompt . get ( _promptInstallExampleApp , ( err : any , res : any ) => {
257
+ let installExampleApp = false ;
258
+ if ( err ) return ;
259
+ if ( res . installExampleApp . toLowerCase ( ) . charAt ( 0 ) === 'y' ) {
260
+ installExampleApp = true ;
261
+ }
262
+ setupLibrary ( res . library , installExampleApp ) ;
263
+ } ) ;
254
264
} ) ;
255
265
}
256
266
@@ -266,7 +276,14 @@ function libraryNameSuggestedAccept() {
266
276
}
267
277
268
278
if ( res . useSuggestedName . toLowerCase ( ) . charAt ( 0 ) === 'y' ) {
269
- setupLibrary ( libraryNameSuggested ( ) ) ;
279
+ _prompt . get ( _promptInstallExampleApp , ( err : any , res : any ) => {
280
+ let installExampleApp = false ;
281
+ if ( err ) return ;
282
+ if ( res . installExampleApp . toLowerCase ( ) . charAt ( 0 ) === 'y' ) {
283
+ installExampleApp = true ;
284
+ }
285
+ setupLibrary ( libraryNameSuggested ( ) , installExampleApp ) ;
286
+ } ) ;
270
287
} else {
271
288
libraryNameCreate ( ) ;
272
289
}
0 commit comments