1 | const fs = require('fs-extra')
|
2 | const path = require('path')
|
3 | const chalk = require('chalk')
|
4 | const __ = require('./translate')
|
5 | const defaults = require('../defaults/build-config')
|
6 | const getPathnameBuildConfigFile = require('./get-pathname-build-config-file')
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | module.exports = (
|
14 | pathname = getPathnameBuildConfigFile()
|
15 | ) => new Promise((resolve, reject) => {
|
16 | const filename = `${path.basename(pathname)}.${path.extname(pathname)}`
|
17 |
|
18 |
|
19 | if (!fs.existsSync(pathname)) {
|
20 | console.log(
|
21 | chalk.redBright('× ')
|
22 | + __('file_not_found', {
|
23 | file: chalk.yellowBright(filename),
|
24 | })
|
25 | )
|
26 | return reject(new Error('FILE NOT FOUND'))
|
27 | }
|
28 |
|
29 | const buildConfig = Object.assign({}, defaults, require(pathname))
|
30 | if (typeof buildConfig !== 'object') {
|
31 | console.log(
|
32 | chalk.redBright('× ')
|
33 | + __('build.config_type_error', {
|
34 | file: chalk.yellowBright(filename),
|
35 | type: chalk.green('Object')
|
36 | })
|
37 | )
|
38 | return reject(new Error('TYPE NOT OBJECT'))
|
39 | }
|
40 |
|
41 | resolve(buildConfig)
|
42 | })
|