/**
* 将 async/await 转为 generator 以 Promise 形式使用,可以在过程中随时打断/等待
* function build(appPath, config) {
return awaiter(this, undefined, undefined, function* () {
const mode = config.mode
const newConfig = yield chain_1.makeConfig(config)
const webpackChain = build_conf_1.default(appPath, mode, newConfig)
yield customizeChain(
webpackChain,
newConfig.modifyWebpackChain,
newConfig.webpackChain
)
}
}
*/
const awaiter = function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P
? value
: new P(function (resolve) {
resolve(value)
})
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value))
} catch (e) {
reject(e)
}
}
function rejected(value) {
try {
step(generator['throw'](value))
} catch (e) {
reject(e)
}
}
function step(result) {
result.done
? resolve(result.value)
: adopt(result.value).then(fulfilled, rejected)
}
step((generator = generator.apply(thisArg, _arguments || [])).next())
})
}