Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
817478e0
W
wechaty
项目概览
.Veneno.
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
817478e0
编写于
4月 28, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add semver checker for puppet plugins
上级
721ef628
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
41 addition
and
18 deletion
+41
-18
src/wechaty.ts
src/wechaty.ts
+41
-18
未找到文件。
src/wechaty.ts
浏览文件 @
817478e0
...
...
@@ -19,6 +19,7 @@
*/
import
*
as
cuid
from
'
cuid
'
import
*
as
os
from
'
os
'
import
*
as
semver
from
'
semver
'
import
{
cloneClass
,
...
...
@@ -65,10 +66,10 @@ export const WECHAT_EVENT_DICT = {
export
const
WECHATY_EVENT_DICT
=
{
...
WECHAT_EVENT_DICT
,
error
:
'
tbw
'
,
heartbeat
:
'
tbw
'
,
start
:
'
tbw
'
,
stop
:
'
tbw
'
,
error
:
'
tbw
'
,
heartbeat
:
'
tbw
'
,
start
:
'
tbw
'
,
stop
:
'
tbw
'
,
}
export
type
WechatEventName
=
keyof
typeof
WECHAT_EVENT_DICT
...
...
@@ -76,7 +77,7 @@ export type WechatyEventName = keyof typeof WECHATY_EVENT_DICT
export
interface
WechatyOptions
{
puppet
?:
PuppetName
|
Puppet
,
profile
?:
string
,
profile
?:
string
|
null
,
}
/**
...
...
@@ -91,10 +92,10 @@ export interface WechatyOptions {
*/
export
class
Wechaty
extends
PuppetAccessory
implements
Sayable
{
/**
* singleton
_i
nstance
* singleton
globalI
nstance
* @private
*/
private
static
_i
nstance
:
Wechaty
private
static
globalI
nstance
:
Wechaty
private
profile
:
Profile
...
...
@@ -134,13 +135,13 @@ export class Wechaty extends PuppetAccessory implements Sayable {
public
static
instance
(
options
?:
WechatyOptions
,
)
{
if
(
options
&&
this
.
_i
nstance
)
{
if
(
options
&&
this
.
globalI
nstance
)
{
throw
new
Error
(
'
there has already a instance. no params will be allowed any more
'
)
}
if
(
!
this
.
_i
nstance
)
{
this
.
_i
nstance
=
new
Wechaty
(
options
)
if
(
!
this
.
globalI
nstance
)
{
this
.
globalI
nstance
=
new
Wechaty
(
options
)
}
return
this
.
_i
nstance
return
this
.
globalI
nstance
}
/**
...
...
@@ -154,7 +155,11 @@ export class Wechaty extends PuppetAccessory implements Sayable {
options
.
puppet
=
options
.
puppet
||
config
.
puppet
this
.
profile
=
new
Profile
(
options
.
profile
)
const
name
=
options
.
profile
===
null
?
null
:
options
.
profile
||
config
.
default
.
DEFAULT_PROFILE
this
.
profile
=
new
Profile
(
name
)
this
.
cuid
=
cuid
()
}
...
...
@@ -187,7 +192,7 @@ export class Wechaty extends PuppetAccessory implements Sayable {
* console.log(Wechaty.instance().version()) // return '#git[af39df]'
* console.log(Wechaty.instance().version(true)) // return '0.7.9'
*/
public
version
(
forceNpm
?)
{
public
version
(
forceNpm
=
false
):
string
{
return
Wechaty
.
version
(
forceNpm
)
}
...
...
@@ -362,6 +367,9 @@ export class Wechaty extends PuppetAccessory implements Sayable {
log
.
verbose
(
'
Wechaty
'
,
'
initPuppet()
'
)
let
puppet
:
Puppet
/**
* 1. Init the Puppet
*/
if
(
typeof
this
.
options
.
puppet
===
'
string
'
)
{
puppet
=
new
PUPPET_DICT
[
this
.
options
.
puppet
]({
profile
:
this
.
profile
,
...
...
@@ -373,6 +381,18 @@ export class Wechaty extends PuppetAccessory implements Sayable {
throw
new
Error
(
'
unsupported options.puppet!
'
)
}
/**
* 2. Plugin Version Range Check
*/
if
(
!
semver
.
satisfies
(
this
.
version
(
true
),
puppet
.
wechatyVersionRange
(),
))
{
throw
new
Error
(
`The Puppet Plugin(
${
puppet
.
constructor
.
name
}
) `
+
`requires a version range(
${
puppet
.
wechatyVersionRange
()}
) `
+
`that is not satisfying the Wechaty version:
${
this
.
version
()}
.`
)
}
for
(
const
event
of
Object
.
keys
(
WECHATY_EVENT_DICT
))
{
log
.
verbose
(
'
Wechaty
'
,
'
initPuppet() puppet.on(%s) registered
'
,
event
)
/// e as any ??? Maybe this is a bug of TypeScript v2.5.3
...
...
@@ -390,11 +410,14 @@ export class Wechaty extends PuppetAccessory implements Sayable {
* See: fix the breaking changes for #518
* https://github.com/Chatie/wechaty/issues/518
*/
if
(
this
===
Wechaty
.
_i
nstance
)
{
if
(
this
===
Wechaty
.
globalI
nstance
)
{
Contact
.
puppet
=
puppet
FriendRequest
.
puppet
=
puppet
Message
.
puppet
=
puppet
Room
.
puppet
=
puppet
;
// seperator
(
this
.
constructor
as
any
as
PuppetAccessory
).
puppet
=
puppet
}
/**
...
...
@@ -405,10 +428,10 @@ export class Wechaty extends PuppetAccessory implements Sayable {
* https://github.com/Microsoft/TypeScript/issues/5843#issuecomment-290972055
* https://github.com/Microsoft/TypeScript/issues/19197
*/
this
.
Contact
=
cloneClass
(
puppet
.
Contact
as
any
)
this
.
FriendRequest
=
cloneClass
(
puppet
.
FriendRequest
as
any
)
this
.
Message
=
cloneClass
(
puppet
.
Message
as
any
)
this
.
Room
=
cloneClass
(
puppet
.
Room
as
any
)
this
.
Contact
=
cloneClass
(
puppet
.
classes
.
Contact
)
this
.
FriendRequest
=
cloneClass
(
puppet
.
classes
.
FriendRequest
)
this
.
Message
=
cloneClass
(
puppet
.
classes
.
Message
)
this
.
Room
=
cloneClass
(
puppet
.
classes
.
Room
)
this
.
Contact
.
puppet
=
puppet
this
.
FriendRequest
.
puppet
=
puppet
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录