From 7fb45e3b4dc23317327d4ccf4f1cc0b1dd32273b Mon Sep 17 00:00:00 2001 From: Shedrack akintayo Date: Mon, 24 Oct 2022 21:11:33 +0100 Subject: [PATCH 1/9] start fix for cp bug on windows --- index.js | 193 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 105 insertions(+), 88 deletions(-) diff --git a/index.js b/index.js index a75f688..7f87669 100755 --- a/index.js +++ b/index.js @@ -1,50 +1,50 @@ #!/usr/bin/env node -import chalk from "chalk"; -import { exec } from "child_process"; -import fs from "fs"; -import path from "path"; -import readline from "readline"; -import util from "util"; -import yargs from "yargs"; -import { hideBin } from "yargs/helpers"; +import chalk from 'chalk' +import { exec } from 'child_process' +import fs from 'fs-extra' +import path from 'path' +import readline from 'readline' +import util from 'util' +import yargs from 'yargs' +import { hideBin } from 'yargs/helpers' -import config from "./config.js"; +import config from './config.js' /* --- Helpers --- */ -const run = util.promisify(exec); +const run = util.promisify(exec) const rl = readline.createInterface({ input: process.stdin, output: process.stdout, -}); +}) function prompt(question, defaultAnswer) { return new Promise((resolve) => { - rl.question(question, (input) => resolve(input || defaultAnswer)); - }); + rl.question(question, (input) => resolve(input || defaultAnswer)) + }) } function getDirName(defaultDirName) { - let dirName = args._[0] ?? defaultDirName; - if (fs.existsSync(dirName)) dirName += `-${timestamp}`; - return dirName; + let dirName = args._[0] ?? defaultDirName + if (fs.existsSync(dirName)) dirName += `-${timestamp}` + return dirName } async function installDependencies(dirName) { - console.log(`Installing dependencies ...`); - await run(`cd ${dirName} && npm install`); + console.log(`Installing dependencies ...`) + await run(`cd ${dirName} && npm install`) } async function initGit(dirName) { - console.log(`Setting up Git ...`); - await run(`rm -rf ${dirName}/.git`); - await run( - `cd ${dirName} && git init && git add . && git commit -m "New Stackbit project"` - ); + console.log(`Setting up Git ...`) + await fs.remove(`${dirName} / .git`, { recursive: true }, async () => { + await run( + `cd ${dirName} && git init && git add . && git commit -m "New Stackbit project"` + ) + }) } - /** * Given a version string, compare it to a control version. Returns: * @@ -57,131 +57,148 @@ async function initGit(dirName) { */ function compareVersion(version, control) { // References - let returnValue = 0; + let returnValue = 0 // Return 0 if the versions match. - if (version === control) return returnValue; + if (version === control) return returnValue // Break the versions into arrays of integers. - const getVersionParts = (str) => str.split(".").map((v) => parseInt(v)); - const versionParts = getVersionParts(version); - const controlParts = getVersionParts(control); + const getVersionParts = (str) => str.split('.').map((v) => parseInt(v)) + const versionParts = getVersionParts(version) + const controlParts = getVersionParts(control) // Loop and compare each item. controlParts.every((controlPart, idx) => { // If the versions are equal at this part, we move on to the next part. - if (versionParts[idx] === controlPart) return true; + if (versionParts[idx] === controlPart) return true // Otherwise, set the return value, then break out of the loop. - returnValue = versionParts[idx] > controlPart ? 1 : -1; - return false; - }); - return returnValue; + returnValue = versionParts[idx] > controlPart ? 1 : -1 + return false + }) + return returnValue } /* --- Parse CLI Arguments */ const args = yargs(hideBin(process.argv)) - .option("starter", { - alias: "s", - describe: "Choose a starter", + .option('starter', { + alias: 's', + describe: 'Choose a starter', choices: config.starters.map((s) => s.name), }) - .option("example", { - alias: "e", - describe: "Start from an example", + .option('example', { + alias: 'e', + describe: 'Start from an example', choices: config.examples.directories, }) .help() - .parse(); + .parse() /* --- References --- */ const starter = config.starters.find( (s) => s.name === (args.starter ?? config.defaults.starter.name) -); +) // Current time in seconds. -const timestamp = Math.round(new Date().getTime() / 1000); +const timestamp = Math.round(new Date().getTime() / 1000) /* --- New Project from Starter --- */ async function cloneStarter() { // Set references - const dirName = getDirName(config.defaults.dirName); + const dirName = getDirName(config.defaults.dirName) // Clone repo - const cloneCommand = `git clone --depth=1 ${starter.repoUrl} ${dirName}`; - console.log(`\nCreating new project in ${dirName} ...`); - await run(cloneCommand); + const cloneCommand = `git clone --depth=1 ${starter.repoUrl} ${dirName}` + console.log(`\nCreating new project in ${dirName} ...`) + await run(cloneCommand) // Project Setup - await installDependencies(dirName); - await initGit(dirName); + await installDependencies(dirName) + await initGit(dirName) // Output next steps: console.log(` -🎉 ${chalk.bold("Welcome to Stackbit!")} 🎉 +🎉 ${chalk.bold('Welcome to Stackbit!')} 🎉 Follow the instructions for getting Started here: ${starter.repoUrl}#readme - `); + `) } /* --- New Project from Example --- */ async function cloneExample() { - const gitResult = await run("git --version"); - const gitVersionMatch = gitResult.stdout.match(/\d+\.\d+\.\d+/); + const gitResult = await run('git --version') + const gitVersionMatch = gitResult.stdout.match(/\d+\.\d+\.\d+/) if (!gitVersionMatch || !gitVersionMatch[0]) { console.error( `Cannot determine git version, which is required for starting from an example.`, `\nPlease report this:`, chalk.underline( - "https://github.com/stackbit/create-stackbit-app/issues/new" + 'https://github.com/stackbit/create-stackbit-app/issues/new' ) - ); - process.exit(1); + ) + process.exit(1) } if (compareVersion(gitVersionMatch[0], config.minGitVersion) < 0) { console.error( `Starting from an example requires git version ${config.minGitVersion} or later.`, - "Please upgrade" - ); - process.exit(1); + 'Please upgrade' + ) + process.exit(1) } - const dirName = getDirName(args.example); - const tmpDir = `__tmp${timestamp}__`; - console.log(`\nCreating new project in ${dirName} ...`); + const dirName = getDirName(args.example) + const tmpDir = `__tmp${timestamp}__` + console.log(`\nCreating new project in ${dirName} ...`) try { // Sparse clone the monorepo. await run( `git clone --depth 1 --filter=blob:none --sparse ${config.examples.repoUrl} ${tmpDir}` - ); + ) // Checkout just the example dir. - await run(`cd ${tmpDir} && git sparse-checkout set ${args.example}`); + await run(`cd ${tmpDir} && git sparse-checkout set ${args.example}`) + // Copy out into a new directory within current working directory. - await run(`cp -R ${tmpDir}/${args.example} ${dirName}`); - // Delete the clone. - await run(`rm -rf ${tmpDir}`); + await fs.copy(`${tmpDir}/${args.example}`, dirName, async (err) => { + if (err) { + console.log(err) + } + }) + // Delete the clone. + await fs.remove(tmpDir, { recursive: true }, (err) => { + if (err) { + console.log(err) + } + }) + + if (fs.existsSync(path.join(process.cwd(), dirName))) + await installDependencies(path.join(process.cwd(), dirName)) // Project Setup - await installDependencies(dirName); - await initGit(dirName); + // await + // await initGit(prestineFolder) } catch (err) { - console.error(err); - if (fs.existsSync(dirName)) await run(`rm -rf ${dirName}`); - if (fs.existsSync(tmpDir)) await run(`rm -rf ${tmpDir}`); - process.exit(1); + + if (fs.existsSync(dirName)) await fs.remove(dirName) + if (fs.existsSync(tmpDir)) + await fs.remove(tmpDir, (err) => { + if (err) { + console.log(err) + } + }) + process.exit(1) } // Output next steps: console.log(` -🎉 ${chalk.bold("Your example project is ready!")} 🎉 +🎉 ${chalk.bold('Your example project is ready!')} 🎉 Follow the instructions and learn more about the example here: ${config.examples.repoUrl}/tree/main/${args.example}#readme - `); + `) } /* --- Existing Project --- */ @@ -190,17 +207,17 @@ async function integrateStackbit() { return new Promise(async (resolve) => { const integrate = await prompt(` This looks like an existing project. - ${chalk.bold("Would you like to install Stackbit in this project?")} [Y/n] `); + ${chalk.bold('Would you like to install Stackbit in this project?')} [Y/n] `) - if (!["yes", "y"].includes(integrate?.toLowerCase())) return resolve(false); + if (!['yes', 'y'].includes(integrate?.toLowerCase())) return resolve(false) console.log(` Visit the following URL to learn more about the integration process: https://docs.stackbit.com/how-to-guides/site-management/integrate-stackbit/ -`); - return resolve(true); - }); +`) + return resolve(true) + }) } /* --- Run --- */ @@ -208,19 +225,19 @@ Visit the following URL to learn more about the integration process: async function doCreate() { // If the current directory has a package.json file, we assume we're in an // active project, and will not create a new project. - const packageJsonFilePath = path.join(process.cwd(), "package.json"); - if (fs.existsSync(packageJsonFilePath)) return integrateStackbit(); + const packageJsonFilePath = path.join(process.cwd(), 'package.json') + if (fs.existsSync(packageJsonFilePath)) return integrateStackbit() // If both starter and example were specified, throw an error message. if (args.starter && args.example) { - console.error("[ERROR] Cannot specify a starter and an example."); - process.exit(1); + console.error('[ERROR] Cannot specify a starter and an example.') + process.exit(1) } // Start from an example if specified. - if (args.example) return cloneExample(); + if (args.example) return cloneExample() // Otherwise, use a starter, which falls back to the default if not set. - return cloneStarter(); + return cloneStarter() } -await doCreate(); +await doCreate() -rl.close(); +rl.close() From bfc7e77cccdd8fc2eb3fc6a7d84cef34192d3a9d Mon Sep 17 00:00:00 2001 From: Shedrack akintayo Date: Mon, 24 Oct 2022 22:28:55 +0100 Subject: [PATCH 2/9] finish up hot fix --- index.js | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 7f87669..81247b8 100755 --- a/index.js +++ b/index.js @@ -39,11 +39,11 @@ async function installDependencies(dirName) { async function initGit(dirName) { console.log(`Setting up Git ...`) - await fs.remove(`${dirName} / .git`, { recursive: true }, async () => { - await run( - `cd ${dirName} && git init && git add . && git commit -m "New Stackbit project"` - ) - }) + // remove .git folder + await fs.removeSync(`${dirName} / .git`) + await run( + `cd ${dirName} && git init && git add . && git commit -m "New Stackbit project"` + ) } /** * Given a version string, compare it to a control version. Returns: @@ -160,29 +160,19 @@ async function cloneExample() { // Checkout just the example dir. await run(`cd ${tmpDir} && git sparse-checkout set ${args.example}`) - // Copy out into a new directory within current working directory. - await fs.copy(`${tmpDir}/${args.example}`, dirName, async (err) => { - if (err) { - console.log(err) - } - }) + // move out into a new directory. + await fs.moveSync(`${tmpDir}/${args.example}`, dirName) // Delete the clone. - await fs.remove(tmpDir, { recursive: true }, (err) => { - if (err) { - console.log(err) - } - }) - - if (fs.existsSync(path.join(process.cwd(), dirName))) - await installDependencies(path.join(process.cwd(), dirName)) + await fs.removeSync(tmpDir) + + await installDependencies(dirName) // Project Setup - // await - // await initGit(prestineFolder) + await initGit(dirName) } catch (err) { - if (fs.existsSync(dirName)) await fs.remove(dirName) if (fs.existsSync(tmpDir)) + // remove temp directory await fs.remove(tmpDir, (err) => { if (err) { console.log(err) From f1ddc6a0bcf5ea25eab88b7c4a7fce78b3ea28e5 Mon Sep 17 00:00:00 2001 From: Shedrack akintayo Date: Mon, 24 Oct 2022 22:34:18 +0100 Subject: [PATCH 3/9] lint --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 81247b8..1bfaa16 100755 --- a/index.js +++ b/index.js @@ -172,7 +172,7 @@ async function cloneExample() { } catch (err) { if (fs.existsSync(dirName)) await fs.remove(dirName) if (fs.existsSync(tmpDir)) - // remove temp directory + // remove temp directory await fs.remove(tmpDir, (err) => { if (err) { console.log(err) From b7c76a2727985e7b234db735443bbb10ea7354c8 Mon Sep 17 00:00:00 2001 From: Shedrack akintayo Date: Mon, 24 Oct 2022 22:40:23 +0100 Subject: [PATCH 4/9] move install dependencies function --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 1bfaa16..a3378a1 100755 --- a/index.js +++ b/index.js @@ -166,8 +166,8 @@ async function cloneExample() { // Delete the clone. await fs.removeSync(tmpDir) - await installDependencies(dirName) // Project Setup + await installDependencies(dirName) await initGit(dirName) } catch (err) { if (fs.existsSync(dirName)) await fs.remove(dirName) From 3f6e96eb0000105fe38e2b0c8d1413a39a957f0c Mon Sep 17 00:00:00 2001 From: Sean C Davis Date: Tue, 25 Oct 2022 09:39:33 -0400 Subject: [PATCH 5/9] Formatting --- index.js | 168 +++++++++++++++++++++++++++---------------------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/index.js b/index.js index a3378a1..5027610 100755 --- a/index.js +++ b/index.js @@ -1,49 +1,49 @@ #!/usr/bin/env node -import chalk from 'chalk' -import { exec } from 'child_process' -import fs from 'fs-extra' -import path from 'path' -import readline from 'readline' -import util from 'util' -import yargs from 'yargs' -import { hideBin } from 'yargs/helpers' +import chalk from "chalk"; +import { exec } from "child_process"; +import fs from "fs-extra"; +import path from "path"; +import readline from "readline"; +import util from "util"; +import yargs from "yargs"; +import { hideBin } from "yargs/helpers"; -import config from './config.js' +import config from "./config.js"; /* --- Helpers --- */ -const run = util.promisify(exec) +const run = util.promisify(exec); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, -}) +}); function prompt(question, defaultAnswer) { return new Promise((resolve) => { - rl.question(question, (input) => resolve(input || defaultAnswer)) - }) + rl.question(question, (input) => resolve(input || defaultAnswer)); + }); } function getDirName(defaultDirName) { - let dirName = args._[0] ?? defaultDirName - if (fs.existsSync(dirName)) dirName += `-${timestamp}` - return dirName + let dirName = args._[0] ?? defaultDirName; + if (fs.existsSync(dirName)) dirName += `-${timestamp}`; + return dirName; } async function installDependencies(dirName) { - console.log(`Installing dependencies ...`) - await run(`cd ${dirName} && npm install`) + console.log(`Installing dependencies ...`); + await run(`cd ${dirName} && npm install`); } async function initGit(dirName) { - console.log(`Setting up Git ...`) + console.log(`Setting up Git ...`); // remove .git folder - await fs.removeSync(`${dirName} / .git`) + await fs.removeSync(`${dirName} / .git`); await run( `cd ${dirName} && git init && git add . && git commit -m "New Stackbit project"` - ) + ); } /** * Given a version string, compare it to a control version. Returns: @@ -57,138 +57,138 @@ async function initGit(dirName) { */ function compareVersion(version, control) { // References - let returnValue = 0 + let returnValue = 0; // Return 0 if the versions match. - if (version === control) return returnValue + if (version === control) return returnValue; // Break the versions into arrays of integers. - const getVersionParts = (str) => str.split('.').map((v) => parseInt(v)) - const versionParts = getVersionParts(version) - const controlParts = getVersionParts(control) + const getVersionParts = (str) => str.split(".").map((v) => parseInt(v)); + const versionParts = getVersionParts(version); + const controlParts = getVersionParts(control); // Loop and compare each item. controlParts.every((controlPart, idx) => { // If the versions are equal at this part, we move on to the next part. - if (versionParts[idx] === controlPart) return true + if (versionParts[idx] === controlPart) return true; // Otherwise, set the return value, then break out of the loop. - returnValue = versionParts[idx] > controlPart ? 1 : -1 - return false - }) - return returnValue + returnValue = versionParts[idx] > controlPart ? 1 : -1; + return false; + }); + return returnValue; } /* --- Parse CLI Arguments */ const args = yargs(hideBin(process.argv)) - .option('starter', { - alias: 's', - describe: 'Choose a starter', + .option("starter", { + alias: "s", + describe: "Choose a starter", choices: config.starters.map((s) => s.name), }) - .option('example', { - alias: 'e', - describe: 'Start from an example', + .option("example", { + alias: "e", + describe: "Start from an example", choices: config.examples.directories, }) .help() - .parse() + .parse(); /* --- References --- */ const starter = config.starters.find( (s) => s.name === (args.starter ?? config.defaults.starter.name) -) +); // Current time in seconds. -const timestamp = Math.round(new Date().getTime() / 1000) +const timestamp = Math.round(new Date().getTime() / 1000); /* --- New Project from Starter --- */ async function cloneStarter() { // Set references - const dirName = getDirName(config.defaults.dirName) + const dirName = getDirName(config.defaults.dirName); // Clone repo - const cloneCommand = `git clone --depth=1 ${starter.repoUrl} ${dirName}` - console.log(`\nCreating new project in ${dirName} ...`) - await run(cloneCommand) + const cloneCommand = `git clone --depth=1 ${starter.repoUrl} ${dirName}`; + console.log(`\nCreating new project in ${dirName} ...`); + await run(cloneCommand); // Project Setup - await installDependencies(dirName) - await initGit(dirName) + await installDependencies(dirName); + await initGit(dirName); // Output next steps: console.log(` -🎉 ${chalk.bold('Welcome to Stackbit!')} 🎉 +🎉 ${chalk.bold("Welcome to Stackbit!")} 🎉 Follow the instructions for getting Started here: ${starter.repoUrl}#readme - `) + `); } /* --- New Project from Example --- */ async function cloneExample() { - const gitResult = await run('git --version') - const gitVersionMatch = gitResult.stdout.match(/\d+\.\d+\.\d+/) + const gitResult = await run("git --version"); + const gitVersionMatch = gitResult.stdout.match(/\d+\.\d+\.\d+/); if (!gitVersionMatch || !gitVersionMatch[0]) { console.error( `Cannot determine git version, which is required for starting from an example.`, `\nPlease report this:`, chalk.underline( - 'https://github.com/stackbit/create-stackbit-app/issues/new' + "https://github.com/stackbit/create-stackbit-app/issues/new" ) - ) - process.exit(1) + ); + process.exit(1); } if (compareVersion(gitVersionMatch[0], config.minGitVersion) < 0) { console.error( `Starting from an example requires git version ${config.minGitVersion} or later.`, - 'Please upgrade' - ) - process.exit(1) + "Please upgrade" + ); + process.exit(1); } - const dirName = getDirName(args.example) - const tmpDir = `__tmp${timestamp}__` - console.log(`\nCreating new project in ${dirName} ...`) + const dirName = getDirName(args.example); + const tmpDir = `__tmp${timestamp}__`; + console.log(`\nCreating new project in ${dirName} ...`); try { // Sparse clone the monorepo. await run( `git clone --depth 1 --filter=blob:none --sparse ${config.examples.repoUrl} ${tmpDir}` - ) + ); // Checkout just the example dir. - await run(`cd ${tmpDir} && git sparse-checkout set ${args.example}`) + await run(`cd ${tmpDir} && git sparse-checkout set ${args.example}`); // move out into a new directory. - await fs.moveSync(`${tmpDir}/${args.example}`, dirName) + await fs.moveSync(`${tmpDir}/${args.example}`, dirName); // Delete the clone. - await fs.removeSync(tmpDir) + await fs.removeSync(tmpDir); // Project Setup - await installDependencies(dirName) - await initGit(dirName) + await installDependencies(dirName); + await initGit(dirName); } catch (err) { - if (fs.existsSync(dirName)) await fs.remove(dirName) + if (fs.existsSync(dirName)) await fs.remove(dirName); if (fs.existsSync(tmpDir)) // remove temp directory await fs.remove(tmpDir, (err) => { if (err) { - console.log(err) + console.log(err); } - }) - process.exit(1) + }); + process.exit(1); } // Output next steps: console.log(` -🎉 ${chalk.bold('Your example project is ready!')} 🎉 +🎉 ${chalk.bold("Your example project is ready!")} 🎉 Follow the instructions and learn more about the example here: ${config.examples.repoUrl}/tree/main/${args.example}#readme - `) + `); } /* --- Existing Project --- */ @@ -197,17 +197,17 @@ async function integrateStackbit() { return new Promise(async (resolve) => { const integrate = await prompt(` This looks like an existing project. - ${chalk.bold('Would you like to install Stackbit in this project?')} [Y/n] `) + ${chalk.bold("Would you like to install Stackbit in this project?")} [Y/n] `); - if (!['yes', 'y'].includes(integrate?.toLowerCase())) return resolve(false) + if (!["yes", "y"].includes(integrate?.toLowerCase())) return resolve(false); console.log(` Visit the following URL to learn more about the integration process: https://docs.stackbit.com/how-to-guides/site-management/integrate-stackbit/ -`) - return resolve(true) - }) +`); + return resolve(true); + }); } /* --- Run --- */ @@ -215,19 +215,19 @@ Visit the following URL to learn more about the integration process: async function doCreate() { // If the current directory has a package.json file, we assume we're in an // active project, and will not create a new project. - const packageJsonFilePath = path.join(process.cwd(), 'package.json') - if (fs.existsSync(packageJsonFilePath)) return integrateStackbit() + const packageJsonFilePath = path.join(process.cwd(), "package.json"); + if (fs.existsSync(packageJsonFilePath)) return integrateStackbit(); // If both starter and example were specified, throw an error message. if (args.starter && args.example) { - console.error('[ERROR] Cannot specify a starter and an example.') - process.exit(1) + console.error("[ERROR] Cannot specify a starter and an example."); + process.exit(1); } // Start from an example if specified. - if (args.example) return cloneExample() + if (args.example) return cloneExample(); // Otherwise, use a starter, which falls back to the default if not set. - return cloneStarter() + return cloneStarter(); } -await doCreate() +await doCreate(); -rl.close() +rl.close(); From ee1c6858a154feba14d93d37c3a958db14599e18 Mon Sep 17 00:00:00 2001 From: Sean C Davis Date: Tue, 25 Oct 2022 09:39:45 -0400 Subject: [PATCH 6/9] Bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6c2d87d..58dabe7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "create-stackbit-app", - "version": "0.1.9", + "version": "0.1.10", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "create-stackbit-app", - "version": "0.1.9", + "version": "0.1.10", "license": "MIT", "dependencies": { "chalk": "^5.0.0", diff --git a/package.json b/package.json index 2a5750c..388747c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "create-stackbit-app", - "version": "0.1.9", + "version": "0.1.10", "description": "Create a new Stackbit site, or add Stackbit to an existing site.", "main": "index.js", "scripts": { From 3eef9d3321615ee4fbee236d1da3c1902c57d1ba Mon Sep 17 00:00:00 2001 From: Shedrack akintayo Date: Tue, 25 Oct 2022 16:54:55 +0100 Subject: [PATCH 7/9] fixes --- index.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 7167f54..6672227 100755 --- a/index.js +++ b/index.js @@ -39,8 +39,7 @@ async function installDependencies(dirName) { async function initGit(dirName) { console.log(`Setting up Git ...`); - // remove .git folder - await fs.removeSync(`${dirName} / .git`); + await fs.removeSync(`${dirName}/.git`); await run(`cd ${dirName} && git init && git add . && git commit -m "New Stackbit project"`); } /** @@ -148,10 +147,8 @@ async function cloneExample() { await run(`git clone --depth 1 --filter=blob:none --sparse ${config.examples.repoUrl} ${tmpDir}`); // Checkout just the example dir. await run(`cd ${tmpDir} && git sparse-checkout set ${args.example}`); - // move out into a new directory. await fs.moveSync(`${tmpDir}/${args.example}`, dirName); - // Delete the clone. await fs.removeSync(tmpDir); @@ -159,14 +156,9 @@ async function cloneExample() { await installDependencies(dirName); await initGit(dirName); } catch (err) { - if (fs.existsSync(dirName)) await fs.remove(dirName); - if (fs.existsSync(tmpDir)) - // remove temp directory - await fs.remove(tmpDir, (err) => { - if (err) { - console.log(err); - } - }); + console.error(err); + if (fs.existsSync(dirName)) await fs.removeSync(dirName); + if (fs.existsSync(tmpDir)) await fs.removeSync(tmpDir); process.exit(1); } From caea7f2d2aca5d701c010a13417c250c0a71ace2 Mon Sep 17 00:00:00 2001 From: Sean C Davis Date: Wed, 26 Oct 2022 16:29:43 -0400 Subject: [PATCH 8/9] Make fs-extra a dep --- package-lock.json | 67 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 68 insertions(+) diff --git a/package-lock.json b/package-lock.json index 58dabe7..568473f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "chalk": "^5.0.0", + "fs-extra": "^10.1.0", "yargs": "^17.3.1" }, "bin": { @@ -88,6 +89,19 @@ "node": ">=6" } }, + "node_modules/fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -96,6 +110,11 @@ "node": "6.* || 8.* || >= 10.*" } }, + "node_modules/graceful-fs": { + "version": "4.2.10", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", + "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==" + }, "node_modules/is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", @@ -104,6 +123,17 @@ "node": ">=8" } }, + "node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -136,6 +166,14 @@ "node": ">=8" } }, + "node_modules/universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -238,16 +276,40 @@ "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==" }, + "fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" }, + "graceful-fs": { + "version": "4.2.10", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", + "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==" + }, "is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" }, + "jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -271,6 +333,11 @@ "ansi-regex": "^5.0.1" } }, + "universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" + }, "wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", diff --git a/package.json b/package.json index 388747c..e62de37 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "type": "module", "dependencies": { "chalk": "^5.0.0", + "fs-extra": "^10.1.0", "yargs": "^17.3.1" } } From d4e4b1bf69712b0ae248f95301cfb90334359956 Mon Sep 17 00:00:00 2001 From: Sean C Davis Date: Wed, 26 Oct 2022 16:29:51 -0400 Subject: [PATCH 9/9] Remove unnecessary awaits --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 6672227..dc5920c 100755 --- a/index.js +++ b/index.js @@ -39,7 +39,7 @@ async function installDependencies(dirName) { async function initGit(dirName) { console.log(`Setting up Git ...`); - await fs.removeSync(`${dirName}/.git`); + fs.removeSync(`${dirName}/.git`); await run(`cd ${dirName} && git init && git add . && git commit -m "New Stackbit project"`); } /** @@ -148,17 +148,17 @@ async function cloneExample() { // Checkout just the example dir. await run(`cd ${tmpDir} && git sparse-checkout set ${args.example}`); // move out into a new directory. - await fs.moveSync(`${tmpDir}/${args.example}`, dirName); + fs.moveSync(`${tmpDir}/${args.example}`, dirName); // Delete the clone. - await fs.removeSync(tmpDir); + fs.removeSync(tmpDir); // Project Setup await installDependencies(dirName); await initGit(dirName); } catch (err) { console.error(err); - if (fs.existsSync(dirName)) await fs.removeSync(dirName); - if (fs.existsSync(tmpDir)) await fs.removeSync(tmpDir); + if (fs.existsSync(dirName)) fs.removeSync(dirName); + if (fs.existsSync(tmpDir)) fs.removeSync(tmpDir); process.exit(1); }