summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bind_package_dependencies.js50
-rw-r--r--scripts/bind_package_version.js50
2 files changed, 100 insertions, 0 deletions
diff --git a/scripts/bind_package_dependencies.js b/scripts/bind_package_dependencies.js
new file mode 100644
index 00000000..eb9a4cc6
--- /dev/null
+++ b/scripts/bind_package_dependencies.js
@@ -0,0 +1,50 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import fs from 'node:fs';
+import path from 'node:path';
+import _ from 'lodash';
+
+function bindPackageDependencies() {
+ const scriptDir = process.cwd();
+ const currentPkgJsonPath = path.join(scriptDir, 'package.json');
+ const currentPkg = JSON.parse(fs.readFileSync(currentPkgJsonPath));
+ // assume packages are all under /<repo_root>/packages/
+ const packagesDir = path.join(path.dirname(scriptDir));
+
+ const geminiCodePkgs = fs
+ .readdirSync(packagesDir)
+ .filter(
+ (name) =>
+ fs.statSync(path.join(packagesDir, name)).isDirectory() &&
+ fs.existsSync(path.join(packagesDir, name, 'package.json')),
+ )
+ .map((packageDirname) => {
+ const packageJsonPath = path.join(
+ packagesDir,
+ packageDirname,
+ 'package.json',
+ );
+ return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
+ })
+ .reduce((pkgs, pkg) => ({ ...pkgs, [pkg.name]: pkg }), {});
+ currentPkg.dependencies = _.mapValues(
+ currentPkg.dependencies,
+ (value, key) => {
+ if (geminiCodePkgs[key]) {
+ console.log(
+ `Package ${currentPkg.name} has a dependency on ${key}. Updating dependent version.`,
+ );
+ return geminiCodePkgs[key].version;
+ }
+ return value;
+ },
+ );
+ const updatedPkgJson = JSON.stringify(currentPkg, null, 2) + '\n';
+ fs.writeFileSync(currentPkgJsonPath, updatedPkgJson);
+}
+
+bindPackageDependencies();
diff --git a/scripts/bind_package_version.js b/scripts/bind_package_version.js
new file mode 100644
index 00000000..51df72ce
--- /dev/null
+++ b/scripts/bind_package_version.js
@@ -0,0 +1,50 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import fs from 'node:fs';
+import path from 'node:path';
+
+// Assuming script is run from a package directory (e.g., packages/cli)
+const packageDir = process.cwd();
+const rootDir = path.join(packageDir, '..', '..'); // Go up two directories to find the repo root
+
+function getBaseVersion() {
+ // Read root package.json
+ const rootPackageJsonPath = path.join(rootDir, 'package.json');
+ const rootPackage = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8'));
+ let baseVersion = rootPackage.version;
+
+ // Append nightly suffix
+ const today = new Date();
+ const yyyy = today.getFullYear();
+ const mm = String(today.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed
+ const dd = String(today.getDate()).padStart(2, '0');
+ const nightlySuffix = `-nightly-${yyyy}${mm}${dd}`;
+ return `${baseVersion}${nightlySuffix}`;
+}
+
+const newVersion = getBaseVersion();
+console.log(`Setting package version to: ${newVersion}`);
+
+const packageJsonPath = path.join(packageDir, 'package.json');
+
+if (fs.existsSync(packageJsonPath)) {
+ console.log(`Updating version for ${packageJsonPath}`);
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
+ packageJson.version = newVersion;
+ fs.writeFileSync(
+ packageJsonPath,
+ JSON.stringify(packageJson, null, 2) + '\n',
+ 'utf8',
+ );
+} else {
+ console.error(
+ `Error: package.json not found in the current directory: ${packageJsonPath}`,
+ );
+ process.exit(1);
+}
+
+console.log('Done.');