wmlocaldevice 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +18 -0
- package/index.mjs +47 -0
- package/package.json +19 -0
- package/publish.ps1 +1 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
// 使用 IntelliSense 了解相关属性。
|
|
3
|
+
// 悬停以查看现有属性的描述。
|
|
4
|
+
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
"type": "node",
|
|
10
|
+
"request": "launch",
|
|
11
|
+
"name": "启动程序",
|
|
12
|
+
"skipFiles": [
|
|
13
|
+
"<node_internals>/**"
|
|
14
|
+
],
|
|
15
|
+
"program": "${workspaceFolder}\\index.mjs"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/index.mjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import axios from 'axios'
|
|
3
|
+
import os from 'os'
|
|
4
|
+
import { FileUtil, Util } from 'weimingcommons'
|
|
5
|
+
function getIpAddress() {
|
|
6
|
+
let ret = []
|
|
7
|
+
let ifaces = os.networkInterfaces()
|
|
8
|
+
for (let dev in ifaces) {
|
|
9
|
+
let iface = ifaces[dev]
|
|
10
|
+
for (let i = 0; i < iface.length; i++) {
|
|
11
|
+
let { family, address, internal } = iface[i]
|
|
12
|
+
if (family === 'IPv4' && address !== '127.0.0.1' && !internal) {
|
|
13
|
+
ret.push(iface[i])
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return ret
|
|
18
|
+
}
|
|
19
|
+
function getGitEmail() {
|
|
20
|
+
let gitConfig = FileUtil.GetFileString(`${os.homedir()}/.gitconfig`)
|
|
21
|
+
if (gitConfig == null) return ""
|
|
22
|
+
for (let line of gitConfig.split("\n")) {
|
|
23
|
+
let content = line.trim()
|
|
24
|
+
if (content.startsWith("email")) {
|
|
25
|
+
return content.substring(content.indexOf("=") + 1).trim()
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return ""
|
|
29
|
+
}
|
|
30
|
+
async function main() {
|
|
31
|
+
while (true) {
|
|
32
|
+
try {
|
|
33
|
+
let info = {}
|
|
34
|
+
info.gitEmail = getGitEmail()
|
|
35
|
+
info.hostname = os.hostname()
|
|
36
|
+
info.ip = getIpAddress()
|
|
37
|
+
await axios.post("http://da2.diandian.info:5100/execute", {
|
|
38
|
+
code: "SetStorage",
|
|
39
|
+
data : { type : "device", name: os.hostname(), value: JSON.stringify(info) }
|
|
40
|
+
})
|
|
41
|
+
} catch {
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
await Util.sleep(60000 * 5)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
main()
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wmlocaldevice",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "index.mjs",
|
|
9
|
+
"bin": {
|
|
10
|
+
"wmlocaldevice": "./index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"axios": "^1.13.2",
|
|
17
|
+
"weimingcommons": "^0.0.52"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/publish.ps1
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npm publish --registry https://registry.npmjs.org
|