diff --git a/.gitignore b/.gitignore index d7ed71db50cbc0584c04fd4e9b108288e274ec51..bbd97061a3bbc9f8dfbb73a18f3e8f6ddf0eba02 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,4 @@ t/ t.* .DS_Store /dev.js +/dist/ diff --git a/src/io-client.ts b/src/io-client.ts index e546b7f110bd8323be7f09ae28823f30b530de04..b14805ceb7a36d100adf1074d42acc612d7dfdeb 100644 --- a/src/io-client.ts +++ b/src/io-client.ts @@ -80,7 +80,7 @@ class IoClient { this.targetState('connected') this.currentState('connecting') - this.wechaty = new Wechaty({ + this.wechaty = Wechaty.instance({ profile: Config.DEFAULT_PROFILE }) @@ -165,7 +165,7 @@ class IoClient { res.send('Wechaty IO Bot Alive!') }) - return new Promise((resolve, reject) => { + return new Promise((resolve) => { app.listen(port, () => { this.log.verbose('IoClient', 'initWeb() Wechaty IO Bot listening on port ' + port + '!') diff --git a/src/puppet.ts b/src/puppet.ts index 5f9859fc42a38d9a0ea7765bc9eb68c75b3b9ee2..d42c1fa49c9825a01a39eb9ea6a8c6314e1db395 100644 --- a/src/puppet.ts +++ b/src/puppet.ts @@ -17,9 +17,9 @@ import Message from './message' import Room from './room' import log from './brolog-env' -type ContactGetterFunc = { - (id: string): Promise -} +// type ContactGetterFunc = { +// (id: string): Promise +// } abstract class Puppet extends EventEmitter { public user: Contact diff --git a/src/wechaty.ts b/src/wechaty.ts index 4e4eedd458b30d3d5205eb0b37dbe880f5052652..9712c540730259de8dbe578daaa0ba8980b789b8 100644 --- a/src/wechaty.ts +++ b/src/wechaty.ts @@ -44,6 +44,16 @@ class Wechaty extends EventEmitter { public uuid: string + public static instance(setting?: WechatySetting) { + if (setting && this._instance) { + throw new Error('there has already a instance. no params allowed any more') + } + if (!this._instance) { + this._instance = new Wechaty(setting) + } + return this._instance + } + private constructor(private setting: WechatySetting) { super() log.verbose('Wechaty', 'contructor()') @@ -72,13 +82,6 @@ class Wechaty extends EventEmitter { // Wechaty._instance = this } - public static instance(setting: WechatySetting) { - if (!this._instance) { - this._instance = new Wechaty(setting) - } - return this._instance - } - public toString() { return 'Class Wechaty(' + this.setting.type + ')'} public version(forceNpm = false) { diff --git a/tsconfig.json b/tsconfig.json index b83b6a8061bd75ee37b5002f6c2a91114f76c092..2f67c145fd230b8e82f4b7f4e25387a308b340ec 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,20 +1,30 @@ { "compilerOptions": { "target": "es6" + , "module": "amd" , "moduleResolution": "node" , "outDir": "dist" - , "noImplicitAny": false - , "strictNullChecks": true + , "outFile": "dist/wechaty.lib.js" + , "sourceMap": true + , "noUnusedLocals": true + + , "noUnusedParameters": false + , "strictNullChecks": false + , "noImplicitAny": false + , "noImplicitThis": false + , "noImplicitReturns": false + , "noFallthroughCasesInSwitch": false } , "exclude": [ "node_modules" , "dist" + , "**/*.spec.ts" ] - , "files": [ - "src/*.ts" - , "bin/*.ts" - , "example/*.ts" + , "include": [ + "src/**/*.ts" + // , "bin/*.ts" + // , "example/*.ts" // , "test/*.ts" ] }