forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.js
More file actions
30 lines (24 loc) · 741 Bytes
/
version.js
File metadata and controls
30 lines (24 loc) · 741 Bytes
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
import preval from 'babel-plugin-preval/macro';
// This is .js for preval
const versionType = preval`module.exports = (() => {
if (process.env.NODE_ENV === 'development') {
return 'DEV';
}
if (process.env.STAGING_BRANCH) {
return 'PR';
}
return 'PROD';
})()`;
const versionNumber = Math.floor(preval`module.exports = Date.now();` / 1000);
const shortCommitSha = preval(`
var execSync = require('child_process').execSync;
try {
module.exports = execSync('git rev-parse --short HEAD').toString().trim();
} catch (e) {
module.exports = 'unknown';
}
`);
export const getTimestamp = version => +version.split('-')[1];
export default preval(
`module.exports = "${versionType}-${versionNumber}-${shortCommitSha}";`
);