11#!/usr/bin/env node
22
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' ;
1111
12- import config from " ./config.js" ;
12+ import config from ' ./config.js' ;
1313
1414/* --- Helpers --- */
1515
@@ -40,9 +40,7 @@ async function installDependencies(dirName) {
4040async function initGit ( dirName ) {
4141 console . log ( `Setting up Git ...` ) ;
4242 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"` ) ;
4644}
4745
4846/**
@@ -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 // Copy out into a new directory within current working directory.
@@ -176,7 +165,7 @@ async function cloneExample() {
176165
177166 // Output next steps:
178167 console . log ( `
179- 🎉 ${ chalk . bold ( " Your example project is ready!" ) } 🎉
168+ 🎉 ${ chalk . bold ( ' Your example project is ready!' ) } 🎉
180169
181170Follow the instructions and learn more about the example here:
182171
@@ -190,9 +179,9 @@ async function integrateStackbit() {
190179 return new Promise ( async ( resolve ) => {
191180 const integrate = await prompt ( `
192181 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] ` ) ;
194183
195- if ( ! [ " yes" , "y" ] . includes ( integrate ?. toLowerCase ( ) ) ) return resolve ( false ) ;
184+ if ( ! [ ' yes' , 'y' ] . includes ( integrate ?. toLowerCase ( ) ) ) return resolve ( false ) ;
196185
197186 console . log ( `
198187Visit 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:
208197async function doCreate ( ) {
209198 // If the current directory has a package.json file, we assume we're in an
210199 // 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' ) ;
212201 if ( fs . existsSync ( packageJsonFilePath ) ) return integrateStackbit ( ) ;
213202 // If both starter and example were specified, throw an error message.
214203 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.' ) ;
216205 process . exit ( 1 ) ;
217206 }
218207 // Start from an example if specified.
0 commit comments