@fireberry/cli 0.0.3 → 0.0.4

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,49 @@
1
+ name: Publish Fireberry CLI to npm
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ version:
7
+ description: "Version to publish (e.g., 0.0.4)"
8
+ required: true
9
+ type: choice
10
+ options:
11
+ - patch
12
+ - minor
13
+ - major
14
+
15
+ jobs:
16
+ publish:
17
+ runs-on: ubuntu-latest
18
+ permissions:
19
+ contents: read
20
+ id-token: write
21
+
22
+ steps:
23
+ - name: Checkout repository
24
+ uses: actions/checkout@v5
25
+
26
+ - name: Setup Node.js
27
+ uses: actions/setup-node@v4
28
+ with:
29
+ node-version: 22
30
+ registry-url: "https://registry.npmjs.org"
31
+ cache: "npm"
32
+ cache-dependency-path: ${{ github.workspace }}/package-lock.json
33
+
34
+ - name: Install dependencies
35
+ run: npm ci
36
+
37
+ - name: Update version
38
+ run: npm version ${{ github.event.inputs.version }} --no-git-tag-version
39
+
40
+ - name: Build package
41
+ run: npm run build --if-present
42
+
43
+ - name: Run tests
44
+ run: npm test
45
+
46
+ - name: Publish to npm
47
+ run: npm publish --provenance --access public
48
+ env:
49
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/bin/fireberry.js CHANGED
@@ -7,13 +7,13 @@ const program = new Command();
7
7
 
8
8
  program
9
9
  .name("fireberry")
10
- .description("Fireberry developer CLI (demo)")
10
+ .description("Fireberry developer CLI")
11
11
  .version("0.0.1");
12
12
 
13
13
  program
14
14
  .command("init")
15
15
  .argument("[tokenid]", "Fireberry token id")
16
- .description("Initiates credentials and stores token in local config (demo)")
16
+ .description("Initiates credentials and stores token in local config")
17
17
  .action(async (tokenid) => {
18
18
  await runInit({ tokenid });
19
19
  });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import chalk from "chalk";
