Nuxt/scripts/build-fixtures

72 lines
1.4 KiB
Plaintext
Raw Normal View History

2018-03-18 20:11:43 +00:00
#!/usr/bin/env node
process.env.NODE_ENV = 'test'
2018-03-19 00:51:06 +00:00
const { resolve } = require('path')
const { cpus } = require('os')
const spawnAsync = require('@expo/spawn-async')
2018-03-18 20:11:43 +00:00
const ORA = require('ora')
2018-03-19 00:51:06 +00:00
const pLimit = require('p-limit')
2018-03-18 20:11:43 +00:00
const fixtures = [
'children',
'custom-dirs',
'debug',
'deprecate',
'dynamic-routes',
'empty',
'error',
'module',
'ssr',
2018-03-19 00:51:06 +00:00
'with-config',
// csr,
// dev,
// generate,
// fail generate,
// fallback generate,
// ssr,
// ssr csp,
// spa
'basic'
2018-03-18 20:11:43 +00:00
]
const spinner = new ORA()
2018-03-19 00:51:06 +00:00
const nuxtBuild = resolve(__dirname, '../bin/nuxt-build')
2018-03-18 20:11:43 +00:00
2018-03-19 00:51:06 +00:00
let _total = fixtures.length
let _done = 0
let remaining = () => ` (${_done}/${_total})`
2018-03-18 20:11:43 +00:00
2018-03-19 00:51:06 +00:00
async function buildFixture(name) {
_done++
2018-03-18 20:11:43 +00:00
2018-03-19 00:51:06 +00:00
let _name = `'${name}'`
2018-03-18 20:11:43 +00:00
2018-03-19 00:51:06 +00:00
spinner.info('Building ' + _name + remaining())
2018-03-18 20:11:43 +00:00
2018-03-19 00:51:06 +00:00
const rootDir = resolve(__dirname, '../test/fixtures', name)
2018-03-18 20:11:43 +00:00
2018-03-19 00:51:06 +00:00
await spawnAsync('node', [nuxtBuild, rootDir])
.catch((err) => {
spinner.warn('Errors while building ' + _name + ': ' + err)
})
.then(() => {
spinner.succeed('Built fixture: ' + _name + remaining())
})
2018-03-18 20:11:43 +00:00
}
async function run() {
2018-03-19 00:51:06 +00:00
const cpuCount = cpus().length
spinner.info('Builing with concurrency of ' + cpuCount)
const limit = pLimit(cpuCount)
await Promise.all(fixtures.map(fixture =>
limit(() => buildFixture(fixture))))
2018-03-18 20:11:43 +00:00
}
run()
.catch(console.error) // eslint-disable-line no-console
.then(() => process.exit(0))