-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.js
executable file
·84 lines (72 loc) · 2.78 KB
/
update.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
const execa = require('execa');
const getStream = require('get-stream');
const fetch = require('node-fetch');
const appConfig = require('./apps.json');
const {lookupServiceUrl} = require('./utils');
async function update() {
try {
const npmCommand = {name: "npm", args: ['i', '--save', 'openfin-__SERVICE__@alpha']};
const gitCommand = {name: "git", args: ['ls-remote', '/~https://github.com/HadoukenIO/__SERVICE__-service.git']};
for (let i in appConfig.services ) {
const service = appConfig.services[i];
// fill out command arg template strings
const npmargs = Object.assign([], npmCommand.args);
npmargs[npmargs.length-1] = npmargs[npmargs.length-1].replace('__SERVICE__', service.name);
const gitargs = Object.assign([], gitCommand.args);
gitargs[gitargs.length-1] = gitargs[gitargs.length-1].replace('__SERVICE__', service.name);
// run the commands and process the output
const npmOut = execa(npmCommand.name, npmargs).stdout;
const npmStream = await getStream(npmOut);
const npmMsg = processNPMOutput(npmStream.split('\n'));
const gitOut = execa(gitCommand.name, gitargs).stdout;
const gitStream = await getStream(gitOut);
const gitMsg = getDevelopSha(gitStream.split('\n'));
// find service's manifest url and then get the startup_app.url
const serviceUrl = service.manifestUrl;
if (!serviceUrl) {
serviceUrl = await lookupServiceUrl(service.name);
}
let appURL = '??';
if (serviceUrl.length >0) {
appURL = await getServiceAppUrl(serviceUrl);
}
// a nice message to the user
console.log(`\nService: ${service.name}`);
console.log(` prerelease: ${npmMsg}`);
console.log(` github sha: ${gitMsg}`);
console.log(` service url: ${serviceUrl}`);
console.log(` app url: ${appURL}\n\n`);
}
} catch(e) {
console.error(e);
}
}
async function getServiceAppUrl(serviceUrl) {
try {
const res = await fetch(serviceUrl);
const json = await res.json();
if (json && json.startup_app) {
return json.startup_app.url;
}
} catch(e) {
console.error(e);
}
return '??';
}
function getDevelopSha(lines) {
// extract sha from output
let sha = '';
for (let j=0; j<lines.length; j++) {
const ref = lines[j];
if (ref.indexOf('refs/heads/develop') > -1) {
sha = ref.split('\t')[0];
break;
}
}
return sha;
}
function processNPMOutput(lines) {
return lines[0].replace('+ ', '');
}
update();