genlayer 0.0.1 → 0.0.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.
@@ -0,0 +1,32 @@
1
+ name: Release & Publish Package to NPM
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches:
7
+ - 8-cli-github-action-to-manage-release-process-to-npm
8
+
9
+ jobs:
10
+ release:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout source code
14
+ uses: actions/checkout@v2
15
+ - name: Setup Node.js
16
+ uses: actions/setup-node@v2
17
+ with:
18
+ node-version: "18"
19
+ - name: Install the dependencies
20
+ run: npm ci
21
+ - name: Initialize Git User
22
+ run: |
23
+ git config --global user.email "github-actions[bot]@genlayer.com"
24
+ git config --global user.name "github-actions[bot]"
25
+ - name: Initialize the NPM configuration
26
+ run: npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN
27
+ env:
28
+ NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
29
+ - run: npm run release
30
+ env:
31
+ GITHUB_TOKEN: ${{ secrets.REPO_PERSONAL_ACCESS_TOKEN }}
32
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
@@ -0,0 +1,64 @@
1
+ {
2
+ "git": {
3
+ "commitMessage": "Release v${version}",
4
+ "tagName": "v${version}",
5
+ "requireCleanWorkingDir": false,
6
+ "requireUpstream": false,
7
+ "requireCommits": false,
8
+ "push": true
9
+ },
10
+ "github": {
11
+ "release": true,
12
+ "tokenRef": "GITHUB_TOKEN"
13
+ },
14
+ "npm": {
15
+ "publish": true
16
+ },
17
+ "plugins": {
18
+ "@release-it/conventional-changelog": {
19
+ "preset": "conventionalcommits",
20
+ "infile": "CHANGELOG.md",
21
+ "types": [
22
+ {
23
+ "type": "feat",
24
+ "section": "Features"
25
+ },
26
+ {
27
+ "type": "fix",
28
+ "section": "Bug Fixes"
29
+ },
30
+ {
31
+ "type": "chore",
32
+ "section": "Improvement Tasks"
33
+ },
34
+ {
35
+ "type": "ci",
36
+ "section": "Continuous Integration"
37
+ },
38
+ {
39
+ "type": "docs",
40
+ "section": "Documentation"
41
+ },
42
+ {
43
+ "type": "style",
44
+ "section": "Styles"
45
+ },
46
+ {
47
+ "type": "refactor",
48
+ "section": "Refactor Tasks"
49
+ },
50
+ {
51
+ "type": "perf",
52
+ "section": "Performance Improvements"
53
+ },
54
+ {
55
+ "type": "test",
56
+ "section": "Testing"
57
+ }
58
+ ]
59
+ }
60
+ },
61
+ "hooks": {
62
+ "after:bump": "npm run build"
63
+ }
64
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+
2
+
3
+ ## 0.0.2 (2024-04-23)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * updated package name ([e27a6b8](https://github.com/yeagerai/genlayer-cli/commit/e27a6b86201771eb39c6fe221df1d9c287c66418))
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ context: {
3
+ tsconfig: "./tsconfig.json",
4
+ entryPoints: ["src/index.ts"],
5
+ bundle: true, // Bundle all dependencies
6
+ outfile: "dist/index.js", // Output file
7
+ platform: "node",
8
+ target: "es6",
9
+ },
10
+ watch: true,
11
+ };
package/esbuild.config.js CHANGED
@@ -1,17 +1,14 @@
1
1
  const esbuild = require("esbuild");
2
+ const isProduction = process.env.NODE_ENV === "production";
3
+ const config = require(isProduction ? "./esbuild.config.prod" : "./esbuild.config.dev");
2
4
 
3
5
  const run = async () => {
4
- // Start build with esbuild
5
- const context = await esbuild.context({
6
- tsconfig: "./tsconfig.json",
7
- entryPoints: ["src/index.ts"],
8
- bundle: true, // Bundle all dependencies
9
- outfile: "dist/index.js", // Output file
10
- platform: "node",
11
- target: "es6",
12
- });
13
-
14
- await context.watch();
6
+ if (config.watch) {
7
+ const context = await esbuild.context(config.context);
8
+ await context.watch();
9
+ } else {
10
+ await esbuild.build(config.context);
11
+ }
15
12
  };
16
13
 
