提交 51625dd4 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

move process.env variables to Config module

上级 bb269545
......@@ -7,8 +7,10 @@
"DEFAULT_HEAD": "phantomjs",
"DEFAULT_PUPPET": "web",
"DEFAULT_PROFILE": "default-profile-name",
"DEFAULT_PORT": 18788,
"DEFAULT_PUPPET_PORT": 28788,
"DEFAULT_PORT": 8788,
"DEFAULT_PUPPET_PORT": 18788,
"DEFAULT_PROTOCOL": "io|0.0.1",
"ENDPOINT": "wss://api.wechaty.io/v0/websocket",
"BINARY_CHROMIUM": "/wechaty/bin/xvfb-chromium"
},
"scripts": {
......@@ -76,7 +78,6 @@
"body-parser": "^1.15.2",
"chromedriver": "^2.23.1",
"co": "^4.6.0",
"eventemitter2": "^2.1.0",
"express": "^4.13.4",
"npmlog": "^4.0.0",
"phantomjs-prebuilt": "^2.1.12",
......
const Config = require('../package.json').wechaty
Object.assign(Config, {
isDocker: !!process.env.WECHATY_DOCKER
, head: process.env.WECHATY_HEAD || Config.DEFAULT_HEAD
isDocker: !!process.env.WECHATY_DOCKER
, head: process.env.WECHATY_HEAD || Config.DEFAULT_HEAD
, puppet: process.env.WECHATY_PUPPET || Config.DEFAULT_PUPPET
, endpoint: process.env.WECHATY_ENDPOINT || Config.ENDPOINT // wechaty.io api endpoint
, port: process.env.WECHATY_PORT || 0 // 0 for disable port
, profile: process.env.WECHATY_PROFILE
, token: process.env.WECHATY_TOKEN
})
module.exports = Config.default = Config.Config = Config
import { test } from 'ava'
import { Config } from './config'
test('Config Module Exports', t => {
test('Config list vars & methods', t => {
t.truthy(Config.default , 'should export default')
t.truthy(Config.Config , 'should export Config')
t.true(typeof Config.isDocker !== 'undefined' , 'should identify docker env by isDocker')
t.true('isDocker' in Config, 'should identify docker env by `isDocker`')
t.true('head' in Config, 'should exist `head` in Config')
t.true('puppet' in Config, 'should exist `puppet` in Config')
t.true('endpoint' in Config, 'should exist `endpoint` in Config')
t.true('port' in Config, 'should exist `port` in Config')
t.true('profile' in Config, 'should exist `profile` in Config')
t.true('token' in Config, 'should exist `token` in Config')
t.truthy(Config.DEFAULT_PUPPET , 'should export DEFAULT_PUPPET')
t.truthy(Config.DEFAULT_PORT , 'should export DEFAULT_PORT')
t.truthy(Config.DEFAULT_PROFILE , 'should export DEFAULT_PROFILE')
t.truthy(Config.DEFAULT_PUPPET , 'should export DEFAULT_PUPPET')
t.truthy(Config.DEFAULT_PORT , 'should export DEFAULT_PORT')
t.truthy(Config.DEFAULT_PROFILE , 'should export DEFAULT_PROFILE')
t.truthy(Config.DEFAULT_HEAD , 'should export DEFAULT_HEAD')
t.truthy(Config.DEFAULT_PUPPET_PORT , 'should export DEFAULT_PUPPET_PORT')
t.truthy(Config.DEFAULT_PROTOCOL , 'should export DEFAULT_PROTOCOL')
t.truthy(Config.ENDPOINT , 'should export ENDPOINT')
t.truthy(Config.BINARY_CHROMIUM , 'should export BINARY_CHROMIUM')
})
......@@ -15,14 +15,15 @@ const co = require('co')
const log = require('./npmlog-env')
const Contact = require('./contact')
const Config = require('./config')
class Io {
constructor({
wechaty = null
, token = null
, endpoint = 'wss://api.wechaty.io/v0/websocket'
, protocol = 'io|0.0.1'
, endpoint = Config.endpoint
, protocol = Config.DEFAULT_PROTOCOL
}) {
if (!wechaty || !token) {
throw new Error('Io must has wechaty & token set')
......
......@@ -22,12 +22,12 @@ const Config = require('./config')
class Wechaty extends EventEmitter {
constructor({
type = process.env.WECHATY_PUPPET || Config.DEFAULT_PUPPET
, head = process.env.WECHATY_HEAD || Config.DEFAULT_HEAD
, port = process.env.WECHATY_PORT || 0 // 0 for disable port
, endpoint = process.env.WECHATY_ENDPOINT // wechaty.io api endpoint
, token = process.env.WECHATY_TOKEN // token for wechaty.io auth
, profile = process.env.WECHATY_PROFILE // no profile, no session save/restore
type = Config.puppet
, head = Config.head
, port = Config.port
, endpoint = Config.endpoint
, token = Config.token // token for wechaty.io auth. will connect to wechaty.io cloud management if token is set
, profile = Config.profile // no profile, no session save/restore
} = {}) {
log.verbose('Wechaty', 'contructor()')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册