1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/bin/next-init
Stephen Sauceda 694c8c56c7 update default page generated by next init (#376)
* use next logo on 'init' start page

* use github cdn for logo
2016-12-11 12:01:39 -08:00

86 lines
1.7 KiB
JavaScript
Executable file

#!/usr/bin/env node
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: {
h: 'help'
},
boolean: ['h']
})
const dir = resolve(argv._[0] || '.')
if (basename(dir) === 'pages') {
console.warn('Your root directory is named "pages". This looks suspicious. You probably want to go one directory up.')
process.exit(1)
}
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)))
}
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)
process.exit(1)
})
const basePackage = `{
"name": "my-app",
"description": "",
"dependencies": {
"next": "latest"
},
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
}
}`
const basePage = `
import React from 'react'
import Head from 'next/head'
export default () => (
<div>
<Head>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<style>{bodyStyles}</style>
</Head>
<img width="112" src="https://cloud.githubusercontent.com/assets/13041/19686250/971bf7f8-9ac0-11e6-975c-188defd82df1.png" alt="next.js" />
</div>
)
const bodyStyles = \`
html, body {
height: 100%
}
body {
display: flex;
align-items: center;
justify-content: center;
}
\`
`