@semaphore-protocol/cli 0.2.0 → 0.4.0

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <h1 align="center">
3
3
  Semaphore CLI
4
4
  </h1>
5
- <p align="center">A command line tool to set up your Semaphore project and query groups.</p>
5
+ <p align="center">A command line tool to set up your Semaphore project and get group data.</p>
6
6
  </p>
7
7
 
8
8
  <p align="center">
@@ -46,23 +46,37 @@
46
46
  </h4>
47
47
  </div>
48
48
 
49
- | ... |
50
- | --- |
49
+ | Setting up a project, although not particularly complex, can be a lengthy process for some people. The Semaphore CLI reduces the set-up time from a few minutes to a few seconds. In addition, it can also be used to obtain on-chain group data. |
50
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
51
51
 
52
52
  ## 🛠 Install
53
53
 
54
- ### npm or yarn
55
-
56
- Install the `@semaphore-protocol/cli` package with npm:
54
+ Install the `@semaphore-protocol/cli` package globally:
57
55
 
58
56
  ```bash
59
- npm i @semaphore-protocol/cli
57
+ npm i -g @semaphore-protocol/cli
60
58
  ```
61
59
 
62
- or yarn:
60
+ or run specific commands with `npx`:
63
61
 
64
62
  ```bash
65
- yarn add @semaphore-protocol/cli
63
+ npx @semaphore-protocol/cli init my-app
66
64
  ```
67
65
 
68
66
  ## 📜 Usage
