@hazejs/cli 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present hazejs contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,27 @@
1
- # Temporary Holding Version
1
+ # @hazejs/cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The `haze` command line.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add -D @hazejs/cli
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ haze dev # hot-reloading dev server (no restarts)
15
+ haze build --preset node # node | bun | deno | docker | cloudflare | vercel | netlify | aws-lambda
16
+ haze preview # run the build output locally
17
+ haze make:controller Post --resource
18
+ haze db:generate && haze db:migrate
19
+ haze queue:work # schedule:work, schedule:run, queue:failed, …
20
+ haze route:list
21
+ ```
22
+
23
+ Part of [hazejs](https://github.com/penna-org/haze) — see the main README for documentation.
24
+
25
+ ## License
26
+
27
+ [MIT](./LICENSE)
package/bin/haze.mjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import '../dist/index.mjs'
@@ -0,0 +1,62 @@
1
+ import { a as resolveRoot, o as rootArg } from "./index.mjs";
2
+ import { defineCommand } from "citty";
3
+ import { existsSync } from "node:fs";
4
+ import { relative } from "node:path";
5
+ import process from "node:process";
6
+ import { PRESET_NAMES, buildServer, findViteConfig } from "@hazejs/vite";
7
+ import { consola } from "consola";
8
+ import { colors } from "consola/utils";
9
+ import { stat } from "node:fs/promises";
10
+ import { createBuilder } from "vite";
11
+ // src/commands/build.ts
12
+ var build_default = defineCommand({
13
+ meta: {
14
+ name: "build",
15
+ description: "构建生产环境产物"
16
+ },
17
+ args: {
18
+ ...rootArg,
19
+ preset: {
20
+ type: "string",
21
+ alias: "p",
22
+ description: `部署预设:${PRESET_NAMES.join(" | ")}(默认读取 haze.config.ts,否则为 node)`
23
+ },
24
+ outDir: {
25
+ type: "string",
26
+ description: "输出目录(默认 dist,仅纯后端项目)"
27
+ },
28
+ minify: {
29
+ type: "boolean",
30
+ description: "压缩产物",
31
+ default: false
32
+ }
33
+ },
34
+ async run({ args }) {
35
+ const root = resolveRoot(args.root);
36
+ const preset = args.preset;
37
+ if (preset && !PRESET_NAMES.includes(preset)) throw new Error(`Unknown preset "${preset}". Available: ${PRESET_NAMES.join(", ")}`);
38
+ const start = performance.now();
39
+ process.env.NODE_ENV ??= "production";
40
+ let info;
41
+ if (findViteConfig(root)) {
42
+ if (preset) process.env.HAZE_PRESET = preset;
43
+ const builder = await createBuilder({
44
+ root,
45
+ mode: "production"
46
+ });
47
+ await builder.buildApp();
48
+ info = builder.config.plugins.find((item) => item.name === "hazejs")?.api?.lastBuild();
49
+ if (!info) throw new Error("Server entry was not generated. Is haze() added to the plugins in vite.config?");
50
+ } else info = await buildServer({
51
+ root,
52
+ outDir: args.outDir,
53
+ minify: args.minify,
54
+ preset
55
+ });
56
+ const size = existsSync(info.entry) ? `${((await stat(info.entry)).size / 1024).toFixed(1)} kB` : "";
57
+ consola.success(`Built ${colors.cyan(info.preset)} in ${Math.round(performance.now() - start)}ms → ${relative(process.cwd(), info.entry)} ${colors.dim(size)}`);
58
+ if (info.externals.length) consola.info(`Runtime dependencies (node_modules): ${info.externals.join(", ")}`);
59
+ consola.info(info.hint);
60
+ }
61
+ });
62
+ export { build_default as default };
@@ -0,0 +1,59 @@
1
+ import { a as resolveRoot, i as parsePort, o as rootArg, r as displayUrl, s as serverArgs } from "./index.mjs";
2
+ import { defineCommand } from "citty";
3
+ import process from "node:process";
4
+ import { createDevServer, findViteConfig } from "@hazejs/vite";
5
+ import { consola } from "consola";
6
+ import { colors } from "consola/utils";
7
+ import { createServer } from "vite";
8
+ // src/commands/dev.ts
9
+ var dev_default = defineCommand({
10
+ meta: {
11
+ name: "dev",
12
+ description: "启动开发服务器(修改代码即时生效,无需重启)"
13
+ },
14
+ args: {
15
+ ...rootArg,
16
+ ...serverArgs
17
+ },
18
+ async run({ args }) {
19
+ const root = resolveRoot(args.root);
20
+ const port = parsePort(args.port);
21
+ const start = performance.now();
22
+ if (findViteConfig(root)) {
23
+ const server = await createServer({
24
+ root,
25
+ server: {
26
+ port,
27
+ host: args.host
28
+ }
29
+ });
30
+ await server.listen();
31
+ server.printUrls();
32
+ onExit(() => server.close());
33
+ return;
34
+ }
35
+ const server = await createDevServer({
36
+ root,
37
+ port,
38
+ host: args.host
39
+ });
40
+ const routes = server.app?.router.list().length ?? 0;
41
+ consola.log("");
42
+ consola.log(` ${colors.bold(colors.cyan("hazejs"))} ${colors.dim("dev server ready in")} ${Math.round(performance.now() - start)}ms`);
43
+ consola.log("");
44
+ consola.log(` ${colors.green("➜")} Local: ${colors.cyan(displayUrl(server.url))}`);
45
+ consola.log(` ${colors.green("➜")} Routes: ${routes}`);
46
+ consola.log(` ${colors.dim("watching for changes...")}`);
47
+ consola.log("");
48
+ onExit(() => server.close());
49
+ }
50
+ });
51
+ function onExit(close) {
52
+ const shutdown = async () => {
53
+ await close();
54
+ process.exit(0);
55
+ };
56
+ process.once("SIGINT", shutdown);
57
+ process.once("SIGTERM", shutdown);
58
+ }
59
+ export { dev_default as default };