@fireberry/cli 0.2.0 → 0.2.1

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.
@@ -4,3 +4,5 @@ export declare const createApp: (manifest: Manifest) => Promise<void>;
4
4
  export declare const pushComponents: (appId: string, components: ZippedComponent[], manifest: Manifest) => Promise<void>;
5
5
  export declare const installApp: (manifest: Manifest) => Promise<void>;
6
6
  export declare const deleteApp: (manifest: Manifest) => Promise<void>;
7
+ export declare const startDebug: (appId: string, componentId: string, debugUrl: string, manifest: Manifest) => Promise<void>;
8
+ export declare const stopDebug: (appId: string, componentId: string, manifest: Manifest) => Promise<void>;
@@ -37,3 +37,21 @@ export const deleteApp = async (manifest) => {
37
37
  throw new Error(error instanceof Error ? error.message : "Unknown error");
38
38
  }
39
39
  };
40
+ export const startDebug = async (appId, componentId, debugUrl, manifest) => {
41
+ const url = `${BASE_SERVICE_URL}/debug`;
42
+ try {
43
+ await api.post(url, { appId, componentId, debugUrl, manifest });
44
+ }
45
+ catch (error) {
46
+ throw new Error(error instanceof Error ? error.message : "Unknown error");
47
+ }
48
+ };
49
+ export const stopDebug = async (appId, componentId, manifest) => {
50
+ const url = `${BASE_SERVICE_URL}/debug`;
51
+ try {
52
+ await api.delete(url, { appId, componentId, manifest });
53
+ }
54
+ catch (error) {
55
+ throw new Error(error instanceof Error ? error.message : "Unknown error");
56
+ }
57
+ };
@@ -7,6 +7,7 @@ import packageJson from "../../package.json" with { type: "json" };
7
7
  import { runPush } from "../commands/push.js";
8
8
  import { runInstall } from "../commands/install.js";
9
9
  import { runDelete } from "../commands/delete.js";
10
+ import { runDebug } from "../commands/debug.js";
10
11
  const program = new Command();
11
12
  program
12
13
  .name("fireberry")
@@ -44,6 +45,15 @@ program
44
45
  .action(async () => {
45
46
  await runDelete();
46
47
  });
48
+ program
49
+ .command("debug")
50
+ .argument("<component-id>", "Component ID to debug")
51
+ .argument("[url]", "Debug URL in format localhost:[port]")
52
+ .option("--stop", "Stop debugging the component")
53
+ .description("Start or stop debugging a component")
54
+ .action(async (componentId, url, options) => {
55
+ await runDebug(componentId, url, options);
56
+ });
47
57
  program.parseAsync(process.argv).catch((err) => {
48
58
  const errorMessage = err instanceof Error
49
59
  ? err.message
@@ -0,0 +1,3 @@
1
+ export declare function runDebug(componentId: string, url?: string, options?: {
2
+ stop?: boolean;
3
+ }): Promise<void>;
@@ -0,0 +1,54 @@
1
+ import ora from "ora";
2
+ import chalk from "chalk";
3
+ import { startDebug, stopDebug } from "../api/requests.js";
4
+ import { getManifest } from "../utils/components.utils.js";
5
+ function validateDebugUrl(url) {
6
+ const localhostPattern = /^localhost:\d+$/;
7
+ if (!localhostPattern.test(url)) {
8
+ throw new Error("Invalid URL format. URL must be in format: localhost:[port] (e.g., localhost:3000)\n" +
9
+ "Do not include http:// or https://");
10
+ }
11
+ }
12
+ function validateComponentExists(manifest, componentId) {
13
+ const component = manifest.components?.find((comp) => comp.id === componentId);
14
+ if (!component) {
15
+ throw new Error(`Component with ID "${componentId}" not found in manifest.\n` +
16
+ `Available components:\n` +
17
+ manifest.components
18
+ ?.map((comp) => ` - ${comp.title} (${comp.id})`)
19
+ .join("\n"));
20
+ }
21
+ }
22
+ export async function runDebug(componentId, url, options) {
23
+ const spinner = ora("Loading manifest...").start();
24
+ try {
25
+ const manifest = await getManifest();
26
+ spinner.succeed("Manifest loaded");
27
+ // Validate component exists
28
+ validateComponentExists(manifest, componentId);
29
+ if (options?.stop) {
30
+ // Stop debugging
31
+ spinner.start("Stopping debug mode...");
32
+ await stopDebug(manifest.app.id, componentId, manifest);
33
+ spinner.succeed(chalk.green(`Debug mode stopped for component: ${componentId}`));
34
+ }
35
+ else {
36
+ // Start debugging
37
+ if (!url) {
38
+ throw new Error("URL is required when starting debug mode.\n" +
39
+ `Usage: fireberry debug ${componentId} localhost:[port]`);
40
+ }
41
+ validateDebugUrl(url);
42
+ spinner.start(`Starting debug mode for component ${componentId}...`);
43
+ await startDebug(manifest.app.id, componentId, url, manifest);
44
+ spinner.succeed(chalk.green(`Debug mode started!\n` +
45
+ ` Component: ${componentId}\n` +
46
+ ` URL: ${url}\n\n` +
47
+ `To stop debugging, run: ${chalk.cyan(`fireberry debug ${componentId} --stop`)}`));
48
+ }
49
+ }
50
+ catch (error) {
51
+ spinner.fail(options?.stop ? "Failed to stop debug mode" : "Failed to start debug mode");
52
+ throw error;
53
+ }
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireberry/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Fireberry CLI tool",
5
5
  "type": "module",
6
6
  "author": "",
@@ -42,3 +42,30 @@ export const deleteApp = async (manifest: Manifest): Promise<void> => {
42
42
  throw new Error(error instanceof Error ? error.message : "Unknown error");
43
43
  }
44
44
  };
45
+
46
+ export const startDebug = async (
47
+ appId: string,
48
+ componentId: string,
49
+ debugUrl: string,
50
+ manifest: Manifest
51
+ ): Promise<void> => {
52
+ const url = `${BASE_SERVICE_URL}/debug`;
53
+ try {
54
+ await api.post<void>(url, { appId, componentId, debugUrl, manifest });
55
+ } catch (error) {
56
+ throw new Error(error instanceof Error ? error.message : "Unknown error");
57
+ }
58
+ };
59
+
60
+ export const stopDebug = async (
61
+ appId: string,
62
+ componentId: string,
63
+ manifest: Manifest
64
+ ): Promise<void> => {
65
+ const url = `${BASE_SERVICE_URL}/debug`;
66
+ try {
67
+ await api.delete<void>(url, { appId, componentId, manifest });
68
+ } catch (error) {
69
+ throw new Error(error instanceof Error ? error.message : "Unknown error");
70
+ }
71
+ };
@@ -7,6 +7,7 @@ import packageJson from "../../package.json" with { type: "json" };
7
7
  import { runPush } from "../commands/push.js";
8
8
  import { runInstall } from "../commands/install.js";
9
9
  import { runDelete } from "../commands/delete.js";
10
+ import { runDebug } from "../commands/debug.js";
10
11
 
11
12
  const program = new Command();
12
13
 
@@ -52,6 +53,16 @@ program
52
53
  await runDelete();
53
54
  });
