#!/usr/bin/env ts-node import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; import { execSync, ExecSyncOptions } from 'child_process'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const workspaceRoot = path.resolve(__dirname, '.'); const rootOutputOptions: ExecSyncOptions = { encoding: 'utf8' } // 获取sqlite3 module list function getModuleList() { const output = execSync(`find node_modules/.pnpm -path '*/build' -prune -o -type d -name 'sqlite3' -print`, rootOutputOptions) as string; return output.split('\n').map(s => s.trim()).filter(s => s) } // 检查 build 是否存在 function hasBuilt(modPath: string): boolean { const buildPath = path.resolve(workspaceRoot, modPath, 'build') console.log({buildPath}); return fs.existsSync(buildPath); } function buildPackage(modPath: string) { const realPath = path.resolve(workspaceRoot, modPath) console.log(`[splite3] 正在构建包...${realPath}`); const pkgOptions: ExecSyncOptions = { cwd: realPath, stdio: 'inherit' } // 进入子包目录,执行 build 脚本 execSync(`pnpm run rebuild`, pkgOptions); } // 主流程 (function main() { const moduleList = getModuleList() if (moduleList.length === 0) return console.log(`[splite3] 获取路径:\n${moduleList}`); moduleList.forEach(modPath => { if (!hasBuilt(modPath)) { buildPackage(modPath) } }) })();