-
Notifications
You must be signed in to change notification settings - Fork 62
/
vendor_build.js
61 lines (55 loc) · 1.88 KB
/
vendor_build.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
const jsyaml = require("js-yaml");
const { readFileSync, copyFileSync, readdirSync, statSync, mkdirSync } = require("fs");
const { join, basename, dirname } = require("path");
const firstBy = require("thenby");
function isDirectory(file) {
return statSync(file).isDirectory();
}
function copyOverwrite(src, dst) {
if (isDirectory(src)) {
readdirSync(src).forEach(file =>
copyOverwrite(join(src, file), join(dst, file))
);
} else {
let dstFile, dstDir;
if (dst.endsWith("/")) {
dstDir = dst;
dstFile = join(dst, basename(src));
} else {
dstDir = dirname(dst);
dstFile = dst;
}
console.log(" copying", src, "to", dstFile);
mkdirSync(dstDir, { recursive: true });
copyFileSync(src, dstFile);
}
}
function main() {
const filename = "vendor.yaml";
const vendorYaml = readFileSync(filename, "utf8");
const vendor = jsyaml.load(vendorYaml, { schema: jsyaml.CORE_SCHEMA, filename });
const sortedLibs = Object.entries(vendor["libs"]).sort(
firstBy(([, lib]) => lib["priority"])
);
for (const [libName, lib] of sortedLibs) {
if (!lib["npmDir"] || !lib["files"]) {
continue;
}
console.log("Processing:", libName);
const distDir = `./lib/_npm/${lib["distDir"] || lib["npmDir"]}/`;
for (let file of lib["files"]) {
const allFilesInDir = file.endsWith("/*");
if (allFilesInDir) {
file = file.replace("/*", "");
}
srcPattern = `./node_modules/${lib["npmDir"]}/${file}`;
if (isDirectory(srcPattern) && !allFilesInDir) {
copyOverwrite(srcPattern, join(distDir, file));
} else {
copyOverwrite(srcPattern, distDir);
}
}
}
require("./vendor_license");
}
main();