forked from Netflix-Skunkworks/stethoscope-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-download-page.js
29 lines (24 loc) · 930 Bytes
/
update-download-page.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
const { readFileSync, writeFileSync } = require('fs')
const pkg = require('./package.json')
const moment = require('moment')
const { build: { publish = [{ url: 'https://test/url/' }] } } = pkg
const [{ url }] = publish
const rev = readFileSync('.git/HEAD').toString()
let revision = rev.trim()
if (rev.includes(':')) {
const [ , pth ] = rev.split(': ')
revision = readFileSync(`.git/${pth.trim()}`)
}
const template = readFileSync('./public/download.html', 'utf8')
const replacements = {
MAC_LINK: `${url}Stethoscope-${pkg.version}.dmg`,
WIN_LINK: `${url}Stethoscope%20Setup%20${pkg.version}.exe`,
VERSION: pkg.version,
BUILD_DATE: moment().format('MMMM Do YYYY'),
REVISION: String(revision).substr(0, 7),
REPO: pkg.repository.url
}
const content = Object.entries(replacements).reduce((file, [key, val]) => {
return file.replace(`{${key}}`, val)
}, template)
writeFileSync('./build/download.html', content)