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

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Fireberry LTD
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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,5 @@
1
1
  import "../config/env.js";
2
- import type { CreateAppRequest } from "./types.js";
2
+ import type { CreateAppRequest, Manifest, 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>;
5
+ export declare const installApp: (manifest: Manifest) => Promise<void>;
@@ -9,3 +9,21 @@ 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
+ };
21
+ export const installApp = async (manifest) => {
22
+ const url = `/services/developer/install`;
23
+ try {
24
+ await api.post(url, { manifest });
25
+ }
26
+ catch (error) {
27
+ throw new Error(error instanceof Error ? error.message : "Unknown error");
28
+ }
29
+ };
@@ -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,8 @@ 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";
8
+ import { runInstall } from "../commands/install.js";
7
9
  const program = new Command();
8
10
  program
9
11
  .name("fireberry")
@@ -18,17 +20,30 @@ program
18
20
  });
19
21
  program
20
22
  .command("create")
21
- .argument("[name]", "App name")
23
+ .argument("[name...]", "App name")
22
24
  .description("Create a new Fireberry app")
23
- .action(async (name) => {
25
+ .action(async (nameArgs) => {
26
+ const name = nameArgs ? nameArgs.join("-") : undefined;
24
27
  await runCreate({ name });
25
28
  });
29
+ program
30
+ .command("push")
31
+ .description("Push app to Fireberry")
32
+ .action(async () => {
33
+ await runPush();
34
+ });
35
+ program.command("install")
36
+ .description("Install app on your Fireberry account")
37
+ .action(async () => {
38
+ await runInstall();
39
+ });
26
40
  program.parseAsync(process.argv).catch((err) => {
27
41
  const errorMessage = err instanceof Error
28
42
  ? err.message
29
43
  : typeof err === 'string'
30
44
  ? err
31
45
  : 'Unexpected error';
32
- console.error(chalk.red(errorMessage));
46
+ const formattedError = errorMessage.startsWith('Error:') ? errorMessage : `Error: ${errorMessage}`;
47
+ console.error(chalk.red(formattedError));
33
48
  process.exit(1);
34
49
  });
@@ -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 runInstall(): Promise<void>;
@@ -0,0 +1,8 @@
1
+ import { installApp } from "../api/requests.js";
2
+ import { getManifest, validateManifestComponents, } from "../utils/components.utils.js";
3
+ export async function runInstall() {
4
+ const manifest = await getManifest();
5
+ await validateManifestComponents(manifest);
6
+ await installApp(manifest);
7
+ console.log("App installed successfully");
8
+ }
@@ -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,6 @@
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 validateManifestComponents: (manifest: Manifest) => Promise<void>;
6
+ export declare const handleComponents: (manifest: Manifest) => Promise<ZippedComponent[]>;
@@ -0,0 +1,95 @@
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 validateManifestComponents = async (manifest) => {
68
+ const components = manifest.components;
69
+ if (!components || components.length === 0) {
70
+ throw new Error("No components found in manifest");
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
+ for (const comp of components) {
77
+ const componentPath = path.join(process.cwd(), comp.path);
78
+ await validateComponentBuild(componentPath, comp);
79
+ }
80
+ };
81
+ export const handleComponents = async (manifest) => {
82
+ await validateManifestComponents(manifest);
83
+ const components = manifest.components;
84
+ const zippedComponents = [];
85
+ for (const comp of components) {
86
+ const componentPath = path.join(process.cwd(), comp.path);
87
+ const buildBuffer = await zipComponentBuild(componentPath, comp.title);
88
+ zippedComponents.push({
89
+ title: comp.title,
90
+ key: comp.key,
91
+ build: buildBuffer,
92
+ });
93
+ }
94
+ return zippedComponents;
95
+ };
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.12",
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,32 @@
1
1
  import "../config/env.js";
2
2
  import { api } from "./axios.js";
3
- import type { CreateAppRequest } from "./types.js";
3
+ import type { CreateAppRequest, Manifest, 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 });
21
+ } catch (error) {
22
+ throw new Error(error instanceof Error ? error.message : "Unknown error");
23
+ }
24
+ };
25
+
26
+ export const installApp = async (manifest: Manifest): Promise<void> => {
27
+ const url = `/services/developer/install`;
28
+ try {
29
+ await api.post<void>(url, { manifest });
9
30
  } catch (error) {
10
31
  throw new Error(error instanceof Error ? error.message : "Unknown error");
11
32
  }
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,8 @@ 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";
8
+ import { runInstall } from "../commands/install.js";
7
9
 
8
10
  const program = new Command();
9
11
 
@@ -22,18 +24,34 @@ program
22
24
 
23
25
  program
24
26
  .command("create")
25
- .argument("[name]", "App name")
27
+ .argument("[name...]", "App name")
26
28
  .description("Create a new Fireberry app")
27
- .action(async (name?: string) => {
28
- await runCreate({ name });
29
+ .action(async (nameArgs?: string[]) => {
30
+ const name = nameArgs ? nameArgs.join("-") : undefined;
31
+ await runCreate({ name });
29
32
  });
30
33
 
34
+ program
35
+ .command("push")
36
+ .description("Push app to Fireberry")
37
+ .action(async () => {
38
+ await runPush();
39
+ });
40
+
41
+ program.command("install")
42
+ .description("Install app on your Fireberry account")
43
+ .action(async () => {
44
+ await runInstall();
45
+ });
46
+
31
47
  program.parseAsync(process.argv).catch((err: unknown) => {
32
48
  const errorMessage = err instanceof Error
33
49
  ? err.message
34
50
  : typeof err === 'string'
35
51
  ? err
36
52
  : 'Unexpected error';
37
- console.error(chalk.red(errorMessage));
53
+
54
+ const formattedError = errorMessage.startsWith('Error:') ? errorMessage : `Error: ${errorMessage}`;
55
+ console.error(chalk.red(formattedError));
38
56
  process.exit(1);
39
57
  });
@@ -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,12 @@
1
+ import { installApp } from "../api/requests.js";
2
+ import {
3
+ getManifest,
4
+ validateManifestComponents,
5
+ } from "../utils/components.utils.js";
6
+
7
+ export async function runInstall(): Promise<void> {
8
+ const manifest = await getManifest();
9
+ await validateManifestComponents(manifest);
10
+ await installApp(manifest);
11
+ console.log("App installed successfully");
12
+ }
@@ -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
+ }
@@ -7,4 +7,7 @@ components:
7
7
  title: my-first-component
8
8
  key: comp
9
9
  path: static/comp/build
10
- settings: {}
10
+ settings:
11
+ iconName: "related-single"
12
+ iconColor: "#7aae7f"
13
+ objectType: 0
@@ -0,0 +1,144 @@
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
+
53
+ if (files.length === 0) {
54
+ throw new Error(`Component <${comp.key}> at: /${comp.path} not found`);
55
+ }
56
+ }
57
+ };
58
+
59
+ export const zipComponentBuild = async (
60
+ componentPath: string,
61
+ title: string
62
+ ): Promise<Buffer> => {
63
+ const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "fireberry-"));
64
+ const tarballPath = path.join(tmpDir, `${title}.tar.gz`);
65
+
66
+ try {
67
+ const stats = await fs.stat(componentPath);
68
+
69
+ if (stats.isDirectory()) {
70
+ await tar.create(
71
+ {
72
+ gzip: true,
73
+ file: tarballPath,
74
+ cwd: componentPath,
75
+ },
76
+ ["."]
77
+ );
78
+ } else {
79
+ const tempBuildDir = path.join(tmpDir, "build");
80
+ await fs.ensureDir(tempBuildDir);
81
+
82
+ const fileName = path.basename(componentPath);
83
+ await fs.copy(componentPath, path.join(tempBuildDir, fileName));
84
+
85
+ await tar.create(
86
+ {
87
+ gzip: true,
88
+ file: tarballPath,
89
+ cwd: tempBuildDir,
90
+ },
91
+ ["."]
92
+ );
93
+ }
94
+
95
+ const buffer = await fs.readFile(tarballPath);
96
+
97
+ await fs.remove(tmpDir);
98
+
99
+ return buffer;
100
+ } catch (error) {
101
+ await fs.remove(tmpDir);
102
+ throw error;
103
+ }
104
+ };
105
+
106
+ export const validateManifestComponents = async (manifest: Manifest) => {
107
+ const components = manifest.components;
108
+ if (!components || components.length === 0) {
109
+ throw new Error("No components found in manifest");
110
+ }
111
+
112
+ const keys = components.map((comp) => comp.key);
113
+ if (new Set(keys).size !== keys.length) {
114
+ throw new Error("All component keys must be unique");
115
+ }
116
+
117
+ for (const comp of components) {
118
+ const componentPath = path.join(process.cwd(), comp.path);
119
+ await validateComponentBuild(componentPath, comp);
120
+ }
121
+ };
122
+
123
+ export const handleComponents = async (
124
+ manifest: Manifest
125
+ ): Promise<ZippedComponent[]> => {
126
+ await validateManifestComponents(manifest);
127
+ const components = manifest.components!;
128
+
129
+ const zippedComponents: ZippedComponent[] = [];
130
+
131
+ for (const comp of components) {
132
+ const componentPath = path.join(process.cwd(), comp.path);
133
+
134
+ const buildBuffer = await zipComponentBuild(componentPath, comp.title);
135
+
136
+ zippedComponents.push({
137
+ title: comp.title,
138
+ key: comp.key,
139
+ build: buildBuffer,
140
+ });
141
+ }
142
+
143
+ return zippedComponents;
144
+ };