17
14
  run().catch(e => {
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ context: {
3
+ tsconfig: "./tsconfig.json",
4
+ entryPoints: ["src/index.ts"],
5
+ bundle: true, // Bundle all dependencies
6
+ outfile: "dist/index.js", // Output file
7
+ platform: "node",
8
+ target: "es6",
9
+ },
10
+ watch: false,
11
+ };
package/jest.config.js CHANGED
@@ -1,5 +1,8 @@
1
1
  /** @type {import('ts-jest').JestConfigWithTsJest} */
2
2
  module.exports = {
3
- preset: 'ts-jest',
4
- testEnvironment: 'node',
5
- };
3
+ preset: "ts-jest",
4
+ testEnvironment: "node",
5
+ moduleNameMapper: {
6
+ "^@/(.*)$": "<rootDir>/src/$1",
7
+ },
8
+ };
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "genlayer",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "GenLayer Command Line Tool",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
7
7
  "test": "jest",
8
- "dev": "node esbuild.config.js"
8
+ "dev": "node esbuild.config.js",
9
+ "build": "cross-env NODE_ENV=production node esbuild.config.js",
10
+ "release": "release-it --ci"
9
11
  },
10
12
  "repository": {
11
13
  "type": "git",
@@ -25,12 +27,14 @@
25
27
  },
26
28
  "homepage": "https://github.com/yeagerai/genlayer-cli#readme",
27
29
  "devDependencies": {
30
+ "@release-it/conventional-changelog": "^8.0.1",
28
31
  "@types/inquirer": "^9.0.7",
29
32
  "@types/jest": "^29.5.12",
30
33
  "@types/node": "^20.12.7",
31
34
  "@types/sinon": "^17.0.3",
32
35
  "@typescript-eslint/eslint-plugin": "^7.7.0",
33
36
  "@typescript-eslint/parser": "^7.7.0",
37
+ "cross-env": "^7.0.3",
34
38
  "esbuild": "^0.20.2",
35
39
  "eslint": "^8.57.0",
36
40
  "eslint-config-prettier": "^9.1.0",
@@ -38,7 +42,7 @@
38
42
  "eslint-plugin-import": "^2.29.1",
39
43
  "jest": "^29.7.0",
40
44
  "prettier": "^3.2.5",
41
- "sinon": "^17.0.1",
45
+ "release-it": "^17.2.0",
42
46
  "ts-jest": "^29.1.2",
43
47
  "ts-node": "^10.9.2",
44
48
  "typescript": "^5.4.5"
@@ -47,8 +51,5 @@
47
51
  "commander": "^12.0.0",
48
52
  "inquirer": "^9.2.19",
49
53
  "node-fetch": "^3.3.2"
50
- },
51
- "directories": {
52
- "test": "tests"
53
54
  }
54
55
  }
@@ -6,7 +6,7 @@ export function initializeGeneralCommands(program: Command) {
6
6
  program
7
7
  .command("init")
8
8
  .description("Initialize the GenLayer Environment")
9
- .option("-n, --numValidators <numValidators>", "Number of validators")
9
+ .option("-n, --numValidators <numValidators>", "Number of validators", "5")
10
10
  .action(initAction);
11
11
  return program;
12
12
  }
@@ -1,7 +1,7 @@
1
1
  import {program} from "commander";
2
2
 
3
3
  import {initializeGeneralCommands} from "../../src/commands/general";
4
- import {getCommand} from "../utils";
4
+ import {getCommand, getCommandOption} from "../utils";
5
5
 
6
6
  jest.mock("inquirer", () => ({
7
7
  prompt: jest.fn().mockResolvedValue({}),
@@ -29,6 +29,12 @@ describe("init command", () => {
29
29
  expect(() => program.parse(["node", "test", "init", "--numValidators", "10"])).not.toThrow();
30
30
  });
31
31
 
32
+ test("option -n, --numValidators default value is 5", async () => {
33
+ // Given // When
34
+ const numValidatorsOption = getCommandOption(initCommand, "--numValidators");
35
+ expect(numValidatorsOption?.defaultValue).toBe("5");
36
+ });
37
+
32
38
  test("random option is not accepted", async () => {
33
39
  initCommand?.exitOverride();
34
40
  expect(() => program.parse(["node", "test", "init", "-random"])).toThrow(
package/tests/utils.ts CHANGED
@@ -1,5 +1,13 @@
1
- import {Command, program} from "commander";
1
+ import {Command, Option, program} from "commander";
2
2
 
3
- export function getCommand(commandName: string): Command | undefined {
4
- return program.commands.find(command => command.name() === commandName);
3
+ export function getCommand(commandName: string): Command {
4
+ const command = program.commands.find(command => command.name() === commandName);
5
+ if (!command) {
6
+ throw new Error(`Command ${commandName} not found`);
7
+ }
8
+ return command;
9
+ }
10
+
11
+ export function getCommandOption(command: Command, optionName: string): Option | undefined {
12
+ return command.options.find(option => option.long === optionName);
5
13
  }