@fireberry/cli 0.0.4 → 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.
- package/.github/workflows/main.yml +36 -7
- package/dist/api/axios.d.ts +12 -0
- package/dist/api/axios.js +70 -0
- package/dist/api/config.d.ts +1 -0
- package/dist/api/config.js +18 -0
- package/dist/api/requests.d.ts +4 -0
- package/dist/api/requests.js +20 -0
- package/dist/api/types.d.ts +35 -0
- package/dist/api/types.js +1 -0
- package/dist/bin/fireberry.js +18 -1
- package/dist/commands/create.d.ts +5 -0
- package/dist/commands/create.js +59 -0
- package/dist/commands/init.d.ts +4 -0
- package/dist/commands/init.js +1 -1
- package/dist/commands/push.d.ts +1 -0
- package/dist/commands/push.js +32 -0
- package/dist/config/env.d.ts +1 -0
- package/dist/config/env.js +8 -0
- package/dist/utils/components.utils.d.ts +5 -0
- package/dist/utils/components.utils.js +88 -0
- package/package.json +15 -4
- package/src/api/axios.ts +95 -0
- package/src/api/config.ts +21 -0
- package/src/api/requests.ts +24 -0
- package/src/api/types.ts +40 -0
- package/src/bin/fireberry.ts +21 -1
- package/src/commands/create.ts +85 -0
- package/src/commands/init.ts +2 -2
- package/src/commands/push.ts +42 -0
- package/src/config/env.ts +10 -0
- package/src/templates/index.html +15 -0
- package/src/templates/manifest.yml +10 -0
- package/src/utils/components.utils.ts +135 -0
- package/bin/fireberry.js +0 -24
|
@@ -3,14 +3,23 @@ name: Publish Fireberry CLI to npm
|
|
|
3
3
|
on:
|
|
4
4
|
workflow_dispatch:
|
|
5
5
|
inputs:
|
|
6
|
-
|
|
7
|
-
description: "
|
|
6
|
+
type:
|
|
7
|
+
description: "Publish type"
|
|
8
8
|
required: true
|
|
9
9
|
type: choice
|
|
10
10
|
options:
|
|
11
|
+
- beta
|
|
12
|
+
- production
|
|
13
|
+
version:
|
|
14
|
+
description: "Version bump (for production only)"
|
|
15
|
+
required: false
|
|
16
|
+
type: choice
|
|
17
|
+
options:
|
|
18
|
+
- prerelease
|
|
11
19
|
- patch
|
|
12
20
|
- minor
|
|
13
21
|
- major
|
|
22
|
+
default: patch
|
|
14
23
|
|
|
15
24
|
jobs:
|
|
16
25
|
publish:
|
|
@@ -18,6 +27,9 @@ jobs:
|
|
|
18
27
|
permissions:
|
|
19
28
|
contents: read
|
|
20
29
|
id-token: write
|
|
30
|
+
environment:
|
|
31
|
+
name: npm
|
|
32
|
+
url: https://www.npmjs.com/package/@fireberry/cli/v/${{ github.event.inputs.version }}
|
|
21
33
|
|
|
22
34
|
steps:
|
|
23
35
|
- name: Checkout repository
|
|
@@ -34,7 +46,18 @@ jobs:
|
|
|
34
46
|
- name: Install dependencies
|
|
35
47
|
run: npm ci
|
|
36
48
|
|
|
37
|
-
- name: Update version
|
|
49
|
+
- name: Update version (Beta)
|
|
50
|
+
if: github.event.inputs.type == 'beta'
|
|
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
|
|
58
|
+
|
|
59
|
+
- name: Update version (Production)
|
|
60
|
+
if: github.event.inputs.type == 'production'
|
|
38
61
|
run: npm version ${{ github.event.inputs.version }} --no-git-tag-version
|
|
39
62
|
|
|
40
63
|
- name: Build package
|
|
@@ -43,7 +66,13 @@ jobs:
|
|
|
43
66
|
- name: Run tests
|
|
44
67
|
run: npm test
|
|
45
68
|
|
|
46
|
-
- name:
|
|
47
|
-
run: npm
|
|
48
|
-
|
|
49
|
-
|
|
69
|
+
- name: Update npm to latest version
|
|
70
|
+
run: npm install -g npm@latest
|
|
71
|
+
|
|
72
|
+
- name: Publish to npm (Beta)
|
|
73
|
+
if: github.event.inputs.type == 'beta'
|
|
74
|
+
run: npm publish --tag beta --provenance --access public
|
|
75
|
+
|
|
76
|
+
- name: Publish to npm (Production)
|
|
77
|
+
if: github.event.inputs.type == 'production'
|
|
78
|
+
run: npm publish --tag latest --provenance --access public
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "../config/env.js";
|
|
2
|
+
import { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
3
|
+
declare const fbApi: AxiosInstance;
|
|
4
|
+
export declare function sendApiRequest<T = any>(config: AxiosRequestConfig): Promise<T>;
|
|
5
|
+
export declare const api: {
|
|
6
|
+
get: <T = any>(url: string, config?: AxiosRequestConfig) => Promise<T>;
|
|
7
|
+
post: <T = any>(url: string, data?: any, config?: AxiosRequestConfig) => Promise<T>;
|
|
8
|
+
put: <T = any>(url: string, data?: any, config?: AxiosRequestConfig) => Promise<T>;
|
|
9
|
+
patch: <T = any>(url: string, data?: any, config?: AxiosRequestConfig) => Promise<T>;
|
|
10
|
+
delete: <T = any>(url: string, data?: any, config?: AxiosRequestConfig) => Promise<T>;
|
|
11
|
+
};
|
|
12
|
+
export default fbApi;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import "../config/env.js";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { getApiToken } from "./config.js";
|
|
4
|
+
import packageJson from "../../package.json" with { type: "json" };
|
|
5
|
+
const getDefaultApiUrl = () => {
|
|
6
|
+
if (process.env.FIREBERRY_API_URL) {
|
|
7
|
+
return process.env.FIREBERRY_API_URL;
|
|
8
|
+
}
|
|
9
|
+
const isBeta = packageJson.version.includes("beta");
|
|
10
|
+
if (isBeta) {
|
|
11
|
+
return process.env.FIREBERRY_STAGING_URL || "https://dev.fireberry.com/api/v3";
|
|
12
|
+
}
|
|
13
|
+
return "https://api.fireberry.com/api/v3";
|
|
14
|
+
};
|
|
15
|
+
const BASE_URL = getDefaultApiUrl();
|
|
16
|
+
const fbApi = axios.create({
|
|
17
|
+
baseURL: BASE_URL,
|
|
18
|
+
timeout: 30000,
|
|
19
|
+
headers: {
|
|
20
|
+
"Content-Type": "application/json",
|
|
21
|
+
"User-Agent": `@fireberry/cli@${packageJson.version}`,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
fbApi.interceptors.request.use(async (config) => {
|
|
25
|
+
try {
|
|
26
|
+
const token = await getApiToken();
|
|
27
|
+
if (token) {
|
|
28
|
+
config.headers.tokenId = token;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.warn("Failed to get API token:", error);
|
|
33
|
+
}
|
|
34
|
+
return config;
|
|
35
|
+
}, (error) => {
|
|
36
|
+
return Promise.reject(error);
|
|
37
|
+
});
|
|
38
|
+
export async function sendApiRequest(config) {
|
|
39
|
+
try {
|
|
40
|
+
const response = await fbApi.request(config);
|
|
41
|
+
return response.data;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (axios.isAxiosError(error)) {
|
|
45
|
+
const status = error.response?.status;
|
|
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}`);
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export const api = {
|
|
64
|
+
get: (url, config) => sendApiRequest({ ...config, method: "GET", url }),
|
|
65
|
+
post: (url, data, config) => sendApiRequest({ ...config, method: "POST", url, data }),
|
|
66
|
+
put: (url, data, config) => sendApiRequest({ ...config, method: "PUT", url, data }),
|
|
67
|
+
patch: (url, data, config) => sendApiRequest({ ...config, method: "PATCH", url, data }),
|
|
68
|
+
delete: (url, data, config) => sendApiRequest({ ...config, method: "DELETE", url, data }),
|
|
69
|
+
};
|
|
70
|
+
export default fbApi;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getApiToken(): Promise<string | null>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import envPaths from "env-paths";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
export async function getApiToken() {
|
|
5
|
+
try {
|
|
6
|
+
const paths = envPaths("Fireberry CLI", { suffix: "" });
|
|
7
|
+
const configFile = path.join(paths.config, "config.json");
|
|
8
|
+
if (!(await fs.pathExists(configFile))) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const config = await fs.readJson(configFile);
|
|
12
|
+
return config.apiToken || null;
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
console.warn("Failed to read config file:", error);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import "../config/env.js";
|
|
2
|
+
import type { CreateAppRequest, ZippedComponent } from "./types.js";
|
|
3
|
+
export declare const createApp: (data: CreateAppRequest) => Promise<void>;
|
|
4
|
+
export declare const pushComponents: (appId: string, components: ZippedComponent[]) => Promise<void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "../config/env.js";
|
|
2
|
+
import { api } from "./axios.js";
|
|
3
|
+
export const createApp = async (data) => {
|
|
4
|
+
const url = "/services/developer/create";
|
|
5
|
+
try {
|
|
6
|
+
await api.post(url, data);
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
throw new Error(error instanceof Error ? error.message : "Unknown error");
|
|
10
|
+
}
|
|
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
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface CreateAppRequest {
|
|
2
|
+
appId: string;
|
|
3
|
+
}
|
|
4
|
+
export interface ApiError {
|
|
5
|
+
message: string;
|
|
6
|
+
code?: string;
|
|
7
|
+
details?: any;
|
|
8
|
+
}
|
|
9
|
+
export interface ApiResponse<T> {
|
|
10
|
+
data: T;
|
|
11
|
+
success: boolean;
|
|
12
|
+
message?: string;
|
|
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 {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/bin/fireberry.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { runInit } from "../commands/init.js";
|
|
5
|
+
import { runCreate } from "../commands/create.js";
|
|
5
6
|
import packageJson from "../../package.json" with { type: "json" };
|
|
7
|
+
import { runPush } from "../commands/push.js";
|
|
6
8
|
const program = new Command();
|
|
7
9
|
program
|
|
8
10
|
.name("fireberry")
|
|
@@ -15,12 +17,27 @@ program
|
|
|
15
17
|
.action(async (tokenid) => {
|
|
16
18
|
await runInit({ tokenid });
|
|
17
19
|
});
|
|
20
|
+
program
|
|
21
|
+
.command("create")
|
|
22
|
+
.argument("[name...]", "App name")
|
|
23
|
+
.description("Create a new Fireberry app")
|
|
24
|
+
.action(async (nameArgs) => {
|
|
25
|
+
const name = nameArgs ? nameArgs.join("-") : undefined;
|
|
26
|
+
await runCreate({ name });
|
|
27
|
+
});
|
|
28
|
+
program
|
|
29
|
+
.command("push")
|
|
30
|
+
.description("Push app to Fireberry")
|
|
31
|
+
.action(async () => {
|
|
32
|
+
await runPush();
|
|
33
|
+
});
|
|
18
34
|
program.parseAsync(process.argv).catch((err) => {
|
|
19
35
|
const errorMessage = err instanceof Error
|
|
20
36
|
? err.message
|
|
21
37
|
: typeof err === 'string'
|
|
22
38
|
? err
|
|
23
39
|
: 'Unexpected error';
|
|
24
|
-
|
|
40
|
+
const formattedError = errorMessage.startsWith('Error:') ? errorMessage : `Error: ${errorMessage}`;
|
|
41
|
+
console.error(chalk.red(formattedError));
|
|
25
42
|
process.exit(1);
|
|
26
43
|
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import { v4 as uuidv4 } from "uuid";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import ora from "ora";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import { createApp } from "../api/requests.js";
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
function slugifyName(name) {
|
|
12
|
+
const validPattern = /^[a-zA-Z0-9_-]+$/;
|
|
13
|
+
if (!validPattern.test(name)) {
|
|
14
|
+
throw new Error(`Invalid app name: "${name}". Only alphanumeric characters, underscores, and hyphens are allowed.`);
|
|
15
|
+
}
|
|
16
|
+
return name;
|
|
17
|
+
}
|
|
18
|
+
export async function runCreate({ name }) {
|
|
19
|
+
let appName = name;
|
|
20
|
+
if (!appName) {
|
|
21
|
+
const answers = await inquirer.prompt([
|
|
22
|
+
{ type: "input", name: "name", message: "App name" },
|
|
23
|
+
]);
|
|
24
|
+
appName = (answers.name || "").trim();
|
|
25
|
+
}
|
|
26
|
+
if (!appName) {
|
|
27
|
+
throw new Error("Missing name.");
|
|
28
|
+
}
|
|
29
|
+
const slug = slugifyName(appName);
|
|
30
|
+
const appId = uuidv4();
|
|
31
|
+
const appDir = path.resolve(process.cwd(), slug);
|
|
32
|
+
if (await fs.pathExists(appDir)) {
|
|
33
|
+
throw new Error(`Already exists. ${chalk.yellow(slug)}`);
|
|
34
|
+
}
|
|
35
|
+
const spinner = ora(`Creating app "${chalk.cyan(appName)}"...`).start();
|
|
36
|
+
try {
|
|
37
|
+
await createApp({ appId });
|
|
38
|
+
await fs.ensureDir(appDir);
|
|
39
|
+
const templatesDir = path.join(__dirname, "..", "..", "src", "templates");
|
|
40
|
+
const manifestTemplate = await fs.readFile(path.join(templatesDir, "manifest.yml"), "utf-8");
|
|
41
|
+
const htmlTemplate = await fs.readFile(path.join(templatesDir, "index.html"), "utf-8");
|
|
42
|
+
const manifestContent = manifestTemplate
|
|
43
|
+
.replace(/{{appName}}/g, appName)
|
|
44
|
+
.replace(/{{appId}}/g, appId);
|
|
45
|
+
const htmlContent = htmlTemplate.replace(/{{appName}}/g, appName);
|
|
46
|
+
await fs.writeFile(path.join(appDir, "manifest.yml"), manifestContent);
|
|
47
|
+
await fs.writeFile(path.join(appDir, "index.html"), htmlContent);
|
|
48
|
+
spinner.succeed(`Successfully created "${chalk.cyan(appName)}" app!`);
|
|
49
|
+
console.log(chalk.gray(`📁 Location: ${appDir}`));
|
|
50
|
+
console.log(chalk.gray(`App ID: ${appId}`));
|
|
51
|
+
console.log(chalk.green("\n🎉 Your app is ready! Next steps:"));
|
|
52
|
+
console.log(chalk.white(` cd ${slug}`));
|
|
53
|
+
console.log(chalk.white(" # Start developing your Fireberry app"));
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
spinner.fail(`Failed to create app "${chalk.cyan(appName)}"`);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
package/dist/commands/init.d.ts
CHANGED
package/dist/commands/init.js
CHANGED
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { config } from "dotenv";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = path.dirname(__filename);
|
|
6
|
+
const projectRoot = path.resolve(__dirname, "..", "..");
|
|
7
|
+
const envPath = path.join(projectRoot, ".env");
|
|
8
|
+
config({ path: envPath, quiet: true });
|
|
@@ -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.
|
|
3
|
+
"version": "0.0.5-beta.10",
|
|
4
4
|
"description": "Fireberry CLI tool",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "",
|
|
@@ -14,11 +14,15 @@
|
|
|
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",
|
|
20
21
|
"prepare": "npm run build",
|
|
21
|
-
"test": "node test/smoke.test.js"
|
|
22
|
+
"test": "node test/smoke.test.js",
|
|
23
|
+
"version:beta": "npm version prerelease --preid=beta",
|
|
24
|
+
"publish:beta": "npm run version:beta && npm publish --tag beta",
|
|
25
|
+
"publish:prod": "npm publish --tag latest"
|
|
22
26
|
},
|
|
23
27
|
"keywords": [
|
|
24
28
|
"cli",
|
|
@@ -27,7 +31,7 @@
|
|
|
27
31
|
],
|
|
28
32
|
"repository": {
|
|
29
33
|
"type": "git",
|
|
30
|
-
"url": "git+https://github.com/fireberry-crm/cli"
|
|
34
|
+
"url": "git+https://github.com/fireberry-crm/cli.git"
|
|
31
35
|
},
|
|
32
36
|
"bugs": {
|
|
33
37
|
"url": "https://github.com/fireberry-crm/cli/issues"
|
|
@@ -37,17 +41,24 @@
|
|
|
37
41
|
"access": "public"
|
|
38
42
|
},
|
|
39
43
|
"dependencies": {
|
|
44
|
+
"axios": "^1.12.2",
|
|
40
45
|
"chalk": "^5.3.0",
|
|
41
46
|
"commander": "^12.1.0",
|
|
47
|
+
"dotenv": "^17.2.3",
|
|
42
48
|
"env-paths": "^3.0.0",
|
|
43
49
|
"fs-extra": "^11.2.0",
|
|
44
50
|
"inquirer": "^9.2.12",
|
|
45
|
-
"
|
|
51
|
+
"js-yaml": "^4.1.0",
|
|
52
|
+
"ora": "^8.0.1",
|
|
53
|
+
"tar": "^7.5.1",
|
|
54
|
+
"uuid": "^13.0.0"
|
|
46
55
|
},
|
|
47
56
|
"devDependencies": {
|
|
48
57
|
"@types/fs-extra": "^11.0.4",
|
|
49
58
|
"@types/inquirer": "^9.0.7",
|
|
59
|
+
"@types/js-yaml": "^4.0.9",
|
|
50
60
|
"@types/node": "^20.11.24",
|
|
61
|
+
"@types/uuid": "^10.0.0",
|
|
51
62
|
"typescript": "^5.3.3"
|
|
52
63
|
}
|
|
53
64
|
}
|
package/src/api/axios.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import "../config/env.js";
|
|
2
|
+
import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
3
|
+
import { getApiToken } from "./config.js";
|
|
4
|
+
import packageJson from "../../package.json" with { type: "json" };
|
|
5
|
+
|
|
6
|
+
const getDefaultApiUrl = () => {
|
|
7
|
+
if (process.env.FIREBERRY_API_URL) {
|
|
8
|
+
return process.env.FIREBERRY_API_URL;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const isBeta = packageJson.version.includes("beta");
|
|
12
|
+
|
|
13
|
+
if (isBeta) {
|
|
14
|
+
return process.env.FIREBERRY_STAGING_URL || "https://dev.fireberry.com/api/v3";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return "https://api.fireberry.com/api/v3";
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const BASE_URL = getDefaultApiUrl();
|
|
21
|
+
|
|
22
|
+
const fbApi: AxiosInstance = axios.create({
|
|
23
|
+
baseURL: BASE_URL,
|
|
24
|
+
timeout: 30000,
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
"User-Agent": `@fireberry/cli@${packageJson.version}`,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
fbApi.interceptors.request.use(
|
|
32
|
+
async (config) => {
|
|
33
|
+
try {
|
|
34
|
+
const token = await getApiToken();
|
|
35
|
+
if (token) {
|
|
36
|
+
config.headers.tokenId = token;
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.warn("Failed to get API token:", error);
|
|
40
|
+
}
|
|
41
|
+
return config;
|
|
42
|
+
},
|
|
43
|
+
(error) => {
|
|
44
|
+
return Promise.reject(error);
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export async function sendApiRequest<T = any>(
|
|
49
|
+
config: AxiosRequestConfig
|
|
50
|
+
): Promise<T> {
|
|
51
|
+
try {
|
|
52
|
+
const response = await fbApi.request<T>(config);
|
|
53
|
+
|
|
54
|
+
return response.data;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (axios.isAxiosError(error)) {
|
|
57
|
+
const status = error.response?.status;
|
|
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}`);
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const api = {
|
|
79
|
+
get: <T = any>(url: string, config?: AxiosRequestConfig) =>
|
|
80
|
+
sendApiRequest<T>({ ...config, method: "GET", url }),
|
|
81
|
+
|
|
82
|
+
post: <T = any>(url: string, data?: any, config?: AxiosRequestConfig) =>
|
|
83
|
+
sendApiRequest<T>({ ...config, method: "POST", url, data }),
|
|
84
|
+
|
|
85
|
+
put: <T = any>(url: string, data?: any, config?: AxiosRequestConfig) =>
|
|
86
|
+
sendApiRequest<T>({ ...config, method: "PUT", url, data }),
|
|
87
|
+
|
|
88
|
+
patch: <T = any>(url: string, data?: any, config?: AxiosRequestConfig) =>
|
|
89
|
+
sendApiRequest<T>({ ...config, method: "PATCH", url, data }),
|
|
90
|
+
|
|
91
|
+
delete: <T = any>(url: string, data?: any, config?: AxiosRequestConfig) =>
|
|
92
|
+
sendApiRequest<T>({ ...config, method: "DELETE", url, data }),
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export default fbApi;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import envPaths from "env-paths";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import type { Config } from "../commands/init.js";
|
|
5
|
+
|
|
6
|
+
export async function getApiToken(): Promise<string | null> {
|
|
7
|
+
try {
|
|
8
|
+
const paths = envPaths("Fireberry CLI", { suffix: "" });
|
|
9
|
+
const configFile = path.join(paths.config, "config.json");
|
|
10
|
+
|
|
11
|
+
if (!(await fs.pathExists(configFile))) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const config: Config = await fs.readJson(configFile);
|
|
16
|
+
return config.apiToken || null;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.warn("Failed to read config file:", error);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "../config/env.js";
|
|
2
|
+
import { api } from "./axios.js";
|
|
3
|
+
import type { CreateAppRequest, ZippedComponent } from "./types.js";
|
|
4
|
+
|
|
5
|
+
export const createApp = async (data: CreateAppRequest): Promise<void> => {
|
|
6
|
+
const url = "/services/developer/create";
|
|
7
|
+
try {
|
|
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
|
+
};
|
package/src/api/types.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface CreateAppRequest {
|
|
2
|
+
appId: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface ApiError {
|
|
6
|
+
message: string;
|
|
7
|
+
code?: string;
|
|
8
|
+
details?: any;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ApiResponse<T> {
|
|
12
|
+
data: T;
|
|
13
|
+
success: boolean;
|
|
14
|
+
message?: string;
|
|
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
|
+
}
|
package/src/bin/fireberry.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { runInit } from "../commands/init.js";
|
|
5
|
+
import { runCreate } from "../commands/create.js";
|
|
5
6
|
import packageJson from "../../package.json" with { type: "json" };
|
|
7
|
+
import { runPush } from "../commands/push.js";
|
|
6
8
|
|
|
7
9
|
const program = new Command();
|
|
8
10
|
|
|
@@ -19,12 +21,30 @@ program
|
|
|
19
21
|
await runInit({ tokenid });
|
|
20
22
|
});
|
|
21
23
|
|
|
24
|
+
program
|
|
25
|
+
.command("create")
|
|
26
|
+
.argument("[name...]", "App name")
|
|
27
|
+
.description("Create a new Fireberry app")
|
|
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();
|
|
38
|
+
});
|
|
39
|
+
|
|
22
40
|
program.parseAsync(process.argv).catch((err: unknown) => {
|
|
23
41
|
const errorMessage = err instanceof Error
|
|
24
42
|
? err.message
|
|
25
43
|
: typeof err === 'string'
|
|
26
44
|
? err
|
|
27
45
|
: 'Unexpected error';
|
|
28
|
-
|
|
46
|
+
|
|
47
|
+
const formattedError = errorMessage.startsWith('Error:') ? errorMessage : `Error: ${errorMessage}`;
|
|
48
|
+
console.error(chalk.red(formattedError));
|
|
29
49
|
process.exit(1);
|
|
30
50
|
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import { v4 as uuidv4 } from "uuid";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import ora from "ora";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import { createApp } from "../api/requests.js";
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
|
|
13
|
+
interface CreateOptions {
|
|
14
|
+
name?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function slugifyName(name: string) {
|
|
18
|
+
const validPattern = /^[a-zA-Z0-9_-]+$/;
|
|
19
|
+
if (!validPattern.test(name)) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Invalid app name: "${name}". Only alphanumeric characters, underscores, and hyphens are allowed.`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return name;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function runCreate({ name }: CreateOptions): Promise<void> {
|
|
29
|
+
let appName = name;
|
|
30
|
+
|
|
31
|
+
if (!appName) {
|
|
32
|
+
const answers = await inquirer.prompt([
|
|
33
|
+
{ type: "input", name: "name", message: "App name" },
|
|
34
|
+
]);
|
|
35
|
+
appName = (answers.name || "").trim();
|
|
36
|
+
}
|
|
37
|
+
if (!appName) {
|
|
38
|
+
throw new Error("Missing name.");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const slug = slugifyName(appName);
|
|
42
|
+
const appId = uuidv4();
|
|
43
|
+
const appDir = path.resolve(process.cwd(), slug);
|
|
44
|
+
|
|
45
|
+
if (await fs.pathExists(appDir)) {
|
|
46
|
+
throw new Error(`Already exists. ${chalk.yellow(slug)}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const spinner = ora(`Creating app "${chalk.cyan(appName)}"...`).start();
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
await createApp({ appId });
|
|
53
|
+
|
|
54
|
+
await fs.ensureDir(appDir);
|
|
55
|
+
|
|
56
|
+
const templatesDir = path.join(__dirname, "..", "..", "src", "templates");
|
|
57
|
+
const manifestTemplate = await fs.readFile(
|
|
58
|
+
path.join(templatesDir, "manifest.yml"),
|
|
59
|
+
"utf-8"
|
|
60
|
+
);
|
|
61
|
+
const htmlTemplate = await fs.readFile(
|
|
62
|
+
path.join(templatesDir, "index.html"),
|
|
63
|
+
"utf-8"
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const manifestContent = manifestTemplate
|
|
67
|
+
.replace(/{{appName}}/g, appName)
|
|
68
|
+
.replace(/{{appId}}/g, appId);
|
|
69
|
+
|
|
70
|
+
const htmlContent = htmlTemplate.replace(/{{appName}}/g, appName);
|
|
71
|
+
|
|
72
|
+
await fs.writeFile(path.join(appDir, "manifest.yml"), manifestContent);
|
|
73
|
+
await fs.writeFile(path.join(appDir, "index.html"), htmlContent);
|
|
74
|
+
|
|
75
|
+
spinner.succeed(`Successfully created "${chalk.cyan(appName)}" app!`);
|
|
76
|
+
console.log(chalk.gray(`📁 Location: ${appDir}`));
|
|
77
|
+
console.log(chalk.gray(`App ID: ${appId}`));
|
|
78
|
+
console.log(chalk.green("\n🎉 Your app is ready! Next steps:"));
|
|
79
|
+
console.log(chalk.white(` cd ${slug}`));
|
|
80
|
+
console.log(chalk.white(" # Start developing your Fireberry app"));
|
|
81
|
+
} catch (error) {
|
|
82
|
+
spinner.fail(`Failed to create app "${chalk.cyan(appName)}"`);
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
package/src/commands/init.ts
CHANGED
|
@@ -9,13 +9,13 @@ interface InitOptions {
|
|
|
9
9
|
tokenid?: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
interface Config {
|
|
12
|
+
export interface Config {
|
|
13
13
|
apiToken: string;
|
|
14
14
|
createdAt: string;
|
|
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,10 @@
|
|
|
1
|
+
import { config } from "dotenv";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
const projectRoot = path.resolve(__dirname, "..", "..");
|
|
8
|
+
const envPath = path.join(projectRoot, ".env");
|
|
9
|
+
|
|
10
|
+
config({ path: envPath, quiet: true });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>{{appName}}</title>
|
|
8
|
+
</head>
|
|
9
|
+
|
|
10
|
+
<body>
|
|
11
|
+
<h1>Hello World</h1>
|
|
12
|
+
<p>Welcome to {{appName}}!</p>
|
|
13
|
+
</body>
|
|
14
|
+
|
|
15
|
+
</html>
|
|
@@ -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
|
+
};
|
package/bin/fireberry.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Command } from "commander";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
import { runInit } from "../src/commands/init.js";
|
|
5
|
-
|
|
6
|
-
const program = new Command();
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.name("fireberry")
|
|
10
|
-
.description("Fireberry developer CLI")
|
|
11
|
-
.version("0.0.1");
|
|
12
|
-
|
|
13
|
-
program
|
|
14
|
-
.command("init")
|
|
15
|
-
.argument("[tokenid]", "Fireberry token id")
|
|
16
|
-
.description("Initiates credentials and stores token in local config")
|
|
17
|
-
.action(async (tokenid) => {
|
|
18
|
-
await runInit({ tokenid });
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
program.parseAsync(process.argv).catch((err) => {
|
|
22
|
-
console.error(chalk.red(err?.message || "Unexpected error"));
|
|
23
|
-
process.exit(1);
|
|
24
|
-
});
|