react-native-bundle-discovery 1.3.1 → 2.0.0-rc.2
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/README.md +3 -3
- package/index.js +240 -1
- package/package.json +5 -21
- package/.discoveryrc.js +0 -22
- package/lib/bin.js +0 -87
- package/lib/build.js +0 -115
- package/lib/customSerializer.js +0 -196
- package/lib/server.js +0 -82
- package/pages/_common.js +0 -267
- package/pages/default.js +0 -211
- package/pages/module.js +0 -314
- package/pages/package.js +0 -161
- package/prepare.js +0 -102
- package/queryHelpers.js +0 -354
- package/setup.js +0 -12
- package/vendors/foamtree.js +0 -9008
- package/vendors/high-contrast-dark.js +0 -1
- package/vendors/highcharts-exporting.js +0 -13
- package/vendors/highcharts-networkgraph.js +0 -1
- package/vendors/highcharts.js +0 -10
- package/views/_theme.js +0 -35
- package/views/foamtree.js +0 -135
- package/views/global.css +0 -169
- package/views/highcharts.css +0 -1
- package/views/highcharts.js +0 -43
- package/views/prettify.js +0 -17
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ There are two ways to install the package:
|
|
|
30
30
|
#### 1. Install (independent tool)
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
|
-
yarn add -D react-native-bundle-discovery
|
|
33
|
+
yarn add -D react-native-bundle-discovery react-native-bundle-discovery-ui
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
Add to your `metro.config.js`:
|
|
@@ -117,7 +117,7 @@ npx react-native bundle \
|
|
|
117
117
|
Run webserver to view the report:
|
|
118
118
|
|
|
119
119
|
```bash
|
|
120
|
-
npx react-native-bundle-discovery server metro-stats.json [--port <port>]
|
|
120
|
+
npx react-native-bundle-discovery-ui server metro-stats.json [--port <port>]
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
##### 4.2 Build the HTML report
|
|
@@ -125,7 +125,7 @@ npx react-native-bundle-discovery server metro-stats.json [--port <port>]
|
|
|
125
125
|
Run the following command to generate an HTML report from the JSON file:
|
|
126
126
|
|
|
127
127
|
```bash
|
|
128
|
-
npx react-native-bundle-discovery build metro-stats.json
|
|
128
|
+
npx react-native-bundle-discovery-ui build metro-stats.json
|
|
129
129
|
```
|
|
130
130
|
|
|
131
131
|
|
package/index.js
CHANGED
|
@@ -1 +1,240 @@
|
|
|
1
|
-
|
|
1
|
+
const { parse, resolve } = require("path");
|
|
2
|
+
const { writeFileSync, existsSync } = require("fs");
|
|
3
|
+
const { Buffer } = require("buffer");
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
|
|
6
|
+
const NAME = require("./package.json").name;
|
|
7
|
+
|
|
8
|
+
function getDefault(module) {
|
|
9
|
+
return module.__esModule ? module.default : module;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getDefaultSerializer() {
|
|
13
|
+
const metroPath = parse(require.resolve("metro/package.json")).dir;
|
|
14
|
+
const bundleToString = getDefault(
|
|
15
|
+
require(`${metroPath}/src/lib/bundleToString.js`),
|
|
16
|
+
);
|
|
17
|
+
const baseJSBundle = getDefault(
|
|
18
|
+
require(`${metroPath}/src/DeltaBundler/Serializers/baseJSBundle.js`),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return function defaultSerializer(entryPoint, preModules, graph, options) {
|
|
22
|
+
let bundle = baseJSBundle(entryPoint, preModules, graph, options);
|
|
23
|
+
|
|
24
|
+
// Sentry support
|
|
25
|
+
// https://docs.sentry.io/platforms/react-native/manual-setup/metro/#wrap-your-custom-serializer
|
|
26
|
+
if (typeof options?.sentryBundleCallback === "function") {
|
|
27
|
+
bundle = options.sentryBundleCallback(bundle);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return bundleToString(bundle).code;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getStringSizeInBytes(str) {
|
|
35
|
+
return Buffer.byteLength(str, "utf8");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* `/Users/i/app/node_modules/metro/node_modules/@babel/runtime/helpers/createClass.js` -> `@babel/runtime`
|
|
40
|
+
* `/Users/i/app/node_modules/react/jsx-runtime.js` -> `react`
|
|
41
|
+
*/
|
|
42
|
+
function getPackageNameFromPath(path) {
|
|
43
|
+
const parts = path.split("node_modules/");
|
|
44
|
+
const lastPart = parts[parts.length - 1];
|
|
45
|
+
if (lastPart.startsWith("@")) {
|
|
46
|
+
return lastPart.split("/").slice(0, 2).join("/");
|
|
47
|
+
}
|
|
48
|
+
return lastPart.split("/")[0];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* `/Users/i/app/node_modules/metro/node_modules/@babel/runtime/helpers/createClass.js` -> `/Users/i/app/node_modules/metro/node_modules/@babel/runtime`
|
|
53
|
+
* `/Users/i/app/node_modules/react/jsx-runtime.js` -> `/Users/i/app/node_modules/react`
|
|
54
|
+
*/
|
|
55
|
+
function getPackageAbsolutePath(path, pkgName) {
|
|
56
|
+
const parts = path.split("node_modules/");
|
|
57
|
+
parts[parts.length - 1] = pkgName;
|
|
58
|
+
return parts.join("node_modules/");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function toPackages(modules) {
|
|
62
|
+
const packages = new Map();
|
|
63
|
+
modules.forEach((module) => {
|
|
64
|
+
if (!module.path.includes("node_modules/")) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const pkgName = getPackageNameFromPath(module.path);
|
|
69
|
+
const absolutePkgPath = getPackageAbsolutePath(module.path, pkgName);
|
|
70
|
+
|
|
71
|
+
if (!packages.has(absolutePkgPath)) {
|
|
72
|
+
packages.set(absolutePkgPath, {
|
|
73
|
+
name: pkgName,
|
|
74
|
+
absolutePath: absolutePkgPath,
|
|
75
|
+
version: require(resolve(absolutePkgPath, "package.json")).version,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return Array.from(packages.values()).sort((a, b) =>
|
|
81
|
+
a.name.localeCompare(b.name),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function toModuleStruct(m, includeCode) {
|
|
86
|
+
const sourceCode = m.getSource().toString("utf8");
|
|
87
|
+
const outputCode = m.output[0].data.code;
|
|
88
|
+
return {
|
|
89
|
+
path: m.path,
|
|
90
|
+
source: {
|
|
91
|
+
code: includeCode ? sourceCode : "",
|
|
92
|
+
lineCount: sourceCode.split("\n").length,
|
|
93
|
+
sizeInBytes: getStringSizeInBytes(sourceCode),
|
|
94
|
+
},
|
|
95
|
+
output: {
|
|
96
|
+
code: includeCode ? outputCode : "",
|
|
97
|
+
lineCount: m.output[0].data.lineCount,
|
|
98
|
+
sizeInBytes: getStringSizeInBytes(outputCode),
|
|
99
|
+
},
|
|
100
|
+
dependencies: Array.from(m?.dependencies?.values?.() ?? [])
|
|
101
|
+
.filter((e) => e.absolutePath)
|
|
102
|
+
.map((e) => ({
|
|
103
|
+
absolutePath: e.absolutePath,
|
|
104
|
+
name: e.data.name,
|
|
105
|
+
})),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function createJsonReport({
|
|
110
|
+
graph,
|
|
111
|
+
entryPoint,
|
|
112
|
+
includeEnvs,
|
|
113
|
+
preModules,
|
|
114
|
+
includeCode,
|
|
115
|
+
outputJsonPath,
|
|
116
|
+
rootFolder,
|
|
117
|
+
silent,
|
|
118
|
+
options,
|
|
119
|
+
}) {
|
|
120
|
+
const { processModuleFilter = () => true } = options || {};
|
|
121
|
+
const dependencies = Array.from(graph.dependencies.values()).filter(
|
|
122
|
+
processModuleFilter,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const stats = {
|
|
126
|
+
date: Date.now(),
|
|
127
|
+
entryPoint,
|
|
128
|
+
transformOptions: graph.transformOptions,
|
|
129
|
+
envs: includeEnvs.reduce((acc, envName) => {
|
|
130
|
+
acc[envName] = process.env[envName];
|
|
131
|
+
return acc;
|
|
132
|
+
}, {}),
|
|
133
|
+
rootFolder,
|
|
134
|
+
packages: toPackages(preModules).concat(toPackages(dependencies)),
|
|
135
|
+
modules: preModules
|
|
136
|
+
.map((m) => toModuleStruct(m, includeCode))
|
|
137
|
+
.concat(dependencies.map((m) => toModuleStruct(m, includeCode))),
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
writeFileSync(outputJsonPath, JSON.stringify(stats));
|
|
141
|
+
|
|
142
|
+
if (!silent) {
|
|
143
|
+
console.log(
|
|
144
|
+
`${chalk.yellow(`[${NAME}]`)}: Saved stats to ${chalk.green(outputJsonPath)}`,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Creates a custom serializer function for Metro bundler, which generates a JSON report
|
|
151
|
+
* and optionally modifies the serialization process.
|
|
152
|
+
*
|
|
153
|
+
* @param {Object} options - Configuration options for the serializer.
|
|
154
|
+
* @param {Function} [options.serializer] - A custom serializer function. If not provided, a default serializer is used.
|
|
155
|
+
* @param {string} options.projectRoot - The root directory of the project. Must exist.
|
|
156
|
+
* @param {string} [options.outputJsonPath] - The path where the JSON report will be saved. Defaults to "metro-stats.json" in the project root.
|
|
157
|
+
* @param {boolean} [options.includeCode=true] - Whether to include the source and output code in the JSON report.
|
|
158
|
+
* @param {string[]} [options.includeEnvs=[]] - A list of environment variable names to include in the JSON report.
|
|
159
|
+
* @returns {Function} - A custom serializer function to be used by Metro.
|
|
160
|
+
* @throws {Error} - Throws an error if the project root does not exist.
|
|
161
|
+
*/
|
|
162
|
+
function createSerializer({
|
|
163
|
+
serializer,
|
|
164
|
+
projectRoot,
|
|
165
|
+
outputJsonPath,
|
|
166
|
+
includeCode = true,
|
|
167
|
+
silent = false,
|
|
168
|
+
includeEnvs = [],
|
|
169
|
+
} = {}) {
|
|
170
|
+
const mySerializer = serializer || getDefaultSerializer();
|
|
171
|
+
|
|
172
|
+
if (!existsSync(projectRoot)) {
|
|
173
|
+
throw new Error(`[${NAME}]: Project root does not exist: ${projectRoot}`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const myOutputJsonPath =
|
|
177
|
+
outputJsonPath ?? resolve(projectRoot, "metro-stats.json");
|
|
178
|
+
|
|
179
|
+
function customSerializer(entryPoint, preModules, graph, options) {
|
|
180
|
+
const code = mySerializer(entryPoint, preModules, graph, options);
|
|
181
|
+
|
|
182
|
+
createJsonReport({
|
|
183
|
+
graph,
|
|
184
|
+
entryPoint,
|
|
185
|
+
includeEnvs,
|
|
186
|
+
preModules,
|
|
187
|
+
includeCode,
|
|
188
|
+
outputJsonPath: myOutputJsonPath,
|
|
189
|
+
rootFolder: projectRoot,
|
|
190
|
+
silent,
|
|
191
|
+
options,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
return code;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return customSerializer;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const createProcessModuleFilter =
|
|
201
|
+
({
|
|
202
|
+
removePromisePolyfill = false, // Remove useless polyfill (Hermes already has Promise)
|
|
203
|
+
removeOldRenderer = false, // Should be true when new ARCH is enabled
|
|
204
|
+
removeNewRenderer = false, // Should be true when new ARCH is disabled
|
|
205
|
+
removeUTFSequence = false, // Remove useless code
|
|
206
|
+
} = {}) =>
|
|
207
|
+
(module) => {
|
|
208
|
+
if (
|
|
209
|
+
removePromisePolyfill &&
|
|
210
|
+
module.path.endsWith("/react-native/Libraries/Promise.js")
|
|
211
|
+
) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
if (
|
|
215
|
+
removeOldRenderer &&
|
|
216
|
+
module.path.endsWith(
|
|
217
|
+
"/react-native/Libraries/Renderer/shims/ReactNative.js",
|
|
218
|
+
)
|
|
219
|
+
) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
if (
|
|
223
|
+
removeNewRenderer &&
|
|
224
|
+
module.path.endsWith(
|
|
225
|
+
"/react-native/Libraries/Renderer/shims/ReactFabric.js",
|
|
226
|
+
)
|
|
227
|
+
) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
if (
|
|
231
|
+
removeUTFSequence &&
|
|
232
|
+
module.path.endsWith("/react-native/Libraries/UTFSequence.js")
|
|
233
|
+
) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return true;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
module.exports = { createSerializer, createProcessModuleFilter };
|
package/package.json
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-bundle-discovery",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-rc.2",
|
|
4
4
|
"main": "index.js",
|
|
5
|
-
"bin": "lib/bin.js",
|
|
6
5
|
"repository": "git@github.com:retyui/react-native-bundle-discovery.git",
|
|
7
6
|
"author": "David <4661784+retyui@users.noreply.github.com>",
|
|
8
7
|
"license": "MIT",
|
|
9
8
|
"scripts": {
|
|
10
|
-
"
|
|
11
|
-
"start": "NODE_ENV=development npx discovery --config .discoveryrc.js",
|
|
12
|
-
"build": "npx discovery-build --config .discoveryrc.js --output build --serve-only-assets --single-file"
|
|
9
|
+
"prepublishOnly": "cp ../README.md README.md"
|
|
13
10
|
},
|
|
14
11
|
"dependencies": {
|
|
15
|
-
"
|
|
16
|
-
"@discoveryjs/discovery": "1.0.0-beta.99",
|
|
17
|
-
"chalk": "^4.1.2",
|
|
18
|
-
"minimist": "^1.2.8",
|
|
19
|
-
"prettier": "^3.8.1"
|
|
12
|
+
"chalk": "^4.1.2"
|
|
20
13
|
},
|
|
21
14
|
"peerDependencies": {
|
|
22
15
|
"metro": "*"
|
|
@@ -27,15 +20,6 @@
|
|
|
27
20
|
}
|
|
28
21
|
},
|
|
29
22
|
"files": [
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
"views",
|
|
33
|
-
"pages",
|
|
34
|
-
"index.js",
|
|
35
|
-
"setup.js",
|
|
36
|
-
"prepare.js",
|
|
37
|
-
"queryHelpers.js",
|
|
38
|
-
".discoveryrc.js"
|
|
39
|
-
],
|
|
40
|
-
"packageManager": "yarn@4.13.0"
|
|
23
|
+
"index.js"
|
|
24
|
+
]
|
|
41
25
|
}
|
package/.discoveryrc.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const path = require("path");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
name: "react-native-bundle-discovery",
|
|
5
|
-
data: () => require("./tmp/metro-stats.json"),
|
|
6
|
-
setup: path.resolve(__dirname, "setup.js"),
|
|
7
|
-
view: {
|
|
8
|
-
assets: [
|
|
9
|
-
// Global styles
|
|
10
|
-
path.resolve(__dirname, "views/global.css"),
|
|
11
|
-
// Pages
|
|
12
|
-
path.resolve(__dirname, "pages/default.js"),
|
|
13
|
-
path.resolve(__dirname, "pages/module.js"),
|
|
14
|
-
path.resolve(__dirname, "pages/package.js"),
|
|
15
|
-
// Custom views
|
|
16
|
-
path.resolve(__dirname, "views/highcharts.css"),
|
|
17
|
-
path.resolve(__dirname, "views/prettify.js"),
|
|
18
|
-
path.resolve(__dirname, "views/highcharts.js"),
|
|
19
|
-
path.resolve(__dirname, "views/foamtree.js"),
|
|
20
|
-
],
|
|
21
|
-
},
|
|
22
|
-
};
|
package/lib/bin.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const minimist = require("minimist");
|
|
3
|
-
|
|
4
|
-
function printHelp() {
|
|
5
|
-
console.log(`react-native-bundle-discovery
|
|
6
|
-
|
|
7
|
-
Usage:
|
|
8
|
-
react-native-bundle-discovery server <file> [port] [--verbose]
|
|
9
|
-
react-native-bundle-discovery build <file> [--output <path>] [--clean] [--single-file] [--verbose]
|
|
10
|
-
|
|
11
|
-
Commands:
|
|
12
|
-
server <file> [port] Run a web server to show a Metro bundler stat report
|
|
13
|
-
build <file> Build a HTML report from the Metro bundler stat file
|
|
14
|
-
|
|
15
|
-
Options:
|
|
16
|
-
-v, --verbose Run with verbose logging
|
|
17
|
-
-o, --output <path> Path for a build result (default: .bundle-discovery)
|
|
18
|
-
-c, --clean Clean output directory before writing build files (default: true)
|
|
19
|
-
-s, --single-file Output report build as a single HTML file (default: true)
|
|
20
|
-
-p, --port <port> Port for server command (same as [port], default: 8079)
|
|
21
|
-
-h, --help Show help
|
|
22
|
-
`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function fail(message) {
|
|
26
|
-
console.error(message);
|
|
27
|
-
console.error("Use --help to see usage.");
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const argv = minimist(process.argv.slice(2), {
|
|
32
|
-
alias: {
|
|
33
|
-
v: "verbose",
|
|
34
|
-
h: "help",
|
|
35
|
-
o: "output",
|
|
36
|
-
c: "clean",
|
|
37
|
-
s: "single-file",
|
|
38
|
-
p: "port",
|
|
39
|
-
},
|
|
40
|
-
boolean: ["verbose", "help", "clean", "single-file"],
|
|
41
|
-
string: ["output"],
|
|
42
|
-
default: {
|
|
43
|
-
clean: true,
|
|
44
|
-
"single-file": true,
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const command = argv._[0];
|
|
49
|
-
|
|
50
|
-
if (argv.help || !command) {
|
|
51
|
-
printHelp();
|
|
52
|
-
process.exit(0);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (command === "server") {
|
|
56
|
-
const file = argv._[1];
|
|
57
|
-
if (!file) {
|
|
58
|
-
fail("Missing required argument: <file>");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const rawPort = argv.port ?? argv._[2] ?? 8079;
|
|
62
|
-
const port = Number(rawPort);
|
|
63
|
-
if (!Number.isFinite(port)) {
|
|
64
|
-
fail(`Invalid port: ${rawPort}`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const { serve } = require("./server.js");
|
|
68
|
-
return serve(file, port, Boolean(argv.verbose));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (command === "build") {
|
|
72
|
-
const file = argv._[1];
|
|
73
|
-
if (!file) {
|
|
74
|
-
fail("Missing required argument: <file>");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const { buildHtmlPage } = require("./build.js");
|
|
78
|
-
return buildHtmlPage(
|
|
79
|
-
file,
|
|
80
|
-
argv.output,
|
|
81
|
-
argv.clean,
|
|
82
|
-
argv["single-file"],
|
|
83
|
-
Boolean(argv.verbose),
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
fail(`Unknown command: ${command}`);
|
package/lib/build.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const chalk = require("chalk");
|
|
4
|
-
const { build } = require("@discoveryjs/cli");
|
|
5
|
-
const config = require("../.discoveryrc.js");
|
|
6
|
-
|
|
7
|
-
function buildHtmlPage(filePath, output, clean, singleFile, verbose) {
|
|
8
|
-
if (verbose) {
|
|
9
|
-
console.info(
|
|
10
|
-
`Building HTML page from file: ${chalk.green(filePath)} options: ${JSON.stringify(
|
|
11
|
-
{ output, clean, singleFile },
|
|
12
|
-
null,
|
|
13
|
-
2,
|
|
14
|
-
)}`,
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (!filePath) {
|
|
19
|
-
console.error(
|
|
20
|
-
`Usage: '${chalk.green("npx react-native-bundle-discovery build <path-to-file>")}', Please provide a path to a JSON file.`,
|
|
21
|
-
);
|
|
22
|
-
process.exit(1);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const jsonFilePath = path.resolve(process.cwd(), filePath);
|
|
26
|
-
if (verbose) {
|
|
27
|
-
console.info(
|
|
28
|
-
`Loading JSON file from: ${chalk.green(jsonFilePath)}, base directory: ${chalk.green(process.cwd())}`,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let fullJsonPath;
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
fullJsonPath = require.resolve(jsonFilePath);
|
|
36
|
-
} catch (err) {
|
|
37
|
-
console.error(`❌Error loading file: ${chalk.red(jsonFilePath)}\n\n`);
|
|
38
|
-
console.error(err.message);
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const configFile = path.resolve(__dirname, "./.tmp.js");
|
|
43
|
-
|
|
44
|
-
if (verbose) {
|
|
45
|
-
console.info(
|
|
46
|
-
`Creating temporary config file at: ${chalk.green(configFile)}, for discovery.js`,
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
fs.writeFileSync(
|
|
50
|
-
configFile,
|
|
51
|
-
`module.exports = ${JSON.stringify(
|
|
52
|
-
{ ...config, data: "<tmp>" },
|
|
53
|
-
null,
|
|
54
|
-
1,
|
|
55
|
-
).replace(`"<tmp>"`, `() => require("${fullJsonPath}")`)};`,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
if (verbose) {
|
|
59
|
-
console.info(`Building HTML page with options:`, {
|
|
60
|
-
output,
|
|
61
|
-
clean,
|
|
62
|
-
singleFile,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const _config = {
|
|
67
|
-
name: "Bundle Discovery",
|
|
68
|
-
mode: "single",
|
|
69
|
-
// models: [ [Object] ],
|
|
70
|
-
colorScheme: "auto",
|
|
71
|
-
download: true,
|
|
72
|
-
upload: false,
|
|
73
|
-
embed: false,
|
|
74
|
-
encodings: false,
|
|
75
|
-
};
|
|
76
|
-
const _options = {
|
|
77
|
-
singleFile,
|
|
78
|
-
clean,
|
|
79
|
-
output,
|
|
80
|
-
//
|
|
81
|
-
cache: true,
|
|
82
|
-
cachedir: path.resolve(__dirname, "./.discoveryjs-cache"),
|
|
83
|
-
checkCacheTtl: false,
|
|
84
|
-
minify: true,
|
|
85
|
-
dataCompression: true,
|
|
86
|
-
sourcemap: false,
|
|
87
|
-
embed: "by-config",
|
|
88
|
-
experimentalJsonxl: false,
|
|
89
|
-
scriptFormat: "esm",
|
|
90
|
-
scriptExternal: [],
|
|
91
|
-
data: true,
|
|
92
|
-
excludeModelOnDataFail: false,
|
|
93
|
-
prettyData: false,
|
|
94
|
-
modelDownload: false,
|
|
95
|
-
modelDataUpload: true,
|
|
96
|
-
modelResetCache: false,
|
|
97
|
-
serveOnlyAssets: true,
|
|
98
|
-
dev: true,
|
|
99
|
-
config: configFile,
|
|
100
|
-
configFile: configFile,
|
|
101
|
-
};
|
|
102
|
-
return build(_options, _config, configFile).then((result) => {
|
|
103
|
-
console.log(`========================================`);
|
|
104
|
-
console.log(
|
|
105
|
-
`✅ HTML page built successfully at: ${chalk.green(
|
|
106
|
-
path.resolve(output, "index.html").replace(process.cwd() + "/", ""),
|
|
107
|
-
)}`,
|
|
108
|
-
);
|
|
109
|
-
console.log(`========================================`);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
module.exports = {
|
|
114
|
-
buildHtmlPage,
|
|
115
|
-
};
|