Commit 77739f4d authored by Tim Oxley's avatar Tim Oxley Committed by Naoyuki Kanezawa

next init: Create supplied directory if it does not exist. (#136)

* next init: Create supplied directory if it does not exist.

* next init: use mkdirp to init into nested dirs.

Picked mkdirp-then out of many alternatives. Same author & similar
dependencies to mz.

Now next init a/b/c works.

Related https://github.com/zeit/next.js/pull/136#discussion_r85543040
parent c4d62610
......@@ -2,6 +2,7 @@
import { resolve, join, basename } from 'path'
import parseArgs from 'minimist'
import { exists, writeFile, mkdir } from 'mz/fs'
import mkdirp from 'mkdirp-then'
const argv = parseArgs(process.argv.slice(2), {
alias: {
......@@ -17,9 +18,13 @@ if (basename(dir) === 'pages') {
process.exit(1)
}
exists(join(dir, 'package.json'))
exists(dir)
.then(async present => {
if (!present) {
await mkdirp(dir)
}
if (!await exists(join(dir, 'package.json'))) {
await writeFile(join(dir, 'package.json'), basePackage.replace(/my-app/g, basename(dir)))
}
......
......@@ -58,6 +58,7 @@
"json-loader": "0.5.4",
"loader-utils": "0.2.16",
"minimist": "1.2.0",
"mkdirp-then": "1.2.0",
"mz": "2.4.0",
"path-match": "1.2.4",
"react": "15.3.2",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment