chore: stabilize Zhinian pilot delivery
This commit is contained in:
@@ -42,17 +42,39 @@ function resolveArch(archEnum) {
|
||||
|
||||
// ── General cleanup ──────────────────────────────────────────────────────────
|
||||
|
||||
function cleanupUnnecessaryFiles(dir) {
|
||||
function pruneOpenClawDocsButKeepRuntimeTemplates(packageRoot) {
|
||||
const docsDir = join(packageRoot, 'docs');
|
||||
const templatesDir = join(docsDir, 'reference', 'templates');
|
||||
if (!existsSync(docsDir)) return false;
|
||||
if (!existsSync(templatesDir)) {
|
||||
rmSync(docsDir, { recursive: true, force: true });
|
||||
return true;
|
||||
}
|
||||
|
||||
const tmpDir = join(packageRoot, '.openclaw-runtime-templates.tmp');
|
||||
rmSync(tmpDir, { recursive: true, force: true });
|
||||
cpSync(templatesDir, tmpDir, { recursive: true, dereference: true });
|
||||
rmSync(docsDir, { recursive: true, force: true });
|
||||
mkdirSync(templatesDir, { recursive: true });
|
||||
cpSync(tmpDir, templatesDir, { recursive: true, dereference: true });
|
||||
rmSync(tmpDir, { recursive: true, force: true });
|
||||
return true;
|
||||
}
|
||||
|
||||
function cleanupUnnecessaryFiles(dir, options = {}) {
|
||||
let removedCount = 0;
|
||||
|
||||
const REMOVE_DIRS = new Set([
|
||||
'test', 'tests', '__tests__', '.github', 'examples', 'example',
|
||||
'__snapshots__', '__image_snapshots__', 'snapshots', 'fixtures', 'fixture',
|
||||
'bench', 'benchmark', 'benchmarks', 'screenshots',
|
||||
]);
|
||||
const REMOVE_FILE_EXTS = ['.d.ts', '.d.ts.map', '.js.map', '.mjs.map', '.ts.map', '.markdown'];
|
||||
const REMOVE_FILE_NAMES = new Set([
|
||||
'.DS_Store', 'README.md', 'CHANGELOG.md', 'LICENSE.md', 'CONTRIBUTING.md',
|
||||
'tsconfig.json', '.npmignore', '.eslintrc', '.prettierrc', '.editorconfig',
|
||||
]);
|
||||
const isEnvFile = (name) => name === '.env' || name.startsWith('.env.');
|
||||
|
||||
function walk(currentDir) {
|
||||
let entries;
|
||||
@@ -62,14 +84,18 @@ function cleanupUnnecessaryFiles(dir) {
|
||||
const fullPath = join(currentDir, entry.name);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
if (REMOVE_DIRS.has(entry.name)) {
|
||||
if (options.preserveOpenClawRuntimeTemplates && fullPath === join(dir, 'docs')) {
|
||||
try {
|
||||
if (pruneOpenClawDocsButKeepRuntimeTemplates(dir)) removedCount++;
|
||||
} catch { /* */ }
|
||||
} else if (REMOVE_DIRS.has(entry.name)) {
|
||||
try { rmSync(fullPath, { recursive: true, force: true }); removedCount++; } catch { /* */ }
|
||||
} else {
|
||||
walk(fullPath);
|
||||
}
|
||||
} else if (entry.isFile()) {
|
||||
const name = entry.name;
|
||||
if (REMOVE_FILE_NAMES.has(name) || REMOVE_FILE_EXTS.some(e => name.endsWith(e))) {
|
||||
if (isEnvFile(name) || REMOVE_FILE_NAMES.has(name) || REMOVE_FILE_EXTS.some(e => name.endsWith(e))) {
|
||||
try { rmSync(fullPath, { force: true }); removedCount++; } catch { /* */ }
|
||||
}
|
||||
}
|
||||
@@ -199,6 +225,45 @@ function cleanupNativePlatformPackages(nodeModulesDir, platform, arch) {
|
||||
return removed;
|
||||
}
|
||||
|
||||
function cleanupNestedPrebuilds(rootDir, platform, arch) {
|
||||
let removed = 0;
|
||||
const keepPrefix = `${platform}-${arch}`;
|
||||
const keepUniversal = `${platform}-universal`;
|
||||
|
||||
function walk(dir) {
|
||||
let entries;
|
||||
try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return; }
|
||||
|
||||
for (const entry of entries) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
const fullPath = join(dir, entry.name);
|
||||
if (entry.name === 'prebuilds') {
|
||||
let prebuildEntries;
|
||||
try { prebuildEntries = readdirSync(fullPath, { withFileTypes: true }); } catch { continue; }
|
||||
for (const prebuild of prebuildEntries) {
|
||||
if (!prebuild.isDirectory()) continue;
|
||||
const isTarget =
|
||||
prebuild.name === keepPrefix ||
|
||||
prebuild.name.startsWith(`${keepPrefix}-`) ||
|
||||
prebuild.name === keepUniversal ||
|
||||
prebuild.name.startsWith(`${keepUniversal}-`);
|
||||
if (!isTarget) {
|
||||
try {
|
||||
rmSync(join(fullPath, prebuild.name), { recursive: true, force: true });
|
||||
removed++;
|
||||
} catch { /* */ }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
walk(fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
walk(rootDir);
|
||||
return removed;
|
||||
}
|
||||
|
||||
function removeOptionalNativeClipboard(nodeModulesDir) {
|
||||
const scopeDir = join(nodeModulesDir, '@mariozechner');
|
||||
if (!existsSync(scopeDir)) return 0;
|
||||
@@ -713,7 +778,7 @@ exports.default = async function afterPack(context) {
|
||||
|
||||
// 2. General cleanup on the full openclaw directory (not just node_modules)
|
||||
console.log('[after-pack] 🧹 Cleaning up unnecessary files ...');
|
||||
const removedRoot = cleanupUnnecessaryFiles(openclawRoot);
|
||||
const removedRoot = cleanupUnnecessaryFiles(openclawRoot, { preserveOpenClawRuntimeTemplates: true });
|
||||
console.log(`[after-pack] ✅ Removed ${removedRoot} unnecessary files/directories.`);
|
||||
|
||||
// 3. Platform-specific: strip koffi non-target platform binaries
|
||||
@@ -728,6 +793,11 @@ exports.default = async function afterPack(context) {
|
||||
console.log(`[after-pack] ✅ Removed ${nativeRemoved} non-target native platform packages.`);
|
||||
}
|
||||
|
||||
const prebuildsRemoved = cleanupNestedPrebuilds(dest, platform, arch);
|
||||
if (prebuildsRemoved > 0) {
|
||||
console.log(`[after-pack] ✅ Removed ${prebuildsRemoved} non-target nested prebuild directories.`);
|
||||
}
|
||||
|
||||
// 5. Patch lru-cache in app.asar.unpacked
|
||||
//
|
||||
// Production dependencies (electron-updater → semver → lru-cache@6,
|
||||
|
||||
Reference in New Issue
Block a user