build: improve build script to support multiple targets
This commit is contained in:
parent
b33f0ceff1
commit
776bc73a5a
@ -20,19 +20,21 @@ const zlib = require('zlib')
|
|||||||
const chalk = require('chalk')
|
const chalk = require('chalk')
|
||||||
const execa = require('execa')
|
const execa = require('execa')
|
||||||
const { compress } = require('brotli')
|
const { compress } = require('brotli')
|
||||||
const { targets, fuzzyMatchTarget } = require('./utils')
|
const { targets: allTargets, fuzzyMatchTarget } = require('./utils')
|
||||||
|
|
||||||
const args = require('minimist')(process.argv.slice(2))
|
const args = require('minimist')(process.argv.slice(2))
|
||||||
const target = args._[0]
|
const targets = args._
|
||||||
const formats = args.formats || args.f
|
const formats = args.formats || args.f
|
||||||
|
const devOnly = args.devOnly || args.d
|
||||||
|
const prodOnly = !devOnly && (args.prodOnly || args.p)
|
||||||
const buildAllMatching = args.all || args.a
|
const buildAllMatching = args.all || args.a
|
||||||
;(async () => {
|
;(async () => {
|
||||||
if (!target) {
|
if (!targets.length) {
|
||||||
await buildAll(targets)
|
await buildAll(allTargets)
|
||||||
checkAllSizes(targets)
|
checkAllSizes(allTargets)
|
||||||
} else {
|
} else {
|
||||||
await buildAll(fuzzyMatchTarget(target, buildAllMatching))
|
await buildAll(fuzzyMatchTarget(targets, buildAllMatching))
|
||||||
checkAllSizes(fuzzyMatchTarget(target, buildAllMatching))
|
checkAllSizes(fuzzyMatchTarget(targets, buildAllMatching))
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
@ -53,11 +55,11 @@ async function build(target) {
|
|||||||
[
|
[
|
||||||
'-c',
|
'-c',
|
||||||
'--environment',
|
'--environment',
|
||||||
`NODE_ENV:production,` +
|
`NODE_ENV:${devOnly ? 'development' : 'production'},` +
|
||||||
`TARGET:${target}` +
|
`TARGET:${target}` +
|
||||||
(formats ? `,FORMATS:${formats}` : ``) +
|
(formats ? `,FORMATS:${formats}` : ``) +
|
||||||
(args.types ? `,TYPES:true` : ``) +
|
(args.types ? `,TYPES:true` : ``) +
|
||||||
(args.p ? `,PROD_ONLY:true` : ``)
|
(prodOnly ? `,PROD_ONLY:true` : ``)
|
||||||
],
|
],
|
||||||
{ stdio: 'inherit' }
|
{ stdio: 'inherit' }
|
||||||
)
|
)
|
||||||
|
@ -11,16 +11,18 @@ const targets = (exports.targets = fs.readdirSync('packages').filter(f => {
|
|||||||
return true
|
return true
|
||||||
}))
|
}))
|
||||||
|
|
||||||
exports.fuzzyMatchTarget = (partialTarget, includeAllMatching) => {
|
exports.fuzzyMatchTarget = (partialTargets, includeAllMatching) => {
|
||||||
const matched = []
|
const matched = []
|
||||||
|
partialTargets.some(partialTarget => {
|
||||||
for (const target of targets) {
|
for (const target of targets) {
|
||||||
if (target.match(partialTarget)) {
|
if (target.match(partialTarget)) {
|
||||||
matched.push(target)
|
matched.push(target)
|
||||||
if (!includeAllMatching) {
|
if (!includeAllMatching) {
|
||||||
return matched
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
if (matched.length) {
|
if (matched.length) {
|
||||||
return matched
|
return matched
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user