-
Notifications
You must be signed in to change notification settings - Fork 0
/
prebuild.js
64 lines (52 loc) · 1.67 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
const fs = require('fs');
const deasync = require('deasync');
const {execSync} = require('child_process');
const licenseCrawler = require('npm-license-crawler');
// Clear buildConstants.js
const buildConstants = {};
// Determine version
const version = execSync('git describe', {encoding: 'utf8'}).trim();
const lastPartStart = version.lastIndexOf('-');
buildConstants.version = `${version.substring(0, lastPartStart)} (${version.substring(lastPartStart + 1)})`;
// Get current date/time
buildConstants.buildDate = new Date().toUTCString().trim();
// Get dependencies
const productionDependencies = getDependencies({
start: ['./'],
production: true,
onlyDirectDependencies: true,
omitVersion: true,
noColor: true,
});
buildConstants.directDependencies = productionDependencies.dependencies;
// Write buildConstants.js
fs.writeFileSync('./src/scripts/constants/buildConstants.js',
`/* eslint-disable */\n\nexport const buildConstants = ${JSON.stringify(buildConstants, null, 2)};`);
function getDependencies(options) {
let dumpDone = false;
let dumpError = undefined;
let dependencies = undefined;
licenseCrawler.dumpLicenses(options, (error, result) => {
if (error) {
dumpError = error;
} else {
const projects = result;
dependencies = [];
for (const project in projects) {
if (Object.prototype.hasOwnProperty.call(projects, project)) {
dependencies.push({
name: project,
repository: projects[project].repository,
});
}
}
}
dumpDone = true;
});
deasync.loopWhile(() => !dumpDone);
return {
dependencies: dependencies,
error: dumpError,
};
}