mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-13 21:07:00 -07:00
feat(ci): generalize publish-bundle action and script
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const rootDir = process.cwd();
|
||||
|
||||
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}`);
|
||||
}
|
||||
|
||||
console.log('Preparing packages for GitHub release...');
|
||||
|
||||
// Update root package.json
|
||||
updatePackageJson('package.json', (pkg) => {
|
||||
pkg.name = '@google-gemini/gemini-cli';
|
||||
});
|
||||
|
||||
// Update @google/gemini-cli-a2a-server
|
||||
updatePackageJson('packages/a2a-server/package.json', (pkg) => {
|
||||
pkg.name = '@google-gemini/gemini-cli-a2a-server';
|
||||
});
|
||||
|
||||
// Update @google/gemini-cli-core
|
||||
updatePackageJson('packages/core/package.json', (pkg) => {
|
||||
pkg.name = '@google-gemini/gemini-cli-core';
|
||||
});
|
||||
|
||||
console.log('Successfully prepared packages for GitHub release.');
|
||||
+38
-34
@@ -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.');
|
||||
|
||||
Reference in New Issue
Block a user