-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-composer-json.js
41 lines (32 loc) · 1.13 KB
/
update-composer-json.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
const https = require('https');
const fs = require('fs');
const args = process.argv.slice(2);
if (args.length !== 1) {
console.log('One argument expected (git tag).');
process.exit(1);
}
const tag = args[0];
const localJson = JSON.parse(fs.readFileSync('./composer.json'));
https.get(`https://raw.githubusercontent.com/dbrekelmans/browser-driver-installer/${tag}/composer.json`, (response) => {
let data = '';
response.on('data', (chunk) => {
data += chunk;
});
response.on('end', () => {
const remoteJson = JSON.parse(data);
// Replace license
localJson.license = remoteJson.license;
// Extract 'php' and 'ext-' from require
let localRequire = {};
Object.entries(remoteJson.require).forEach(([key, value]) => {
if (key === 'php' || key.startsWith('ext-')) {
localRequire[key] = value;
}
})
localJson.require = localRequire;
fs.writeFileSync('./composer.json', JSON.stringify(localJson, null, 4));
});
}).on('error', (error) => {
console.log(`Error: ${error.message}`);
process.exit(1);
});