调用 so.sysconfig(rawConfig) 来提供基础配置参数,从而可以不提供 ConfigBasic.js 等配置文件。

This commit is contained in:
陆柯 2021-01-26 20:03:42 +08:00
parent 83581c72c8
commit 75c4f1c6a3

View File

@ -1,30 +1,27 @@
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const Config = Object.assign( const Config = require('so.sysconfig')({
{ commanderOptions: [
commanderOptions: [ // 命令行里可以接受的参数。将传给 config.js 里的 commander。每个参数的定义格式是 [参数名,参数键,描述]后两者用于传给commander取值后覆盖掉Config里的同名变量。
// 命令行里可以接受的参数。将传给 config.js 里的 commander。每个参数的定义格式是 [参数名,参数键,描述]后两者用于传给commander取值后覆盖掉Config里的同名变量。 ['protocol', '-P, --protocol <string>', 'Web Server protocol: http|https|httpall.'],
['protocol', '-P, --protocol <string>', 'Web Server protocol: http|https|httpall.'], ['host', '-h, --host <string>', 'Host IP or domain name, default to localhost.'],
['host', '-h, --host <string>', 'Host IP or domain name, default to localhost.'],
['port', '-p, --port <number>', 'HTTP port number.'], ['port', '-p, --port <number>', 'HTTP port number.'],
['from', '-f, --from <string>', 'Seed list such as \'["http://ip_or_dn:port"]\' or "noseed" to disable seeding.'], ['from', '-f, --from <string>', 'Seed list such as \'["http://ip_or_dn:port"]\' or "noseed" to disable seeding.'],
['env', '-e, --env <string>', 'Runtime environment: production | development.'], ['env', '-e, --env <string>', 'Runtime environment: production | development.'],
], ],
// 最基础的必须的默认配置,如果用户什么也没有提供 // 最基础的必须的默认配置,如果用户什么也没有提供
protocol: 'http', protocol: 'http',
host: 'localhost', host: 'localhost',
from: './dist', // local path to serve as webroot from: './dist', // local path to serve as webroot
// 如果使用虚拟主机 // 如果使用虚拟主机
/* /*
vhosts: [ vhosts: [
{ webroot: 'dist', webindex: 'index.html', domainList: ['']} { webroot: 'dist', webindex: 'index.html', domainList: ['']}
], ],
*/ */
}, })
require('so.sysconfig')
)
if (typeof Config.ssl === 'string') { if (typeof Config.ssl === 'string') {
Config.ssl = eval(`(${Config.ssl})`) Config.ssl = eval(`(${Config.ssl})`)
} }