-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.js
37 lines (30 loc) · 1.02 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
const { execSync } = require('child_process');
const fs = require('fs');
const Handlebars = require('handlebars');
function downloadFile(url, filename) {
execSync(`curl ${url} -o ${filename} -s`);
}
const version = process.argv[2];
const config = JSON.parse(fs.readFileSync(`./${version}/update.json`).toString());
const {
path,
files,
lines: {
start,
end,
}
} = config;
const baseUrl = 'https://raw.githubusercontent.com/docker-library/php'
files.forEach(file => {
downloadFile(`${baseUrl}/${path}/${file}`, `${version}/${file}`)
});
const template = Handlebars.compile(fs.readFileSync(`./${version}/Dockerfile.hbs`).toString(), { noEscape: true });
const lines = fs.readFileSync(`./${version}/Dockerfile`).toString().split('\n');
const content = lines.slice(start, end).join('\n');
const result = template({ content });
fs.writeFileSync(`./${version}/Dockerfile`, result);
fs.readdirSync(version).forEach(file => {
if (file.startsWith('docker-php-')) {
execSync(`git add --chmod=+x ${version}/${file}`);
}
});