@microsoft/ccf-app 6.0.0-dev9 → 6.0.0-rc0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -1
- package/scripts/build_bundle.d.ts +2 -0
- package/scripts/build_bundle.js +61 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/ccf-app",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-rc0",
|
|
4
4
|
"description": "CCF app support package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -31,5 +31,8 @@
|
|
|
31
31
|
"ts-node": "^10.4.0",
|
|
32
32
|
"typedoc": "^0.27.0",
|
|
33
33
|
"typescript": "^5.7.2"
|
|
34
|
+
},
|
|
35
|
+
"bin": {
|
|
36
|
+
"ccf-build-bundle": "scripts/build_bundle.js"
|
|
34
37
|
}
|
|
35
38
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readdirSync, statSync, readFileSync, writeFileSync, existsSync, } from "fs";
|
|
3
|
+
import { join, resolve, sep } from "path";
|
|
4
|
+
function getAllFiles(dirPath) {
|
|
5
|
+
const toSearch = [dirPath];
|
|
6
|
+
const agg = [];
|
|
7
|
+
for (const filePath of toSearch) {
|
|
8
|
+
if (statSync(filePath).isDirectory()) {
|
|
9
|
+
for (const subfile of readdirSync(filePath)) {
|
|
10
|
+
toSearch.push(join(filePath, subfile));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
agg.push(filePath);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return agg;
|
|
18
|
+
}
|
|
19
|
+
function removePrefix(s, prefix) {
|
|
20
|
+
if (s.startsWith(prefix)) {
|
|
21
|
+
return s.slice(prefix.length).split(sep).join(sep);
|
|
22
|
+
}
|
|
23
|
+
console.log("Warn: tried to remove invalid prefix", s, prefix);
|
|
24
|
+
return s;
|
|
25
|
+
}
|
|
26
|
+
const args = process.argv.slice(2);
|
|
27
|
+
if (args.length < 1) {
|
|
28
|
+
console.log("Usage: build_bundle <root_directory>");
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
function assertFileExists(path) {
|
|
32
|
+
if (!existsSync(path)) {
|
|
33
|
+
console.log("File not found: %s", path);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const argRootDirPath = args[0];
|
|
38
|
+
assertFileExists(argRootDirPath);
|
|
39
|
+
const rootDirPath = resolve(argRootDirPath);
|
|
40
|
+
const metadataPath = join(rootDirPath, "app.json");
|
|
41
|
+
assertFileExists(metadataPath);
|
|
42
|
+
const srcDirPath = join(rootDirPath, "src");
|
|
43
|
+
assertFileExists(srcDirPath);
|
|
44
|
+
const metadata = JSON.parse(readFileSync(metadataPath, "utf-8"));
|
|
45
|
+
const allFiles = getAllFiles(srcDirPath);
|
|
46
|
+
// The trailing / is included so that it is trimmed in removePrefix.
|
|
47
|
+
// This produces "foo/bar.js" rather than "/foo/bar.js"
|
|
48
|
+
const toTrim = srcDirPath + "/";
|
|
49
|
+
const modules = allFiles.map(function (filePath) {
|
|
50
|
+
return {
|
|
51
|
+
name: removePrefix(filePath, toTrim),
|
|
52
|
+
module: readFileSync(filePath, "utf-8"),
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
const bundlePath = join(args[0], "bundle.json");
|
|
56
|
+
const bundle = {
|
|
57
|
+
metadata: metadata,
|
|
58
|
+
modules: modules,
|
|
59
|
+
};
|
|
60
|
+
console.log(`Writing bundle containing ${modules.length} modules to ${bundlePath}`);
|
|
61
|
+
writeFileSync(bundlePath, JSON.stringify(bundle));
|