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
This commit is contained in:
parent
c4d626108e
commit
77739f4d5e
2 changed files with 7 additions and 1 deletions
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue