@fireberry/cli 0.0.5-beta.0 → 0.0.5-beta.10

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.
@@ -15,6 +15,7 @@ on:
15
15
  required: false
16
16
  type: choice
17
17
  options:
18
+ - prerelease
18
19
  - patch
19
20
  - minor
20
21
  - major
@@ -26,6 +27,9 @@ jobs:
26
27
  permissions:
27
28
  contents: read
28
29
  id-token: write
30
+ environment:
31
+ name: npm
32
+ url: https://www.npmjs.com/package/@fireberry/cli/v/${{ github.event.inputs.version }}
29
33
 
30
34
  steps:
31
35
  - name: Checkout repository
@@ -44,7 +48,13 @@ jobs:
44
48
 
45
49
  - name: Update version (Beta)
46
50
  if: github.event.inputs.type == 'beta'
47
- run: npm version prerelease --preid=beta --no-git-tag-version
51
+ run: |
52
+ CURRENT_VERSION=$(node -p "require('./package.json').version")
53
+ if [[ $CURRENT_VERSION == *"-beta."* ]]; then
54
+ npm version prerelease --preid=beta --no-git-tag-version
55
+ else
56
+ npm version prepatch --preid=beta --no-git-tag-version
57
+ fi
48
58
 
49
59
  - name: Update version (Production)
50
60
  if: github.event.inputs.type == 'production'
@@ -56,14 +66,13 @@ jobs:
56
66
  - name: Run tests
57
67
  run: npm test
58
68
 
69
+ - name: Update npm to latest version
70
+ run: npm install -g npm@latest
71
+
59
72
  - name: Publish to npm (Beta)
60
73
  if: github.event.inputs.type == 'beta'
61
74
  run: npm publish --tag beta --provenance --access public
62
- env:
63
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
64
75
 
65
76
  - name: Publish to npm (Production)
66
77
  if: github.event.inputs.type == 'production'
67
78
  run: npm publish --tag latest --provenance --access public
68
- env:
69
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
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) {
@@ -43,9 +42,20 @@ export async function sendApiRequest(config) {
43
42
  }
44
43
  catch (error) {
45
44
  if (axios.isAxiosError(error)) {
46
- const message = error.response?.data?.message || error.message;
47
45
  const status = error.response?.status;
48
- throw new Error(`API Error${status ? ` (${status})` : ""}: ${message}`);
46
+ let errorMessage;
47
+ switch (status) {
48
+ case 401:
49
+ console.log(error.response?.data?.message || error.message); // TODO: remove this
50
+ errorMessage = "Unauthorized user.";
51
+ break;
52
+ case 500:
53
+ errorMessage = "Internal server error.";
54
+ break;
55
+ default:
56
+ errorMessage = error.response?.data?.message || error.message;
57
+ }
58
+ throw new Error(`Error: ${errorMessage}`);
49
59
  }
50
60
  throw error;
51
61
  }
@@ -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")
@@ -18,17 +19,25 @@ program
18
19
  });
19
20
  program
20
21
  .command("create")
21
- .argument("[name]", "App name")
22
+ .argument("[name...]", "App name")
22
23
  .description("Create a new Fireberry app")