67
+
68
+ ```
69
+ Usage: semaphore [options] [command]
70
+
71
+ A command line tool to set up your Semaphore project and get group data.
72
+
73
+ Options:
74
+ -v, --version Show Semaphore CLI version.
75
+ -h, --help Display this help.
76
+
77
+ Commands:
78
+ init <project-directory> Initialize a Semaphore project with a supported template.
79
+ get-groups [options] Get the list of groups from a supported network (Goerli or Arbitrum).
80
+ get-group [options] <group-id> Get the data of a group from a supported network (Goerli or Arbitrum).
81
+ help [command] Display help for a specific command.
82
+ ```
package/dist/index.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  /**
4
4
  * @module @semaphore-protocol/cli
5
- * @version 0.2.0
6
- * @file A command line tool to set up your Semaphore project and query groups.
5
+ * @version 0.4.0
6
+ * @file A command line tool to set up your Semaphore project and get group data.
7
7
  * @copyright Ethereum Foundation 2022
8
8
  * @license MIT
9
9
  * @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/cli}
@@ -38,10 +38,10 @@ class Spinner {
38
38
  }
39
39
 
40
40
  const packagePath = `${dirname(fileURLToPath(import.meta.url))}/..`;
41
- const { version } = JSON.parse(readFileSync(`${packagePath}/package.json`, "utf8"));
41
+ const { description, version } = JSON.parse(readFileSync(`${packagePath}/package.json`, "utf8"));
42
42
  program
43
43
  .name("semaphore")
44
- .description("A command line tool to set up your Semaphore project and query groups.")
44
+ .description(description)
45
45
  .version(version, "-v, --version", "Show Semaphore CLI version.")
46
46
  .addHelpText("before", `${figlet.textSync("Semaphore")}\n`)
47
47
  .addHelpText("after", "\r")
@@ -58,24 +58,38 @@ program
58
58
  .argument("<project-directory>", "Directory of the project.")
59
59
  // .option("-t, --template <template-name>", "Supported Semaphore template.", "hardhat")
60
60
  .action(async (projectDirectory) => {
61
- // const originalDirectory = process.cwd()
62
- const spinner = new Spinner(`Creating '${projectDirectory}' project`);
61
+ const currentDirectory = process.cwd();
62
+ const spinner = new Spinner(`Creating your project in ${chalk.green(`./${projectDirectory}`)}`);
63
63
  const templateURL = `https://registry.npmjs.org/@semaphore-protocol/cli-template-hardhat/-/cli-template-hardhat-${version}.tgz`;
64
64
  if (existsSync(projectDirectory)) {
65
65
  console.info(`\n ${logSymbols.error}`, `error: the '${projectDirectory}' folder already exists\n`);
66
66
  return;
67
67
  }
68
68
  spinner.start();
69
- await download(templateURL, "./", { extract: true });
70
- renameSync("package", projectDirectory);
69
+ await download(templateURL, currentDirectory, { extract: true });
70
+ renameSync(`${currentDirectory}/package`, `${currentDirectory}/${projectDirectory}`);
71
71
  spinner.stop();
72
- console.info(` ${logSymbols.success}`, `Your '${projectDirectory}' project is ready!\n`);
72
+ console.info(` ${logSymbols.success}`, `Your project is ready!\n`);
73
+ console.info(` Please, install your dependencies by running:\n`);
74
+ console.info(` ${chalk.cyan("cd")} ${projectDirectory}`);
75
+ console.info(` ${chalk.cyan("npm i")}\n`);
76
+ const { scripts } = JSON.parse(readFileSync(`${currentDirectory}/${projectDirectory}/package.json`, "utf8"));
77
+ if (scripts) {
78
+ console.info(` Available scripts:\n`);
79
+ console.info(`${Object.keys(scripts)
80
+ .map((s) => ` ${chalk.cyan(`npm run ${s}`)}`)
81
+ .join("\n")}\n`);
82
+ }
73
83
  });
74
84
  program
75
85
  .command("get-groups")
76
- .description("Get the list of groups from a supported network (Goerli or Arbitrum).")
86
+ .description("Get the list of groups from a supported network (goerli or arbitrum).")
77
87
  .option("-n, --network <network-name>", "Supported Ethereum network.", "goerli")
78
88
  .action(async ({ network }) => {
89
+ if (!["goerli", "arbitrum"].includes(network)) {
90
+ console.info(`\n ${logSymbols.error}`, `error: the network '${network}' is not supported\n`);
91
+ return;
92
+ }
79
93
  const subgraph = new Subgraph(network);
80
94
  const spinner = new Spinner("Fetching groups");
81
95
  spinner.start();
@@ -102,6 +116,10 @@ program
102
116
  .option("--members", "Show group members.")
103
117
  .option("--signals", "Show group signals.")
104
118
  .action(async (groupId, { network, members, signals }) => {
119
+ if (!["goerli", "arbitrum"].includes(network)) {
120
+ console.info(`\n ${logSymbols.error}`, `error: the network '${network}' is not supported\n`);
121
+ return;
122
+ }
105
123
  const subgraph = new Subgraph(network);
106
124
  const spinner = new Spinner(`Fetching group ${groupId}`);
107
125
  spinner.start();
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@semaphore-protocol/cli",
3
3
  "type": "module",
4
- "version": "0.2.0",
5
- "description": "A command line tool to set up your Semaphore project and query groups.",
4
+ "version": "0.4.0",
5
+ "description": "A command line tool to set up your Semaphore project and get group data.",
6
6
  "license": "MIT",
7
7
  "bin": {
8
8
  "semaphore": "dist/index.js"
@@ -32,6 +32,7 @@
32
32
  "access": "public"
33
33
  },
34
34
  "devDependencies": {
35
+ "@types/clear": "^0.1.2",
35
36
  "@types/figlet": "^1.5.5",
36
37
  "rollup-plugin-cleanup": "^3.2.1",
37
38
  "rollup-plugin-typescript2": "^0.31.2",
@@ -40,7 +41,6 @@
40
41
  },
41
42
  "dependencies": {
42
43
  "@semaphore-protocol/subgraph": "2.6.1",
43
- "@types/clear": "^0.1.2",
44
44
  "chalk": "^5.1.2",
45
45
  "commander": "^9.4.1",
46
46
  "download": "^8.0.0",
package/src/index.ts CHANGED
@@ -10,11 +10,11 @@ import { fileURLToPath } from "url"
10
10
  import Spinner from "./spinner.js"
11
11
 
12
12
  const packagePath = `${dirname(fileURLToPath(import.meta.url))}/..`
13
- const { version } = JSON.parse(readFileSync(`${packagePath}/package.json`, "utf8"))
13
+ const { description, version } = JSON.parse(readFileSync(`${packagePath}/package.json`, "utf8"))
14
14
 
15
15
  program
16
16
  .name("semaphore")
17
- .description("A command line tool to set up your Semaphore project and query groups.")
17
+ .description(description)
18
18
  .version(version, "-v, --version", "Show Semaphore CLI version.")
19
19
  .addHelpText("before", `${figlet.textSync("Semaphore")}\n`)
20
20
  .addHelpText("after", "\r")
@@ -32,8 +32,8 @@ program
32
32
  .argument("<project-directory>", "Directory of the project.")
33
33
  // .option("-t, --template <template-name>", "Supported Semaphore template.", "hardhat")
34
34
  .action(async (projectDirectory) => {
35
- // const originalDirectory = process.cwd()
36
- const spinner = new Spinner(`Creating '${projectDirectory}' project`)
35
+ const currentDirectory = process.cwd()
36
+ const spinner = new Spinner(`Creating your project in ${chalk.green(`./${projectDirectory}`)}`)
37
37
  const templateURL = `https://registry.npmjs.org/@semaphore-protocol/cli-template-hardhat/-/cli-template-hardhat-${version}.tgz`
38
38
 
39
39
  if (existsSync(projectDirectory)) {
@@ -43,20 +43,40 @@ program
43
43
 
44
44
  spinner.start()
45
45
 
46
- await download(templateURL, "./", { extract: true })
46
+ await download(templateURL, currentDirectory, { extract: true })
47
47
 
48
- renameSync("package", projectDirectory)
48
+ renameSync(`${currentDirectory}/package`, `${currentDirectory}/${projectDirectory}`)
49
49
 
50
50
  spinner.stop()
51
51
 
52
- console.info(` ${logSymbols.success}`, `Your '${projectDirectory}' project is ready!\n`)
52
+ console.info(` ${logSymbols.success}`, `Your project is ready!\n`)
53
+ console.info(` Please, install your dependencies by running:\n`)
54
+ console.info(` ${chalk.cyan("cd")} ${projectDirectory}`)
55
+ console.info(` ${chalk.cyan("npm i")}\n`)
56
+
57
+ const { scripts } = JSON.parse(readFileSync(`${currentDirectory}/${projectDirectory}/package.json`, "utf8"))
58
+
59
+ if (scripts) {
60
+ console.info(` Available scripts:\n`)
61
+
62
+ console.info(
63
+ `${Object.keys(scripts)
64
+ .map((s) => ` ${chalk.cyan(`npm run ${s}`)}`)
65
+ .join("\n")}\n`
66
+ )
67
+ }
53
68
  })
54
69
 
55
70
  program
56
71
  .command("get-groups")
57
- .description("Get the list of groups from a supported network (Goerli or Arbitrum).")
72
+ .description("Get the list of groups from a supported network (goerli or arbitrum).")
58
73
  .option("-n, --network <network-name>", "Supported Ethereum network.", "goerli")
59
74
  .action(async ({ network }) => {
75
+ if (!["goerli", "arbitrum"].includes(network)) {
76
+ console.info(`\n ${logSymbols.error}`, `error: the network '${network}' is not supported\n`)
77
+ return
78
+ }
79
+
60
80
  const subgraph = new Subgraph(network)
61
81
  const spinner = new Spinner("Fetching groups")
62
82
 
@@ -90,6 +110,11 @@ program
90
110
  .option("--members", "Show group members.")
91
111
  .option("--signals", "Show group signals.")
92
112
  .action(async (groupId, { network, members, signals }) => {
113
+ if (!["goerli", "arbitrum"].includes(network)) {
114
+ console.info(`\n ${logSymbols.error}`, `error: the network '${network}' is not supported\n`)
115
+ return
116
+ }
117
+
93
118
  const subgraph = new Subgraph(network)
94
119
  const spinner = new Spinner(`Fetching group ${groupId}`)
95
120