create-bunli 0.8.0 → 0.8.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/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 +3 -3
- 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 +3 -3
- 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,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@{{name}}/core",
|
|
3
3
|
"version": "0.1.0",
|
|
4
|
-
"type": "module",
|
|
5
4
|
"description": "Core functionality for {{name}}",
|
|
6
|
-
"author": "{{author}}",
|
|
7
5
|
"license": "MIT",
|
|
6
|
+
"author": "{{author}}",
|
|
7
|
+
"type": "module",
|
|
8
8
|
"main": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"exports": {
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"zod": "^3.22.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@tsconfig/bun": "catalog:",
|
|
29
28
|
"@bunli/test": "latest",
|
|
29
|
+
"@tsconfig/bun": "catalog:",
|
|
30
30
|
"@types/bun": "latest",
|
|
31
31
|
"typescript": "^5.0.0"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { $ } from
|
|
2
|
+
import { $ } from "bun";
|
|
3
3
|
|
|
4
4
|
// Clean dist directory
|
|
5
|
-
await $`rm -rf dist
|
|
6
|
-
await $`mkdir -p dist
|
|
5
|
+
await $`rm -rf dist`;
|
|
6
|
+
await $`mkdir -p dist`;
|
|
7
7
|
|
|
8
8
|
// Build TypeScript files
|
|
9
9
|
await Bun.build({
|
|
10
|
-
entrypoints: [
|
|
11
|
-
outdir:
|
|
12
|
-
target:
|
|
13
|
-
format:
|
|
10
|
+
entrypoints: ["./src/index.ts"],
|
|
11
|
+
outdir: "./dist",
|
|
12
|
+
target: "bun",
|
|
13
|
+
format: "esm",
|
|
14
14
|
minify: false,
|
|
15
|
-
external: [
|
|
16
|
-
})
|
|
15
|
+
external: ["@bunli/core", "@{{name}}/utils", "zod"],
|
|
16
|
+
});
|
|
17
17
|
|
|
18
|
-
console.log(
|
|
18
|
+
console.log("✅ @{{name}}/core built successfully");
|
|
@@ -1,92 +1,93 @@
|
|
|
1
|
-
import { defineCommand, option } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { defineCommand, option } from "@bunli/core";
|
|
2
|
+
import { logger, formatTable } from "@{{name}}/utils";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
import type { AnalyzeResult } from "../types.js";
|
|
5
6
|
|
|
6
7
|
const analyzeCommand = defineCommand({
|
|
7
|
-
name:
|
|
8
|
-
description:
|
|
8
|
+
name: "analyze",
|
|
9
|
+
description: "Analyze files and generate reports",
|
|
9
10
|
options: {
|
|
10
|
-
detailed: option(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
argumentKind: 'flag'
|
|
16
|
-
}
|
|
17
|
-
)
|
|
11
|
+
detailed: option(z.boolean().default(false), {
|
|
12
|
+
short: "d",
|
|
13
|
+
description: "Show detailed analysis",
|
|
14
|
+
argumentKind: "flag",
|
|
15
|
+
}),
|
|
18
16
|
},
|
|
19
17
|
handler: async ({ positional, flags, colors }) => {
|
|
20
|
-
const files = positional
|
|
18
|
+
const files = positional;
|
|
21
19
|
if (files.length === 0) {
|
|
22
|
-
logger.error(
|
|
23
|
-
process.exit(1)
|
|
20
|
+
logger.error("Usage: analyze <file...>");
|
|
21
|
+
process.exit(1);
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
logger.info(
|
|
27
|
-
|
|
28
|
-
const results: AnalyzeResult[] = []
|
|
29
|
-
|
|
24
|
+
logger.info("Starting analysis...");
|
|
25
|
+
|
|
26
|
+
const results: AnalyzeResult[] = [];
|
|
27
|
+
|
|
30
28
|
for (const file of files) {
|
|
31
29
|
try {
|
|
32
|
-
const result = await analyzeFile(file)
|
|
33
|
-
results.push(result)
|
|
30
|
+
const result = await analyzeFile(file);
|
|
31
|
+
results.push(result);
|
|
34
32
|
} catch (error) {
|
|
35
|
-
logger.error(`Failed to analyze ${file}:`, error)
|
|
33
|
+
logger.error(`Failed to analyze ${file}:`, error);
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
|
-
|
|
36
|
+
|
|
39
37
|
// Display results
|
|
40
|
-
console.log()
|
|
41
|
-
console.log(colors.bold(
|
|
42
|
-
console.log()
|
|
43
|
-
|
|
44
|
-
const tableData = results.map(r => ({
|
|
38
|
+
console.log();
|
|
39
|
+
console.log(colors.bold("Analysis Results:"));
|
|
40
|
+
console.log();
|
|
41
|
+
|
|
42
|
+
const tableData = results.map((r) => ({
|
|
45
43
|
File: r.file,
|
|
46
44
|
Lines: r.metrics.lines,
|
|
47
45
|
Words: r.metrics.words,
|
|
48
|
-
Issues: r.issues.length
|
|
49
|
-
}))
|
|
50
|
-
|
|
51
|
-
console.log(formatTable(tableData))
|
|
52
|
-
|
|
46
|
+
Issues: r.issues.length,
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
console.log(formatTable(tableData));
|
|
50
|
+
|
|
53
51
|
if (flags.detailed) {
|
|
54
|
-
console.log()
|
|
55
|
-
console.log(colors.bold(
|
|
56
|
-
|
|
52
|
+
console.log();
|
|
53
|
+
console.log(colors.bold("Detailed Issues:"));
|
|
54
|
+
|
|
57
55
|
for (const result of results) {
|
|
58
56
|
if (result.issues.length > 0) {
|
|
59
|
-
console.log()
|
|
60
|
-
console.log(colors.underline(result.file))
|
|
61
|
-
|
|
57
|
+
console.log();
|
|
58
|
+
console.log(colors.underline(result.file));
|
|
59
|
+
|
|
62
60
|
for (const issue of result.issues) {
|
|
63
|
-
const icon = issue.type ===
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
const icon = issue.type === "error" ? "✗" : issue.type === "warning" ? "⚠" : "ℹ";
|
|
62
|
+
const color =
|
|
63
|
+
issue.type === "error"
|
|
64
|
+
? colors.red
|
|
65
|
+
: issue.type === "warning"
|
|
66
|
+
? colors.yellow
|
|
67
|
+
: colors.blue;
|
|
68
|
+
|
|
69
|
+
console.log(color(` ${icon} ${issue.line}:${issue.column} ${issue.message}`));
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
|
-
}
|
|
74
|
-
})
|
|
74
|
+
},
|
|
75
|
+
});
|
|
75
76
|
|
|
76
77
|
async function analyzeFile(file: string): Promise<AnalyzeResult> {
|
|
77
|
-
const content = await Bun.file(file).text()
|
|
78
|
-
const lines = content.split(
|
|
79
|
-
const words = content.split(/\\s+/).filter(w => w.length > 0)
|
|
80
|
-
|
|
78
|
+
const content = await Bun.file(file).text();
|
|
79
|
+
const lines = content.split("\n");
|
|
80
|
+
const words = content.split(/\\s+/).filter((w) => w.length > 0);
|
|
81
|
+
|
|
81
82
|
return {
|
|
82
83
|
file,
|
|
83
84
|
metrics: {
|
|
84
85
|
lines: lines.length,
|
|
85
86
|
characters: content.length,
|
|
86
|
-
words: words.length
|
|
87
|
+
words: words.length,
|
|
87
88
|
},
|
|
88
|
-
issues: []
|
|
89
|
-
}
|
|
89
|
+
issues: [],
|
|
90
|
+
};
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
export default analyzeCommand
|
|
93
|
+
export default analyzeCommand;
|
|
@@ -1,72 +1,64 @@
|
|
|
1
|
-
import { defineCommand, option } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { defineCommand, option } from "@bunli/core";
|
|
2
|
+
import { logger } from "@{{name}}/utils";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
import type { ProcessOptions } from "../types.js";
|
|
5
6
|
|
|
6
7
|
const processCommand = defineCommand({
|
|
7
|
-
name:
|
|
8
|
-
description:
|
|
8
|
+
name: "process",
|
|
9
|
+
description: "Process input files",
|
|
9
10
|
options: {
|
|
10
|
-
output: option(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
),
|
|
24
|
-
verbose: option(
|
|
25
|
-
z.boolean().default(false),
|
|
26
|
-
{
|
|
27
|
-
short: 'v',
|
|
28
|
-
description: 'Verbose output',
|
|
29
|
-
argumentKind: 'flag'
|
|
30
|
-
}
|
|
31
|
-
)
|
|
11
|
+
output: option(z.string().optional(), {
|
|
12
|
+
short: "o",
|
|
13
|
+
description: "Output directory",
|
|
14
|
+
}),
|
|
15
|
+
format: option(z.enum(["json", "yaml", "text"]).default("json"), {
|
|
16
|
+
short: "f",
|
|
17
|
+
description: "Output format",
|
|
18
|
+
}),
|
|
19
|
+
verbose: option(z.boolean().default(false), {
|
|
20
|
+
short: "v",
|
|
21
|
+
description: "Verbose output",
|
|
22
|
+
argumentKind: "flag",
|
|
23
|
+
}),
|
|
32
24
|
},
|
|
33
25
|
handler: async ({ positional, flags, spinner }) => {
|
|
34
|
-
const files = positional
|
|
26
|
+
const files = positional;
|
|
35
27
|
if (files.length === 0) {
|
|
36
|
-
logger.error(
|
|
37
|
-
process.exit(1)
|
|
28
|
+
logger.error("Usage: process <file...>");
|
|
29
|
+
process.exit(1);
|
|
38
30
|
}
|
|
39
31
|
|
|
40
|
-
const spin = spinner(
|
|
41
|
-
spin.start()
|
|
42
|
-
|
|
32
|
+
const spin = spinner("Processing files...");
|
|
33
|
+
spin.start();
|
|
34
|
+
|
|
43
35
|
try {
|
|
44
36
|
for (const file of files) {
|
|
45
37
|
if (flags.verbose) {
|
|
46
|
-
logger.info(`Processing ${file}`)
|
|
38
|
+
logger.info(`Processing ${file}`);
|
|
47
39
|
}
|
|
48
|
-
|
|
40
|
+
|
|
49
41
|
// Process logic here
|
|
50
42
|
await processFile(file, {
|
|
51
43
|
input: file,
|
|
52
44
|
output: flags.output,
|
|
53
45
|
format: flags.format,
|
|
54
|
-
verbose: flags.verbose
|
|
55
|
-
})
|
|
46
|
+
verbose: flags.verbose,
|
|
47
|
+
});
|
|
56
48
|
}
|
|
57
|
-
|
|
58
|
-
spin.succeed(`Processed ${files.length} files`)
|
|
49
|
+
|
|
50
|
+
spin.succeed(`Processed ${files.length} files`);
|
|
59
51
|
} catch (error) {
|
|
60
|
-
spin.fail(
|
|
61
|
-
logger.error(error)
|
|
62
|
-
process.exit(1)
|
|
52
|
+
spin.fail("Processing failed");
|
|
53
|
+
logger.error(error);
|
|
54
|
+
process.exit(1);
|
|
63
55
|
}
|
|
64
|
-
}
|
|
65
|
-
})
|
|
56
|
+
},
|
|
57
|
+
});
|
|
66
58
|
|
|
67
59
|
async function processFile(file: string, options: ProcessOptions): Promise<void> {
|
|
68
60
|
// Implementation here
|
|
69
|
-
logger.debug(`Processing ${file} with options:`, options)
|
|
61
|
+
logger.debug(`Processing ${file} with options:`, options);
|
|
70
62
|
}
|
|
71
63
|
|
|
72
|
-
export default processCommand
|
|
64
|
+
export default processCommand;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default as processCommand } from
|
|
2
|
-
export { default as analyzeCommand } from
|
|
3
|
-
export type { ProcessOptions, AnalyzeResult } from
|
|
1
|
+
export { default as processCommand } from "./commands/process.js";
|
|
2
|
+
export { default as analyzeCommand } from "./commands/analyze.js";
|
|
3
|
+
export type { ProcessOptions, AnalyzeResult } from "./types.js";
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
export interface ProcessOptions {
|
|
2
|
-
input: string
|
|
3
|
-
output?: string
|
|
4
|
-
format?:
|
|
5
|
-
verbose?: boolean
|
|
2
|
+
input: string;
|
|
3
|
+
output?: string;
|
|
4
|
+
format?: "json" | "yaml" | "text";
|
|
5
|
+
verbose?: boolean;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export interface AnalyzeResult {
|
|
9
|
-
file: string
|
|
9
|
+
file: string;
|
|
10
10
|
metrics: {
|
|
11
|
-
lines: number
|
|
12
|
-
characters: number
|
|
13
|
-
words: number
|
|
14
|
-
}
|
|
11
|
+
lines: number;
|
|
12
|
+
characters: number;
|
|
13
|
+
words: number;
|
|
14
|
+
};
|
|
15
15
|
issues: Array<{
|
|
16
|
-
type:
|
|
17
|
-
line: number
|
|
18
|
-
column: number
|
|
19
|
-
message: string
|
|
20
|
-
}
|
|
21
|
-
}
|
|
16
|
+
type: "error" | "warning" | "info";
|
|
17
|
+
line: number;
|
|
18
|
+
column: number;
|
|
19
|
+
message: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@{{name}}/utils",
|
|
3
3
|
"version": "0.1.0",
|
|
4
|
-
"type": "module",
|
|
5
4
|
"description": "Shared utilities for {{name}}",
|
|
6
|
-
"author": "{{author}}",
|
|
7
5
|
"license": "MIT",
|
|
6
|
+
"author": "{{author}}",
|
|
7
|
+
"type": "module",
|
|
8
8
|
"main": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"exports": {
|
|
@@ -24,4 +24,4 @@
|
|
|
24
24
|
"@types/bun": "latest",
|
|
25
25
|
"typescript": "^5.0.0"
|
|
26
26
|
}
|
|
27
|
-
}
|
|
27
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { $ } from
|
|
2
|
+
import { $ } from "bun";
|
|
3
3
|
|
|
4
4
|
// Clean dist directory
|
|
5
|
-
await $`rm -rf dist
|
|
6
|
-
await $`mkdir -p dist
|
|
5
|
+
await $`rm -rf dist`;
|
|
6
|
+
await $`mkdir -p dist`;
|
|
7
7
|
|
|
8
8
|
// Build TypeScript files
|
|
9
9
|
await Bun.build({
|
|
10
|
-
entrypoints: [
|
|
11
|
-
outdir:
|
|
12
|
-
target:
|
|
13
|
-
format:
|
|
14
|
-
minify: false
|
|
15
|
-
})
|
|
10
|
+
entrypoints: ["./src/index.ts"],
|
|
11
|
+
outdir: "./dist",
|
|
12
|
+
target: "bun",
|
|
13
|
+
format: "esm",
|
|
14
|
+
minify: false,
|
|
15
|
+
});
|
|
16
16
|
|
|
17
|
-
console.log(
|
|
17
|
+
console.log("✅ @{{name}}/utils built successfully");
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
export function formatTable(data: Record<string, any>[]): string {
|
|
2
|
-
if (data.length === 0) return
|
|
3
|
-
|
|
4
|
-
const headers = Object.keys(data[0])
|
|
5
|
-
const rows = data.map(item => headers.map(h => String(item[h] ??
|
|
6
|
-
|
|
2
|
+
if (data.length === 0) return "";
|
|
3
|
+
|
|
4
|
+
const headers = Object.keys(data[0]);
|
|
5
|
+
const rows = data.map((item) => headers.map((h) => String(item[h] ?? "")));
|
|
6
|
+
|
|
7
7
|
// Calculate column widths
|
|
8
8
|
const widths = headers.map((h, i) => {
|
|
9
|
-
const headerWidth = h.length
|
|
10
|
-
const maxDataWidth = Math.max(...rows.map(r => r[i].length))
|
|
11
|
-
return Math.max(headerWidth, maxDataWidth)
|
|
12
|
-
})
|
|
13
|
-
|
|
9
|
+
const headerWidth = h.length;
|
|
10
|
+
const maxDataWidth = Math.max(...rows.map((r) => r[i].length));
|
|
11
|
+
return Math.max(headerWidth, maxDataWidth);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
14
|
// Build table
|
|
15
|
-
const lines: string[] = []
|
|
16
|
-
|
|
15
|
+
const lines: string[] = [];
|
|
16
|
+
|
|
17
17
|
// Header
|
|
18
|
-
lines.push(headers.map((h, i) => h.padEnd(widths[i])).join(
|
|
19
|
-
lines.push(widths.map(w =>
|
|
20
|
-
|
|
18
|
+
lines.push(headers.map((h, i) => h.padEnd(widths[i])).join(" "));
|
|
19
|
+
lines.push(widths.map((w) => "-".repeat(w)).join(" "));
|
|
20
|
+
|
|
21
21
|
// Rows
|
|
22
22
|
for (const row of rows) {
|
|
23
|
-
lines.push(row.map((cell, i) => cell.padEnd(widths[i])).join(
|
|
23
|
+
lines.push(row.map((cell, i) => cell.padEnd(widths[i])).join(" "));
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
return lines.join(
|
|
27
|
-
}
|
|
25
|
+
|
|
26
|
+
return lines.join("\\n");
|
|
27
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { logger } from
|
|
2
|
-
export { formatTable } from
|
|
3
|
-
export { parseJSON, stringifyJSON } from
|
|
1
|
+
export { logger } from "./logger.js";
|
|
2
|
+
export { formatTable } from "./format.js";
|
|
3
|
+
export { parseJSON, stringifyJSON } from "./json.js";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export function parseJSON<T = any>(text: string): T {
|
|
2
2
|
try {
|
|
3
|
-
return JSON.parse(text)
|
|
3
|
+
return JSON.parse(text);
|
|
4
4
|
} catch (error) {
|
|
5
|
-
throw new Error(`Invalid JSON: ${error}`)
|
|
5
|
+
throw new Error(`Invalid JSON: ${error}`);
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function stringifyJSON(data: any, pretty = false): string {
|
|
10
|
-
return JSON.stringify(data, null, pretty ? 2 : 0)
|
|
11
|
-
}
|
|
10
|
+
return JSON.stringify(data, null, pretty ? 2 : 0);
|
|
11
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
export const logger = {
|
|
2
2
|
debug: (...args: any[]) => {
|
|
3
3
|
if (process.env.DEBUG) {
|
|
4
|
-
console.log(
|
|
4
|
+
console.log("[DEBUG]", ...args);
|
|
5
5
|
}
|
|
6
6
|
},
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
info: (...args: any[]) => {
|
|
9
|
-
console.log(
|
|
9
|
+
console.log("[INFO]", ...args);
|
|
10
10
|
},
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
warn: (...args: any[]) => {
|
|
13
|
-
console.warn(
|
|
13
|
+
console.warn("[WARN]", ...args);
|
|
14
14
|
},
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
error: (...args: any[]) => {
|
|
17
|
-
console.error(
|
|
18
|
-
}
|
|
19
|
-
}
|
|
17
|
+
console.error("[ERROR]", ...args);
|
|
18
|
+
},
|
|
19
|
+
};
|