Skip to content

Commit

Permalink
Added next init command for starting a new project (vercel#15)
Browse files Browse the repository at this point in the history
* Added next bootstrap command for starting a new project

* renamed bootstrap to init and check we are not in a dir called pages

* Removed extra empty line
  • Loading branch information
impronunciable authored and rauchg committed Oct 16, 2016
1 parent 7a33108 commit 97ad053
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/next
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { spawn } from 'cross-spawn';
const defaultCommand = 'dev'
const commands = new Set([
defaultCommand,
'init',
'build',
'start'
])
Expand Down
56 changes: 56 additions & 0 deletions bin/next-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env node
import { resolve, join, basename } from 'path'
import parseArgs from 'minimist'
import { exists, writeFile, mkdir } from 'mz/fs'

const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help'
},
boolean: ['h']
})

const dir = resolve(argv._[0] || '.')

exists(join(dir, 'package.json'))
.then(async present => {
if (basename(dir) === 'pages') {
console.warn('Your root directory is named "pages". This looks suspicious. You probably want to go one directory up.')
return
}

if (!present) {
await writeFile(join(dir, 'package.json'), basePackage)
}

if (!await exists(join(dir, 'static'))) {
await mkdir(join(dir, 'static'))
}

if (!await exists(join(dir, 'pages'))) {
await mkdir(join(dir, 'pages'))
await writeFile(join(dir, 'pages', 'index.js'), basePage)
}
})
.catch((err) => {
console.error(err)
exit(1)
})

const basePackage = `{
"name": "my-app",
"description": "my app",
"dependencies": {
"next": "latest"
},
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
}
}`

const basePage =`
import React from 'react'
export default () => <p>Hello, world</p>
`

0 comments on commit 97ad053

Please sign in to comment.