forked from mensatt/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prebuild.js
37 lines (30 loc) · 1.33 KB
/
prebuild.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
// we'll package up all build time info into the /assets/version.json file
const fs = require('fs')
const revision = require('child_process')
.execSync('git rev-parse HEAD')
.toString().trim()
const commitTime = require('child_process')
.execSync('git log -1 --format="%at" | xargs -I{} date -d @{} +%d.%m.%Y_%H:%M:%S')
.toString().trim().split('_').join(' ')
const commitMessage = require('child_process')
.execSync('git log -1 --pretty=%B')
.toString().trim()
const commitAuthor = require('child_process')
.execSync('git log -1 --pretty=format:\'%ae\'')
.toString().trim()
const data = {
'_': 'DO NOT CHANGE THIS FILE MANUALLY. THIS FILE WILL GET FILLED IN AT BUILD/DEPLOY TIME. LEAVE ALL FIELDS AT <unknown> SO WE CAN SEE IF FIELDS DID NOT GET POPULATED DURING DEPLOYMENT.',
version: process.env.npm_package_version,
revision,
commitTime,
commitMessage,
commitAuthor,
buildTime: new Date().toLocaleString('de').replace(',', ''),
buildId: process.env.BUILD_ID ?? '<unknown>',
buildContext: process.env.CONTEXT ?? '<unknown>',
buildNodeVersion: process.env.NODE_VERSION ?? '<unknown>',
buildYarnVersion: process.env.YARN_VERSION ?? '<unknown>',
deployId: process.env.DEPLOY_ID ?? '<unknown>',
deployUrl: process.env.DEPLOY_URL ?? '<unknown>'
}
fs.writeFileSync('./assets/version.json', JSON.stringify(data, null, 2))