@semaphore-protocol/cli 4.4.1 → 4.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  * @module @semaphore-protocol/cli
5
- * @version 4.4.1
5
+ * @version 4.4.2
6
6
  * @file A command line tool to set up your Semaphore project and get group data.
7
7
  * @copyright Ethereum Foundation 2024
8
8
  * @license MIT
@@ -170,6 +170,24 @@ async function getGroupId(groupIds) {
170
170
  return selectedGroupId;
171
171
  }
172
172
 
173
+ // Remove the prepublish script from the package.json file when creating a new project using the Semaphore CLI.
174
+ function removePrePublishScript(packageJsonContent) {
175
+ try {
176
+ const packageJson = JSON.parse(packageJsonContent);
177
+ if (packageJson.scripts && "prepublish" in packageJson.scripts) {
178
+ delete packageJson.scripts.prepublish;
179
+ if (Object.keys(packageJson.scripts).length === 0) {
180
+ delete packageJson.scripts;
181
+ }
182
+ }
183
+ return JSON.stringify(packageJson, null, 2);
184
+ }
185
+ catch (error) {
186
+ console.error("Error processing package.json:", error);
187
+ return packageJsonContent;
188
+ }
189
+ }
190
+
173
191
  // Define the path to the package.json file to extract metadata for the CLI.
174
192
  const packagePath = `${dirname(fileURLToPath(import.meta.url))}/..`;
175
193
  const { description, version } = JSON.parse(readFileSync(`${packagePath}/package.json`, "utf8"));
@@ -238,13 +256,18 @@ program
238
256
  copyFileSync(`${currentDirectory}/${projectDirectory}/.env.example`, `${currentDirectory}/${projectDirectory}/.env`);
239
257
  // Create an empty yarn.lock file to install dependencies successfully
240
258
  writeFileSync(`${currentDirectory}/${projectDirectory}/yarn.lock`, "");
259
+ // Read and modify package.json to remove prepublish script
260
+ const packageJsonPath = `${currentDirectory}/${projectDirectory}/package.json`;
261
+ const packageJsonContent = readFileSync(packageJsonPath, "utf8");
262
+ const updatedPackageJsonContent = removePrePublishScript(packageJsonContent);
263
+ writeFileSync(packageJsonPath, updatedPackageJsonContent);
241
264
  spinner.stop();
242
265
  console.info(`\n ${logSymbols.success}`, `Your project is ready!\n`);
243
266
  console.info(` Please, install your dependencies by running:\n`);
244
267
  console.info(` ${chalk.cyan("cd")} ${projectDirectory}`);
245
268
  console.info(` ${chalk.cyan("yarn install")}\n`);
246
269
  // Read the package.json to list available npm scripts.
247
- const { scripts } = JSON.parse(readFileSync(`${currentDirectory}/${projectDirectory}/package.json`, "utf8"));
270
+ const { scripts } = JSON.parse(updatedPackageJsonContent);
248
271
  if (scripts) {
249
272
  console.info(` Available scripts:\n`);
250
273
  console.info(`${Object.keys(scripts)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@semaphore-protocol/cli",
3
3
  "type": "module",
4
- "version": "4.4.1",
4
+ "version": "4.4.2",
5
5
  "description": "A command line tool to set up your Semaphore project and get group data.",
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -41,8 +41,8 @@
41
41
  "rollup-plugin-cleanup": "^3.2.1"
42
42
  },
43
43
  "dependencies": {
44
- "@semaphore-protocol/data": "4.4.1",
45
- "@semaphore-protocol/utils": "4.4.1",
44
+ "@semaphore-protocol/data": "4.4.2",
45
+ "@semaphore-protocol/utils": "4.4.2",
46
46
  "axios": "^1.6.7",
47
47
  "boxen": "^7.1.1",
48
48
  "chalk": "^5.3.0",
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@ import checkLatestVersion from "./checkLatestVersion.js"
13
13
  import getGroupIds from "./getGroupIds.js"
14
14
  import { getGroupId, getProjectName, getSupportedNetwork, getSupportedTemplate } from "./inquirerPrompts.js"
15
15
  import Spinner from "./spinner.js"
16
+ import removePrePublishScript from "./removePrePublishScript.js"
16
17
 
17
18
  // Define the path to the package.json file to extract metadata for the CLI.
18
19
  const packagePath = `${dirname(fileURLToPath(import.meta.url))}/..`
@@ -103,6 +104,12 @@ program
103
104
  // Create an empty yarn.lock file to install dependencies successfully
104
105
  writeFileSync(`${currentDirectory}/${projectDirectory}/yarn.lock`, "")
105
106
 
107
+ // Read and modify package.json to remove prepublish script
108
+ const packageJsonPath = `${currentDirectory}/${projectDirectory}/package.json`
109
+ const packageJsonContent = readFileSync(packageJsonPath, "utf8")
110
+ const updatedPackageJsonContent = removePrePublishScript(packageJsonContent)
111
+ writeFileSync(packageJsonPath, updatedPackageJsonContent)
112
+
106
113
  spinner.stop()
107
114
 
108
115
  console.info(`\n ${logSymbols.success}`, `Your project is ready!\n`)
@@ -111,7 +118,7 @@ program
111
118
  console.info(` ${chalk.cyan("yarn install")}\n`)
112
119
 
113
120
  // Read the package.json to list available npm scripts.
114
- const { scripts } = JSON.parse(readFileSync(`${currentDirectory}/${projectDirectory}/package.json`, "utf8"))
121
+ const { scripts } = JSON.parse(updatedPackageJsonContent)
115
122
 
116
123
  if (scripts) {
117
124
  console.info(` Available scripts:\n`)
@@ -0,0 +1,16 @@
1
+ // Remove the prepublish script from the package.json file when creating a new project using the Semaphore CLI.
2
+ export default function removePrePublishScript(packageJsonContent: string): string {
3
+ try {
4
+ const packageJson = JSON.parse(packageJsonContent)
5
+ if (packageJson.scripts && "prepublish" in packageJson.scripts) {
6
+ delete packageJson.scripts.prepublish
7
+ if (Object.keys(packageJson.scripts).length === 0) {
8
+ delete packageJson.scripts
9
+ }
10
+ }
11
+ return JSON.stringify(packageJson, null, 2)
12
+ } catch (error) {
13
+ console.error("Error processing package.json:", error)
14
+ return packageJsonContent
15
+ }
16
+ }