Skip to content

Commit 77739f4

Browse files
timoxleynkzawa
authored andcommitted
next init: Create supplied directory if it does not exist. (vercel#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 vercel#136 (comment)
1 parent c4d6261 commit 77739f4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

bin/next-init

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { resolve, join, basename } from 'path'
33
import parseArgs from 'minimist'
44
import { exists, writeFile, mkdir } from 'mz/fs'
5+
import mkdirp from 'mkdirp-then'
56

67
const argv = parseArgs(process.argv.slice(2), {
78
alias: {
@@ -17,9 +18,13 @@ if (basename(dir) === 'pages') {
1718
process.exit(1)
1819
}
1920

20-
exists(join(dir, 'package.json'))
21+
exists(dir)
2122
.then(async present => {
2223
if (!present) {
24+
await mkdirp(dir)
25+
}
26+
27+
if (!await exists(join(dir, 'package.json'))) {
2328
await writeFile(join(dir, 'package.json'), basePackage.replace(/my-app/g, basename(dir)))
2429
}
2530

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"json-loader": "0.5.4",
5959
"loader-utils": "0.2.16",
6060
"minimist": "1.2.0",
61+
"mkdirp-then": "1.2.0",
6162
"mz": "2.4.0",
6263
"path-match": "1.2.4",
6364
"react": "15.3.2",

0 commit comments

Comments
 (0)