1
1
#!/usr/bin/env node
2
2
3
- import chalk from " chalk" ;
4
- import { exec } from " child_process" ;
5
- import fs from " fs-extra" ;
6
- import path from " path" ;
7
- import readline from " readline" ;
8
- import util from " util" ;
9
- import yargs from " yargs" ;
10
- import { hideBin } from " yargs/helpers" ;
3
+ import chalk from ' chalk' ;
4
+ import { exec } from ' child_process' ;
5
+ import fs from ' fs-extra' ;
6
+ import path from ' path' ;
7
+ import readline from ' readline' ;
8
+ import util from ' util' ;
9
+ import yargs from ' yargs' ;
10
+ import { hideBin } from ' yargs/helpers' ;
11
11
12
- import config from " ./config.js" ;
12
+ import config from ' ./config.js' ;
13
13
14
14
/* --- Helpers --- */
15
15
@@ -41,9 +41,7 @@ async function initGit(dirName) {
41
41
console . log ( `Setting up Git ...` ) ;
42
42
// remove .git folder
43
43
await fs . removeSync ( `${ dirName } / .git` ) ;
44
- await run (
45
- `cd ${ dirName } && git init && git add . && git commit -m "New Stackbit project"`
46
- ) ;
44
+ await run ( `cd ${ dirName } && git init && git add . && git commit -m "New Stackbit project"` ) ;
47
45
}
48
46
/**
49
47
* Given a version string, compare it to a control version. Returns:
@@ -61,7 +59,7 @@ function compareVersion(version, control) {
61
59
// Return 0 if the versions match.
62
60
if ( version === control ) return returnValue ;
63
61
// Break the versions into arrays of integers.
64
- const getVersionParts = ( str ) => str . split ( "." ) . map ( ( v ) => parseInt ( v ) ) ;
62
+ const getVersionParts = ( str ) => str . split ( '.' ) . map ( ( v ) => parseInt ( v ) ) ;
65
63
const versionParts = getVersionParts ( version ) ;
66
64
const controlParts = getVersionParts ( control ) ;
67
65
// Loop and compare each item.
@@ -78,24 +76,22 @@ function compareVersion(version, control) {
78
76
/* --- Parse CLI Arguments */
79
77
80
78
const args = yargs ( hideBin ( process . argv ) )
81
- . option ( " starter" , {
82
- alias : "s" ,
83
- describe : " Choose a starter" ,
79
+ . option ( ' starter' , {
80
+ alias : 's' ,
81
+ describe : ' Choose a starter' ,
84
82
choices : config . starters . map ( ( s ) => s . name ) ,
85
83
} )
86
- . option ( " example" , {
87
- alias : "e" ,
88
- describe : " Start from an example" ,
84
+ . option ( ' example' , {
85
+ alias : 'e' ,
86
+ describe : ' Start from an example' ,
89
87
choices : config . examples . directories ,
90
88
} )
91
89
. help ( )
92
90
. parse ( ) ;
93
91
94
92
/* --- References --- */
95
93
96
- const starter = config . starters . find (
97
- ( s ) => s . name === ( args . starter ?? config . defaults . starter . name )
98
- ) ;
94
+ const starter = config . starters . find ( ( s ) => s . name === ( args . starter ?? config . defaults . starter . name ) ) ;
99
95
100
96
// Current time in seconds.
101
97
const timestamp = Math . round ( new Date ( ) . getTime ( ) / 1000 ) ;
@@ -117,7 +113,7 @@ async function cloneStarter() {
117
113
118
114
// Output next steps:
119
115
console . log ( `
120
- 🎉 ${ chalk . bold ( " Welcome to Stackbit!" ) } 🎉
116
+ 🎉 ${ chalk . bold ( ' Welcome to Stackbit!' ) } 🎉
121
117
122
118
Follow the instructions for getting Started here:
123
119
@@ -128,23 +124,18 @@ Follow the instructions for getting Started here:
128
124
/* --- New Project from Example --- */
129
125
130
126
async function cloneExample ( ) {
131
- const gitResult = await run ( " git --version" ) ;
127
+ const gitResult = await run ( ' git --version' ) ;
132
128
const gitVersionMatch = gitResult . stdout . match ( / \d + \. \d + \. \d + / ) ;
133
129
if ( ! gitVersionMatch || ! gitVersionMatch [ 0 ] ) {
134
130
console . error (
135
131
`Cannot determine git version, which is required for starting from an example.` ,
136
132
`\nPlease report this:` ,
137
- chalk . underline (
138
- "https://github.com/stackbit/create-stackbit-app/issues/new"
139
- )
133
+ chalk . underline ( 'https://github.com/stackbit/create-stackbit-app/issues/new' ) ,
140
134
) ;
141
135
process . exit ( 1 ) ;
142
136
}
143
137
if ( compareVersion ( gitVersionMatch [ 0 ] , config . minGitVersion ) < 0 ) {
144
- console . error (
145
- `Starting from an example requires git version ${ config . minGitVersion } or later.` ,
146
- "Please upgrade"
147
- ) ;
138
+ console . error ( `Starting from an example requires git version ${ config . minGitVersion } or later.` , 'Please upgrade' ) ;
148
139
process . exit ( 1 ) ;
149
140
}
150
141
@@ -154,9 +145,7 @@ async function cloneExample() {
154
145
155
146
try {
156
147
// Sparse clone the monorepo.
157
- await run (
158
- `git clone --depth 1 --filter=blob:none --sparse ${ config . examples . repoUrl } ${ tmpDir } `
159
- ) ;
148
+ await run ( `git clone --depth 1 --filter=blob:none --sparse ${ config . examples . repoUrl } ${ tmpDir } ` ) ;
160
149
// Checkout just the example dir.
161
150
await run ( `cd ${ tmpDir } && git sparse-checkout set ${ args . example } ` ) ;
162
151
@@ -183,7 +172,7 @@ async function cloneExample() {
183
172
184
173
// Output next steps:
185
174
console . log ( `
186
- 🎉 ${ chalk . bold ( " Your example project is ready!" ) } 🎉
175
+ 🎉 ${ chalk . bold ( ' Your example project is ready!' ) } 🎉
187
176
188
177
Follow the instructions and learn more about the example here:
189
178
@@ -197,9 +186,9 @@ async function integrateStackbit() {
197
186
return new Promise ( async ( resolve ) => {
198
187
const integrate = await prompt ( `
199
188
This looks like an existing project.
200
- ${ chalk . bold ( " Would you like to install Stackbit in this project?" ) } [Y/n] ` ) ;
189
+ ${ chalk . bold ( ' Would you like to install Stackbit in this project?' ) } [Y/n] ` ) ;
201
190
202
- if ( ! [ " yes" , "y" ] . includes ( integrate ?. toLowerCase ( ) ) ) return resolve ( false ) ;
191
+ if ( ! [ ' yes' , 'y' ] . includes ( integrate ?. toLowerCase ( ) ) ) return resolve ( false ) ;
203
192
204
193
console . log ( `
205
194
Visit the following URL to learn more about the integration process:
@@ -215,11 +204,11 @@ Visit the following URL to learn more about the integration process:
215
204
async function doCreate ( ) {
216
205
// If the current directory has a package.json file, we assume we're in an
217
206
// active project, and will not create a new project.
218
- const packageJsonFilePath = path . join ( process . cwd ( ) , " package.json" ) ;
207
+ const packageJsonFilePath = path . join ( process . cwd ( ) , ' package.json' ) ;
219
208
if ( fs . existsSync ( packageJsonFilePath ) ) return integrateStackbit ( ) ;
220
209
// If both starter and example were specified, throw an error message.
221
210
if ( args . starter && args . example ) {
222
- console . error ( " [ERROR] Cannot specify a starter and an example." ) ;
211
+ console . error ( ' [ERROR] Cannot specify a starter and an example.' ) ;
223
212
process . exit ( 1 ) ;
224
213
}
225
214
// Start from an example if specified.
0 commit comments