summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Keiji <[email protected]>2025-06-26 23:49:43 +0000
committerGitHub <[email protected]>2025-06-26 23:49:43 +0000
commitbf873a1d85d4400fd22c175db0f3b80a47bc27fb (patch)
tree3d9b24e45e439dba99198de0ab633a7440960e31
parentd9892ada7f313c10f3206d286091803126f3ea72 (diff)
feat: add prepublishOnly checks (#2052)
-rw-r--r--package.json3
-rw-r--r--packages/cli/package.json3
-rw-r--r--packages/core/package.json3
-rw-r--r--scripts/prepare-cli-packagejson.js6
-rw-r--r--scripts/prepublish.js45
5 files changed, 51 insertions, 9 deletions
diff --git a/package.json b/package.json
index 5ff66d8c..e3f670bb 100644
--- a/package.json
+++ b/package.json
@@ -49,7 +49,8 @@
"publish:npm": "npm publish --workspaces ${NPM_PUBLISH_TAG:+--tag=$NPM_PUBLISH_TAG} ${NPM_DRY_RUN:+--dry-run}",
"publish:release": "npm run build:packages && npm run prepare:cli-packagejson && npm run build:sandbox:fast && npm run publish:sandbox && npm run publish:npm",
"telemetry": "node scripts/telemetry.js",
- "start:gcp": "concurrently --raw --kill-others \"npm run telemetry -- --target=gcp\" \"npm start\""
+ "start:gcp": "concurrently --raw --kill-others \"npm run telemetry -- --target=gcp\" \"npm start\"",
+ "prepublishOnly": "node scripts/prepublish.js"
},
"bin": {
"gemini": "bundle/gemini.js"
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 61e9b283..a73223bc 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -20,7 +20,8 @@
"typecheck": "tsc --noEmit",
"prerelease:version": "node ../../scripts/bind_package_version.js",
"prerelease:deps": "node ../../scripts/bind_package_dependencies.js",
- "prepack": "npm run build"
+ "prepack": "npm run build",
+ "prepublishOnly": "node ../../scripts/prepublish.js"
},
"files": [
"dist"
diff --git a/packages/core/package.json b/packages/core/package.json
index 10acb1d0..eb04da88 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -16,7 +16,8 @@
"typecheck": "tsc --noEmit",
"prerelease:version": "node ../../scripts/bind_package_version.js",
"prerelease:deps": "node ../../scripts/bind_package_dependencies.js",
- "prepack": "npm run build"
+ "prepack": "npm run build",
+ "prepublishOnly": "node ../../scripts/prepublish.js"
},
"files": [
"dist"
diff --git a/scripts/prepare-cli-packagejson.js b/scripts/prepare-cli-packagejson.js
index d7960708..33bbb7f8 100644
--- a/scripts/prepare-cli-packagejson.js
+++ b/scripts/prepare-cli-packagejson.js
@@ -46,12 +46,6 @@ if (!cliPackageJson.config) {
}
cliPackageJson.config.sandboxImageUri = containerImageUri;
-// Remove 'prepublishOnly' from scripts if it exists
-if (cliPackageJson.scripts && cliPackageJson.scripts.prepublishOnly) {
- delete cliPackageJson.scripts.prepublishOnly;
- console.log('Removed prepublishOnly script from packages/cli/package.json');
-}
-
fs.writeFileSync(
cliPackageJsonPath,
JSON.stringify(cliPackageJson, null, 2) + '\n',
diff --git a/scripts/prepublish.js b/scripts/prepublish.js
new file mode 100644
index 00000000..f97e450f
--- /dev/null
+++ b/scripts/prepublish.js
@@ -0,0 +1,45 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import fs from 'fs';
+import path from 'path';
+
+const packageJsonPath = path.resolve(process.cwd(), 'package.json');
+const readmePath = path.resolve(process.cwd(), 'README.md');
+const licensePath = path.resolve(process.cwd(), 'LICENSE');
+
+const errors = [];
+
+// 1. Check for package.json and the 'repository' field
+// Required for publishing through wombat-dressing-room
+if (!fs.existsSync(packageJsonPath)) {
+ errors.push(`Error: package.json not found in ${process.cwd()}`);
+} else {
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
+ if (packageJson.repository !== 'google-gemini/gemini-cli') {
+ errors.push(
+ `Error: The "repository" field in ${packageJsonPath} must be "google-gemini/gemini-cli".`,
+ );
+ }
+}
+
+// 2. Check for README.md
+if (!fs.existsSync(readmePath)) {
+ errors.push(`Error: README.md not found in ${process.cwd()}`);
+}
+
+// 3. Check for LICENSE
+if (!fs.existsSync(licensePath)) {
+ errors.push(`Error: LICENSE file not found in ${process.cwd()}`);
+}
+
+if (errors.length > 0) {
+ console.error('Pre-publish checks failed:');
+ errors.forEach((error) => console.error(`- ${error}`));
+ process.exit(1);
+}
+
+console.log('Pre-publish checks passed.');