Skip to content

Hotfix: use node fs-extra to handle copying and removing files #3hk00xt #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import chalk from 'chalk';
import { exec } from 'child_process';
import fs from 'fs';
import fs from 'fs-extra';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to use a package, it should be listed as a dependency in package.json. Although widely used, it's not safe to rely on dependencies' dependencies.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also like to know why this is necessary beyond the fs basics? It doesn't seem like we're doing anything fancy, and I like to keep dependencies to a minimum.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because of the move and remove functions, there are some underlying issues especially with callbacks that fs has but fs-extra solves it.

import path from 'path';
import readline from 'readline';
import util from 'util';
Expand Down Expand Up @@ -39,10 +39,9 @@ async function installDependencies(dirName) {

async function initGit(dirName) {
console.log(`Setting up Git ...`);
await run(`rm -rf ${dirName}/.git`);
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:
*
Expand Down Expand Up @@ -148,18 +147,18 @@ 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}`);
// Copy out into a new directory within current working directory.
await run(`cp -R ${tmpDir}/${args.example} ${dirName}`);
// move out into a new directory.
fs.moveSync(`${tmpDir}/${args.example}`, dirName);
// Delete the clone.
await run(`rm -rf ${tmpDir}`);
fs.removeSync(tmpDir);

// Project Setup
await installDependencies(dirName);
await initGit(dirName);
} catch (err) {
console.error(err);
if (fs.existsSync(dirName)) await run(`rm -rf ${dirName}`);
if (fs.existsSync(tmpDir)) await run(`rm -rf ${tmpDir}`);
if (fs.existsSync(dirName)) fs.removeSync(dirName);
if (fs.existsSync(tmpDir)) fs.removeSync(tmpDir);
process.exit(1);
}

Expand Down
71 changes: 69 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -15,6 +15,7 @@
"type": "module",
"dependencies": {
"chalk": "^5.0.0",
"fs-extra": "^10.1.0",
"yargs": "^17.3.1"
}
}