新增中台关卡测试包导出
This commit is contained in:
+11
-2
@@ -7,7 +7,7 @@
|
||||
return Array.from(new Uint8Array(digest), value => value.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
async function create(prepared, mode = 'changes') {
|
||||
if (!['changes', 'all'].includes(mode)) throw new Error('导出范围无效');
|
||||
if (!['changes', 'all', 'staging'].includes(mode)) throw new Error('导出范围无效');
|
||||
const { data, files, package: bundle } = prepared, hashes = new Map(), uuids = new Map();
|
||||
const uuid = name => {
|
||||
if (!uuids.has(name)) {
|
||||
@@ -22,11 +22,20 @@
|
||||
await Promise.all([...hashes.keys()].map(async text => hashes.set(text, await sha256(text))));
|
||||
const writes = Object.fromEntries(Object.entries(ProjectFiles.plan(data, files, bundle, text => hashes.get(text), uuid)).filter(([name]) => name.endsWith('.json')));
|
||||
const changedCount = Object.keys(writes).length;
|
||||
if (mode === 'all') {
|
||||
if (mode !== 'changes') {
|
||||
for (const [name, text] of Object.entries(files)) {
|
||||
if (name.endsWith('.json') && !writes[name]) writes[name] = { before: text, text };
|
||||
}
|
||||
}
|
||||
if (mode === 'staging') {
|
||||
const revision = 'test-' + uuid('中台批次');
|
||||
const archive = Object.fromEntries(Object.entries(writes)
|
||||
.filter(([name]) => name.startsWith(ProjectFiles.directory))
|
||||
.map(([name, value]) => [revision + '/' + name.slice(ProjectFiles.directory.length), encode(value.text)]));
|
||||
archive['release.json'] = encode(JSON.stringify({ schemaVersion: 1, revision }) + '\n');
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
return { bytes: fflate.zipSync(archive, { level: 6 }), revision };
|
||||
}
|
||||
if (!Object.keys(writes).length) throw new Error('没有变更的 JSON,请选择“导出全部 JSON”');
|
||||
const manifest = { formatVersion: 1, createdAt: new Date().toISOString(), dataVersion: data.dataVersion,
|
||||
rulesVersion: data.rulesVersion, levelCount: bundle.order.length, exportMode: mode, changedCount,
|
||||
|
||||
Reference in New Issue
Block a user