UNPKG

1.15 kBJavaScriptView Raw
1const fs = require('fs-extra')
2const path = require('path')
3const chalk = require('chalk')
4const __ = require('./translate')
5const defaults = require('../defaults/build-config')
6
7module.exports = (
8 pathname = typeof process.env.WEBPACK_BUILD_CONFIG_PATHNAME === 'undefined'
9 ? path.resolve(process.cwd(), './super.build.js')
10 : process.env.WEBPACK_BUILD_CONFIG_PATHNAME
11) => new Promise((resolve, reject) => {
12 // 读取构建配置
13 if (!fs.existsSync(pathname)) {
14 console.log(
15 chalk.red('× ')
16 + __('file_not_found', {
17 file: chalk.yellowBright('./super.build.js'),
18 })
19 )
20 return reject(new Error('FILE NOT FOUND'))
21 }
22
23 const buildConfig = Object.assign({}, defaults, require(pathname))
24 if (typeof buildConfig !== 'object') {
25 console.log(
26 chalk.red('× ')
27 + __('build.config_type_error', {
28 file: chalk.yellowBright('./super.build.js'),
29 type: chalk.green('Object')
30 })
31 )
32 return reject(new Error('TYPE NOT OBJECT'))
33 }
34
35 resolve(buildConfig)
36})