create-bunli 0.8.0 → 0.8.2
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 +18 -6
- package/dist/cli.js +589 -560
- package/dist/create-project.d.ts +4 -4
- package/dist/create-project.d.ts.map +1 -1
- package/dist/create.d.ts +3 -3
- package/dist/create.d.ts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +518 -512
- package/dist/steps.d.ts +5 -5
- package/dist/steps.d.ts.map +1 -1
- package/dist/template-engine.d.ts +2 -2
- package/dist/template-engine.d.ts.map +1 -1
- package/dist/templates/advanced/README.md +8 -4
- package/dist/templates/advanced/bunli.config.ts +19 -19
- package/dist/templates/advanced/package.json +8 -4
- package/dist/templates/advanced/src/commands/config.ts +129 -119
- package/dist/templates/advanced/src/commands/init.ts +53 -60
- package/dist/templates/advanced/src/commands/serve.ts +77 -83
- package/dist/templates/advanced/src/commands/validate.ts +58 -66
- package/dist/templates/advanced/src/index.ts +30 -29
- package/dist/templates/advanced/src/utils/config.ts +48 -47
- package/dist/templates/advanced/src/utils/constants.ts +6 -6
- package/dist/templates/advanced/src/utils/glob.ts +29 -28
- package/dist/templates/advanced/src/utils/validator.ts +60 -61
- package/dist/templates/advanced/template.json +2 -6
- package/dist/templates/advanced/tsconfig.json +1 -1
- package/dist/templates/basic/README.md +1 -1
- package/dist/templates/basic/bunli.config.ts +17 -17
- package/dist/templates/basic/package.json +3 -3
- package/dist/templates/basic/src/commands/hello.ts +20 -26
- package/dist/templates/basic/src/index.ts +9 -8
- package/dist/templates/basic/template.json +2 -6
- package/dist/templates/basic/tsconfig.json +1 -1
- package/dist/templates/monorepo/README.md +1 -1
- package/dist/templates/monorepo/bunli.config.ts +21 -21
- package/dist/templates/monorepo/package.json +3 -3
- package/dist/templates/monorepo/packages/cli/package.json +9 -5
- package/dist/templates/monorepo/packages/cli/src/index.ts +13 -13
- package/dist/templates/monorepo/packages/cli/tsconfig.json +2 -5
- package/dist/templates/monorepo/packages/core/package.json +4 -4
- package/dist/templates/monorepo/packages/core/scripts/build.ts +10 -10
- package/dist/templates/monorepo/packages/core/src/commands/analyze.ts +58 -57
- package/dist/templates/monorepo/packages/core/src/commands/process.ts +39 -47
- package/dist/templates/monorepo/packages/core/src/index.ts +3 -3
- package/dist/templates/monorepo/packages/core/src/types.ts +15 -15
- package/dist/templates/monorepo/packages/core/tsconfig.json +2 -4
- package/dist/templates/monorepo/packages/utils/package.json +4 -4
- package/dist/templates/monorepo/packages/utils/scripts/build.ts +10 -10
- package/dist/templates/monorepo/packages/utils/src/format.ts +19 -19
- package/dist/templates/monorepo/packages/utils/src/index.ts +3 -3
- package/dist/templates/monorepo/packages/utils/src/json.ts +4 -4
- package/dist/templates/monorepo/packages/utils/src/logger.ts +9 -9
- package/dist/templates/monorepo/packages/utils/tsconfig.json +1 -1
- package/dist/templates/monorepo/template.json +2 -6
- package/dist/templates/monorepo/tsconfig.json +1 -1
- package/dist/templates/monorepo/turbo.json +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +28 -28
- package/templates/advanced/README.md +8 -4
- package/templates/advanced/bunli.config.ts +19 -19
- package/templates/advanced/package.json +8 -4
- package/templates/advanced/src/commands/config.ts +129 -119
- package/templates/advanced/src/commands/init.ts +53 -60
- package/templates/advanced/src/commands/serve.ts +77 -83
- package/templates/advanced/src/commands/validate.ts +58 -66
- package/templates/advanced/src/index.ts +30 -29
- package/templates/advanced/src/utils/config.ts +48 -47
- package/templates/advanced/src/utils/constants.ts +6 -6
- package/templates/advanced/src/utils/glob.ts +29 -28
- package/templates/advanced/src/utils/validator.ts +60 -61
- package/templates/advanced/template.json +2 -6
- package/templates/advanced/tsconfig.json +1 -1
- package/templates/basic/README.md +1 -1
- package/templates/basic/bunli.config.ts +17 -17
- package/templates/basic/package.json +3 -3
- package/templates/basic/src/commands/hello.ts +20 -26
- package/templates/basic/src/index.ts +9 -8
- package/templates/basic/template.json +2 -6
- package/templates/basic/tsconfig.json +1 -1
- package/templates/monorepo/README.md +1 -1
- package/templates/monorepo/bunli.config.ts +21 -21
- package/templates/monorepo/package.json +3 -3
- package/templates/monorepo/packages/cli/package.json +9 -5
- package/templates/monorepo/packages/cli/src/index.ts +13 -13
- package/templates/monorepo/packages/cli/tsconfig.json +2 -5
- package/templates/monorepo/packages/core/package.json +4 -4
- package/templates/monorepo/packages/core/scripts/build.ts +10 -10
- package/templates/monorepo/packages/core/src/commands/analyze.ts +58 -57
- package/templates/monorepo/packages/core/src/commands/process.ts +39 -47
- package/templates/monorepo/packages/core/src/index.ts +3 -3
- package/templates/monorepo/packages/core/src/types.ts +15 -15
- package/templates/monorepo/packages/core/tsconfig.json +2 -4
- package/templates/monorepo/packages/utils/package.json +4 -4
- package/templates/monorepo/packages/utils/scripts/build.ts +10 -10
- package/templates/monorepo/packages/utils/src/format.ts +19 -19
- package/templates/monorepo/packages/utils/src/index.ts +3 -3
- package/templates/monorepo/packages/utils/src/json.ts +4 -4
- package/templates/monorepo/packages/utils/src/logger.ts +9 -9
- package/templates/monorepo/packages/utils/tsconfig.json +1 -1
- package/templates/monorepo/template.json +2 -6
- package/templates/monorepo/tsconfig.json +1 -1
- package/templates/monorepo/turbo.json +1 -1
|
@@ -1,75 +1,68 @@
|
|
|
1
|
-
import { defineCommand, option } from
|
|
2
|
-
import { z } from
|
|
3
|
-
|
|
1
|
+
import { defineCommand, option } from "@bunli/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
import { CONFIG_FILE_NAME, DEFAULT_CONFIG } from "../utils/constants.js";
|
|
4
5
|
|
|
5
6
|
const initCommand = defineCommand({
|
|
6
|
-
name:
|
|
7
|
-
description:
|
|
7
|
+
name: "init",
|
|
8
|
+
description: "Initialize a new configuration file",
|
|
8
9
|
options: {
|
|
9
|
-
force: option(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
z.enum(['minimal', 'default', 'full']).default('default'),
|
|
19
|
-
{
|
|
20
|
-
short: 't',
|
|
21
|
-
description: 'Config template to use'
|
|
22
|
-
}
|
|
23
|
-
)
|
|
10
|
+
force: option(z.boolean().default(false), {
|
|
11
|
+
short: "f",
|
|
12
|
+
description: "Overwrite existing config",
|
|
13
|
+
argumentKind: "flag",
|
|
14
|
+
}),
|
|
15
|
+
template: option(z.enum(["minimal", "default", "full"]).default("default"), {
|
|
16
|
+
short: "t",
|
|
17
|
+
description: "Config template to use",
|
|
18
|
+
}),
|
|
24
19
|
},
|
|
25
20
|
handler: async ({ flags, colors, prompt, spinner }) => {
|
|
26
|
-
const configPath = `${process.cwd()}/${CONFIG_FILE_NAME}
|
|
27
|
-
|
|
21
|
+
const configPath = `${process.cwd()}/${CONFIG_FILE_NAME}`;
|
|
22
|
+
|
|
28
23
|
// Check if config already exists
|
|
29
|
-
const configFile = Bun.file(configPath)
|
|
30
|
-
if (await configFile.exists() && !flags.force) {
|
|
31
|
-
const overwrite = await prompt.confirm(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
const configFile = Bun.file(configPath);
|
|
25
|
+
if ((await configFile.exists()) && !flags.force) {
|
|
26
|
+
const overwrite = await prompt.confirm(`Config file already exists. Overwrite?`, {
|
|
27
|
+
default: false,
|
|
28
|
+
});
|
|
29
|
+
|
|
36
30
|
if (!overwrite) {
|
|
37
|
-
console.log(colors.yellow(
|
|
38
|
-
return
|
|
31
|
+
console.log(colors.yellow("Init cancelled"));
|
|
32
|
+
return;
|
|
39
33
|
}
|
|
40
34
|
}
|
|
41
|
-
|
|
42
|
-
const spin = spinner(
|
|
43
|
-
spin.start()
|
|
44
|
-
|
|
35
|
+
|
|
36
|
+
const spin = spinner("Creating config file...");
|
|
37
|
+
spin.start();
|
|
38
|
+
|
|
45
39
|
try {
|
|
46
40
|
// Get template content
|
|
47
|
-
const configContent = getConfigTemplate(flags.template)
|
|
48
|
-
|
|
41
|
+
const configContent = getConfigTemplate(flags.template);
|
|
42
|
+
|
|
49
43
|
// Write config file
|
|
50
|
-
await Bun.write(configPath, configContent)
|
|
51
|
-
|
|
52
|
-
spin.succeed(
|
|
53
|
-
console.log(colors.dim(` ${CONFIG_FILE_NAME}`))
|
|
54
|
-
|
|
44
|
+
await Bun.write(configPath, configContent);
|
|
45
|
+
|
|
46
|
+
spin.succeed("Config file created");
|
|
47
|
+
console.log(colors.dim(` ${CONFIG_FILE_NAME}`));
|
|
48
|
+
|
|
55
49
|
// Next steps
|
|
56
|
-
console.log()
|
|
57
|
-
console.log(
|
|
58
|
-
console.log(colors.gray(` 1. Edit ${CONFIG_FILE_NAME} to customize your configuration`))
|
|
59
|
-
console.log(colors.gray(` 2. Run '{{name}} validate' to check your files`))
|
|
60
|
-
|
|
50
|
+
console.log();
|
|
51
|
+
console.log("Next steps:");
|
|
52
|
+
console.log(colors.gray(` 1. Edit ${CONFIG_FILE_NAME} to customize your configuration`));
|
|
53
|
+
console.log(colors.gray(` 2. Run '{{name}} validate' to check your files`));
|
|
61
54
|
} catch (error) {
|
|
62
|
-
spin.fail(
|
|
63
|
-
console.error(colors.red(String(error)))
|
|
64
|
-
process.exit(1)
|
|
55
|
+
spin.fail("Failed to create config file");
|
|
56
|
+
console.error(colors.red(String(error)));
|
|
57
|
+
process.exit(1);
|
|
65
58
|
}
|
|
66
|
-
}
|
|
67
|
-
})
|
|
59
|
+
},
|
|
60
|
+
});
|
|
68
61
|
|
|
69
|
-
function getConfigTemplate(template:
|
|
62
|
+
function getConfigTemplate(template: "minimal" | "default" | "full"): string {
|
|
70
63
|
const templates = {
|
|
71
64
|
minimal: `export default ${JSON.stringify(DEFAULT_CONFIG, null, 2)}`,
|
|
72
|
-
|
|
65
|
+
|
|
73
66
|
default: `export default {
|
|
74
67
|
// Validation rules
|
|
75
68
|
rules: {
|
|
@@ -89,7 +82,7 @@ function getConfigTemplate(template: 'minimal' | 'default' | 'full'): string {
|
|
|
89
82
|
include: ['src/**/*.{js,ts}'],
|
|
90
83
|
exclude: ['node_modules', 'dist', 'test'],
|
|
91
84
|
}`,
|
|
92
|
-
|
|
85
|
+
|
|
93
86
|
full: `import { defineConfig } from '{{name}}'
|
|
94
87
|
|
|
95
88
|
export default defineConfig({
|
|
@@ -147,10 +140,10 @@ export default defineConfig({
|
|
|
147
140
|
console.log(\`Found \${results.errors} errors and \${results.warnings} warnings\`)
|
|
148
141
|
},
|
|
149
142
|
},
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return templates[template]
|
|
143
|
+
})`,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
return templates[template];
|
|
154
147
|
}
|
|
155
148
|
|
|
156
|
-
export default initCommand
|
|
149
|
+
export default initCommand;
|
|
@@ -1,113 +1,107 @@
|
|
|
1
|
-
import { defineCommand, option } from
|
|
2
|
-
import { z } from
|
|
3
|
-
|
|
1
|
+
import { defineCommand, option } from "@bunli/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
import { loadConfig } from "../utils/config.js";
|
|
4
5
|
|
|
5
6
|
const serveCommand = defineCommand({
|
|
6
|
-
name:
|
|
7
|
-
description:
|
|
7
|
+
name: "serve",
|
|
8
|
+
description: "Start a development server",
|
|
8
9
|
options: {
|
|
9
|
-
port: option(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
),
|
|
23
|
-
open: option(
|
|
24
|
-
z.boolean().default(true),
|
|
25
|
-
{
|
|
26
|
-
description: 'Open browser on start',
|
|
27
|
-
argumentKind: 'flag'
|
|
28
|
-
}
|
|
29
|
-
)
|
|
10
|
+
port: option(z.coerce.number().int().min(1).max(65535).default(3000), {
|
|
11
|
+
short: "p",
|
|
12
|
+
description: "Port to listen on",
|
|
13
|
+
}),
|
|
14
|
+
host: option(z.string().default("localhost"), {
|
|
15
|
+
short: "h",
|
|
16
|
+
description: "Host to bind to",
|
|
17
|
+
}),
|
|
18
|
+
open: option(z.boolean().default(true), {
|
|
19
|
+
description: "Open browser on start",
|
|
20
|
+
argumentKind: "flag",
|
|
21
|
+
}),
|
|
30
22
|
},
|
|
31
23
|
handler: async ({ flags, colors, spinner, shell }) => {
|
|
32
|
-
const spin = spinner(
|
|
33
|
-
spin.start()
|
|
34
|
-
|
|
24
|
+
const spin = spinner("Starting server...");
|
|
25
|
+
spin.start();
|
|
26
|
+
|
|
35
27
|
try {
|
|
36
28
|
// Load config
|
|
37
|
-
const config = await loadConfig()
|
|
38
|
-
|
|
29
|
+
const config = await loadConfig();
|
|
30
|
+
|
|
39
31
|
// Merge flags with config
|
|
40
|
-
const port = flags.port || config.server?.port || 3000
|
|
41
|
-
const host = flags.host || config.server?.host ||
|
|
42
|
-
const shouldOpen = flags.open ?? config.server?.open ?? true
|
|
43
|
-
|
|
32
|
+
const port = flags.port || config.server?.port || 3000;
|
|
33
|
+
const host = flags.host || config.server?.host || "localhost";
|
|
34
|
+
const shouldOpen = flags.open ?? config.server?.open ?? true;
|
|
35
|
+
|
|
44
36
|
// Create server
|
|
45
37
|
const server = Bun.serve({
|
|
46
38
|
port,
|
|
47
39
|
hostname: host,
|
|
48
40
|
fetch(req) {
|
|
49
|
-
const url = new URL(req.url)
|
|
50
|
-
|
|
41
|
+
const url = new URL(req.url);
|
|
42
|
+
|
|
51
43
|
// Simple router
|
|
52
|
-
if (url.pathname ===
|
|
44
|
+
if (url.pathname === "/") {
|
|
53
45
|
return new Response(getHomePage(), {
|
|
54
|
-
headers: {
|
|
55
|
-
})
|
|
46
|
+
headers: { "Content-Type": "text/html" },
|
|
47
|
+
});
|
|
56
48
|
}
|
|
57
|
-
|
|
58
|
-
if (url.pathname ===
|
|
49
|
+
|
|
50
|
+
if (url.pathname === "/api/status") {
|
|
59
51
|
return Response.json({
|
|
60
|
-
status:
|
|
61
|
-
version:
|
|
62
|
-
uptime: process.uptime()
|
|
63
|
-
})
|
|
52
|
+
status: "ok",
|
|
53
|
+
version: "0.1.0",
|
|
54
|
+
uptime: process.uptime(),
|
|
55
|
+
});
|
|
64
56
|
}
|
|
65
|
-
|
|
66
|
-
return new Response(
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
spin.succeed(`Server running at http://${host}:${port}`)
|
|
71
|
-
|
|
57
|
+
|
|
58
|
+
return new Response("Not Found", { status: 404 });
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
spin.succeed(`Server running at http://${host}:${port}`);
|
|
63
|
+
|
|
72
64
|
// Open browser
|
|
73
65
|
if (shouldOpen) {
|
|
74
|
-
const openSpin = spinner(
|
|
75
|
-
openSpin.start()
|
|
76
|
-
|
|
66
|
+
const openSpin = spinner("Opening browser...");
|
|
67
|
+
openSpin.start();
|
|
68
|
+
|
|
77
69
|
try {
|
|
78
|
-
const url = `http://${host ===
|
|
79
|
-
|
|
70
|
+
const url = `http://${host === "0.0.0.0" ? "localhost" : host}:${port}`;
|
|
71
|
+
|
|
80
72
|
// Platform-specific open commands
|
|
81
|
-
const openCommand =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
const openCommand =
|
|
74
|
+
process.platform === "darwin"
|
|
75
|
+
? "open"
|
|
76
|
+
: process.platform === "win32"
|
|
77
|
+
? "start"
|
|
78
|
+
: "xdg-open";
|
|
79
|
+
|
|
80
|
+
await shell`${openCommand} ${url}`.quiet();
|
|
81
|
+
openSpin.succeed("Browser opened");
|
|
87
82
|
} catch {
|
|
88
|
-
openSpin.fail(
|
|
83
|
+
openSpin.fail("Failed to open browser");
|
|
89
84
|
}
|
|
90
85
|
}
|
|
91
|
-
|
|
86
|
+
|
|
92
87
|
// Keep server running
|
|
93
|
-
console.log()
|
|
94
|
-
console.log(colors.dim(
|
|
95
|
-
|
|
88
|
+
console.log();
|
|
89
|
+
console.log(colors.dim("Press Ctrl+C to stop the server"));
|
|
90
|
+
|
|
96
91
|
// Handle shutdown
|
|
97
|
-
process.on(
|
|
98
|
-
console.log()
|
|
99
|
-
console.log(colors.yellow(
|
|
100
|
-
server.stop()
|
|
101
|
-
process.exit(0)
|
|
102
|
-
})
|
|
103
|
-
|
|
92
|
+
process.on("SIGINT", () => {
|
|
93
|
+
console.log();
|
|
94
|
+
console.log(colors.yellow("Shutting down server..."));
|
|
95
|
+
server.stop();
|
|
96
|
+
process.exit(0);
|
|
97
|
+
});
|
|
104
98
|
} catch (error) {
|
|
105
|
-
spin.fail(
|
|
106
|
-
console.error(colors.red(String(error)))
|
|
107
|
-
process.exit(1)
|
|
99
|
+
spin.fail("Failed to start server");
|
|
100
|
+
console.error(colors.red(String(error)));
|
|
101
|
+
process.exit(1);
|
|
108
102
|
}
|
|
109
|
-
}
|
|
110
|
-
})
|
|
103
|
+
},
|
|
104
|
+
});
|
|
111
105
|
|
|
112
106
|
function getHomePage(): string {
|
|
113
107
|
return `
|
|
@@ -173,7 +167,7 @@ function getHomePage(): string {
|
|
|
173
167
|
</div>
|
|
174
168
|
</body>
|
|
175
169
|
</html>
|
|
176
|
-
`.trim()
|
|
170
|
+
`.trim();
|
|
177
171
|
}
|
|
178
172
|
|
|
179
|
-
export default serveCommand
|
|
173
|
+
export default serveCommand;
|
|
@@ -1,115 +1,107 @@
|
|
|
1
|
-
import { defineCommand, option } from
|
|
2
|
-
import { z } from
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import { glob } from
|
|
1
|
+
import { defineCommand, option } from "@bunli/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
import { loadConfig } from "../utils/config.js";
|
|
5
|
+
import { glob } from "../utils/glob.js";
|
|
6
|
+
import { validateFiles } from "../utils/validator.js";
|
|
6
7
|
|
|
7
8
|
const validateCommand = defineCommand({
|
|
8
|
-
name:
|
|
9
|
-
description:
|
|
9
|
+
name: "validate",
|
|
10
|
+
description: "Validate files against defined rules",
|
|
10
11
|
options: {
|
|
11
|
-
config: option(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
),
|
|
26
|
-
cache: option(
|
|
27
|
-
z.boolean().default(true),
|
|
28
|
-
{
|
|
29
|
-
description: 'Enable caching',
|
|
30
|
-
argumentKind: 'flag'
|
|
31
|
-
}
|
|
32
|
-
)
|
|
12
|
+
config: option(z.string().optional(), {
|
|
13
|
+
short: "c",
|
|
14
|
+
description: "Path to config file",
|
|
15
|
+
}),
|
|
16
|
+
fix: option(z.boolean().default(false), {
|
|
17
|
+
short: "f",
|
|
18
|
+
description: "Auto-fix issues",
|
|
19
|
+
argumentKind: "flag",
|
|
20
|
+
}),
|
|
21
|
+
cache: option(z.boolean().default(true), {
|
|
22
|
+
description: "Enable caching",
|
|
23
|
+
argumentKind: "flag",
|
|
24
|
+
}),
|
|
33
25
|
},
|
|
34
26
|
handler: async ({ positional, flags, colors, spinner }) => {
|
|
35
|
-
const spin = spinner(
|
|
36
|
-
spin.start()
|
|
27
|
+
const spin = spinner("Loading configuration...");
|
|
28
|
+
spin.start();
|
|
37
29
|
|
|
38
30
|
try {
|
|
39
|
-
const config = await loadConfig(flags.config)
|
|
40
|
-
spin.succeed(
|
|
31
|
+
const config = await loadConfig(flags.config);
|
|
32
|
+
spin.succeed("Configuration loaded");
|
|
41
33
|
|
|
42
|
-
const patterns = positional.length > 0 ? positional : config.include || [
|
|
34
|
+
const patterns = positional.length > 0 ? positional : config.include || ["src/**/*.{js,ts}"];
|
|
43
35
|
|
|
44
|
-
const fileSpin = spinner(
|
|
45
|
-
fileSpin.start()
|
|
36
|
+
const fileSpin = spinner("Resolving files...");
|
|
37
|
+
fileSpin.start();
|
|
46
38
|
|
|
47
39
|
const files = await glob(patterns, {
|
|
48
40
|
include: config.include,
|
|
49
|
-
exclude: config.exclude
|
|
50
|
-
})
|
|
41
|
+
exclude: config.exclude,
|
|
42
|
+
});
|
|
51
43
|
|
|
52
|
-
fileSpin.succeed(`Found ${files.length} files to validate`)
|
|
44
|
+
fileSpin.succeed(`Found ${files.length} files to validate`);
|
|
53
45
|
|
|
54
46
|
if (files.length === 0) {
|
|
55
|
-
console.log(colors.yellow(
|
|
56
|
-
return
|
|
47
|
+
console.log(colors.yellow("No files matched the pattern"));
|
|
48
|
+
return;
|
|
57
49
|
}
|
|
58
50
|
|
|
59
|
-
const validateSpin = spinner(
|
|
60
|
-
validateSpin.start()
|
|
51
|
+
const validateSpin = spinner("Validating files...");
|
|
52
|
+
validateSpin.start();
|
|
61
53
|
|
|
62
54
|
const results = await validateFiles(files, {
|
|
63
55
|
rules: config.rules,
|
|
64
56
|
fix: flags.fix,
|
|
65
|
-
cache: flags.cache && config.cache?.enabled
|
|
66
|
-
})
|
|
57
|
+
cache: flags.cache && config.cache?.enabled,
|
|
58
|
+
});
|
|
67
59
|
|
|
68
|
-
validateSpin.stop()
|
|
60
|
+
validateSpin.stop();
|
|
69
61
|
|
|
70
|
-
let hasErrors = false
|
|
62
|
+
let hasErrors = false;
|
|
71
63
|
|
|
72
64
|
for (const result of results) {
|
|
73
65
|
if (result.errors.length > 0 || result.warnings.length > 0) {
|
|
74
|
-
console.log()
|
|
75
|
-
console.log(colors.bold(result.file))
|
|
66
|
+
console.log();
|
|
67
|
+
console.log(colors.bold(result.file));
|
|
76
68
|
|
|
77
69
|
for (const error of result.errors) {
|
|
78
|
-
console.log(colors.red(` ✗ ${error.line}:${error.column} ${error.message}`))
|
|
79
|
-
hasErrors = true
|
|
70
|
+
console.log(colors.red(` ✗ ${error.line}:${error.column} ${error.message}`));
|
|
71
|
+
hasErrors = true;
|
|
80
72
|
}
|
|
81
73
|
|
|
82
74
|
for (const warning of result.warnings) {
|
|
83
|
-
console.log(colors.yellow(` ⚠ ${warning.line}:${warning.column} ${warning.message}`))
|
|
75
|
+
console.log(colors.yellow(` ⚠ ${warning.line}:${warning.column} ${warning.message}`));
|
|
84
76
|
}
|
|
85
77
|
}
|
|
86
78
|
}
|
|
87
79
|
|
|
88
|
-
const totalErrors = results.reduce((sum, r) => sum + r.errors.length, 0)
|
|
89
|
-
const totalWarnings = results.reduce((sum, r) => sum + r.warnings.length, 0)
|
|
80
|
+
const totalErrors = results.reduce((sum, r) => sum + r.errors.length, 0);
|
|
81
|
+
const totalWarnings = results.reduce((sum, r) => sum + r.warnings.length, 0);
|
|
90
82
|
|
|
91
|
-
console.log()
|
|
83
|
+
console.log();
|
|
92
84
|
if (totalErrors === 0 && totalWarnings === 0) {
|
|
93
|
-
console.log(colors.green(
|
|
85
|
+
console.log(colors.green("✅ All files passed validation!"));
|
|
94
86
|
} else {
|
|
95
|
-
console.log(colors.bold(
|
|
87
|
+
console.log(colors.bold("Summary:"));
|
|
96
88
|
if (totalErrors > 0) {
|
|
97
|
-
console.log(colors.red(` ${totalErrors} error${totalErrors !== 1 ?
|
|
89
|
+
console.log(colors.red(` ${totalErrors} error${totalErrors !== 1 ? "s" : ""}`));
|
|
98
90
|
}
|
|
99
91
|
if (totalWarnings > 0) {
|
|
100
|
-
console.log(colors.yellow(` ${totalWarnings} warning${totalWarnings !== 1 ?
|
|
92
|
+
console.log(colors.yellow(` ${totalWarnings} warning${totalWarnings !== 1 ? "s" : ""}`));
|
|
101
93
|
}
|
|
102
94
|
|
|
103
95
|
if (hasErrors) {
|
|
104
|
-
process.exit(1)
|
|
96
|
+
process.exit(1);
|
|
105
97
|
}
|
|
106
98
|
}
|
|
107
99
|
} catch (error) {
|
|
108
|
-
spin.fail(
|
|
109
|
-
console.error(colors.red(String(error)))
|
|
110
|
-
process.exit(1)
|
|
100
|
+
spin.fail("Validation failed");
|
|
101
|
+
console.error(colors.red(String(error)));
|
|
102
|
+
process.exit(1);
|
|
111
103
|
}
|
|
112
|
-
}
|
|
113
|
-
})
|
|
104
|
+
},
|
|
105
|
+
});
|
|
114
106
|
|
|
115
|
-
export default validateCommand
|
|
107
|
+
export default validateCommand;
|
|
@@ -1,55 +1,56 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { createCLI } from
|
|
3
|
-
import { Result, TaggedError } from
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
2
|
+
import { createCLI } from "@bunli/core";
|
|
3
|
+
import { Result, TaggedError } from "better-result";
|
|
4
|
+
|
|
5
|
+
import configCommand from "./commands/config.js";
|
|
6
|
+
import initCommand from "./commands/init.js";
|
|
7
|
+
import serveCommand from "./commands/serve.js";
|
|
8
|
+
import validateCommand from "./commands/validate.js";
|
|
9
|
+
import { loadConfig } from "./utils/config.js";
|
|
9
10
|
|
|
10
11
|
const toErrorMessage = (error: unknown): string =>
|
|
11
|
-
error instanceof Error ? error.message : String(error)
|
|
12
|
+
error instanceof Error ? error.message : String(error);
|
|
12
13
|
|
|
13
|
-
class CliStartupError extends TaggedError(
|
|
14
|
-
message: string
|
|
15
|
-
cause: unknown
|
|
14
|
+
class CliStartupError extends TaggedError("CliStartupError")<{
|
|
15
|
+
message: string;
|
|
16
|
+
cause: unknown;
|
|
16
17
|
}>() {
|
|
17
18
|
constructor(cause: unknown) {
|
|
18
|
-
super({ message: `Failed to start CLI: ${toErrorMessage(cause)}`, cause })
|
|
19
|
+
super({ message: `Failed to start CLI: ${toErrorMessage(cause)}`, cause });
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
const cli = await createCLI({
|
|
23
|
-
name:
|
|
24
|
-
version:
|
|
25
|
-
description:
|
|
26
|
-
})
|
|
24
|
+
name: "{{name}}",
|
|
25
|
+
version: "0.1.0",
|
|
26
|
+
description: "{{description}}",
|
|
27
|
+
});
|
|
27
28
|
|
|
28
|
-
cli.command(initCommand)
|
|
29
|
-
cli.command(validateCommand)
|
|
30
|
-
cli.command(serveCommand)
|
|
31
|
-
cli.command(configCommand)
|
|
29
|
+
cli.command(initCommand);
|
|
30
|
+
cli.command(validateCommand);
|
|
31
|
+
cli.command(serveCommand);
|
|
32
|
+
cli.command(configCommand);
|
|
32
33
|
|
|
33
34
|
async function run(): Promise<Result<void, CliStartupError>> {
|
|
34
35
|
const configResult = await Result.tryPromise({
|
|
35
36
|
try: () => loadConfig(),
|
|
36
|
-
catch: (cause) => new CliStartupError(cause)
|
|
37
|
-
})
|
|
37
|
+
catch: (cause) => new CliStartupError(cause),
|
|
38
|
+
});
|
|
38
39
|
|
|
39
40
|
if (Result.isError(configResult)) {
|
|
40
|
-
return configResult
|
|
41
|
+
return configResult;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
return Result.tryPromise({
|
|
44
45
|
try: async () => {
|
|
45
|
-
await cli.run()
|
|
46
|
+
await cli.run();
|
|
46
47
|
},
|
|
47
|
-
catch: (cause) => new CliStartupError(cause)
|
|
48
|
-
})
|
|
48
|
+
catch: (cause) => new CliStartupError(cause),
|
|
49
|
+
});
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
const result = await run()
|
|
52
|
+
const result = await run();
|
|
52
53
|
if (Result.isError(result)) {
|
|
53
|
-
console.error(result.error.message)
|
|
54
|
-
process.exit(1)
|
|
54
|
+
console.error(result.error.message);
|
|
55
|
+
process.exit(1);
|
|
55
56
|
}
|