mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-05 07:37:50 -07:00
perf(build): optimize build speed and parallelize asset copying
This commit is contained in:
+25
-2
@@ -18,7 +18,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
import { execSync } from 'node:child_process';
|
||||
import { existsSync } from 'node:fs';
|
||||
import { existsSync, writeFileSync, readdirSync, statSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
@@ -31,8 +31,19 @@ if (!existsSync(join(root, 'node_modules'))) {
|
||||
}
|
||||
|
||||
// build all workspaces/packages
|
||||
console.log('Generating commit info...');
|
||||
execSync('npm run generate', { stdio: 'inherit', cwd: root });
|
||||
execSync('npm run build --workspaces', { stdio: 'inherit', cwd: root });
|
||||
|
||||
console.log('Building TypeScript packages (incremental)...');
|
||||
execSync('npx tsc -b', { stdio: 'inherit', cwd: root });
|
||||
|
||||
console.log(
|
||||
'Running asset copy and package-specific build steps in parallel...',
|
||||
);
|
||||
execSync('npx npm-run-all --parallel build:assets build:clients build:devs', {
|
||||
stdio: 'inherit',
|
||||
cwd: root,
|
||||
});
|
||||
|
||||
// also build container image if sandboxing is enabled
|
||||
// skip (-s) npm install + build since we did that above
|
||||
@@ -53,3 +64,15 @@ try {
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
// Final step: update the .last_build timestamp for all packages to ensure
|
||||
// they are newer than any files modified during the build (like git-commit.ts).
|
||||
console.log('Updating build timestamps...');
|
||||
const packagesDir = join(root, 'packages');
|
||||
const packages = readdirSync(packagesDir);
|
||||
for (const pkg of packages) {
|
||||
const distDir = join(packagesDir, pkg, 'dist');
|
||||
if (existsSync(distDir) && statSync(distDir).isDirectory()) {
|
||||
writeFileSync(join(distDir, '.last_build'), '');
|
||||
}
|
||||
}
|
||||
|
||||
+15
-27
@@ -18,41 +18,29 @@
|
||||
// limitations under the License.
|
||||
|
||||
import { execSync } from 'node:child_process';
|
||||
import { writeFileSync, existsSync, cpSync } from 'node:fs';
|
||||
import { join, basename } from 'node:path';
|
||||
import { writeFileSync, existsSync, readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
|
||||
if (!process.cwd().includes('packages')) {
|
||||
console.error('must be invoked from a package directory');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const packageName = basename(process.cwd());
|
||||
// build typescript files incrementally
|
||||
execSync('tsc -b', { stdio: 'inherit' });
|
||||
|
||||
// build typescript files
|
||||
execSync('tsc --build', { stdio: 'inherit' });
|
||||
|
||||
// Run package-specific bundling if the script exists
|
||||
const bundleScript = join(process.cwd(), 'scripts', 'bundle-browser-mcp.mjs');
|
||||
if (packageName === 'core' && existsSync(bundleScript)) {
|
||||
console.log('Running chrome devtools MCP bundling...');
|
||||
execSync('npm run bundle:browser-mcp', {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
}
|
||||
|
||||
// copy .{md,json} files
|
||||
execSync('node ../../scripts/copy_files.js', { stdio: 'inherit' });
|
||||
|
||||
// Copy documentation for the core package
|
||||
if (packageName === 'core') {
|
||||
const docsSource = join(process.cwd(), '..', '..', 'docs');
|
||||
const docsTarget = join(process.cwd(), 'dist', 'docs');
|
||||
if (existsSync(docsSource)) {
|
||||
cpSync(docsSource, docsTarget, { recursive: true, dereference: true });
|
||||
console.log('Copied documentation to dist/docs');
|
||||
}
|
||||
// Check for copy:assets script in package.json
|
||||
const packageJson = JSON.parse(readFileSync('package.json', 'utf8'));
|
||||
if (packageJson.scripts && packageJson.scripts['copy:assets']) {
|
||||
execSync('npm run copy:assets', { stdio: 'inherit' });
|
||||
} else {
|
||||
// fallback to generic copy
|
||||
execSync('node ../../scripts/copy_files.js', { stdio: 'inherit' });
|
||||
}
|
||||
|
||||
// touch dist/.last_build
|
||||
writeFileSync(join(process.cwd(), 'dist', '.last_build'), '');
|
||||
const distDir = join(process.cwd(), 'dist');
|
||||
if (existsSync(distDir)) {
|
||||
writeFileSync(join(distDir, '.last_build'), '');
|
||||
}
|
||||
process.exit(0);
|
||||
|
||||
@@ -81,6 +81,14 @@ if (packageName === 'core') {
|
||||
if (fs.existsSync(builtinSkillsSource)) {
|
||||
fs.cpSync(builtinSkillsSource, builtinSkillsTarget, { recursive: true });
|
||||
}
|
||||
|
||||
// Copy documentation for the core package
|
||||
const docsSource = path.join(process.cwd(), '..', '..', 'docs');
|
||||
const docsTarget = path.join(process.cwd(), 'dist', 'docs');
|
||||
if (fs.existsSync(docsSource)) {
|
||||
fs.cpSync(docsSource, docsTarget, { recursive: true, dereference: true });
|
||||
console.log('Copied documentation to dist/docs');
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Successfully copied files.');
|
||||
|
||||
Reference in New Issue
Block a user