-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscflog-logs.js
executable file
·54 lines (49 loc) · 1.75 KB
/
scflog-logs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
const program = require('commander')
const WebSocketClient = require('websocket').client;
const path = require('path')
const fs = require('fs')
const os = require('os')
program
.option('-f, --funtion [funtion]', '函数名称')
.option('-r, --region [region]', '常用函数的区域(非必选,默认ap-guangzhou)')
.option('-n, --namespace [namespace]', '常用函数的命名空间(非必选,默认default)')
.parse(process.argv);
if(program.funtion){
const configurePath = path.join(os.homedir(), ".scf_python_logs")
let configureData
if (fs.existsSync(configurePath)) {
try {
configureData = JSON.parse(fs.readFileSync(configurePath, 'utf-8'))
const url = `${configureData.websocket}?name=${program.funtion}&namespace=${program.namespace || configureData.namespace}®ion=${program.region || configureData.region}`
console.log(url)
const client = new WebSocketClient()
client.on('connectFailed', function(error) {
throw new Error("链接失败: " + error.toString());
});
client.on('connect', function(connection) {
console.log('链接成功');
connection.on('error', function(error) {
console.log("连击错误: " + error.toString());
});
connection.on('close', function() {
console.log('关闭链接');
});
connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log(message.utf8Data + "'");
}
})
});
client.connect(url, 'echo-protocol');
} catch (e) {
console.log(e)
console.log("配置文件异常,请使用scflog configure指令重新进行配置")
}
}
if (!configureData) {
console.log("未找到配置文件,请使用scflog configure指令进行配置")
}
}else{
console.log("name字段必须填写")
}