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

merge

......@@ -55,11 +55,7 @@ WORKDIR /wechaty
COPY package.json .
RUN npm install \
&& npm install \
wechaty-puppet-ioscat \
wechaty-puppet-puppeteer \
wechaty-puppet-padchat \
wechaty-puppet-wechat4u \
&& npm run puppet-install \
&& sudo rm -fr /tmp/* ~/.npm
COPY . .
......
......@@ -57,7 +57,7 @@ log.info('Client', 'Starting for WECHATY_TOKEN: %s', token)
const client = new IoClient({
token,
wechaty: new Wechaty({ profile: token }),
wechaty: new Wechaty({ name: token }),
})
client.start()
......
#!/usr/bin/env ts-node
import { PuppetManager } from '../src/puppet-manager'
PuppetManager.installAll()
.catch(console.error)
......@@ -32,7 +32,7 @@ import { generate } from 'qrcode-terminal'
*
*/
const bot = new Wechaty({
profile : config.default.DEFAULT_PROFILE,
name : config.default.DEFAULT_PROFILE,
})
/**
......
{
"name": "wechaty",
"version": "0.19.130",
"version": "0.19.132",
"description": "Wechaty is a Bot SDK for Wechat Personal Account",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
......@@ -25,6 +25,7 @@
"lint:md": "markdownlint README.md",
"lint:ts": "tslint --project tsconfig.json && tsc --noEmit",
"lint:sh": "bash -n bin/*.sh",
"puppet-install": "ts-node bin/puppet-install.ts",
"sloc": "sloc bin examples scripts src tests --details --format cli-table --keys total,source,comment && sloc bin examples scripts src tests",
"ts-node": "ts-node",
"test": "npm run lint && npm run test:unit && npm run test:shell && npm run sloc",
......@@ -43,8 +44,9 @@
"url": "git+https://github.com/chatie/wechaty.git"
},
"bin": {
"wechaty-io-client": "dist/bin/io-client.js",
"wechaty-doctor": "dist/bin/doctor.js",
"wechaty-io-client": "dist/bin/io-client.js",
"wechaty-puppet-install": "dist/bin/puppet-install.js",
"wechaty-version": "dist/bin/version.js"
},
"keywords": [
......@@ -90,6 +92,10 @@
"state-switch": "^0.6.2",
"watchdog": "^0.8.1",
"wechaty-puppet": "^0.11.3",
"wechaty-puppet-ioscat": "^0.4.18",
"wechaty-puppet-padchat": "^0.9.16",
"wechaty-puppet-puppeteer": "^0.8.10",
"wechaty-puppet-wechat4u": "^0.8.5",
"ws": "^6.0.0"
},
"devDependencies": {
......@@ -140,7 +146,7 @@
"tuling123-client": "^0.0.2",
"typedoc": "^0.11.1",
"typescript": "^3.1.0-dev.20180731",
"wechaty-puppet-mock": "^0.8.1"
"wechaty-puppet-mock": "^0.8.6"
},
"files_comment__whitelist_npm_publish": "http://stackoverflow.com/a/8617868/1123955",
"files": [
......
......@@ -33,7 +33,7 @@ import {
} from 'file-box'
import {
PuppetName,
PuppetModuleName,
} from './puppet-config'
// https://github.com/Microsoft/TypeScript/issues/14151#issuecomment-280812617
......@@ -119,10 +119,10 @@ export class Config {
public apihost = process.env.WECHATY_APIHOST || DEFAULT_SETTING.DEFAULT_APIHOST
public head = ('WECHATY_HEAD' in process.env) ? (!!process.env.WECHATY_HEAD) : (!!(DEFAULT_SETTING.DEFAULT_HEAD))
public systemPuppetName (): PuppetName {
public systemPuppetName (): PuppetModuleName {
return (
process.env.WECHATY_PUPPET || 'default'
).toLowerCase() as PuppetName
).toLowerCase() as PuppetModuleName
}
public profile = process.env.WECHATY_PROFILE || null // DO NOT set DEFAULT_PROFILE, because sometimes user do not want to save session
......
......@@ -14,4 +14,4 @@ export const PUPPET_DEPENDENCIES = {
export const PUPPET_DEFAULT = 'wechaty-puppet-puppeteer'
export type PuppetName = keyof typeof PUPPET_DEPENDENCIES
export type PuppetModuleName = keyof typeof PUPPET_DEPENDENCIES
......@@ -17,7 +17,7 @@ import {
import {
PUPPET_DEFAULT,
PUPPET_DEPENDENCIES,
PuppetName,
PuppetModuleName,
} from './puppet-config'
import {
Wechaty,
......@@ -25,7 +25,7 @@ import {
export interface ResolveOptions {
wechaty : Wechaty,
puppet : Puppet | PuppetName,
puppet : Puppet | PuppetModuleName,
puppetOptions? : PuppetOptions,
}
......@@ -71,7 +71,7 @@ export class PuppetManager {
return puppetInstance
}
protected static async resolveName (puppetName: PuppetName): Promise<PuppetImplementation> {
protected static async resolveName (puppetName: PuppetModuleName): Promise<PuppetImplementation> {
log.verbose('PuppetManager', 'resolveName(%s)', puppetName)
await this.checkModule(puppetName)
......@@ -82,7 +82,7 @@ export class PuppetManager {
return MyPuppet
}
protected static async checkModule (puppetName: PuppetName): Promise<void> {
protected static async checkModule (puppetName: PuppetModuleName): Promise<void> {
log.verbose('PuppetManager', 'checkModule(%s)', puppetName)
const versionRange = PUPPET_DEPENDENCIES[puppetName]
......@@ -177,4 +177,23 @@ export class PuppetManager {
log.info('PuppetManager', 'install(%s@%s) done', puppetModule, puppetVersion)
}
public static async installAll (): Promise<void> {
log.info('PuppetManager', 'installAll() please wait ...')
for (const puppetModuleName of Object.keys(PUPPET_DEPENDENCIES)) {
const version = PUPPET_DEPENDENCIES[puppetModuleName as any as PuppetModuleName]
if (version === '0.0.0') {
continue
}
await npm.install(
`${puppetModuleName}@${version}`,
{
cwd : await pkgDir(__dirname),
output : true,
save : false,
},
)
}
}
}
......@@ -68,7 +68,7 @@ import {
Io,
} from './io'
import {
PuppetName,
PuppetModuleName,
} from './puppet-config'
import {
PuppetManager,
......@@ -97,8 +97,9 @@ export type WechatyEventName = keyof typeof WECHATY_EVENT_DICT
export interface WechatyOptions {
memory? : MemoryCard,
profile? : null | string, // Wechaty Name
puppet? : PuppetName | Puppet, // Puppet name or instance
name? : null | string, // Wechaty Name
profile? : null | string, // DEPRECATED: use name instead
puppet? : PuppetModuleName | Puppet, // Puppet name or instance
puppetOptions? : PuppetOptions, // Puppet TOKEN
ioToken? : string, // Io TOKEN
}
......@@ -215,7 +216,7 @@ export class Wechaty extends Accessory implements Sayable {
* If the file is valid, the bot can auto login so you don't need to scan the qrcode to login again. </br>
* Also, you can set the environment variable for `WECHATY_PROFILE` to set this value when you start. </br>
* eg: `WECHATY_PROFILE="your-cute-bot-name" node bot.js`
* @property {PuppetName | Puppet} puppet -Puppet name or instance
* @property {PuppetModuleName | Puppet} puppet -Puppet name or instance
* @property {Partial<PuppetOptions>} puppetOptions -Puppet TOKEN
* @property {string} ioToken -Io TOKEN
*/
......@@ -231,17 +232,22 @@ export class Wechaty extends Accessory implements Sayable {
super()
log.verbose('Wechaty', 'contructor()')
options.profile = options.profile === null
? null
: (options.profile || config.default.DEFAULT_PROFILE)
if (!options.name && options.profile) {
log.verbose('Wechaty', 'constuctor() WechatyOptions.profile DEPRECATED. use WechatyOptions.name instead.')
options.name = options.profile
}
options.name = options.name === null
? null
: (options.name || config.default.DEFAULT_PROFILE)
this.id = cuid()
this.id = cuid()
this.memory = options.memory
? options.memory
: new MemoryCard(
options.profile
? { name: options.profile }
options.name
? { name: options.name }
: undefined,
)
......@@ -331,6 +337,7 @@ export class Wechaty extends Accessory implements Sayable {
* @property {string} heartbeat - Get bot's heartbeat.
* @property {string} friend - When someone sends you a friend request, there will be a Wechaty friend event fired.
* @property {string} message - Emit when there's a new message.
* @property {string} ready - Emit when all data has load completed, in wechaty-puppet-padchat, it means it has sync Contact and Room completed
* @property {string} room-join - Emit when anyone join any room.
* @property {string} room-topic - Get topic event, emitted when someone change room topic.
* @property {string} room-leave - Emit when anyone leave the room.<br>
......@@ -360,6 +367,7 @@ export class Wechaty extends Accessory implements Sayable {
* @property {Function} heartbeat -(this: Wechaty, data: any) => void
* @property {Function} friendship -(this: Wechaty, friendship: Friendship) => void
* @property {Function} message -(this: Wechaty, message: Message) => void
* @property {Function} ready -(this: Wechaty) => void
* @property {Function} room-join -(this: Wechaty, room: Room, inviteeList: Contact[], inviter: Contact) => void
* @property {Function} room-topic -(this: Wechaty, room: Room, newTopic: string, oldTopic: string, changer: Contact) => void
* @property {Function} room-leave -(this: Wechaty, room: Room, leaverList: Contact[]) => void
......@@ -778,7 +786,7 @@ export class Wechaty extends Accessory implements Sayable {
this.version(),
)
log.verbose('Wechaty', 'puppet: %s' , this.options.puppet)
log.verbose('Wechaty', 'profile: %s' , this.options.profile)
log.verbose('Wechaty', 'profile: %s' , this.options.name)
log.verbose('Wechaty', 'id: %s' , this.id)
if (this.state.on()) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册