forked from airkitjeremy/ngcproto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
99 lines (91 loc) · 3.15 KB
/
build.js
File metadata and controls
99 lines (91 loc) · 3.15 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import {
readdir,
statSync,
existsSync,
readFileSync,
mkdirSync,
rmSync,
cpSync,
writeFileSync,
} from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
const __dirname = dirname(fileURLToPath(import.meta.url));
const ngcBuildsDir = resolve(__dirname, "./builds/ngc");
const distDir = resolve(__dirname, "./dist");
console.log({ ngcBuildsDir, distDir });
const createDefaultManifest = () => ({
manifest_version: "1.0",
manifest_publish_date: new Date().toISOString(),
available_versions: [],
});
const buildManifest = async () => {
const ngcBuilds = await promisify(readdir)(ngcBuildsDir);
console.log({ ngcBuilds });
const manifest = ngcBuilds.reduce((m, dir) => {
if (!statSync(resolve(ngcBuildsDir, dir)).isDirectory()) {
console.log(`${dir} is not a directory`);
return m;
}
// look for and load the BUILDINFO file
const buildinfoPath = resolve(ngcBuildsDir, dir, "BUILDINFO.json");
if (!existsSync(buildinfoPath)) {
console.log(`${dir} does not contain BUILDINFO.json`);
return m;
}
const yamlFile = readFileSync(buildinfoPath, { encoding: "utf8" });
try {
const buildinfo = JSON.parse(yamlFile);
console.log(`BUILDINFO for ${dir}:`, buildinfo);
const {
version,
minimum_bootstrap_versions = [],
build_date,
entry_point = "index.js",
css_file,
} = buildinfo;
if (version) {
const majorMinorVersion =
version.match(/^([0-9]+\.[0-9]+)\./)?.[1];
if (!majorMinorVersion) {
console.log(
`Could not match regular expression against ${version}`
);
return m;
}
const versionTag = version.match(/-([-a-zA-Z0-9]+)$/)?.[1];
const destVersion = `${majorMinorVersion}${
versionTag ? `-${versionTag}` : ""
}`;
const path = `<root>/releases/ngc/${destVersion}/${entry_point}`;
m.available_versions.push({
version: destVersion,
full_version: version,
minimum_bootstrap_versions,
path,
css_file,
build_date,
});
}
} catch (ex) {
console.error(`Error while reading YAML for ${dir}`, ex, yamlFile);
}
return m;
}, createDefaultManifest());
console.log("rebuildManifest", manifest);
return manifest;
};
const manifest = await buildManifest();
if (!existsSync(distDir)) {
mkdirSync(distDir);
}
rmSync(distDir, { recursive: true });
mkdirSync(resolve(distDir, "releases/ngc"), { recursive: true });
cpSync(resolve(ngcBuildsDir, "./"), resolve(distDir, "releases/ngc"), {
recursive: true,
});
writeFileSync(
resolve(distDir, "manifest.json"),
JSON.stringify(manifest, null, 2)
);