perf(build-fixtures): parallel builds

This commit is contained in:
Pooya Parsa 2018-03-19 04:21:06 +03:30
parent 584b943688
commit 19775d58f7
3 changed files with 48 additions and 27 deletions

View File

@ -116,6 +116,7 @@
"webpack-stylish": "^0.1.6"
},
"devDependencies": {
"@expo/spawn-async": "^1.3.0",
"babel-eslint": "^8.2.1",
"codecov": "^3.0.0",
"eslint": "^4.18.2",
@ -134,6 +135,7 @@
"jest": "^22.4.2",
"jest-runner-eslint": "^0.4.0",
"jsdom": "^11.6.2",
"p-limit": "^1.2.0",
"puppeteer": "^1.0.0",
"request": "^2.83.0",
"request-promise-native": "^1.0.5",

View File

@ -1,16 +1,14 @@
#!/usr/bin/env node
process.env.NODE_ENV = 'test'
const { Builder, Nuxt } = require('..')
const { requireModule } = require('../lib/common/module')
const path = require('path')
const fs = require('fs')
const { resolve } = require('path')
const { cpus } = require('os')
const spawnAsync = require('@expo/spawn-async')
const ORA = require('ora')
const pLimit = require('p-limit')
const fixtures = [
// csr, dev, generate, fail generate, fallback generate, ssr, ssr csp, spa
'basic',
'children',
'custom-dirs',
'debug',
@ -20,37 +18,52 @@ const fixtures = [
'error',
'module',
'ssr',
'with-config'
'with-config',
// csr,
// dev,
// generate,
// fail generate,
// fallback generate,
// ssr,
// ssr csp,
// spa
'basic'
]
const spinner = new ORA()
const nuxtBuild = resolve(__dirname, '../bin/nuxt-build')
let _total = fixtures.length
let _done = 0
let remaining = () => ` (${_done}/${_total})`
async function buildFixture(name) {
spinner.info('Loading config for fixture ' + name)
_done++
const rootDir = path.resolve(__dirname, '../test/fixtures', name)
const configFile = path.resolve(rootDir, 'nuxt.config.js')
const config = fs.existsSync(configFile) ? requireModule(configFile) : {}
let _name = `'${name}'`
config.rootDir = rootDir
config.dev = false
spinner.info('Building ' + _name + remaining())
spinner.start('Building fixture ' + name)
const rootDir = resolve(__dirname, '../test/fixtures', name)
const nuxt = new Nuxt(config)
const builder = new Builder(nuxt)
await builder.build()
spinner.succeed('Built fixture ' + name)
await nuxt.close()
await spawnAsync('node', [nuxtBuild, rootDir])
.catch((err) => {
spinner.warn('Errors while building ' + _name + ': ' + err)
})
.then(() => {
spinner.succeed('Built fixture: ' + _name + remaining())
})
}
async function run() {
for (let fixture of fixtures) {
await buildFixture(fixture)
}
const cpuCount = cpus().length
spinner.info('Builing with concurrency of ' + cpuCount)
const limit = pLimit(cpuCount)
await Promise.all(fixtures.map(fixture =>
limit(() => buildFixture(fixture))))
}
run()

View File

@ -85,6 +85,12 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"
"@expo/spawn-async@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@expo/spawn-async/-/spawn-async-1.3.0.tgz#01b8a4f6bba10b792663f9272df66c7e90166dad"
dependencies:
cross-spawn "^5.1.0"
"@nuxtjs/friendly-errors-webpack-plugin@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@nuxtjs/friendly-errors-webpack-plugin/-/friendly-errors-webpack-plugin-2.0.0.tgz#70fb321c78362e2b4bce1d522ecdf7f87a4dacec"
@ -4997,7 +5003,7 @@ p-finally@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
p-limit@^1.1.0:
p-limit@^1.1.0, p-limit@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.2.0.tgz#0e92b6bedcb59f022c13d0f1949dc82d15909f1c"
dependencies: