@buenojs/bueno 0.8.3 → 0.8.5
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/README.md +136 -16
- package/dist/cli/{index.js → bin.js} +3036 -1421
- package/dist/container/index.js +250 -0
- package/dist/context/index.js +219 -0
- package/dist/database/index.js +493 -0
- package/dist/frontend/index.js +7697 -0
- package/dist/health/index.js +364 -0
- package/dist/i18n/index.js +345 -0
- package/dist/index.js +11043 -6482
- package/dist/jobs/index.js +819 -0
- package/dist/lock/index.js +367 -0
- package/dist/logger/index.js +281 -0
- package/dist/metrics/index.js +289 -0
- package/dist/middleware/index.js +77 -0
- package/dist/migrations/index.js +571 -0
- package/dist/modules/index.js +3346 -0
- package/dist/notification/index.js +484 -0
- package/dist/observability/index.js +331 -0
- package/dist/openapi/index.js +776 -0
- package/dist/orm/index.js +1356 -0
- package/dist/router/index.js +886 -0
- package/dist/rpc/index.js +691 -0
- package/dist/schema/index.js +400 -0
- package/dist/telemetry/index.js +595 -0
- package/dist/template/index.js +640 -0
- package/dist/templates/index.js +640 -0
- package/dist/testing/index.js +1111 -0
- package/dist/types/index.js +60 -0
- package/package.json +121 -27
- package/src/cache/index.ts +2 -1
- package/src/cli/bin.ts +2 -2
- package/src/cli/commands/build.ts +183 -165
- package/src/cli/commands/dev.ts +96 -89
- package/src/cli/commands/generate.ts +142 -111
- package/src/cli/commands/help.ts +20 -16
- package/src/cli/commands/index.ts +3 -6
- package/src/cli/commands/migration.ts +124 -105
- package/src/cli/commands/new.ts +392 -438
- package/src/cli/commands/start.ts +81 -79
- package/src/cli/core/args.ts +68 -50
- package/src/cli/core/console.ts +89 -95
- package/src/cli/core/index.ts +4 -4
- package/src/cli/core/prompt.ts +65 -62
- package/src/cli/core/spinner.ts +23 -20
- package/src/cli/index.ts +46 -38
- package/src/cli/templates/database/index.ts +61 -0
- package/src/cli/templates/database/mysql.ts +14 -0
- package/src/cli/templates/database/none.ts +16 -0
- package/src/cli/templates/database/postgresql.ts +14 -0
- package/src/cli/templates/database/sqlite.ts +14 -0
- package/src/cli/templates/deploy.ts +29 -26
- package/src/cli/templates/docker.ts +41 -30
- package/src/cli/templates/frontend/index.ts +63 -0
- package/src/cli/templates/frontend/none.ts +17 -0
- package/src/cli/templates/frontend/react.ts +140 -0
- package/src/cli/templates/frontend/solid.ts +134 -0
- package/src/cli/templates/frontend/svelte.ts +131 -0
- package/src/cli/templates/frontend/vue.ts +130 -0
- package/src/cli/templates/generators/index.ts +339 -0
- package/src/cli/templates/generators/types.ts +56 -0
- package/src/cli/templates/index.ts +35 -2
- package/src/cli/templates/project/api.ts +81 -0
- package/src/cli/templates/project/default.ts +140 -0
- package/src/cli/templates/project/fullstack.ts +111 -0
- package/src/cli/templates/project/index.ts +95 -0
- package/src/cli/templates/project/minimal.ts +45 -0
- package/src/cli/templates/project/types.ts +94 -0
- package/src/cli/templates/project/website.ts +263 -0
- package/src/cli/utils/fs.ts +55 -41
- package/src/cli/utils/index.ts +3 -2
- package/src/cli/utils/strings.ts +47 -33
- package/src/cli/utils/version.ts +47 -0
- package/src/config/env-validation.ts +100 -0
- package/src/config/env.ts +169 -41
- package/src/config/index.ts +28 -20
- package/src/config/loader.ts +25 -16
- package/src/config/merge.ts +21 -10
- package/src/config/types.ts +545 -25
- package/src/config/validation.ts +215 -7
- package/src/container/forward-ref.ts +22 -22
- package/src/container/index.ts +34 -12
- package/src/context/index.ts +11 -1
- package/src/database/index.ts +7 -190
- package/src/database/orm/builder.ts +457 -0
- package/src/database/orm/casts/index.ts +130 -0
- package/src/database/orm/casts/types.ts +25 -0
- package/src/database/orm/compiler.ts +304 -0
- package/src/database/orm/hooks/index.ts +114 -0
- package/src/database/orm/index.ts +61 -0
- package/src/database/orm/model-registry.ts +59 -0
- package/src/database/orm/model.ts +821 -0
- package/src/database/orm/relationships/base.ts +146 -0
- package/src/database/orm/relationships/belongs-to-many.ts +179 -0
- package/src/database/orm/relationships/belongs-to.ts +56 -0
- package/src/database/orm/relationships/has-many.ts +45 -0
- package/src/database/orm/relationships/has-one.ts +41 -0
- package/src/database/orm/relationships/index.ts +11 -0
- package/src/database/orm/scopes/index.ts +55 -0
- package/src/events/__tests__/event-system.test.ts +235 -0
- package/src/events/config.ts +238 -0
- package/src/events/example-usage.ts +185 -0
- package/src/events/index.ts +278 -0
- package/src/events/manager.ts +385 -0
- package/src/events/registry.ts +182 -0
- package/src/events/types.ts +124 -0
- package/src/frontend/api-routes.ts +65 -23
- package/src/frontend/bundler.ts +76 -34
- package/src/frontend/console-client.ts +2 -2
- package/src/frontend/console-stream.ts +94 -38
- package/src/frontend/dev-server.ts +94 -46
- package/src/frontend/file-router.ts +61 -19
- package/src/frontend/frameworks/index.ts +37 -10
- package/src/frontend/frameworks/react.ts +10 -8
- package/src/frontend/frameworks/solid.ts +11 -9
- package/src/frontend/frameworks/svelte.ts +15 -9
- package/src/frontend/frameworks/vue.ts +13 -11
- package/src/frontend/hmr-client.ts +12 -10
- package/src/frontend/hmr.ts +146 -103
- package/src/frontend/index.ts +14 -5
- package/src/frontend/islands.ts +41 -22
- package/src/frontend/isr.ts +59 -37
- package/src/frontend/layout.ts +36 -21
- package/src/frontend/ssr/react.ts +74 -27
- package/src/frontend/ssr/solid.ts +54 -20
- package/src/frontend/ssr/svelte.ts +48 -14
- package/src/frontend/ssr/vue.ts +50 -18
- package/src/frontend/ssr.ts +83 -39
- package/src/frontend/types.ts +91 -56
- package/src/health/index.ts +21 -9
- package/src/i18n/engine.ts +305 -0
- package/src/i18n/index.ts +38 -0
- package/src/i18n/loader.ts +218 -0
- package/src/i18n/middleware.ts +164 -0
- package/src/i18n/negotiator.ts +162 -0
- package/src/i18n/types.ts +158 -0
- package/src/index.ts +179 -27
- package/src/jobs/drivers/memory.ts +315 -0
- package/src/jobs/drivers/redis.ts +459 -0
- package/src/jobs/index.ts +30 -0
- package/src/jobs/queue.ts +281 -0
- package/src/jobs/types.ts +295 -0
- package/src/jobs/worker.ts +380 -0
- package/src/logger/index.ts +1 -3
- package/src/logger/transports/index.ts +62 -22
- package/src/metrics/index.ts +25 -16
- package/src/migrations/index.ts +9 -0
- package/src/modules/filters.ts +13 -17
- package/src/modules/guards.ts +49 -26
- package/src/modules/index.ts +409 -298
- package/src/modules/interceptors.ts +58 -20
- package/src/modules/lazy.ts +11 -19
- package/src/modules/lifecycle.ts +15 -7
- package/src/modules/metadata.ts +15 -5
- package/src/modules/pipes.ts +94 -72
- package/src/notification/channels/base.ts +68 -0
- package/src/notification/channels/email.ts +105 -0
- package/src/notification/channels/push.ts +104 -0
- package/src/notification/channels/sms.ts +105 -0
- package/src/notification/channels/whatsapp.ts +104 -0
- package/src/notification/index.ts +48 -0
- package/src/notification/service.ts +354 -0
- package/src/notification/types.ts +344 -0
- package/src/observability/__tests__/observability.test.ts +483 -0
- package/src/observability/breadcrumbs.ts +114 -0
- package/src/observability/index.ts +136 -0
- package/src/observability/interceptor.ts +85 -0
- package/src/observability/service.ts +303 -0
- package/src/observability/trace.ts +37 -0
- package/src/observability/types.ts +196 -0
- package/src/openapi/__tests__/decorators.test.ts +335 -0
- package/src/openapi/__tests__/document-builder.test.ts +285 -0
- package/src/openapi/__tests__/route-scanner.test.ts +334 -0
- package/src/openapi/__tests__/schema-generator.test.ts +275 -0
- package/src/openapi/decorators.ts +328 -0
- package/src/openapi/document-builder.ts +274 -0
- package/src/openapi/index.ts +112 -0
- package/src/openapi/metadata.ts +112 -0
- package/src/openapi/route-scanner.ts +289 -0
- package/src/openapi/schema-generator.ts +256 -0
- package/src/openapi/swagger-module.ts +166 -0
- package/src/openapi/types.ts +398 -0
- package/src/orm/index.ts +10 -0
- package/src/rpc/index.ts +3 -1
- package/src/schema/index.ts +9 -0
- package/src/security/index.ts +15 -6
- package/src/ssg/index.ts +9 -8
- package/src/telemetry/index.ts +76 -22
- package/src/template/index.ts +7 -0
- package/src/templates/engine.ts +224 -0
- package/src/templates/index.ts +9 -0
- package/src/templates/loader.ts +331 -0
- package/src/templates/renderers/markdown.ts +212 -0
- package/src/templates/renderers/simple.ts +269 -0
- package/src/templates/types.ts +154 -0
- package/src/testing/index.ts +100 -27
- package/src/types/optional-deps.d.ts +347 -187
- package/src/validation/index.ts +92 -2
- package/src/validation/schemas.ts +536 -0
- package/tests/integration/fullstack.test.ts +4 -4
- package/tests/unit/database.test.ts +2 -72
- package/tests/unit/env-validation.test.ts +166 -0
- package/tests/unit/events.test.ts +910 -0
- package/tests/unit/i18n.test.ts +455 -0
- package/tests/unit/jobs.test.ts +493 -0
- package/tests/unit/notification.test.ts +988 -0
- package/tests/unit/observability.test.ts +453 -0
- package/tests/unit/orm/builder.test.ts +323 -0
- package/tests/unit/orm/casts.test.ts +179 -0
- package/tests/unit/orm/compiler.test.ts +220 -0
- package/tests/unit/orm/eager-loading.test.ts +285 -0
- package/tests/unit/orm/hooks.test.ts +191 -0
- package/tests/unit/orm/model.test.ts +373 -0
- package/tests/unit/orm/relationships.test.ts +303 -0
- package/tests/unit/orm/scopes.test.ts +74 -0
- package/tests/unit/templates-simple.test.ts +53 -0
- package/tests/unit/templates.test.ts +454 -0
- package/tests/unit/validation.test.ts +18 -24
- package/tsconfig.json +11 -3
|
@@ -4,43 +4,53 @@
|
|
|
4
4
|
* Build the application for production
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { getOption, hasFlag, type ParsedArgs } from '../core/args';
|
|
9
|
-
import { cliConsole, colors, formatSize, formatDuration } from '../core/console';
|
|
10
|
-
import { spinner } from '../core/spinner';
|
|
7
|
+
import { type ParsedArgs, getOption, hasFlag } from "../core/args";
|
|
11
8
|
import {
|
|
9
|
+
cliConsole,
|
|
10
|
+
colors,
|
|
11
|
+
formatDuration,
|
|
12
|
+
formatSize,
|
|
13
|
+
} from "../core/console";
|
|
14
|
+
import { spinner } from "../core/spinner";
|
|
15
|
+
import { CLIError, CLIErrorType } from "../index";
|
|
16
|
+
import {
|
|
17
|
+
deleteDirectory,
|
|
12
18
|
fileExists,
|
|
13
19
|
getProjectRoot,
|
|
14
20
|
isBuenoProject,
|
|
15
21
|
joinPaths,
|
|
16
|
-
readFile,
|
|
17
|
-
deleteDirectory,
|
|
18
22
|
listFiles,
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
readFile,
|
|
24
|
+
} from "../utils/fs";
|
|
25
|
+
import { defineCommand } from "./index";
|
|
21
26
|
|
|
22
27
|
/**
|
|
23
28
|
* Build targets
|
|
24
29
|
*/
|
|
25
|
-
type BuildTarget =
|
|
30
|
+
type BuildTarget = "bun" | "node" | "standalone";
|
|
26
31
|
|
|
27
32
|
/**
|
|
28
33
|
* Cross-compile targets
|
|
29
34
|
*/
|
|
30
|
-
type CrossCompileTarget =
|
|
35
|
+
type CrossCompileTarget =
|
|
36
|
+
| "linux-x64"
|
|
37
|
+
| "linux-arm64"
|
|
38
|
+
| "windows-x64"
|
|
39
|
+
| "darwin-x64"
|
|
40
|
+
| "darwin-arm64";
|
|
31
41
|
|
|
32
42
|
/**
|
|
33
43
|
* Find the entry point for the application
|
|
34
44
|
*/
|
|
35
45
|
async function findEntryPoint(projectRoot: string): Promise<string | null> {
|
|
36
46
|
const possibleEntries = [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
"server/main.ts",
|
|
48
|
+
"src/main.ts",
|
|
49
|
+
"src/index.ts",
|
|
50
|
+
"main.ts",
|
|
51
|
+
"index.ts",
|
|
52
|
+
"server.ts",
|
|
53
|
+
"app.ts",
|
|
44
54
|
];
|
|
45
55
|
|
|
46
56
|
for (const entry of possibleEntries) {
|
|
@@ -58,58 +68,58 @@ async function findEntryPoint(projectRoot: string): Promise<string | null> {
|
|
|
58
68
|
*/
|
|
59
69
|
async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
60
70
|
// Get options
|
|
61
|
-
const target = getOption(args,
|
|
62
|
-
name:
|
|
63
|
-
alias:
|
|
64
|
-
type:
|
|
65
|
-
default:
|
|
66
|
-
description:
|
|
71
|
+
const target = getOption(args, "target", {
|
|
72
|
+
name: "target",
|
|
73
|
+
alias: "t",
|
|
74
|
+
type: "string",
|
|
75
|
+
default: "bun",
|
|
76
|
+
description: "",
|
|
67
77
|
}) as BuildTarget;
|
|
68
78
|
|
|
69
|
-
const outDir = getOption<string>(args,
|
|
70
|
-
name:
|
|
71
|
-
alias:
|
|
72
|
-
type:
|
|
73
|
-
default:
|
|
74
|
-
description:
|
|
79
|
+
const outDir = getOption<string>(args, "outdir", {
|
|
80
|
+
name: "outdir",
|
|
81
|
+
alias: "o",
|
|
82
|
+
type: "string",
|
|
83
|
+
default: "./dist",
|
|
84
|
+
description: "",
|
|
75
85
|
});
|
|
76
86
|
|
|
77
|
-
const minify = !hasFlag(args,
|
|
78
|
-
const sourcemap = hasFlag(args,
|
|
79
|
-
const analyze = hasFlag(args,
|
|
80
|
-
const configPath = getOption(args,
|
|
81
|
-
name:
|
|
82
|
-
alias:
|
|
83
|
-
type:
|
|
84
|
-
description:
|
|
87
|
+
const minify = !hasFlag(args, "no-minify");
|
|
88
|
+
const sourcemap = hasFlag(args, "sourcemap");
|
|
89
|
+
const analyze = hasFlag(args, "analyze");
|
|
90
|
+
const configPath = getOption(args, "config", {
|
|
91
|
+
name: "config",
|
|
92
|
+
alias: "c",
|
|
93
|
+
type: "string",
|
|
94
|
+
description: "",
|
|
85
95
|
});
|
|
86
96
|
|
|
87
97
|
// Compile options
|
|
88
|
-
const compile = hasFlag(args,
|
|
89
|
-
const crossCompile = getOption(args,
|
|
90
|
-
name:
|
|
91
|
-
type:
|
|
92
|
-
description:
|
|
98
|
+
const compile = hasFlag(args, "compile");
|
|
99
|
+
const crossCompile = getOption(args, "cross-compile", {
|
|
100
|
+
name: "cross-compile",
|
|
101
|
+
type: "string",
|
|
102
|
+
description: "",
|
|
93
103
|
}) as CrossCompileTarget | undefined;
|
|
94
|
-
const executableName = getOption<string>(args,
|
|
95
|
-
name:
|
|
96
|
-
type:
|
|
97
|
-
default:
|
|
98
|
-
description:
|
|
104
|
+
const executableName = getOption<string>(args, "executable-name", {
|
|
105
|
+
name: "executable-name",
|
|
106
|
+
type: "string",
|
|
107
|
+
default: "main",
|
|
108
|
+
description: "",
|
|
99
109
|
});
|
|
100
110
|
|
|
101
111
|
// Validate cross-compile target
|
|
102
112
|
if (crossCompile) {
|
|
103
113
|
const validCrossCompileTargets: CrossCompileTarget[] = [
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
"linux-x64",
|
|
115
|
+
"linux-arm64",
|
|
116
|
+
"windows-x64",
|
|
117
|
+
"darwin-x64",
|
|
118
|
+
"darwin-arm64",
|
|
109
119
|
];
|
|
110
120
|
if (!validCrossCompileTargets.includes(crossCompile)) {
|
|
111
121
|
throw new CLIError(
|
|
112
|
-
`Invalid cross-compile target: ${crossCompile}. Valid targets: ${validCrossCompileTargets.join(
|
|
122
|
+
`Invalid cross-compile target: ${crossCompile}. Valid targets: ${validCrossCompileTargets.join(", ")}`,
|
|
113
123
|
CLIErrorType.INVALID_ARGS,
|
|
114
124
|
);
|
|
115
125
|
}
|
|
@@ -118,16 +128,16 @@ async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
|
118
128
|
// Validate that cross-compile requires compile
|
|
119
129
|
if (crossCompile && !compile) {
|
|
120
130
|
throw new CLIError(
|
|
121
|
-
|
|
131
|
+
"--cross-compile requires --compile flag",
|
|
122
132
|
CLIErrorType.INVALID_ARGS,
|
|
123
133
|
);
|
|
124
134
|
}
|
|
125
135
|
|
|
126
136
|
// Validate target
|
|
127
|
-
const validTargets: BuildTarget[] = [
|
|
137
|
+
const validTargets: BuildTarget[] = ["bun", "node", "standalone"];
|
|
128
138
|
if (!validTargets.includes(target)) {
|
|
129
139
|
throw new CLIError(
|
|
130
|
-
`Invalid target: ${target}. Valid targets: ${validTargets.join(
|
|
140
|
+
`Invalid target: ${target}. Valid targets: ${validTargets.join(", ")}`,
|
|
131
141
|
CLIErrorType.INVALID_ARGS,
|
|
132
142
|
);
|
|
133
143
|
}
|
|
@@ -136,14 +146,14 @@ async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
|
136
146
|
const projectRoot = await getProjectRoot();
|
|
137
147
|
if (!projectRoot) {
|
|
138
148
|
throw new CLIError(
|
|
139
|
-
|
|
149
|
+
"Not in a project directory. Run this command from a Bueno project.",
|
|
140
150
|
CLIErrorType.NOT_FOUND,
|
|
141
151
|
);
|
|
142
152
|
}
|
|
143
153
|
|
|
144
154
|
if (!(await isBuenoProject())) {
|
|
145
155
|
throw new CLIError(
|
|
146
|
-
|
|
156
|
+
"Not a Bueno project. Make sure you have a bueno.config.ts or bueno in your dependencies.",
|
|
147
157
|
CLIErrorType.NOT_FOUND,
|
|
148
158
|
);
|
|
149
159
|
}
|
|
@@ -152,33 +162,39 @@ async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
|
152
162
|
const entryPoint = await findEntryPoint(projectRoot);
|
|
153
163
|
if (!entryPoint) {
|
|
154
164
|
throw new CLIError(
|
|
155
|
-
|
|
165
|
+
"Could not find entry point. Make sure you have a main.ts or index.ts file.",
|
|
156
166
|
CLIErrorType.FILE_NOT_FOUND,
|
|
157
167
|
);
|
|
158
168
|
}
|
|
159
169
|
|
|
160
170
|
// Display build info
|
|
161
171
|
if (compile) {
|
|
162
|
-
cliConsole.header(
|
|
172
|
+
cliConsole.header("Compiling Single-File Executable");
|
|
163
173
|
} else {
|
|
164
|
-
cliConsole.header(
|
|
174
|
+
cliConsole.header("Building for Production");
|
|
165
175
|
}
|
|
166
|
-
cliConsole.log(`${colors.bold(
|
|
167
|
-
cliConsole.log(`${colors.bold(
|
|
176
|
+
cliConsole.log(`${colors.bold("Entry:")} ${entryPoint}`);
|
|
177
|
+
cliConsole.log(`${colors.bold("Target:")} ${target}`);
|
|
168
178
|
if (compile) {
|
|
169
|
-
cliConsole.log(`${colors.bold(
|
|
179
|
+
cliConsole.log(`${colors.bold("Compile:")} ${colors.green("enabled")}`);
|
|
170
180
|
if (crossCompile) {
|
|
171
|
-
cliConsole.log(
|
|
181
|
+
cliConsole.log(
|
|
182
|
+
`${colors.bold("Cross-compile:")} ${colors.cyan(crossCompile)}`,
|
|
183
|
+
);
|
|
172
184
|
}
|
|
173
|
-
cliConsole.log(`${colors.bold(
|
|
185
|
+
cliConsole.log(`${colors.bold("Executable:")} ${executableName}`);
|
|
174
186
|
}
|
|
175
|
-
cliConsole.log(`${colors.bold(
|
|
176
|
-
cliConsole.log(
|
|
177
|
-
|
|
178
|
-
|
|
187
|
+
cliConsole.log(`${colors.bold("Output:")} ${outDir}`);
|
|
188
|
+
cliConsole.log(
|
|
189
|
+
`${colors.bold("Minify:")} ${minify ? colors.green("enabled") : colors.red("disabled")}`,
|
|
190
|
+
);
|
|
191
|
+
cliConsole.log(
|
|
192
|
+
`${colors.bold("Sourcemap:")} ${sourcemap ? colors.green("enabled") : colors.red("disabled")}`,
|
|
193
|
+
);
|
|
194
|
+
cliConsole.log("");
|
|
179
195
|
|
|
180
196
|
const startTime = Date.now();
|
|
181
|
-
const s = spinner(
|
|
197
|
+
const s = spinner("Building...");
|
|
182
198
|
|
|
183
199
|
try {
|
|
184
200
|
// Clean output directory
|
|
@@ -190,7 +206,7 @@ async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
|
190
206
|
// Handle compile build
|
|
191
207
|
if (compile) {
|
|
192
208
|
// Determine the executable filename
|
|
193
|
-
const isWindows = crossCompile ===
|
|
209
|
+
const isWindows = crossCompile === "windows-x64";
|
|
194
210
|
const executableFileName = isWindows
|
|
195
211
|
? `${executableName}.exe`
|
|
196
212
|
: executableName;
|
|
@@ -200,13 +216,13 @@ async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
|
200
216
|
const buildOptions: any = {
|
|
201
217
|
entrypoints: [joinPaths(projectRoot, entryPoint)],
|
|
202
218
|
outdir: fullOutDir,
|
|
203
|
-
target: crossCompile ||
|
|
219
|
+
target: crossCompile || "bun",
|
|
204
220
|
minify,
|
|
205
|
-
sourcemap: sourcemap ?
|
|
221
|
+
sourcemap: sourcemap ? "external" : undefined,
|
|
206
222
|
naming: executableFileName,
|
|
207
223
|
compile: true,
|
|
208
224
|
define: {
|
|
209
|
-
|
|
225
|
+
"process.env.NODE_ENV": '"production"',
|
|
210
226
|
},
|
|
211
227
|
};
|
|
212
228
|
|
|
@@ -218,21 +234,18 @@ async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
|
218
234
|
for (const error of buildResult.logs) {
|
|
219
235
|
cliConsole.error(error.message);
|
|
220
236
|
}
|
|
221
|
-
throw new CLIError(
|
|
222
|
-
'Compile failed',
|
|
223
|
-
CLIErrorType.TEMPLATE_ERROR,
|
|
224
|
-
);
|
|
237
|
+
throw new CLIError("Compile failed", CLIErrorType.TEMPLATE_ERROR);
|
|
225
238
|
}
|
|
226
239
|
|
|
227
240
|
const elapsed = Date.now() - startTime;
|
|
228
241
|
s.success(`Compile completed in ${formatDuration(elapsed)}`);
|
|
229
242
|
|
|
230
243
|
// Show output info
|
|
231
|
-
cliConsole.log(
|
|
232
|
-
cliConsole.log(`${colors.bold(
|
|
233
|
-
|
|
244
|
+
cliConsole.log("");
|
|
245
|
+
cliConsole.log(`${colors.bold("Output Executable:")}`);
|
|
246
|
+
|
|
234
247
|
// Get executable file size
|
|
235
|
-
const fs = require(
|
|
248
|
+
const fs = require("fs");
|
|
236
249
|
let executableSize = 0;
|
|
237
250
|
try {
|
|
238
251
|
const stat = fs.statSync(executablePath);
|
|
@@ -243,17 +256,19 @@ async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
|
243
256
|
executableSize = buildResult.outputs[0].size;
|
|
244
257
|
}
|
|
245
258
|
}
|
|
246
|
-
|
|
247
|
-
cliConsole.log(
|
|
248
|
-
|
|
249
|
-
|
|
259
|
+
|
|
260
|
+
cliConsole.log(
|
|
261
|
+
` ${colors.cyan(executablePath.replace(projectRoot, "."))} ${colors.dim(`(${formatSize(executableSize)})`)}`,
|
|
262
|
+
);
|
|
263
|
+
cliConsole.log("");
|
|
264
|
+
|
|
250
265
|
// Show success message with run instructions
|
|
251
|
-
cliConsole.success(
|
|
266
|
+
cliConsole.success("Single-file executable created successfully!");
|
|
252
267
|
if (crossCompile) {
|
|
253
|
-
cliConsole.log(`${colors.bold(
|
|
268
|
+
cliConsole.log(`${colors.bold("Target Platform:")} ${crossCompile}`);
|
|
254
269
|
}
|
|
255
|
-
cliConsole.log(
|
|
256
|
-
cliConsole.info(
|
|
270
|
+
cliConsole.log("");
|
|
271
|
+
cliConsole.info("You can run the executable directly:");
|
|
257
272
|
if (isWindows) {
|
|
258
273
|
cliConsole.log(colors.cyan(` .${outDir}/${executableFileName}`));
|
|
259
274
|
} else {
|
|
@@ -262,9 +277,9 @@ async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
|
262
277
|
|
|
263
278
|
// Analyze if requested
|
|
264
279
|
if (analyze) {
|
|
265
|
-
cliConsole.log(
|
|
266
|
-
cliConsole.header(
|
|
267
|
-
cliConsole.log(
|
|
280
|
+
cliConsole.log("");
|
|
281
|
+
cliConsole.header("Bundle Analysis");
|
|
282
|
+
cliConsole.log("Output:");
|
|
268
283
|
for (const entry of buildResult.outputs) {
|
|
269
284
|
cliConsole.log(` ${entry.path} (${formatSize(entry.size)})`);
|
|
270
285
|
}
|
|
@@ -277,14 +292,14 @@ async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
|
277
292
|
const buildResult = await Bun.build({
|
|
278
293
|
entrypoints: [joinPaths(projectRoot, entryPoint)],
|
|
279
294
|
outdir: fullOutDir,
|
|
280
|
-
target: target ===
|
|
295
|
+
target: target === "node" ? "node" : "bun",
|
|
281
296
|
minify,
|
|
282
|
-
sourcemap: sourcemap ?
|
|
297
|
+
sourcemap: sourcemap ? "external" : undefined,
|
|
283
298
|
splitting: true,
|
|
284
|
-
format:
|
|
285
|
-
external: target ===
|
|
299
|
+
format: "esm",
|
|
300
|
+
external: target === "standalone" ? [] : ["bun:*"],
|
|
286
301
|
define: {
|
|
287
|
-
|
|
302
|
+
"process.env.NODE_ENV": '"production"',
|
|
288
303
|
},
|
|
289
304
|
});
|
|
290
305
|
|
|
@@ -293,10 +308,7 @@ async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
|
293
308
|
for (const error of buildResult.logs) {
|
|
294
309
|
cliConsole.error(error.message);
|
|
295
310
|
}
|
|
296
|
-
throw new CLIError(
|
|
297
|
-
'Build failed',
|
|
298
|
-
CLIErrorType.TEMPLATE_ERROR,
|
|
299
|
-
);
|
|
311
|
+
throw new CLIError("Build failed", CLIErrorType.TEMPLATE_ERROR);
|
|
300
312
|
}
|
|
301
313
|
|
|
302
314
|
const elapsed = Date.now() - startTime;
|
|
@@ -304,43 +316,48 @@ async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
|
304
316
|
// Get output files info
|
|
305
317
|
const outputFiles = await listFiles(fullOutDir, { recursive: true });
|
|
306
318
|
const totalSize = outputFiles.reduce((acc, file) => {
|
|
307
|
-
const stat = require(
|
|
319
|
+
const stat = require("fs").statSync(file);
|
|
308
320
|
return acc + stat.size;
|
|
309
321
|
}, 0);
|
|
310
322
|
|
|
311
323
|
s.success(`Build completed in ${formatDuration(elapsed)}`);
|
|
312
324
|
|
|
313
325
|
// Show output info
|
|
314
|
-
cliConsole.log(
|
|
315
|
-
cliConsole.log(`${colors.bold(
|
|
326
|
+
cliConsole.log("");
|
|
327
|
+
cliConsole.log(`${colors.bold("Output Files:")}`);
|
|
316
328
|
for (const file of outputFiles.slice(0, 10)) {
|
|
317
|
-
const stat = require(
|
|
318
|
-
const relativePath = file.replace(projectRoot,
|
|
319
|
-
cliConsole.log(
|
|
329
|
+
const stat = require("fs").statSync(file);
|
|
330
|
+
const relativePath = file.replace(projectRoot, ".");
|
|
331
|
+
cliConsole.log(
|
|
332
|
+
` ${colors.dim(relativePath)} ${colors.dim(`(${formatSize(stat.size)})`)}`,
|
|
333
|
+
);
|
|
320
334
|
}
|
|
321
335
|
if (outputFiles.length > 10) {
|
|
322
|
-
cliConsole.log(
|
|
336
|
+
cliConsole.log(
|
|
337
|
+
` ${colors.dim(`... and ${outputFiles.length - 10} more files`)}`,
|
|
338
|
+
);
|
|
323
339
|
}
|
|
324
|
-
cliConsole.log(
|
|
325
|
-
cliConsole.log(`${colors.bold(
|
|
340
|
+
cliConsole.log("");
|
|
341
|
+
cliConsole.log(`${colors.bold("Total Size:")} ${formatSize(totalSize)}`);
|
|
326
342
|
|
|
327
343
|
// Analyze if requested
|
|
328
344
|
if (analyze) {
|
|
329
|
-
cliConsole.log(
|
|
330
|
-
cliConsole.header(
|
|
331
|
-
cliConsole.log(
|
|
345
|
+
cliConsole.log("");
|
|
346
|
+
cliConsole.header("Bundle Analysis");
|
|
347
|
+
cliConsole.log("Entry points:");
|
|
332
348
|
for (const entry of buildResult.outputs) {
|
|
333
349
|
cliConsole.log(` ${entry.path} (${formatSize(entry.size)})`);
|
|
334
350
|
}
|
|
335
351
|
}
|
|
336
352
|
|
|
337
353
|
// Show standalone build info
|
|
338
|
-
if (target ===
|
|
339
|
-
cliConsole.log(
|
|
340
|
-
cliConsole.info(
|
|
341
|
-
cliConsole.log(
|
|
354
|
+
if (target === "standalone") {
|
|
355
|
+
cliConsole.log("");
|
|
356
|
+
cliConsole.info("Standalone bundle created. You can run it with:");
|
|
357
|
+
cliConsole.log(
|
|
358
|
+
colors.cyan(` bun .${outDir}/${entryPoint.replace(".ts", ".js")}`),
|
|
359
|
+
);
|
|
342
360
|
}
|
|
343
|
-
|
|
344
361
|
} catch (error) {
|
|
345
362
|
s.error();
|
|
346
363
|
throw error;
|
|
@@ -350,76 +367,77 @@ async function handleBuild(args: ParsedArgs): Promise<void> {
|
|
|
350
367
|
// Register the command
|
|
351
368
|
defineCommand(
|
|
352
369
|
{
|
|
353
|
-
name:
|
|
354
|
-
description:
|
|
370
|
+
name: "build",
|
|
371
|
+
description: "Build the application for production",
|
|
355
372
|
options: [
|
|
356
373
|
{
|
|
357
|
-
name:
|
|
358
|
-
alias:
|
|
359
|
-
type:
|
|
360
|
-
default:
|
|
361
|
-
description:
|
|
374
|
+
name: "target",
|
|
375
|
+
alias: "t",
|
|
376
|
+
type: "string",
|
|
377
|
+
default: "bun",
|
|
378
|
+
description: "Build target (bun, node, standalone)",
|
|
362
379
|
},
|
|
363
380
|
{
|
|
364
|
-
name:
|
|
365
|
-
alias:
|
|
366
|
-
type:
|
|
367
|
-
default:
|
|
368
|
-
description:
|
|
381
|
+
name: "outdir",
|
|
382
|
+
alias: "o",
|
|
383
|
+
type: "string",
|
|
384
|
+
default: "./dist",
|
|
385
|
+
description: "Output directory",
|
|
369
386
|
},
|
|
370
387
|
{
|
|
371
|
-
name:
|
|
372
|
-
type:
|
|
388
|
+
name: "no-minify",
|
|
389
|
+
type: "boolean",
|
|
373
390
|
default: false,
|
|
374
|
-
description:
|
|
391
|
+
description: "Disable minification",
|
|
375
392
|
},
|
|
376
393
|
{
|
|
377
|
-
name:
|
|
378
|
-
type:
|
|
394
|
+
name: "sourcemap",
|
|
395
|
+
type: "boolean",
|
|
379
396
|
default: false,
|
|
380
|
-
description:
|
|
397
|
+
description: "Generate source maps",
|
|
381
398
|
},
|
|
382
399
|
{
|
|
383
|
-
name:
|
|
384
|
-
type:
|
|
400
|
+
name: "analyze",
|
|
401
|
+
type: "boolean",
|
|
385
402
|
default: false,
|
|
386
|
-
description:
|
|
403
|
+
description: "Analyze bundle size",
|
|
387
404
|
},
|
|
388
405
|
{
|
|
389
|
-
name:
|
|
390
|
-
alias:
|
|
391
|
-
type:
|
|
392
|
-
description:
|
|
406
|
+
name: "config",
|
|
407
|
+
alias: "c",
|
|
408
|
+
type: "string",
|
|
409
|
+
description: "Path to config file",
|
|
393
410
|
},
|
|
394
411
|
{
|
|
395
|
-
name:
|
|
396
|
-
type:
|
|
412
|
+
name: "compile",
|
|
413
|
+
type: "boolean",
|
|
397
414
|
default: false,
|
|
398
|
-
description:
|
|
415
|
+
description: "Create a single-file executable using Bun compile",
|
|
399
416
|
},
|
|
400
417
|
{
|
|
401
|
-
name:
|
|
402
|
-
type:
|
|
403
|
-
description:
|
|
418
|
+
name: "cross-compile",
|
|
419
|
+
type: "string",
|
|
420
|
+
description:
|
|
421
|
+
"Cross-compile for different platforms (linux-x64, linux-arm64, windows-x64, darwin-x64, darwin-arm64)",
|
|
404
422
|
},
|
|
405
423
|
{
|
|
406
|
-
name:
|
|
407
|
-
type:
|
|
408
|
-
default:
|
|
409
|
-
description:
|
|
424
|
+
name: "executable-name",
|
|
425
|
+
type: "string",
|
|
426
|
+
default: "main",
|
|
427
|
+
description: "Custom name for the output executable (default: main)",
|
|
410
428
|
},
|
|
411
429
|
],
|
|
412
430
|
examples: [
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
431
|
+
"bueno build",
|
|
432
|
+
"bueno build --target node",
|
|
433
|
+
"bueno build --target standalone",
|
|
434
|
+
"bueno build --sourcemap",
|
|
435
|
+
"bueno build --analyze",
|
|
436
|
+
"bueno build --compile",
|
|
437
|
+
"bueno build --compile --outdir ./bin",
|
|
438
|
+
"bueno build --compile --cross-compile linux-x64",
|
|
439
|
+
"bueno build --compile --executable-name myapp",
|
|
422
440
|
],
|
|
423
441
|
},
|
|
424
442
|
handleBuild,
|
|
425
|
-
);
|
|
443
|
+
);
|