11#!/usr/bin/env node
22
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' ;
1111
12- import config from " ./config.js" ;
12+ import config from ' ./config.js' ;
1313
1414/* --- Helpers --- */
1515
@@ -41,9 +41,7 @@ async function initGit(dirName) {
4141 console . log ( `Setting up Git ...` ) ;
4242 // remove .git folder
4343 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"` ) ;
4745}
4846/**
4947 * Given a version string, compare it to a control version. Returns:
@@ -61,7 +59,7 @@ function compareVersion(version, control) {
6159 // Return 0 if the versions match.
6260 if ( version === control ) return returnValue ;
6361 // 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 ) ) ;
6563 const versionParts = getVersionParts ( version ) ;
6664 const controlParts = getVersionParts ( control ) ;
6765 // Loop and compare each item.
@@ -78,24 +76,22 @@ function compareVersion(version, control) {
7876/* --- Parse CLI Arguments */
7977
8078const 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' ,
8482 choices : config . starters . map ( ( s ) => s . name ) ,
8583 } )
86- . option ( " example" , {
87- alias : "e" ,
88- describe : " Start from an example" ,
84+ . option ( ' example' , {
85+ alias : 'e' ,
86+ describe : ' Start from an example' ,
8987 choices : config . examples . directories ,
9088 } )
9189 . help ( )
9290 . parse ( ) ;
9391
9492/* --- References --- */
9593
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 ) ) ;
9995
10096// Current time in seconds.
10197const timestamp = Math . round ( new Date ( ) . getTime ( ) / 1000 ) ;
@@ -117,7 +113,7 @@ async function cloneStarter() {
117113
118114 // Output next steps:
119115 console . log ( `
120- 🎉 ${ chalk . bold ( " Welcome to Stackbit!" ) } 🎉
116+ 🎉 ${ chalk . bold ( ' Welcome to Stackbit!' ) } 🎉
121117
122118Follow the instructions for getting Started here:
123119
@@ -128,23 +124,18 @@ Follow the instructions for getting Started here:
128124/* --- New Project from Example --- */
129125
130126async function cloneExample ( ) {
131- const gitResult = await run ( " git --version" ) ;
127+ const gitResult = await run ( ' git --version' ) ;
132128 const gitVersionMatch = gitResult . stdout . match ( / \d + \. \d + \. \d + / ) ;
133129 if ( ! gitVersionMatch || ! gitVersionMatch [ 0 ] ) {
134130 console . error (
135131 `Cannot determine git version, which is required for starting from an example.` ,
136132 `\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' ) ,
140134 ) ;
141135 process . exit ( 1 ) ;
142136 }
143137 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' ) ;
148139 process . exit ( 1 ) ;
149140 }
150141
@@ -154,9 +145,7 @@ async function cloneExample() {
154145
155146 try {
156147 // 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 } ` ) ;
160149 // Checkout just the example dir.
161150 await run ( `cd ${ tmpDir } && git sparse-checkout set ${ args . example } ` ) ;
162151
@@ -183,7 +172,7 @@ async function cloneExample() {
183172
184173 // Output next steps:
185174 console . log ( `
186- 🎉 ${ chalk . bold ( " Your example project is ready!" ) } 🎉
175+ 🎉 ${ chalk . bold ( ' Your example project is ready!' ) } 🎉
187176
188177Follow the instructions and learn more about the example here:
189178
@@ -197,9 +186,9 @@ async function integrateStackbit() {
197186 return new Promise ( async ( resolve ) => {
198187 const integrate = await prompt ( `
199188 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] ` ) ;
201190
202- if ( ! [ " yes" , "y" ] . includes ( integrate ?. toLowerCase ( ) ) ) return resolve ( false ) ;
191+ if ( ! [ ' yes' , 'y' ] . includes ( integrate ?. toLowerCase ( ) ) ) return resolve ( false ) ;
203192
204193 console . log ( `
205194Visit 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:
215204async function doCreate ( ) {
216205 // If the current directory has a package.json file, we assume we're in an
217206 // 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' ) ;
219208 if ( fs . existsSync ( packageJsonFilePath ) ) return integrateStackbit ( ) ;
220209 // If both starter and example were specified, throw an error message.
221210 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.' ) ;
223212 process . exit ( 1 ) ;
224213 }
225214 // Start from an example if specified.
0 commit comments