4
+ import { runInit } from "../commands/init.js";
5
+ import packageJson from "../../package.json" with { type: "json" };
6
+ const program = new Command();
7
+ program
8
+ .name("fireberry")
9
+ .description("Fireberry developer CLI")
10
+ .version(packageJson.version);
11
+ program
12
+ .command("init")
13
+ .argument("[tokenid]", "Fireberry token id")
14
+ .description("Initiates credentials and stores token in local config")
15
+ .action(async (tokenid) => {
16
+ await runInit({ tokenid });
17
+ });
18
+ program.parseAsync(process.argv).catch((err) => {
19
+ const errorMessage = err instanceof Error
20
+ ? err.message
21
+ : typeof err === 'string'
22
+ ? err
23
+ : 'Unexpected error';
24
+ console.error(chalk.red(errorMessage));
25
+ process.exit(1);
26
+ });
@@ -0,0 +1,5 @@
1
+ interface InitOptions {
2
+ tokenid?: string;
3
+ }
4
+ export declare function runInit({ tokenid }?: InitOptions): Promise<void>;
5
+ export {};
@@ -0,0 +1,41 @@
1
+ import inquirer from "inquirer";
2
+ import envPaths from "env-paths";
3
+ import path from "node:path";
4
+ import fs from "fs-extra";
5
+ import ora from "ora";
6
+ import chalk from "chalk";
7
+ export async function runInit({ tokenid } = {}) {
8
+ let token = tokenid;
9
+ if (!token) {
10
+ const answers = await inquirer.prompt([
11
+ {
12
+ type: "password",
13
+ name: "token",
14
+ message: "Enter Fireberry token id",
15
+ mask: "*",
16
+ },
17
+ ]);
18
+ token = answers.token?.trim();
19
+ }
20
+ if (!token) {
21
+ throw new Error("An access token must be provided.");
22
+ }
23
+ const paths = envPaths("Fireberry CLI", { suffix: "" });
24
+ const configDir = paths.config;
25
+ const configFile = path.join(configDir, "config.json");
26
+ const spinner = ora("Saving API Token to local config").start();
27
+ try {
28
+ await fs.ensureDir(configDir);
29
+ const config = {
30
+ apiToken: token,
31
+ createdAt: new Date().toISOString(),
32
+ };
33
+ await fs.writeJson(configFile, config, { spaces: 2 });
34
+ spinner.succeed("Initialized. Token stored locally.");
35
+ console.log(chalk.gray(`Config: ${configFile}`));
36
+ }
37
+ catch (err) {
38
+ spinner.fail("Failed to save token.");
39
+ throw err;
40
+ }
41
+ }
package/package.json CHANGED
@@ -1,18 +1,24 @@
1
1
  {
2
2
  "name": "@fireberry/cli",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Fireberry CLI tool",
5
5
  "type": "module",
6
6
  "author": "",
7
7
  "license": "MIT",
8
8
  "bin": {
9
- "fireberry": "bin/fireberry.js"
9
+ "fireberry": "dist/bin/fireberry.js"
10
10
  },
11
11
  "engines": {
12
12
  "node": ">=18"
13
13
  },
14
14
  "scripts": {
15
- "start": "node bin/fireberry.js"
15
+ "start": "node dist/bin/fireberry.js",
16
+ "build": "tsc",
17
+ "dev": "tsc --watch",
18
+ "clean": "rm -rf dist",
19
+ "prebuild": "npm run clean",
20
+ "prepare": "npm run build",
21
+ "test": "node test/smoke.test.js"
16
22
  },
17
23
  "keywords": [
18
24
  "cli",
@@ -37,5 +43,11 @@
37
43
  "fs-extra": "^11.2.0",
38
44
  "inquirer": "^9.2.12",
39
45
  "ora": "^8.0.1"
46
+ },
47
+ "devDependencies": {
48
+ "@types/fs-extra": "^11.0.4",
49
+ "@types/inquirer": "^9.0.7",
50
+ "@types/node": "^20.11.24",
51
+ "typescript": "^5.3.3"
40
52
  }
41
53
  }
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import chalk from "chalk";
4
+ import { runInit } from "../commands/init.js";
5
+ import packageJson from "../../package.json" with { type: "json" };
6
+
7
+ const program = new Command();
8
+
9
+ program
10
+ .name("fireberry")
11
+ .description("Fireberry developer CLI")
12
+ .version(packageJson.version);
13
+
14
+ program
15
+ .command("init")
16
+ .argument("[tokenid]", "Fireberry token id")
17
+ .description("Initiates credentials and stores token in local config")
18
+ .action(async (tokenid?: string) => {
19
+ await runInit({ tokenid });
20
+ });
21
+
22
+ program.parseAsync(process.argv).catch((err: unknown) => {
23
+ const errorMessage = err instanceof Error
24
+ ? err.message
25
+ : typeof err === 'string'
26
+ ? err
27
+ : 'Unexpected error';
28
+ console.error(chalk.red(errorMessage));
29
+ process.exit(1);
30
+ });
@@ -5,7 +5,16 @@ import fs from "fs-extra";
5
5
  import ora from "ora";
6
6
  import chalk from "chalk";
7
7
 
8
- export async function runInit({ tokenid } = {}) {
8
+ interface InitOptions {
9
+ tokenid?: string;
10
+ }
11
+
12
+ interface Config {
13
+ apiToken: string;
14
+ createdAt: string;
15
+ }
16
+
17
+ export async function runInit({ tokenid }: InitOptions = {}): Promise<void> {
9
18
  let token = tokenid;
10
19
  if (!token) {
11
20
  const answers = await inquirer.prompt([
@@ -26,15 +35,15 @@ export async function runInit({ tokenid } = {}) {
26
35
  const configDir = paths.config;
27
36
  const configFile = path.join(configDir, "config.json");
28
37
 
29
- const spinner = ora("Saving token to local config (demo)").start();
38
+ const spinner = ora("Saving API Token to local config").start();
30
39
  try {
31
40
  await fs.ensureDir(configDir);
32
- const config = {
33
- token,
41
+ const config: Config = {
42
+ apiToken: token,
34
43
  createdAt: new Date().toISOString(),
35
44
  };
36
45
  await fs.writeJson(configFile, config, { spaces: 2 });
37
- spinner.succeed("Initialized. Token stored locally for demo purposes.");
46
+ spinner.succeed("Initialized. Token stored locally.");
38
47
  console.log(chalk.gray(`Config: ${configFile}`));
39
48
  } catch (err) {
40
49
  spinner.fail("Failed to save token.");
@@ -0,0 +1,8 @@
1
+ import { execSync } from "child_process";
2
+
3
+ try {
4
+ execSync("node ./dist/bin/fireberry.js --help", { stdio: "pipe" });
5
+ process.exit(0);
6
+ } catch (error) {
7
+ process.exit(1);
8
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "declaration": true,
13
+ "resolveJsonModule": true
14
+ },
15
+ "include": ["src/**/*", "bin/**/*", "package.json"],
16
+ "exclude": ["node_modules", "dist"]
17
+ }