From acb3b56bec314dea1aa1e1bdb60d27315c178b93 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Fri, 29 Sep 2023 23:02:05 -0700 Subject: Improve helptext --- src/cli.zig | 138 ++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 55 deletions(-) diff --git a/src/cli.zig b/src/cli.zig index baa6114aa..25f370335 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -55,43 +55,43 @@ pub const Cli = struct { MainPanicHandler.Singleton = &panicker; Command.start(allocator, log) catch |err| { switch (err) { - error.MissingEntryPoint => { - Output.prettyErrorln("bun build v" ++ Global.package_json_version_with_sha ++ "", .{}); - Output.prettyErrorln( - \\error: Missing entrypoints. What would you like to bundle? - \\ - \\Usage: bun build [flags] [...entrypoints] - \\ - \\Common Flags: - \\ --outfile Write the output to a specific file (default: stdout) - \\ --outdir Write the output to a directory (required for splitting) - \\ --minify Enable all minification flags - \\ --minify-whitespace Remove unneeded whitespace - \\ --minify-syntax Transform code to use less syntax - \\ --minify-identifiers Shorten variable names - \\ --sourcemap Generate sourcemaps - \\ ("none", "inline", or "external") - \\ --target The intended execution environment for the bundle. - \\ ("browser", "bun" or "node") - \\ --splitting Enable code splitting (requires --outdir) - \\ --watch Run bundler in watch mode - \\ - \\Examples: - \\ Frontend web apps: - \\ bun build ./src/index.ts --outfile=bundle.js - \\ bun build --minify --splitting --outdir=out ./index.jsx ./lib/worker.ts - \\ - \\ Bundle code to be run in Bun (reduces server startup time) - \\ bun build --target=bun ./server.ts --outfile=server.js - \\ - \\ Creating a standalone executable (see https://bun.sh/docs/bundler/executables) - \\ bun build --compile ./cli.ts --outfile=my-app - \\ - \\A full list of flags is available at https://bun.sh/docs/bundler - \\ - , .{}); - Global.exit(1); - }, + // error.MissingEntryPoint => { + // Output.prettyErrorln("bun build v" ++ Global.package_json_version_with_sha ++ "", .{}); + // Output.prettyErrorln( + // \\error: Missing entrypoints. What would you like to bundle? + // \\ + // \\Usage: bun build [flags] [...entrypoints] + // \\ + // \\Common Flags: + // \\ --outfile Write the output to a specific file (default: stdout) + // \\ --outdir Write the output to a directory (required for splitting) + // \\ --minify Enable all minification flags + // \\ --minify-whitespace Remove unneeded whitespace + // \\ --minify-syntax Transform code to use less syntax + // \\ --minify-identifiers Shorten variable names + // \\ --sourcemap Generate sourcemaps + // \\ none | inline | external + // \\ --target The intended execution environment for the bundle. + // \\ browser | bun | node + // \\ --splitting Enable code splitting (requires --outdir) + // \\ --watch Run bundler in watch mode + // \\ + // \\Examples: + // \\ Frontend web apps: + // \\ bun build ./src/index.ts --outfile=bundle.js + // \\ bun build --minify --splitting --outdir=out ./index.jsx ./lib/worker.ts + // \\ + // \\ Bundle code to be run in Bun (reduces server startup time) + // \\ bun build --target=bun ./server.ts --outfile=server.js + // \\ + // \\ Creating a standalone executable (see https://bun.sh/docs/bundler/executables) + // \\ bun build --compile ./cli.ts --outfile=my-app + // \\ + // \\A full list of flags is available at https://bun.sh/docs/bundler + // \\ + // , .{}); + // Global.exit(1); + // }, else => { // Always dump the logs // std.debug.print("dump logs", .{}); @@ -804,7 +804,17 @@ pub const Arguments = struct { if (cmd == .BuildCommand) { if (opts.entry_points.len == 0 and opts.framework == null) { - return error.MissingEntryPoint; + Output.prettyErrorln("bun build v" ++ Global.package_json_version_with_sha ++ "", .{}); + // Output.flush(); + // cmd.print_helptext(); + // Output.pretty("\n-------------\n", .{}); + Output.prettyError("error: Missing entrypoints. What would you like to bundle?\n\n", .{}); + Output.flush(); + Output.pretty("Usage:\n $ bun build \\ [...\\] [flags] \n", .{}); + Output.pretty("\nTo see full documentation:\n $ bun build --help\n", .{}); + Output.flush(); + // return error.MissingEntryPoint; + Global.exit(1); } } @@ -1815,35 +1825,53 @@ pub const Command = struct { pub fn print_helptext(cmd: Tag) void { return switch (cmd) { Command.Tag.BuildCommand => { + // clap.parseParam("--format Specifies the module format to build to. Only esm is supported.") catch unreachable, + // clap.parseParam("--outdir Default to \"dist\" if multiple files") catch unreachable, + // clap.parseParam("--outfile Write to a file") catch unreachable, + // clap.parseParam("--root Root directory used for multiple entry points") catch unreachable, + // clap.parseParam("--splitting Enable code splitting") catch unreachable, + // clap.parseParam("--public-path A prefix to be appended to any import paths in bundled code") catch unreachable, + // clap.parseParam("--sourcemap ? Build with sourcemaps - 'inline', 'external', or 'none'") catch unreachable, + // clap.parseParam("--entry-naming Customize entry point filenames. Defaults to \"[dir]/[name].[ext]\"") catch unreachable, + // clap.parseParam("--chunk-naming Customize chunk filenames. Defaults to \"[name]-[hash].[ext]\"") catch unreachable, + // clap.parseParam("--asset-naming Customize asset filenames. Defaults to \"[name]-[hash].[ext]\"") catch unreachable, + // clap.parseParam("--server-components Enable React Server Components (experimental)") catch unreachable, + // clap.parseParam("--no-bundle Transpile file only, do not bundle") catch unreachable, + // clap.parseParam("--compile Generate a standalone Bun executable containing your bundled code") catch unreachable, const build_helptext = \\Usage: bun build [flags] [...entrypoints] \\ \\Flags: - \\ --outfile Write the output to a specific file (default: stdout) - \\ --outdir Write the output to a directory (required for splitting) - \\ --minify Enable all minification flags - \\ --minify-whitespace Remove unneeded whitespace - \\ --minify-syntax Transform code to use less syntax - \\ --minify-identifiers Shorten variable names - \\ --sourcemap Generate sourcemaps - \\ ("none", "inline", or "external") - \\ --target The intended execution environment for the bundle. - \\ ("browser", "bun" or "node") - \\ --splitting Enable code splitting (requires --outdir) - \\ --watch Run bundler in watch mode + // \\ --format Specify the module format of the bundle. Only "esm". + \\ --target The intended execution environment for the bundle. + \\ One of browser | bun | node + \\ --outfile Write the output to a specific file (default: stdout) + \\ --outdir Write the output to a directory (required for splitting) + \\ --sourcemap Generate sourcemaps + \\ One of none | inline | external + \\ --splitting Enable code splitting (requires --outdir) + \\ --watch Run bundler in watch mode + \\ --compile Compile code into a standalone executable + \\ --root Root directory used for multiple entry points + \\ --public-path A prefix, often a URL, appended to all import paths + \\ --minify Enable all minification flags + \\ --minify-whitespace Remove unneeded whitespace + \\ --minify-syntax Transform code to use less syntax + \\ --minify-identifiers Shorten variable names \\ \\Examples: \\ Frontend web apps: \\ bun build ./src/index.ts --outfile=bundle.js - \\ bun build --minify --splitting --outdir=out ./index.jsx ./lib/worker.ts + \\ bun build ./index.jsx ./lib/worker.ts --minify --splitting --outdir=out \\ \\ Bundle code to be run in Bun (reduces server startup time) - \\ bun build --target=bun ./server.ts --outfile=server.js + \\ bun build ./server.ts --target=bun --outfile=server.js \\ \\ Creating a standalone executable (see https://bun.sh/docs/bundler/executables) - \\ bun build --compile ./cli.ts --outfile=my-app + \\ bun build ./cli.ts --compile --outfile=my-app + \\ + \\A full list of flags is available at https://bun.sh/docs/bundler \\ - \\Run `bun build --help --all` A full list of flags is available at https://bun.sh/docs/bundler ; Output.pretty(build_helptext, .{}); Output.flush(); @@ -1873,7 +1901,7 @@ pub const Command = struct { \\ Run all test files, only including tests whose names includes "baz" \\ bun test --test-name-pattern baz \\ - \\Run `bun test --help --all` A full list of flags is available at https://bun.sh/docs/bundler + \\Full documenatation is available at https://bun.sh/docs/cli/test ; Output.pretty(test_helptext, .{}); Output.flush(); -- cgit v1.2.3