-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·41 lines (33 loc) · 1 KB
/
index.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
#!/usr/bin/env node
const cp = require('child_process');
const http = require('http');
const https = require('https');
const path = require('path');
const { URL } = require('url');
const packagejson = require(path.join(process.cwd(), 'package.json'));
const { hostname, port, protocol, pathname } = new URL(process.argv[2]);
const package = {
name: `${packagejson.name}@${packagejson.version}`
};
const message = {
"text": `> \`${package.name}\` has been published!`
};
cp.exec(`npm info ${package.name}`, (err, stdout) => {
if (stdout.length) {
const req = (protocol.match('https') ? https : http).request({
hostname,
path: pathname,
port,
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
}, (res) => {
res.on('data', (data) => {
process.stdout.write(data);
});
});
req.write(JSON.stringify(message));
req.end();
}
});