@burger-api/cli 0.6.6 → 0.7.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.
@@ -1,100 +1,100 @@
1
- /**
2
- * Serve Command
3
- *
4
- * Runs a development server with hot reload (auto-restart on file changes).
5
- * This is perfect for development - just edit your code and see changes instantly!
6
- *
7
- * Example: burger-api serve
8
- * Example: burger-api serve --port 4000
9
- */
10
-
11
- import { Command } from 'commander';
12
- import { existsSync } from 'fs';
13
- import {
14
- success,
15
- error as logError,
16
- info,
17
- newline,
18
- highlight,
19
- dim,
20
- } from '../utils/logger';
21
-
22
- /**
23
- * Serve command options
24
- */
25
- interface ServeCommandOptions {
26
- port: string;
27
- file: string;
28
- }
29
-
30
- /**
31
- * Create the "serve" command
32
- * Starts a development server with hot reload
33
- */
34
- export const serveCommand = new Command('serve')
35
- .description('Start development server with hot reload')
36
- .option('-p, --port <port>', 'Port to run the server on', '4000')
37
- .option('-f, --file <file>', 'Entry file to run', 'src/index.ts')
38
- .action(async (options: ServeCommandOptions) => {
39
- const file = options.file;
40
- const port = options.port;
41
-
42
- // Check if the entry file exists
43
- if (!existsSync(file)) {
44
- logError(`Entry file not found: ${file}`);
45
- info('Make sure you are in the project directory.');
46
- process.exit(1);
47
- }
48
-
49
- // Show startup message
50
- newline();
51
- info('Starting development server...');
52
- newline();
53
- success(`Server running on ${highlight(`http://localhost:${port}`)}`);
54
- info('Press Ctrl+C to stop');
55
- dim('File changes will automatically restart the server');
56
- newline();
57
-
58
- try {
59
- // Run bun with --watch flag for hot reload
60
- // We use --watch to automatically restart when files change
61
- const proc = Bun.spawn(['bun', '--watch', file], {
62
- stdout: 'inherit', // Show output in the terminal
63
- stderr: 'inherit', // Show errors in the terminal
64
- stdin: 'inherit', // Allow user input
65
- env: {
66
- ...process.env,
67
- PORT: port, // Pass port as environment variable
68
- },
69
- });
70
-
71
- // Handle Ctrl+C gracefully
72
- process.on('SIGINT', () => {
73
- newline();
74
- info('Shutting down server...');
75
- proc.kill();
76
- process.exit(0);
77
- });
78
-
79
- // Handle Ctrl+Break on Windows
80
- process.on('SIGBREAK', () => {
81
- newline();
82
- info('Shutting down server...');
83
- proc.kill();
84
- process.exit(0);
85
- });
86
-
87
- // Wait for the process to exit
88
- const exitCode = await proc.exited;
89
-
90
- if (exitCode !== 0) {
91
- logError('Server stopped unexpectedly');
92
- process.exit(exitCode);
93
- }
94
- } catch (err) {
95
- logError(
96
- err instanceof Error ? err.message : 'Failed to start server'
97
- );
98
- process.exit(1);
99
- }
100
- });
1
+ /**
2
+ * Serve Command
3
+ *
4
+ * Runs a development server with hot reload (auto-restart on file changes).
5
+ * This is perfect for development - just edit your code and see changes instantly!
6
+ *
7
+ * Example: burger-api serve
8
+ * Example: burger-api serve --port 4000
9
+ */
10
+
11
+ import { Command } from 'commander';
12
+ import { existsSync } from 'fs';
13
+ import {
14
+ success,
15
+ error as logError,
16
+ info,
17
+ newline,
18
+ highlight,
19
+ dim,
20
+ } from '../utils/logger';
21
+
22
+ /**
23
+ * Serve command options
24
+ */
25
+ interface ServeCommandOptions {
26
+ port: string;
27
+ file: string;
28
+ }
29
+
30
+ /**
31
+ * Create the "serve" command
32
+ * Starts a development server with hot reload
33
+ */
34
+ export const serveCommand = new Command('serve')
35
+ .description('Start development server with hot reload')
36
+ .option('-p, --port <port>', 'Port to run the server on', '4000')
37
+ .option('-f, --file <file>', 'Entry file to run', 'src/index.ts')
38
+ .action(async (options: ServeCommandOptions) => {
39
+ const file = options.file;
40
+ const port = options.port;
41
+
42
+ // Check if the entry file exists
43
+ if (!existsSync(file)) {
44
+ logError(`Entry file not found: ${file}`);
45
+ info('Make sure you are in the project directory.');
46
+ process.exit(1);
47
+ }
48
+
49
+ // Show startup message
50
+ newline();
51
+ info('Starting development server...');
52
+ newline();
53
+ success(`Server running on ${highlight(`http://localhost:${port}`)}`);
54
+ info('Press Ctrl+C to stop');
55
+ dim('File changes will automatically restart the server');
56
+ newline();
57
+
58
+ try {
59
+ // Run bun with --watch flag for hot reload
60
+ // We use --watch to automatically restart when files change
61
+ const proc = Bun.spawn(['bun', '--watch', file], {
62
+ stdout: 'inherit', // Show output in the terminal
63
+ stderr: 'inherit', // Show errors in the terminal
64
+ stdin: 'inherit', // Allow user input
65
+ env: {
66
+ ...process.env,
67
+ PORT: port, // Pass port as environment variable
68
+ },
69
+ });
70
+
71
+ // Handle Ctrl+C gracefully
72
+ process.on('SIGINT', () => {
73
+ newline();
74
+ info('Shutting down server...');
75
+ proc.kill();
76
+ process.exit(0);
77
+ });
78
+
79
+ // Handle Ctrl+Break on Windows
80
+ process.on('SIGBREAK', () => {
81
+ newline();
82
+ info('Shutting down server...');
83
+ proc.kill();
84
+ process.exit(0);
85
+ });
86
+
87
+ // Wait for the process to exit
88
+ const exitCode = await proc.exited;
89
+
90
+ if (exitCode !== 0) {
91
+ logError('Server stopped unexpectedly');
92
+ process.exit(exitCode);
93
+ }
94
+ } catch (err) {
95
+ logError(
96
+ err instanceof Error ? err.message : 'Failed to start server'
97
+ );
98
+ process.exit(1);
99
+ }
100
+ });
package/src/index.ts CHANGED
@@ -1,59 +1,59 @@
1
- #!/usr/bin/env bun
2
-
3
- /**
4
- * BurgerAPI CLI Tool
5
- *
6
- * This is the main entry point for the CLI.
7
- * It sets up all the commands users can run.
8
- *
9
- * We use commander to handle command parsing and routing.
10
- * This makes it easy to add new commands and provide helpful error messages.
11
- */
12
-
13
- import { Command } from 'commander';
14
- import { createCommand } from './commands/create';
15
- import { addCommand } from './commands/add';
16
- import { listCommand } from './commands/list';
17
- import { buildCommand, buildExecutableCommand } from './commands/build';
18
- import { serveCommand } from './commands/serve';
19
- import { showBanner } from './utils/logger';
20
-
21
- /**
22
- * Create the main CLI program
23
- * This is what runs when someone types 'burger-api' in their terminal
24
- */
25
- const program = new Command();
26
-
27
- // Set up basic information about our CLI
28
- program
29
- .name('burger-api')
30
- .description('Simple tool to work with BurgerAPI projects')
31
- .version('0.6.6');
32
-
33
- // Add all our commands to the CLI
34
- // Each command is defined in its own file for better organization
35
- program.addCommand(createCommand); // Create new projects
36
- program.addCommand(addCommand); // Add middleware to projects
37
- program.addCommand(listCommand); // List available middleware
38
- program.addCommand(buildCommand); // Bundle to JS file
39
- program.addCommand(buildExecutableCommand); // Compile to executable
40
- program.addCommand(serveCommand); // Run development server
41
-
42
- // Show banner + help when no command is provided
43
- program.action(() => {
44
- showBanner();
45
- program.help();
46
- });
47
-
48
- // Override the help display to include banner
49
- program.configureOutput({
50
- writeOut: (str) => {
51
- process.stdout.write(str);
52
- },
53
- writeErr: (str) => {
54
- process.stderr.write(str);
55
- },
56
- });
57
-
58
- // Run the CLI - this parses the arguments the user typed
59
- program.parse();
1
+ #!/usr/bin/env bun
2
+
3
+ /**
4
+ * BurgerAPI CLI Tool
5
+ *
6
+ * This is the main entry point for the CLI.
7
+ * It sets up all the commands users can run.
8
+ *
9
+ * We use commander to handle command parsing and routing.
10
+ * This makes it easy to add new commands and provide helpful error messages.
11
+ */
12
+
13
+ import { Command } from 'commander';
14
+ import { createCommand } from './commands/create';
15
+ import { addCommand } from './commands/add';
16
+ import { listCommand } from './commands/list';
17
+ import { buildCommand, buildExecutableCommand } from './commands/build';
18
+ import { serveCommand } from './commands/serve';
19
+ import { showBanner } from './utils/logger';
20
+
21
+ /**
22
+ * Create the main CLI program
23
+ * This is what runs when someone types 'burger-api' in their terminal
24
+ */
25
+ const program = new Command();
26
+
27
+ // Set up basic information about our CLI
28
+ program
29
+ .name('burger-api')
30
+ .description('Simple tool to work with BurgerAPI projects')
31
+ .version('0.7.1');
32
+
33
+ // Add all our commands to the CLI
34
+ // Each command is defined in its own file for better organization
35
+ program.addCommand(createCommand); // Create new projects
36
+ program.addCommand(addCommand); // Add middleware to projects
37
+ program.addCommand(listCommand); // List available middleware
38
+ program.addCommand(buildCommand); // Bundle to JS file
39
+ program.addCommand(buildExecutableCommand); // Compile to executable
40
+ program.addCommand(serveCommand); // Run development server
41
+
42
+ // Show banner + help when no command is provided
43
+ program.action(() => {
44
+ showBanner();
45
+ program.help();
46
+ });
47
+
48
+ // Override the help display to include banner
49
+ program.configureOutput({
50
+ writeOut: (str) => {
51
+ process.stdout.write(str);
52
+ },
53
+ writeErr: (str) => {
54
+ process.stderr.write(str);
55
+ },
56
+ });
57
+
58
+ // Run the CLI - this parses the arguments the user typed
59
+ program.parse();
@@ -1,53 +1,53 @@
1
- /**
2
- * Shared TypeScript types for the CLI
3
- *
4
- * These types are used across different parts of the CLI
5
- * to ensure type safety and good developer experience.
6
- */
7
-
8
- /**
9
- * Options for creating a new Burger API project
10
- */
11
- export interface CreateOptions {
12
- /** Name of the project */
13
- name: string;
14
- /** Whether to include API routes */
15
- useApi: boolean;
16
- /** Directory for API routes (e.g., 'api') */
17
- apiDir?: string;
18
- /** Prefix for API routes (e.g., '/api') */
19
- apiPrefix?: string;
20
- /** Enable debug mode */
21
- debug?: boolean;
22
- /** Whether to include Page routes */
23
- usePages: boolean;
24
- /** Directory for Page routes (e.g., 'pages') */
25
- pageDir?: string;
26
- /** Prefix for Page routes (e.g., '/') */
27
- pagePrefix?: string;
28
- }
29
-
30
- /**
31
- * Information about a middleware/feature from GitHub
32
- */
33
- export interface MiddlewareInfo {
34
- /** Name of the middleware (e.g., 'cors') */
35
- name: string;
36
- /** Short description of what it does */
37
- description: string;
38
- /** Path in the GitHub repo */
39
- path: string;
40
- /** Files that are part of this middleware */
41
- files: string[];
42
- }
43
-
44
- /**
45
- * GitHub API response for directory contents
46
- */
47
- export interface GitHubFile {
48
- name: string;
49
- path: string;
50
- type: 'file' | 'dir';
51
- download_url?: string;
52
- size: number;
53
- }
1
+ /**
2
+ * Shared TypeScript types for the CLI
3
+ *
4
+ * These types are used across different parts of the CLI
5
+ * to ensure type safety and good developer experience.
6
+ */
7
+
8
+ /**
9
+ * Options for creating a new Burger API project
10
+ */
11
+ export interface CreateOptions {
12
+ /** Name of the project */
13
+ name: string;
14
+ /** Whether to include API routes */
15
+ useApi: boolean;
16
+ /** Directory for API routes (e.g., 'api') */
17
+ apiDir?: string;
18
+ /** Prefix for API routes (e.g., '/api') */
19
+ apiPrefix?: string;
20
+ /** Enable debug mode */
21
+ debug?: boolean;
22
+ /** Whether to include Page routes */
23
+ usePages: boolean;
24
+ /** Directory for Page routes (e.g., 'pages') */
25
+ pageDir?: string;
26
+ /** Prefix for Page routes (e.g., '/') */
27
+ pagePrefix?: string;
28
+ }
29
+
30
+ /**
31
+ * Information about a middleware/feature from GitHub
32
+ */
33
+ export interface MiddlewareInfo {
34
+ /** Name of the middleware (e.g., 'cors') */
35
+ name: string;
36
+ /** Short description of what it does */
37
+ description: string;
38
+ /** Path in the GitHub repo */
39
+ path: string;
40
+ /** Files that are part of this middleware */
41
+ files: string[];
42
+ }
43
+
44
+ /**
45
+ * GitHub API response for directory contents
46
+ */
47
+ export interface GitHubFile {
48
+ name: string;
49
+ path: string;
50
+ type: 'file' | 'dir';
51
+ download_url?: string;
52
+ size: number;
53
+ }