1
1
#!/usr/bin/env node
2
2
3
- import chalk from " chalk" ;
4
- import { exec } from " child_process" ;
5
- import fs from "fs" ;
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' ;
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
@@ -40,9 +40,7 @@ async function installDependencies(dirName) {
40
40
async function initGit ( dirName ) {
41
41
console . log ( `Setting up Git ...` ) ;
42
42
await run ( `rm -rf ${ dirName } /.git` ) ;
43
- await run (
44
- `cd ${ dirName } && git init && git add . && git commit -m "New Stackbit project"`
45
- ) ;
43
+ await run ( `cd ${ dirName } && git init && git add . && git commit -m "New Stackbit project"` ) ;
46
44
}
47
45
48
46
/**
@@ -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
// Copy out into a new directory within current working directory.
@@ -176,7 +165,7 @@ async function cloneExample() {
176
165
177
166
// Output next steps:
178
167
console . log ( `
179
- 🎉 ${ chalk . bold ( " Your example project is ready!" ) } 🎉
168
+ 🎉 ${ chalk . bold ( ' Your example project is ready!' ) } 🎉
180
169
181
170
Follow the instructions and learn more about the example here:
182
171
@@ -190,9 +179,9 @@ async function integrateStackbit() {
190
179
return new Promise ( async ( resolve ) => {
191
180
const integrate = await prompt ( `
192
181
This looks like an existing project.
193
- ${ chalk . bold ( " Would you like to install Stackbit in this project?" ) } [Y/n] ` ) ;
182
+ ${ chalk . bold ( ' Would you like to install Stackbit in this project?' ) } [Y/n] ` ) ;
194
183
195
- if ( ! [ " yes" , "y" ] . includes ( integrate ?. toLowerCase ( ) ) ) return resolve ( false ) ;
184
+ if ( ! [ ' yes' , 'y' ] . includes ( integrate ?. toLowerCase ( ) ) ) return resolve ( false ) ;
196
185
197
186
console . log ( `
198
187
Visit the following URL to learn more about the integration process:
@@ -208,11 +197,11 @@ Visit the following URL to learn more about the integration process:
208
197
async function doCreate ( ) {
209
198
// If the current directory has a package.json file, we assume we're in an
210
199
// active project, and will not create a new project.
211
- const packageJsonFilePath = path . join ( process . cwd ( ) , " package.json" ) ;
200
+ const packageJsonFilePath = path . join ( process . cwd ( ) , ' package.json' ) ;
212
201
if ( fs . existsSync ( packageJsonFilePath ) ) return integrateStackbit ( ) ;
213
202
// If both starter and example were specified, throw an error message.
214
203
if ( args . starter && args . example ) {
215
- console . error ( " [ERROR] Cannot specify a starter and an example." ) ;
204
+ console . error ( ' [ERROR] Cannot specify a starter and an example.' ) ;
216
205
process . exit ( 1 ) ;
217
206
}
218
207
// Start from an example if specified.
0 commit comments