54
55
 
56
+ program
57
+ .command("debug")
58
+ .argument("<component-id>", "Component ID to debug")
59
+ .argument("[url]", "Debug URL in format localhost:[port]")
60
+ .option("--stop", "Stop debugging the component")
61
+ .description("Start or stop debugging a component")
62
+ .action(async (componentId: string, url?: string, options?: { stop?: boolean }) => {
63
+ await runDebug(componentId, url, options);
64
+ });
65
+
55
66
  program.parseAsync(process.argv).catch((err: unknown) => {
56
67
  const errorMessage = err instanceof Error
57
68
  ? err.message
@@ -0,0 +1,84 @@
1
+ import ora from "ora";
2
+ import chalk from "chalk";
3
+ import { startDebug, stopDebug } from "../api/requests.js";
4
+ import { getManifest } from "../utils/components.utils.js";
5
+
6
+ function validateDebugUrl(url: string): void {
7
+ const localhostPattern = /^localhost:\d+$/;
8
+
9
+ if (!localhostPattern.test(url)) {
10
+ throw new Error(
11
+ "Invalid URL format. URL must be in format: localhost:[port] (e.g., localhost:3000)\n" +
12
+ "Do not include http:// or https://"
13
+ );
14
+ }
15
+ }
16
+
17
+ function validateComponentExists(manifest: any, componentId: string): void {
18
+ const component = manifest.components?.find(
19
+ (comp: any) => comp.id === componentId
20
+ );
21
+
22
+ if (!component) {
23
+ throw new Error(
24
+ `Component with ID "${componentId}" not found in manifest.\n` +
25
+ `Available components:\n` +
26
+ manifest.components
27
+ ?.map((comp: any) => ` - ${comp.title} (${comp.id})`)
28
+ .join("\n")
29
+ );
30
+ }
31
+ }
32
+
33
+ export async function runDebug(
34
+ componentId: string,
35
+ url?: string,
36
+ options?: { stop?: boolean }
37
+ ): Promise<void> {
38
+ const spinner = ora("Loading manifest...").start();
39
+
40
+ try {
41
+ const manifest = await getManifest();
42
+ spinner.succeed("Manifest loaded");
43
+
44
+ // Validate component exists
45
+ validateComponentExists(manifest, componentId);
46
+
47
+ if (options?.stop) {
48
+ // Stop debugging
49
+ spinner.start("Stopping debug mode...");
50
+ await stopDebug(manifest.app.id, componentId, manifest);
51
+ spinner.succeed(
52
+ chalk.green(`Debug mode stopped for component: ${componentId}`)
53
+ );
54
+ } else {
55
+ // Start debugging
56
+ if (!url) {
57
+ throw new Error(
58
+ "URL is required when starting debug mode.\n" +
59
+ `Usage: fireberry debug ${componentId} localhost:[port]`
60
+ );
61
+ }
62
+
63
+ validateDebugUrl(url);
64
+
65
+ spinner.start(`Starting debug mode for component ${componentId}...`);
66
+ await startDebug(manifest.app.id, componentId, url, manifest);
67
+ spinner.succeed(
68
+ chalk.green(
69
+ `Debug mode started!\n` +
70
+ ` Component: ${componentId}\n` +
71
+ ` URL: ${url}\n\n` +
72
+ `To stop debugging, run: ${chalk.cyan(
73
+ `fireberry debug ${componentId} --stop`
74
+ )}`
75
+ )
76
+ );
77
+ }
78
+ } catch (error) {
79
+ spinner.fail(
80
+ options?.stop ? "Failed to stop debug mode" : "Failed to start debug mode"
81
+ );
82
+ throw error;
83
+ }
84
+ }