-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathmanifest-generate.mjs
More file actions
54 lines (44 loc) · 1.84 KB
/
manifest-generate.mjs
File metadata and controls
54 lines (44 loc) · 1.84 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
import { debuglog } from 'node:util';
import { importModule } from '@eggjs/utils';
const debug = debuglog('egg/bin/scripts/manifest-generate');
async function main() {
debug('argv: %o', process.argv);
const options = JSON.parse(process.argv[2]);
debug('manifest generate options: %o', options);
// Set server env before importing framework
if (options.env) {
process.env.EGG_SERVER_ENV = options.env;
}
const framework = await importModule(options.framework);
const app = await framework.start({
baseDir: options.baseDir,
framework: options.framework,
env: options.env,
metadataOnly: true,
});
// Generate manifest from collected metadata
const manifest = app.loader.generateManifest();
// Write manifest to .egg/manifest.json
// Resolve @eggjs/core from the framework path (not the project root),
// because pnpm strict mode may not hoist it to the project's node_modules.
const { ManifestStore } = await importModule('@eggjs/core', {
paths: [options.framework],
});
await ManifestStore.write(options.baseDir, manifest);
// Log stats
const resolveCacheCount = Object.keys(manifest.resolveCache).length;
const fileDiscoveryCount = Object.keys(manifest.fileDiscovery).length;
const extensionCount = Object.keys(manifest.extensions).length;
console.log('[manifest] Generated manifest v%d at %s', manifest.version, manifest.generatedAt);
console.log('[manifest] resolveCache entries: %d', resolveCacheCount);
console.log('[manifest] fileDiscovery entries: %d', fileDiscoveryCount);
console.log('[manifest] extension entries: %d', extensionCount);
console.log('[manifest] Written to %s/.egg/manifest.json', options.baseDir);
// Clean up and exit
await app.close();
process.exit(0);
}
main().catch((err) => {
console.error('[manifest] Generation failed:', err);
process.exit(1);
});