@fireberry/cli 0.0.5-beta.7 → 0.0.5-beta.8

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/api/axios.js CHANGED
@@ -2,7 +2,6 @@ import "../config/env.js";
2
2
  import axios from "axios";
3
3
  import { getApiToken } from "./config.js";
4
4
  import packageJson from "../../package.json" with { type: "json" };
5
- // Determine default API URL based on version
6
5
  const getDefaultApiUrl = () => {
7
6
  if (process.env.FIREBERRY_API_URL) {
8
7
  return process.env.FIREBERRY_API_URL;
@@ -26,7 +25,7 @@ fbApi.interceptors.request.use(async (config) => {
26
25
  try {
27
26
  const token = await getApiToken();
28
27
  if (token) {
29
- config.headers.tokenid = token;
28
+ config.headers.tokenId = token;
30
29
  }
31
30
  }
32
31
  catch (error) {
@@ -1,3 +1,4 @@
1
1
  import "../config/env.js";
2
- import type { CreateAppRequest } from "./types.js";
2
+ import type { CreateAppRequest, ZippedComponent } from "./types.js";
3
3
  export declare const createApp: (data: CreateAppRequest) => Promise<void>;
4
+ export declare const pushComponents: (appId: string, components: ZippedComponent[]) => Promise<void>;
@@ -9,3 +9,12 @@ export const createApp = async (data) => {
9
9
  throw new Error(error instanceof Error ? error.message : "Unknown error");
10
10
  }
11
11
  };
12
+ export const pushComponents = async (appId, components) => {
13
+ const url = `/services/developer/push`;
14
+ try {
15
+ await api.post(url, { appId, components });
16
+ }
17
+ catch (error) {
18
+ throw new Error(error instanceof Error ? error.message : "Unknown error");
19
+ }
20
+ };
@@ -11,3 +11,25 @@ export interface ApiResponse<T> {
11
11
  success: boolean;
12
12
  message?: string;
13
13
  }
14
+ interface ManifestApp {
15
+ id: string;
16
+ name: string;
17
+ description?: string;
18
+ }
19
+ export interface ManifestComponent {
20
+ type: string;
21
+ title: string;
22
+ key: string;
23
+ path: string;
24
+ settings?: Record<string, unknown>;
25
+ }
26
+ export interface Manifest {
27
+ app: ManifestApp;
28
+ components?: ManifestComponent[];
29
+ }
30
+ export interface ZippedComponent {
31
+ title: string;
32
+ key: string;
33
+ build: Buffer;
34
+ }
35
+ export {};
@@ -4,6 +4,7 @@ import chalk from "chalk";
4
4
  import { runInit } from "../commands/init.js";
5
5
  import { runCreate } from "../commands/create.js";
6
6
  import packageJson from "../../package.json" with { type: "json" };
7
+ import { runPush } from "../commands/push.js";
7
8
  const program = new Command();
8
9
  program
9
10
  .name("fireberry")
@@ -24,6 +25,12 @@ program
24
25
  const name = nameArgs ? nameArgs.join("-") : undefined;
25
26
  await runCreate({ name });
26
27
  });
28
+ program
29
+ .command("push")
30
+ .description("Push app to Fireberry")
31
+ .action(async () => {
32
+ await runPush();
33
+ });
27
34
  program.parseAsync(process.argv).catch((err) => {
28
35
  const errorMessage = err instanceof Error
29
36
  ? err.message
@@ -5,7 +5,7 @@ import fs from "fs-extra";
5
5
  import ora from "ora";
6
6
  import chalk from "chalk";
7
7
  export async function runInit({ tokenid } = {}) {
8
- let token = tokenid;
8
+ let token = tokenid?.trim();
9
9
  if (!token) {
10
10
  const answers = await inquirer.prompt([
11
11
  {
@@ -0,0 +1 @@
1
+ export declare function runPush(): Promise<void>;
@@ -0,0 +1,32 @@
1
+ import ora from "ora";
2
+ import chalk from "chalk";
3
+ import { getManifest, handleComponents } from "../utils/components.utils.js";
4
+ import { pushComponents } from "../api/requests.js";
5
+ export async function runPush() {
6
+ const spinner = ora("Checking manifest...").start();
7
+ try {
8
+ const manifest = await getManifest();
9
+ spinner.succeed("Manifest loaded successfully");
10
+ spinner.start("Validating and zipping components...");
11
+ const zippedComponents = await handleComponents(manifest);
12
+ const count = zippedComponents.length;
13
+ if (count > 0) {
14
+ spinner.succeed(`${count} component${count > 1 ? "s" : ""} validated and zipped`);
15
+ console.log(chalk.cyan("\nComponents ready to push:"));
16
+ zippedComponents.forEach((comp, idx) => {
17
+ const sizeKB = (comp.build.length / 1024).toFixed(2);
18
+ console.log(chalk.gray(` ${idx + 1}. ${comp.title} (${comp.key}) - ${sizeKB} KB`));
19
+ });
20
+ spinner.start("Uploading to Fireberry...");
21
+ await pushComponents(manifest.app.id, zippedComponents);
22
+ spinner.succeed("Components pushed successfully");
23
+ }
24
+ else {
25
+ spinner.succeed("No components to push");
26
+ }
27
+ }
28
+ catch (error) {
29
+ spinner.fail("Push failed");
30
+ throw error;
31
+ }
32
+ }
@@ -0,0 +1,5 @@
1
+ import { Manifest, ManifestComponent, ZippedComponent } from "../api/types.js";
2
+ export declare const getManifest: () => Promise<Manifest>;
3
+ export declare const validateComponentBuild: (componentPath: string, comp: ManifestComponent) => Promise<void>;
4
+ export declare const zipComponentBuild: (componentPath: string, title: string) => Promise<Buffer>;
5
+ export declare const handleComponents: (manifest: Manifest) => Promise<ZippedComponent[]>;
@@ -0,0 +1,88 @@
1
+ import path from "node:path";
2
+ import fs from "fs-extra";
3
+ import yaml from "js-yaml";
4
+ import chalk from "chalk";
5
+ import * as tar from "tar";
6
+ import os from "node:os";
7
+ export const getManifest = async () => {
8
+ const manifestPath = path.join(process.cwd(), "manifest.yml");
9
+ if (!(await fs.pathExists(manifestPath))) {
10
+ throw new Error(`No manifest.yml found at ${chalk.yellow(process.cwd())}.\n` +
11
+ `Please run this command from your Fireberry app directory.`);
12
+ }
13
+ const manifestContent = await fs.readFile(manifestPath, "utf-8");
14
+ const manifest = yaml.load(manifestContent);
15
+ if (!manifest || !manifest.app) {
16
+ throw new Error("manifest.yml must contain an 'app' section");
17
+ }
18
+ if (!manifest.app.id || !manifest.app.name) {
19
+ throw new Error("manifest.yml app section must contain 'id' and 'name' fields");
20
+ }
21
+ return manifest;
22
+ };
23
+ export const validateComponentBuild = async (componentPath, comp) => {
24
+ if (!(await fs.pathExists(componentPath))) {
25
+ throw new Error(`Component "${comp.title}" path does not exist: ${chalk.yellow(componentPath)}\n` + `Make sure the path in manifest.yml is correct.`);
26
+ }
27
+ const stats = await fs.stat(componentPath);
28
+ if (stats.isDirectory()) {
29
+ const files = await fs.readdir(componentPath);
30
+ if (files.length === 0) {
31
+ throw new Error(`Component <${comp.key}> at: /${comp.path} not found`);
32
+ }
33
+ }
34
+ };
35
+ export const zipComponentBuild = async (componentPath, title) => {
36
+ const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "fireberry-"));
37
+ const tarballPath = path.join(tmpDir, `${title}.tar.gz`);
38
+ try {
39
+ const stats = await fs.stat(componentPath);
40
+ if (stats.isDirectory()) {
41
+ await tar.create({
42
+ gzip: true,
43
+ file: tarballPath,
44
+ cwd: componentPath,
45
+ }, ["."]);
46
+ }
47
+ else {
48
+ const tempBuildDir = path.join(tmpDir, "build");
49
+ await fs.ensureDir(tempBuildDir);
50
+ const fileName = path.basename(componentPath);
51
+ await fs.copy(componentPath, path.join(tempBuildDir, fileName));
52
+ await tar.create({
53
+ gzip: true,
54
+ file: tarballPath,
55
+ cwd: tempBuildDir,
56
+ }, ["."]);
57
+ }
58
+ const buffer = await fs.readFile(tarballPath);
59
+ await fs.remove(tmpDir);
60
+ return buffer;
61
+ }
62
+ catch (error) {
63
+ await fs.remove(tmpDir);
64
+ throw error;
65
+ }
66
+ };
67
+ export const handleComponents = async (manifest) => {
68
+ const components = manifest.components;
69
+ if (!components || components.length === 0) {
70
+ return [];
71
+ }
72
+ const keys = components.map((comp) => comp.key);
73
+ if (new Set(keys).size !== keys.length) {
74
+ throw new Error("All component keys must be unique");
75
+ }
76
+ const zippedComponents = [];
77
+ for (const comp of components) {
78
+ const componentPath = path.join(process.cwd(), comp.path);
79
+ await validateComponentBuild(componentPath, comp);
80
+ const buildBuffer = await zipComponentBuild(componentPath, comp.title);
81
+ zippedComponents.push({
82
+ title: comp.title,
83
+ key: comp.key,
84
+ build: buildBuffer,
85
+ });
86
+ }
87
+ return zippedComponents;
88
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireberry/cli",
3
- "version": "0.0.5-beta.7",
3
+ "version": "0.0.5-beta.8",
4
4
  "description": "Fireberry CLI tool",
5
5
  "type": "module",
6
6
  "author": "",
@@ -14,6 +14,7 @@
14
14
  "scripts": {
15
15
  "start": "node dist/bin/fireberry.js",
16
16
  "build": "tsc",
17
+ "build:dev": "npm run clean && tsc && npm link && chmod +x dist/bin/fireberry.js",
17
18
  "dev": "tsc --watch",
18
19
  "clean": "rm -rf dist",
19
20
  "prebuild": "npm run clean",
@@ -47,12 +48,15 @@
47
48
  "env-paths": "^3.0.0",
48
49
  "fs-extra": "^11.2.0",
49
50
  "inquirer": "^9.2.12",
51
+ "js-yaml": "^4.1.0",
50
52
  "ora": "^8.0.1",
53
+ "tar": "^7.5.1",
51
54
  "uuid": "^13.0.0"
52
55
  },
53
56
  "devDependencies": {
54
57
  "@types/fs-extra": "^11.0.4",
55
58
  "@types/inquirer": "^9.0.7",
59
+ "@types/js-yaml": "^4.0.9",
56
60
  "@types/node": "^20.11.24",
57
61
  "@types/uuid": "^10.0.0",
58
62
  "typescript": "^5.3.3"
package/src/api/axios.ts CHANGED
@@ -3,7 +3,6 @@ import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
3
3
  import { getApiToken } from "./config.js";
4
4
  import packageJson from "../../package.json" with { type: "json" };
5
5
 
6
- // Determine default API URL based on version
7
6
  const getDefaultApiUrl = () => {
8
7
  if (process.env.FIREBERRY_API_URL) {
9
8
  return process.env.FIREBERRY_API_URL;
@@ -34,7 +33,7 @@ fbApi.interceptors.request.use(
34
33
  try {
35
34
  const token = await getApiToken();
36
35
  if (token) {
37
- config.headers.tokenid = token;
36
+ config.headers.tokenId = token;
38
37
  }
39
38
  } catch (error) {
40
39
  console.warn("Failed to get API token:", error);
@@ -1,11 +1,23 @@
1
1
  import "../config/env.js";
2
2
  import { api } from "./axios.js";
3
- import type { CreateAppRequest } from "./types.js";
3
+ import type { CreateAppRequest, ZippedComponent } from "./types.js";
4
4
 
5
5
  export const createApp = async (data: CreateAppRequest): Promise<void> => {
6
6
  const url = "/services/developer/create";
7
7
  try {
8
- await api.post(url, data);
8
+ await api.post<void>(url, data);
9
+ } catch (error) {
10
+ throw new Error(error instanceof Error ? error.message : "Unknown error");
11
+ }
12
+ };
13
+
14
+ export const pushComponents = async (
15
+ appId: string,
16
+ components: ZippedComponent[]
17
+ ): Promise<void> => {
18
+ const url = `/services/developer/push`;
19
+ try {
20
+ await api.post<void>(url, { appId, components });
9
21
  } catch (error) {
10
22
  throw new Error(error instanceof Error ? error.message : "Unknown error");
11
23
  }
package/src/api/types.ts CHANGED
@@ -13,3 +13,28 @@ export interface ApiResponse<T> {
13
13
  success: boolean;
14
14
  message?: string;
15
15
  }
16
+
17
+ interface ManifestApp {
18
+ id: string;
19
+ name: string;
20
+ description?: string;
21
+ }
22
+
23
+ export interface ManifestComponent {
24
+ type: string;
25
+ title: string;
26
+ key: string;
27
+ path: string;
28
+ settings?: Record<string, unknown>;
29
+ }
30
+
31
+ export interface Manifest {
32
+ app: ManifestApp;
33
+ components?: ManifestComponent[];
34
+ }
35
+
36
+ export interface ZippedComponent {
37
+ title: string;
38
+ key: string;
39
+ build: Buffer;
40
+ }
@@ -4,6 +4,7 @@ import chalk from "chalk";
4
4
  import { runInit } from "../commands/init.js";
5
5
  import { runCreate } from "../commands/create.js";
6
6
  import packageJson from "../../package.json" with { type: "json" };
7
+ import { runPush } from "../commands/push.js";
7
8
 
8
9
  const program = new Command();
9
10
 
@@ -29,6 +30,13 @@ program
29
30
  await runCreate({ name });
30
31
  });
31
32
 
33
+ program
34
+ .command("push")
35
+ .description("Push app to Fireberry")
36
+ .action(async () => {
37
+ await runPush();
38
+ });
39
+
32
40
  program.parseAsync(process.argv).catch((err: unknown) => {
33
41
  const errorMessage = err instanceof Error
34
42
  ? err.message
@@ -15,7 +15,7 @@ export interface Config {
15
15
  }
16
16
 
17
17
  export async function runInit({ tokenid }: InitOptions = {}): Promise<void> {
18
- let token = tokenid;
18
+ let token = tokenid?.trim();
19
19
  if (!token) {
20
20
  const answers = await inquirer.prompt([
21
21
  {
@@ -0,0 +1,42 @@
1
+ import ora from "ora";
2
+ import chalk from "chalk";
3
+ import { getManifest, handleComponents } from "../utils/components.utils.js";
4
+ import { pushComponents } from "../api/requests.js";
5
+
6
+ export async function runPush(): Promise<void> {
7
+ const spinner = ora("Checking manifest...").start();
8
+
9
+ try {
10
+ const manifest = await getManifest();
11
+ spinner.succeed("Manifest loaded successfully");
12
+
13
+ spinner.start("Validating and zipping components...");
14
+
15
+ const zippedComponents = await handleComponents(manifest);
16
+
17
+ const count = zippedComponents.length;
18
+ if (count > 0) {
19
+ spinner.succeed(
20
+ `${count} component${count > 1 ? "s" : ""} validated and zipped`
21
+ );
22
+
23
+ console.log(chalk.cyan("\nComponents ready to push:"));
24
+ zippedComponents.forEach((comp, idx) => {
25
+ const sizeKB = (comp.build.length / 1024).toFixed(2);
26
+ console.log(
27
+ chalk.gray(` ${idx + 1}. ${comp.title} (${comp.key}) - ${sizeKB} KB`)
28
+ );
29
+ });
30
+
31
+ spinner.start("Uploading to Fireberry...");
32
+
33
+ await pushComponents(manifest.app.id, zippedComponents);
34
+ spinner.succeed("Components pushed successfully");
35
+ } else {
36
+ spinner.succeed("No components to push");
37
+ }
38
+ } catch (error) {
39
+ spinner.fail("Push failed");
40
+ throw error;
41
+ }
42
+ }
@@ -0,0 +1,135 @@
1
+ import path from "node:path";
2
+ import fs from "fs-extra";
3
+ import yaml from "js-yaml";
4
+ import chalk from "chalk";
5
+ import * as tar from "tar";
6
+ import os from "node:os";
7
+ import { Manifest, ManifestComponent, ZippedComponent } from "../api/types.js";
8
+
9
+ export const getManifest = async (): Promise<Manifest> => {
10
+ const manifestPath = path.join(process.cwd(), "manifest.yml");
11
+
12
+ if (!(await fs.pathExists(manifestPath))) {
13
+ throw new Error(
14
+ `No manifest.yml found at ${chalk.yellow(process.cwd())}.\n` +
15
+ `Please run this command from your Fireberry app directory.`
16
+ );
17
+ }
18
+
19
+ const manifestContent = await fs.readFile(manifestPath, "utf-8");
20
+
21
+ const manifest = yaml.load(manifestContent) as Manifest;
22
+
23
+ if (!manifest || !manifest.app) {
24
+ throw new Error("manifest.yml must contain an 'app' section");
25
+ }
26
+
27
+ if (!manifest.app.id || !manifest.app.name) {
28
+ throw new Error(
29
+ "manifest.yml app section must contain 'id' and 'name' fields"
30
+ );
31
+ }
32
+
33
+ return manifest;
34
+ };
35
+
36
+ export const validateComponentBuild = async (
37
+ componentPath: string,
38
+ comp: ManifestComponent
39
+ ) => {
40
+ if (!(await fs.pathExists(componentPath))) {
41
+ throw new Error(
42
+ `Component "${comp.title}" path does not exist: ${chalk.yellow(
43
+ componentPath
44
+ )}\n` + `Make sure the path in manifest.yml is correct.`
45
+ );
46
+ }
47
+
48
+ const stats = await fs.stat(componentPath);
49
+
50
+ if (stats.isDirectory()) {
51
+ const files = await fs.readdir(componentPath);
52
+ if (files.length === 0) {
53
+ throw new Error(`Component <${comp.key}> at: /${comp.path} not found`);
54
+ }
55
+ }
56
+ };
57
+
58
+ export const zipComponentBuild = async (
59
+ componentPath: string,
60
+ title: string
61
+ ): Promise<Buffer> => {
62
+ const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "fireberry-"));
63
+ const tarballPath = path.join(tmpDir, `${title}.tar.gz`);
64
+
65
+ try {
66
+ const stats = await fs.stat(componentPath);
67
+
68
+ if (stats.isDirectory()) {
69
+ await tar.create(
70
+ {
71
+ gzip: true,
72
+ file: tarballPath,
73
+ cwd: componentPath,
74
+ },
75
+ ["."]
76
+ );
77
+ } else {
78
+ const tempBuildDir = path.join(tmpDir, "build");
79
+ await fs.ensureDir(tempBuildDir);
80
+
81
+ const fileName = path.basename(componentPath);
82
+ await fs.copy(componentPath, path.join(tempBuildDir, fileName));
83
+
84
+ await tar.create(
85
+ {
86
+ gzip: true,
87
+ file: tarballPath,
88
+ cwd: tempBuildDir,
89
+ },
90
+ ["."]
91
+ );
92
+ }
93
+
94
+ const buffer = await fs.readFile(tarballPath);
95
+
96
+ await fs.remove(tmpDir);
97
+
98
+ return buffer;
99
+ } catch (error) {
100
+ await fs.remove(tmpDir);
101
+ throw error;
102
+ }
103
+ };
104
+
105
+ export const handleComponents = async (
106
+ manifest: Manifest
107
+ ): Promise<ZippedComponent[]> => {
108
+ const components = manifest.components;
109
+ if (!components || components.length === 0) {
110
+ return [];
111
+ }
112
+
113
+ const keys = components.map((comp) => comp.key);
114
+ if (new Set(keys).size !== keys.length) {
115
+ throw new Error("All component keys must be unique");
116
+ }
117
+
118
+ const zippedComponents: ZippedComponent[] = [];
119
+
120
+ for (const comp of components) {
121
+ const componentPath = path.join(process.cwd(), comp.path);
122
+
123
+ await validateComponentBuild(componentPath, comp);
124
+
125
+ const buildBuffer = await zipComponentBuild(componentPath, comp.title);
126
+
127
+ zippedComponents.push({
128
+ title: comp.title,
129
+ key: comp.key,
130
+ build: buildBuffer,
131
+ });
132
+ }
133
+
134
+ return zippedComponents;
135
+ };