doctor.ts 1.6 KB
Newer Older
1
#!/usr/bin/env node
2
/**
3
 *   Wechaty - https://github.com/wechaty/wechaty
4
 *
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
5
 *   @copyright 2016-2018 Huan LI <zixia@zixia.net>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
6 7 8 9 10 11 12 13 14 15 16 17
 *
 *   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.
18 19
 *
 */
20

21
import os from 'os'
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
22

23 24 25
import { config }   from '../src/config'
import { Doctor }   from '../src/doctor'
import { Wechaty }  from '../src/wechaty'
26

27
const wechaty = Wechaty.instance()
28 29
const doctor = new Doctor()

30
async function main () {
31 32 33 34 35
  let ipcTestResult: string
  try {
    await doctor.testTcp()
    ipcTestResult = 'PASS'
  } catch (err) {
36
    console.info(err)
37 38 39
    ipcTestResult = 'FAIL. Please check your tcp network, Wechaty need to listen on localhost and connect to it.'
  }

40
  console.info(`
41 42 43 44
  #### Wechaty Doctor

  1. Wechaty version: ${wechaty.version()}
  2. ${os.type()} ${os.arch()} version ${os.release()} memory ${Math.floor(os.freemem() / 1024 / 1024)}/${Math.floor(os.totalmem() / 1024 / 1024)} MB
45
  3. Docker: ${config.docker}
46 47
  4. Node version: ${process.version}
  5. Tcp IPC TEST: ${ipcTestResult}
48

49
  `)
50

51
}
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
52

53
main()
54
  .catch(err => console.error('main() exception: %s', err))