2016-10-06 11:05:52 +00:00
|
|
|
import { resolve } from 'path'
|
|
|
|
import glob from 'glob-promise'
|
|
|
|
import transpile from './transpile'
|
|
|
|
import bundle from './bundle'
|
|
|
|
|
|
|
|
export default async function build (dir) {
|
|
|
|
const dstDir = resolve(dir, '.next')
|
2016-10-09 09:25:38 +00:00
|
|
|
const templateDir = resolve(__dirname, '..', '..', 'lib', 'pages')
|
|
|
|
|
|
|
|
// create `.next/pages/_error.js`
|
|
|
|
// which may be overwriten by the user sciprt, `pages/_error.js`
|
|
|
|
const templatPaths = await glob('**/*.js', { cwd: templateDir })
|
|
|
|
await Promise.all(templatPaths.map(async (p) => {
|
|
|
|
await transpile(resolve(templateDir, p), resolve(dstDir, 'pages', p))
|
|
|
|
}))
|
2016-10-06 11:05:52 +00:00
|
|
|
|
|
|
|
const paths = await glob('**/*.js', { cwd: dir, ignore: 'node_modules/**' })
|
|
|
|
await Promise.all(paths.map(async (p) => {
|
|
|
|
await transpile(resolve(dir, p), resolve(dstDir, p))
|
|
|
|
}))
|
|
|
|
|
|
|
|
const pagePaths = await glob('pages/**/*.js', { cwd: dstDir })
|
|
|
|
await Promise.all(pagePaths.map(async (p) => {
|
|
|
|
await bundle(resolve(dstDir, p), resolve(dstDir, '_bundles', p))
|
|
|
|
}))
|
|
|
|
}
|