Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
511e77ea
W
wechaty
项目概览
wechaty
/
wechaty
上一次同步 大约 3 年
通知
304
Star
10499
Fork
6
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
152
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
152
Issue
152
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
511e77ea
编写于
9月 15, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean puppet manager code
上级
b0e0e808
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
91 addition
and
27 deletion
+91
-27
src/puppet-config.ts
src/puppet-config.ts
+3
-2
src/puppet-manager.spec.ts
src/puppet-manager.spec.ts
+49
-0
src/puppet-manager.ts
src/puppet-manager.ts
+38
-24
src/wechaty.ts
src/wechaty.ts
+1
-1
未找到文件。
src/puppet-config.ts
浏览文件 @
511e77ea
...
...
@@ -3,6 +3,7 @@
*/
export
const
PUPPET_DEPENDENCIES
=
{
'
default
'
:
'
0.0.0
'
,
// will be replaced with PUPPET_DEFAULT
'
mock
'
:
'
0.0.0
'
,
// compatible with v0.18, will be replaced with wechaty-puppet-padchat
'
padchat
'
:
'
0.0.0
'
,
// compatible with v0.18, will be replaced with wechaty-puppet-padchat
/////////////////////////////////////
// 'wechaty-puppet-hostie' : '^0.0.1',
...
...
@@ -13,6 +14,6 @@ export const PUPPET_DEPENDENCIES = {
'
wechaty-puppet-wechat4u
'
:
'
^0.14.1
'
,
}
export
const
PUPPET_DEFAULT
=
'
wechaty-puppet-puppeteer
'
export
type
PuppetModuleName
=
keyof
typeof
PUPPET_DEPENDENCIES
export
const
PUPPET_NAME_DEFAULT
:
PuppetModuleName
=
'
wechaty-puppet-puppeteer
'
src/puppet-manager.spec.ts
0 → 100755
浏览文件 @
511e77ea
#!/usr/bin/env ts-node
/**
* Wechaty - https://github.com/chatie/wechaty
*
* @copyright 2016-2018 Huan LI <zixia@zixia.net>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// tslint:disable:no-shadowed-variable
import
test
from
'
blue-tape
'
import
{
PuppetManager
,
}
from
'
./puppet-manager
'
test
(
'
resolve an unsupported puppet name
'
,
async
t
=>
{
try
{
await
PuppetManager
.
resolve
(
'
fasdfsfasfsfdfs
'
as
any
)
t
.
fail
(
'
should reject
'
)
}
catch
(
e
)
{
t
.
ok
(
'
reject when options is a string
'
)
}
try
{
await
PuppetManager
.
resolve
({
puppet
:
'
fadfdsafa
'
as
any
})
t
.
fail
(
'
should reject
'
)
}
catch
(
e
)
{
t
.
ok
(
'
reject when options.puppet is unknown
'
)
}
try
{
await
PuppetManager
.
resolve
({
puppet
:
'
mock
'
})
t
.
pass
(
'
should allow "mock" as puppet name
'
)
}
catch
(
e
)
{
t
.
fail
(
'
should pass "mock" as puppet name
'
)
}
})
src/puppet-manager.ts
浏览文件 @
511e77ea
...
...
@@ -15,16 +15,16 @@ import {
log
,
}
from
'
./config
'
import
{
PUPPET_DEFAULT
,
PUPPET_DEPENDENCIES
,
PUPPET_NAME_DEFAULT
,
PuppetModuleName
,
}
from
'
./puppet-config
'
import
{
Wechaty
,
//
Wechaty,
}
from
'
./wechaty
'
export
interface
ResolveOptions
{
wechaty
:
Wechaty
,
//
wechaty : Wechaty,
puppet
:
Puppet
|
PuppetModuleName
,
puppetOptions
?
:
PuppetOptions
,
}
...
...
@@ -35,19 +35,11 @@ export class PuppetManager {
options
:
ResolveOptions
):
Promise
<
Puppet
>
{
log
.
verbose
(
'
PuppetManager
'
,
'
resolve({wechaty: %s, puppet: %s, puppetOptions: %s})
'
,
options
.
wechaty
,
//
options.wechaty,
options
.
puppet
,
JSON
.
stringify
(
options
.
puppetOptions
),
)
if
(
!
options
.
puppet
||
options
.
puppet
===
'
default
'
)
{
options
.
puppet
=
PUPPET_DEFAULT
}
else
if
(
options
.
puppet
===
'
padchat
'
)
{
// issue #1496 https://github.com/Chatie/wechaty/issues/1496
// compatible old settings for padchat
options
.
puppet
=
'
wechaty-puppet-padchat
'
}
let
puppetInstance
:
Puppet
if
(
options
.
puppet
instanceof
Puppet
)
{
...
...
@@ -74,6 +66,40 @@ export class PuppetManager {
protected
static
async
resolveName
(
puppetName
:
PuppetModuleName
):
Promise
<
PuppetImplementation
>
{
log
.
verbose
(
'
PuppetManager
'
,
'
resolveName(%s)
'
,
puppetName
)
if
(
!
puppetName
)
{
throw
new
Error
(
'
must provide a puppet name
'
)
}
switch
(
puppetName
)
{
case
'
padchat
'
:
// issue #1496 https://github.com/Chatie/wechaty/issues/1496
// compatible old settings for padchat
puppetName
=
'
wechaty-puppet-padchat
'
break
case
'
mock
'
:
puppetName
=
'
wechaty-puppet-mock
'
break
case
'
default
'
:
puppetName
=
PUPPET_NAME_DEFAULT
break
default
:
if
(
!
(
puppetName
in
PUPPET_DEPENDENCIES
))
{
throw
new
Error
(
[
''
,
'
puppet npm module not supported: "
'
+
puppetName
+
'
"
'
,
'
learn more about supported Wechaty Puppet from our directory at
'
,
'
<https://github.com/Chatie/wechaty-puppet/wiki/Directory>
'
,
''
,
].
join
(
'
\n
'
)
)
}
break
}
await
this
.
checkModule
(
puppetName
)
const
puppetModule
=
await
import
(
puppetName
)
...
...
@@ -85,18 +111,6 @@ export class PuppetManager {
protected
static
async
checkModule
(
puppetName
:
PuppetModuleName
):
Promise
<
void
>
{
log
.
verbose
(
'
PuppetManager
'
,
'
checkModule(%s)
'
,
puppetName
)
if
(
!
(
puppetName
in
PUPPET_DEPENDENCIES
))
{
throw
new
Error
(
[
''
,
'
puppet npm module not supported: "
'
+
puppetName
+
'
"
'
,
'
learn more about supported Wechaty Puppet from our directory at
'
,
'
<https://github.com/Chatie/wechaty-puppet/wiki/Directory>
'
,
''
,
].
join
(
'
\n
'
)
)
}
const
versionRange
=
PUPPET_DEPENDENCIES
[
puppetName
]
/**
...
...
src/wechaty.ts
浏览文件 @
511e77ea
...
...
@@ -569,7 +569,7 @@ export class Wechaty extends Accessory implements Sayable {
const
puppetInstance
=
await
PuppetManager
.
resolve
({
puppet
,
puppetOptions
:
this
.
options
.
puppetOptions
,
wechaty
:
this
,
//
wechaty : this,
})
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录