-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild.js
More file actions
129 lines (117 loc) · 4.1 KB
/
build.js
File metadata and controls
129 lines (117 loc) · 4.1 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import archiver from "archiver";
import {
readdir,
statSync,
existsSync,
readFileSync,
mkdirSync,
rmSync,
cpSync,
writeFileSync,
createWriteStream,
} 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 zipDirectory = async (sourceDir, outPath) => {
const archive = archiver("zip", { zlib: { level: 9 } });
const stream = createWriteStream(outPath);
return new Promise((resolve, reject) => {
archive
.directory(sourceDir, false)
.on("error", (err) => reject(err))
.pipe(stream);
stream.on("close", () => resolve());
archive.finalize();
});
};
const createDefaultManifest = () => ({
manifest_version: "1.0",
manifest_publish_date: new Date().toISOString(),
available_versions: [],
});
const buildManifest = async (buildZip = false) => {
const ngcBuilds = await promisify(readdir)(ngcBuildsDir);
console.log({ ngcBuilds });
let manifest = createDefaultManifest();
for (const dir of ngcBuilds) {
if (!statSync(resolve(ngcBuildsDir, dir)).isDirectory()) {
console.log(`${dir} is not a directory`);
continue;
}
// 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`);
continue;
}
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}`
);
continue;
}
const versionTag = version.match(/-([-a-zA-Z0-9]+)$/)?.[1];
const destVersion = `${majorMinorVersion}${
versionTag ? `-${versionTag}` : ""
}`;
const path = `<root>/releases/ngc/${destVersion}/${entry_point}`;
// build a ZIP
const archive = buildZip ? `agentforce-messaging-release-${destVersion}.zip` : undefined;
if (buildZip) {
await zipDirectory(
resolve(ngcBuildsDir, dir),
resolve(
distDir,
archive
)
);
}
manifest.available_versions.push({
version: destVersion,
full_version: version,
minimum_bootstrap_versions,
path,
css_file,
build_date,
...buildZip && { archive },
});
}
} catch (ex) {
console.error(`Error processing build for ${dir}`, ex, yamlFile);
}
};
console.log("rebuildManifest", manifest);
return manifest;
};
if (!existsSync(distDir)) {
mkdirSync(distDir);
}
rmSync(distDir, { recursive: true });
mkdirSync(resolve(distDir, "releases/ngc"), { recursive: true });
const manifest = await buildManifest(true);
cpSync(resolve(ngcBuildsDir, "./"), resolve(distDir, "releases/ngc"), {
recursive: true,
});
writeFileSync(
resolve(distDir, "manifest.json"),
JSON.stringify(manifest, null, 2)
);