-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnpm.js
31 lines (26 loc) · 1 KB
/
snpm.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
const fetch = require('node-fetch'),
fs = require('fs'),
path = require('path'),
util = require('util'),
io = require('socket.io-client'),
readFileAsync = util.promisify(fs.readFile),
REGISTRY_API = process.env.REGISTRY_URL || 'http://localhost',
REGISTRY_PORT = parseInt(process.env.REGISTRY_PORT) || parseInt(3000),
socket = io.connect(`${REGISTRY_API}:${REGISTRY_PORT}`)
socket.on('connect', async () => {
socket.on('error', err => console.error(err))
socket.on('message', message => console.log(`registry > ${message}`))
const pkgJsonPath = path.resolve(process.argv[2], 'package.json')
let pkg
try {
console.log('snpm > Reading project package.json...')
const raw = await readFileAsync(pkgJsonPath)
pkg = JSON.parse(raw)
} catch (err) {
console.log(`snpm > Cannot read package.json from ${pkgJsonPath}`)
console.error(err)
process.exit(1)
}
console.log('snpm > Publishing package...')
socket.emit('publish', {url: pkg.repository.url, version: pkg.version})
})