23
- .action(async (name) => {
24
+ .action(async (nameArgs) => {
25
+ const name = nameArgs ? nameArgs.join("-") : undefined;
24
26
  await runCreate({ name });
25
27
  });
28
+ program
29
+ .command("push")
30
+ .description("Push app to Fireberry")
31
+ .action(async () => {
32
+ await runPush();
33
+ });
26
34
  program.parseAsync(process.argv).catch((err) => {
27
35
  const errorMessage = err instanceof Error
28
36
  ? err.message
29
37
  : typeof err === 'string'
30
38
  ? err
31
39
  : 'Unexpected error';
32
- console.error(chalk.red(errorMessage));
40
+ const formattedError = errorMessage.startsWith('Error:') ? errorMessage : `Error: ${errorMessage}`;
41
+ console.error(chalk.red(formattedError));
33
42
  process.exit(1);
34
43
  });
@@ -13,11 +13,7 @@ function slugifyName(name) {
13
13
  if (!validPattern.test(name)) {
14
14
  throw new Error(`Invalid app name: "${name}". Only alphanumeric characters, underscores, and hyphens are allowed.`);
15
15
  }
16
- return name
17
- .toLowerCase()
18
- .replace(/[^a-z0-9]+/g, "-")
19
- .replace(/-+/g, "-")
20
- .replace(/^-|-$/g, "");
16
+ return name;
21
17
  }
22
18
  export async function runCreate({ name }) {
23
19
  let appName = name;
@@ -28,13 +24,13 @@ export async function runCreate({ name }) {
28
24
  appName = (answers.name || "").trim();
29
25
  }
30
26
  if (!appName) {
31
- throw new Error("App name is required.");
27
+ throw new Error("Missing name.");
32
28
  }
33
29
  const slug = slugifyName(appName);
34
30
  const appId = uuidv4();
35
31
  const appDir = path.resolve(process.cwd(), slug);
36
32
  if (await fs.pathExists(appDir)) {
37
- throw new Error(`Directory already exists: ${chalk.yellow(appDir)}`);
33
+ throw new Error(`Already exists. ${chalk.yellow(slug)}`);
38
34
  }
39
35
  const spinner = ora(`Creating app "${chalk.cyan(appName)}"...`).start();
40
36
  try {
@@ -45,7 +41,7 @@ export async function runCreate({ name }) {
45
41
  const htmlTemplate = await fs.readFile(path.join(templatesDir, "index.html"), "utf-8");
46
42
  const manifestContent = manifestTemplate
47
43
  .replace(/{{appName}}/g, appName)
48
- .replace(/{ { appId } }/g, appId);
44
+ .replace(/{{appId}}/g, appId);
49
45
  const htmlContent = htmlTemplate.replace(/{{appName}}/g, appName);
50
46
  await fs.writeFile(path.join(appDir, "manifest.yml"), manifestContent);
51
47
  await fs.writeFile(path.join(appDir, "index.html"), htmlContent);
@@ -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.0",
3
+ "version": "0.0.5-beta.10",
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",
@@ -30,7 +31,7 @@
30
31
  ],
31
32
  "repository": {
32
33
  "type": "git",
33
- "url": "git+https://github.com/fireberry-crm/cli"
34
+ "url": "git+https://github.com/fireberry-crm/cli.git"
34
35
  },
35
36
  "bugs": {
36
37
  "url": "https://github.com/fireberry-crm/cli/issues"
@@ -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);
@@ -55,9 +54,22 @@ export async function sendApiRequest<T = any>(
55
54
  return response.data;
56
55
  } catch (error) {
57
56
  if (axios.isAxiosError(error)) {
58
- const message = error.response?.data?.message || error.message;
59
57
  const status = error.response?.status;
60
- throw new Error(`API Error${status ? ` (${status})` : ""}: ${message}`);
58
+ let errorMessage:string;
59
+
60
+ switch (status) {
61
+ case 401:
62
+ console.log(error.response?.data?.message || error.message); // TODO: remove this
63
+ errorMessage = "Unauthorized user.";
64
+ break;
65
+ case 500:
66
+ errorMessage = "Internal server error.";
67
+ break;
68
+ default:
69
+ errorMessage = error.response?.data?.message || error.message;
70
+ }
71
+
72
+ throw new Error(`Error: ${errorMessage}`);
61
73
  }
62
74
  throw error;
63
75
  }
@@ -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
 
@@ -22,10 +23,18 @@ program
22
23
 
23
24
  program
24
25
  .command("create")
25
- .argument("[name]", "App name")
26
+ .argument("[name...]", "App name")
26
27
  .description("Create a new Fireberry app")
27
- .action(async (name?: string) => {
28
- await runCreate({ name });
28
+ .action(async (nameArgs?: string[]) => {
29
+ const name = nameArgs ? nameArgs.join("-") : undefined;
30
+ await runCreate({ name });
31
+ });
32
+
33
+ program
34
+ .command("push")
35
+ .description("Push app to Fireberry")
36
+ .action(async () => {
37
+ await runPush();
29
38
  });
30
39
 
31
40
  program.parseAsync(process.argv).catch((err: unknown) => {
@@ -34,6 +43,8 @@ program.parseAsync(process.argv).catch((err: unknown) => {
34
43
  : typeof err === 'string'
35
44
  ? err
36
45
  : 'Unexpected error';
37
- console.error(chalk.red(errorMessage));
46
+
47
+ const formattedError = errorMessage.startsWith('Error:') ? errorMessage : `Error: ${errorMessage}`;
48
+ console.error(chalk.red(formattedError));
38
49
  process.exit(1);
39
50
  });
@@ -22,15 +22,12 @@ function slugifyName(name: string) {
22
22
  );
23
23
  }
24
24
 
25
- return name
26
- .toLowerCase()
27
- .replace(/[^a-z0-9]+/g, "-")
28
- .replace(/-+/g, "-")
29
- .replace(/^-|-$/g, "");
25
+ return name;
30
26
  }
31
27
 
32
28
  export async function runCreate({ name }: CreateOptions): Promise<void> {
33
29
  let appName = name;
30
+
34
31
  if (!appName) {
35
32
  const answers = await inquirer.prompt([
36
33
  { type: "input", name: "name", message: "App name" },
@@ -38,7 +35,7 @@ export async function runCreate({ name }: CreateOptions): Promise<void> {
38
35
  appName = (answers.name || "").trim();
39
36
  }
40
37
  if (!appName) {
41
- throw new Error("App name is required.");
38
+ throw new Error("Missing name.");
42
39
  }
43
40
 
44
41
  const slug = slugifyName(appName);
@@ -46,7 +43,7 @@ export async function runCreate({ name }: CreateOptions): Promise<void> {
46
43
  const appDir = path.resolve(process.cwd(), slug);
47
44
 
48
45
  if (await fs.pathExists(appDir)) {
49
- throw new Error(`Directory already exists: ${chalk.yellow(appDir)}`);
46
+ throw new Error(`Already exists. ${chalk.yellow(slug)}`);
50
47
  }
51
48
 
52
49
  const spinner = ora(`Creating app "${chalk.cyan(appName)}"...`).start();
@@ -68,7 +65,7 @@ export async function runCreate({ name }: CreateOptions): Promise<void> {
68
65
 
69
66
  const manifestContent = manifestTemplate
70
67
  .replace(/{{appName}}/g, appName)
71
- .replace(/{ { appId } }/g, appId);
68
+ .replace(/{{appId}}/g, appId);
72
69
 
73
70
  const htmlContent = htmlTemplate.replace(/{{appName}}/g, appName);
74
71
 
@@ -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
+ };