feat(ci): generalize publish-bundle action and script

This commit is contained in:
mkorwel
2025-10-28 12:43:10 -07:00
parent 1666218952
commit 3fa8a7e9fd
9 changed files with 593 additions and 180 deletions
+38 -34
View File
@@ -6,46 +6,50 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
// ES module equivalent of __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootDir = process.cwd();
const rootDir = path.resolve(__dirname, '..');
function copyFiles(packageName, filesToCopy) {
const packageDir = path.resolve(rootDir, 'packages', packageName);
if (!fs.existsSync(packageDir)) {
console.error(`Error: Package directory not found at ${packageDir}`);
process.exit(1);
}
console.log(`Preparing package: ${packageName}`);
for (const [source, dest] of Object.entries(filesToCopy)) {
const sourcePath = path.resolve(rootDir, source);
const destPath = path.resolve(packageDir, dest);
try {
fs.copyFileSync(sourcePath, destPath);
console.log(`Copied ${source} to packages/${packageName}/`);
} catch (err) {
console.error(`Error copying ${source}:`, err);
process.exit(1);
}
function getArg(name) {
const arg = process.argv.find((arg) => arg.startsWith(name));
if (!arg) {
return null;
}
return arg.split('=')[1];
}
// Prepare 'core' package
copyFiles('core', {
'README.md': 'README.md',
LICENSE: 'LICENSE',
'.npmrc': '.npmrc',
function updatePackageJson(packagePath, updateFn) {
const packageJsonPath = path.resolve(rootDir, packagePath);
if (!fs.existsSync(packageJsonPath)) {
console.error(`Error: package.json not found at ${packageJsonPath}`);
process.exit(1);
}
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
updateFn(packageJson);
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
console.log(`Updated ${packagePath}`);
}
const scope = getArg('--scope');
if (!scope) {
console.error('Error: --scope argument is required.');
process.exit(1);
}
console.log(`Preparing packages with scope: ${scope}...`);
// Update root package.json
updatePackageJson('package.json', (pkg) => {
pkg.name = `${scope}/gemini-cli`;
});
// Prepare 'cli' package
copyFiles('cli', {
'README.md': 'README.md',
LICENSE: 'LICENSE',
// Update @google/gemini-cli-a2a-server
updatePackageJson('packages/a2a-server/package.json', (pkg) => {
pkg.name = `${scope}/gemini-cli-a2a-server`;
});
console.log('Successfully prepared all packages.');
// Update @google/gemini-cli-core
updatePackageJson('packages/core/package.json', (pkg) => {
pkg.name = `${scope}/gemini-cli-core`;
});
console.log('Successfully prepared packages.');