Skip to content

Commit

Permalink
refactor: create-wmr checks dir before installing (#365)
Browse files Browse the repository at this point in the history
* refactor: create-wmr checks dir before installing

* docs: Adding changeset
  • Loading branch information
rschristian authored Feb 23, 2021
1 parent ee75298 commit cce35d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-pens-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-wmr': minor
---

Blocks accidentally creating a new WMR project into a directory that already exists
7 changes: 7 additions & 0 deletions packages/create-wmr/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ const { dim, bold, cyan, red } = kleur;

sade('create-wmr [dir]', true)
.option('--eslint', 'Set up the Preact ESLint configuration (takes a lot longer)', false)
.option('--force', 'Force install into an existing directory', false)
.describe('Initialize a WMR project')
.example('npm init wmr ./some-directory')
.action(async (dir, opts) => {
const origCwd = process.cwd();
let cwd = process.cwd();
if (dir) {
if ((await fs.stat(dir)).isDirectory() && !opts.force) {
process.stderr.write(
`${red(`Refusing to overwrite directory! Please specify a different directory or use the '--force' flag`)}\n`
);
process.exit(1);
}
cwd = resolve(cwd, dir || '.');
await fs.mkdir(cwd, { recursive: true });
process.chdir(cwd);
Expand Down

0 comments on commit cce35d3

Please sign in to comment.