@quallens/cli 0.0.0-stage → 0.4.0

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.
@@ -0,0 +1,29 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { createRequire } from 'node:module';
4
+ import { createHash } from 'node:crypto';
5
+ const require = createRequire(import.meta.url);
6
+ const packageRoot = import.meta.dirname;
7
+ const manifest = JSON.parse(await fs.readFile(path.join(packageRoot, 'manifest.json'), 'utf8'));
8
+ if (manifest.schemaVersion !== '1.0' || typeof manifest.version !== 'string' ||
9
+ !/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/.test(manifest.version)) throw Error('PACKAGE_VERSION');
10
+ const expected = ['bridge.mjs', 'quallens.mjs', 'launcher.mjs', 'hvigor-plugin.cjs', 'LICENSE', 'NOTICE',
11
+ 'restore.mjs', 'knowledge.json.gz', 'heavy-tools.json.gz', 'quallens-debug-kit.har'];
12
+ if (JSON.stringify(Object.keys(manifest.files ?? {}).sort()) !== JSON.stringify([...expected].sort())) throw Error('PACKAGE_MANIFEST');
13
+ for (const [name, hash] of Object.entries(manifest.files)) {
14
+ if (!expected.includes(name)) throw Error('PACKAGE_PATH');
15
+ const stat = await fs.lstat(path.join(packageRoot, name));
16
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.size > (name === 'knowledge.json.gz' ? 24 : 8) * 1024 * 1024 ||
17
+ createHash('sha256').update(await fs.readFile(path.join(packageRoot, name))).digest('hex') !== hash) throw Error('PACKAGE_HASH');
18
+ }
19
+ const args = process.argv.slice(2);
20
+ const selection = args.filter(value => value.startsWith('--kit-modules='));
21
+ if (selection.length > 1) throw Error('KIT_MODULE: 重复模块选项');
22
+ const kitModules = selection.length ? selection[0].slice('--kit-modules='.length).split(',').filter(Boolean) : undefined;
23
+ const [root, action = 'apply', product, execute] = args.filter(value => !value.startsWith('--kit-modules='));
24
+ if (!root || !['apply', 'remove', 'recover'].includes(action) || execute && execute !== '--apply')
25
+ throw Error('Usage: node restore.mjs <project> [apply|remove|recover] [product] [--apply] [--kit-modules=entry,feature],默认只预览;空模块列表仅移除Kit');
26
+ const { integrationPlan, applyIntegration } = require('./hvigor-plugin.cjs');
27
+ const plan = await integrationPlan(path.resolve(root), { action, product, packageRoot, kitModules });
28
+ if (execute === '--apply') { await applyIntegration(path.resolve(root), plan); console.log('接入计划已应用;请运行 Hvigor quallensQuality 验证'); }
29
+ else console.log(JSON.stringify(plan, null, 2));