create-bunli 0.1.0
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 +302 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +310 -0
- package/dist/create-project.d.ts +13 -0
- package/dist/create.d.ts +13 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +217 -0
- package/dist/template-engine.d.ts +27 -0
- package/dist/templates/advanced/README.md +114 -0
- package/dist/templates/advanced/package.json +36 -0
- package/dist/templates/advanced/src/commands/config.ts +145 -0
- package/dist/templates/advanced/src/commands/init.ts +153 -0
- package/dist/templates/advanced/src/commands/serve.ts +176 -0
- package/dist/templates/advanced/src/commands/validate.ts +116 -0
- package/dist/templates/advanced/src/index.ts +44 -0
- package/dist/templates/advanced/src/utils/config.ts +83 -0
- package/dist/templates/advanced/src/utils/constants.ts +12 -0
- package/dist/templates/advanced/src/utils/glob.ts +49 -0
- package/dist/templates/advanced/src/utils/validator.ts +131 -0
- package/dist/templates/advanced/template.json +37 -0
- package/dist/templates/advanced/test/commands.test.ts +34 -0
- package/dist/templates/advanced/tsconfig.json +23 -0
- package/dist/templates/basic/README.md +41 -0
- package/dist/templates/basic/package.json +29 -0
- package/dist/templates/basic/src/commands/hello.ts +29 -0
- package/dist/templates/basic/src/index.ts +13 -0
- package/dist/templates/basic/template.json +31 -0
- package/dist/templates/basic/test/hello.test.ts +26 -0
- package/dist/templates/basic/tsconfig.json +19 -0
- package/dist/templates/monorepo/README.md +74 -0
- package/dist/templates/monorepo/package.json +28 -0
- package/dist/templates/monorepo/packages/cli/package.json +34 -0
- package/dist/templates/monorepo/packages/cli/src/index.ts +22 -0
- package/dist/templates/monorepo/packages/cli/tsconfig.json +15 -0
- package/dist/templates/monorepo/packages/core/package.json +32 -0
- package/dist/templates/monorepo/packages/core/scripts/build.ts +18 -0
- package/dist/templates/monorepo/packages/core/src/commands/analyze.ts +84 -0
- package/dist/templates/monorepo/packages/core/src/commands/process.ts +64 -0
- package/dist/templates/monorepo/packages/core/src/index.ts +3 -0
- package/dist/templates/monorepo/packages/core/src/types.ts +21 -0
- package/dist/templates/monorepo/packages/core/tsconfig.json +15 -0
- package/dist/templates/monorepo/packages/utils/package.json +26 -0
- package/dist/templates/monorepo/packages/utils/scripts/build.ts +17 -0
- package/dist/templates/monorepo/packages/utils/src/format.ts +27 -0
- package/dist/templates/monorepo/packages/utils/src/index.ts +3 -0
- package/dist/templates/monorepo/packages/utils/src/json.ts +11 -0
- package/dist/templates/monorepo/packages/utils/src/logger.ts +19 -0
- package/dist/templates/monorepo/packages/utils/tsconfig.json +12 -0
- package/dist/templates/monorepo/template.json +24 -0
- package/dist/templates/monorepo/tsconfig.json +14 -0
- package/dist/templates/monorepo/turbo.json +28 -0
- package/dist/types.d.ts +48 -0
- package/package.json +57 -0
- package/templates/advanced/README.md +114 -0
- package/templates/advanced/package.json +36 -0
- package/templates/advanced/src/commands/config.ts +145 -0
- package/templates/advanced/src/commands/init.ts +153 -0
- package/templates/advanced/src/commands/serve.ts +176 -0
- package/templates/advanced/src/commands/validate.ts +116 -0
- package/templates/advanced/src/index.ts +44 -0
- package/templates/advanced/src/utils/config.ts +83 -0
- package/templates/advanced/src/utils/constants.ts +12 -0
- package/templates/advanced/src/utils/glob.ts +49 -0
- package/templates/advanced/src/utils/validator.ts +131 -0
- package/templates/advanced/template.json +37 -0
- package/templates/advanced/test/commands.test.ts +34 -0
- package/templates/advanced/tsconfig.json +23 -0
- package/templates/basic/README.md +41 -0
- package/templates/basic/package.json +29 -0
- package/templates/basic/src/commands/hello.ts +29 -0
- package/templates/basic/src/index.ts +13 -0
- package/templates/basic/template.json +31 -0
- package/templates/basic/test/hello.test.ts +26 -0
- package/templates/basic/tsconfig.json +19 -0
- package/templates/monorepo/README.md +74 -0
- package/templates/monorepo/package.json +28 -0
- package/templates/monorepo/packages/cli/package.json +34 -0
- package/templates/monorepo/packages/cli/src/index.ts +22 -0
- package/templates/monorepo/packages/cli/tsconfig.json +15 -0
- package/templates/monorepo/packages/core/package.json +32 -0
- package/templates/monorepo/packages/core/scripts/build.ts +18 -0
- package/templates/monorepo/packages/core/src/commands/analyze.ts +84 -0
- package/templates/monorepo/packages/core/src/commands/process.ts +64 -0
- package/templates/monorepo/packages/core/src/index.ts +3 -0
- package/templates/monorepo/packages/core/src/types.ts +21 -0
- package/templates/monorepo/packages/core/tsconfig.json +15 -0
- package/templates/monorepo/packages/utils/package.json +26 -0
- package/templates/monorepo/packages/utils/scripts/build.ts +17 -0
- package/templates/monorepo/packages/utils/src/format.ts +27 -0
- package/templates/monorepo/packages/utils/src/index.ts +3 -0
- package/templates/monorepo/packages/utils/src/json.ts +11 -0
- package/templates/monorepo/packages/utils/src/logger.ts +19 -0
- package/templates/monorepo/packages/utils/tsconfig.json +12 -0
- package/templates/monorepo/template.json +24 -0
- package/templates/monorepo/tsconfig.json +14 -0
- package/templates/monorepo/turbo.json +28 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { defineCommand, option } from '@bunli/core'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { logger, formatTable } from '@{{projectName}}/utils'
|
|
4
|
+
import type { AnalyzeResult } from '../types.js'
|
|
5
|
+
|
|
6
|
+
export const analyzeCommand = defineCommand({
|
|
7
|
+
name: 'analyze',
|
|
8
|
+
description: 'Analyze files and generate reports',
|
|
9
|
+
args: z.array(z.string()).min(1).describe('Files to analyze'),
|
|
10
|
+
options: {
|
|
11
|
+
detailed: option(
|
|
12
|
+
z.boolean().default(false),
|
|
13
|
+
{
|
|
14
|
+
short: 'd',
|
|
15
|
+
description: 'Show detailed analysis'
|
|
16
|
+
}
|
|
17
|
+
)
|
|
18
|
+
},
|
|
19
|
+
handler: async ({ args, flags, colors }) => {
|
|
20
|
+
logger.info('Starting analysis...')
|
|
21
|
+
|
|
22
|
+
const results: AnalyzeResult[] = []
|
|
23
|
+
|
|
24
|
+
for (const file of args) {
|
|
25
|
+
try {
|
|
26
|
+
const result = await analyzeFile(file)
|
|
27
|
+
results.push(result)
|
|
28
|
+
} catch (error) {
|
|
29
|
+
logger.error(`Failed to analyze ${file}:`, error)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Display results
|
|
34
|
+
console.log()
|
|
35
|
+
console.log(colors.bold('Analysis Results:'))
|
|
36
|
+
console.log()
|
|
37
|
+
|
|
38
|
+
const tableData = results.map(r => ({
|
|
39
|
+
File: r.file,
|
|
40
|
+
Lines: r.metrics.lines,
|
|
41
|
+
Words: r.metrics.words,
|
|
42
|
+
Issues: r.issues.length
|
|
43
|
+
}))
|
|
44
|
+
|
|
45
|
+
console.log(formatTable(tableData))
|
|
46
|
+
|
|
47
|
+
if (flags.detailed) {
|
|
48
|
+
console.log()
|
|
49
|
+
console.log(colors.bold('Detailed Issues:'))
|
|
50
|
+
|
|
51
|
+
for (const result of results) {
|
|
52
|
+
if (result.issues.length > 0) {
|
|
53
|
+
console.log()
|
|
54
|
+
console.log(colors.underline(result.file))
|
|
55
|
+
|
|
56
|
+
for (const issue of result.issues) {
|
|
57
|
+
const icon = issue.type === 'error' ? '✗' :
|
|
58
|
+
issue.type === 'warning' ? '⚠' : 'ℹ'
|
|
59
|
+
const color = issue.type === 'error' ? colors.red :
|
|
60
|
+
issue.type === 'warning' ? colors.yellow : colors.blue
|
|
61
|
+
|
|
62
|
+
console.log(color(` ${icon} ${issue.line}:${issue.column} ${issue.message}`))
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
async function analyzeFile(file: string): Promise<AnalyzeResult> {
|
|
71
|
+
const content = await Bun.file(file).text()
|
|
72
|
+
const lines = content.split('\n')
|
|
73
|
+
const words = content.split(/\\s+/).filter(w => w.length > 0)
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
file,
|
|
77
|
+
metrics: {
|
|
78
|
+
lines: lines.length,
|
|
79
|
+
characters: content.length,
|
|
80
|
+
words: words.length
|
|
81
|
+
},
|
|
82
|
+
issues: []
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { defineCommand, option } from '@bunli/core'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { logger } from '@{{projectName}}/utils'
|
|
4
|
+
import type { ProcessOptions } from '../types.js'
|
|
5
|
+
|
|
6
|
+
export const processCommand = defineCommand({
|
|
7
|
+
name: 'process',
|
|
8
|
+
description: 'Process input files',
|
|
9
|
+
args: z.array(z.string()).min(1).describe('Files to process'),
|
|
10
|
+
options: {
|
|
11
|
+
output: option(
|
|
12
|
+
z.string().optional(),
|
|
13
|
+
{
|
|
14
|
+
short: 'o',
|
|
15
|
+
description: 'Output directory'
|
|
16
|
+
}
|
|
17
|
+
),
|
|
18
|
+
format: option(
|
|
19
|
+
z.enum(['json', 'yaml', 'text']).default('json'),
|
|
20
|
+
{
|
|
21
|
+
short: 'f',
|
|
22
|
+
description: 'Output format'
|
|
23
|
+
}
|
|
24
|
+
),
|
|
25
|
+
verbose: option(
|
|
26
|
+
z.boolean().default(false),
|
|
27
|
+
{
|
|
28
|
+
short: 'v',
|
|
29
|
+
description: 'Verbose output'
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
},
|
|
33
|
+
handler: async ({ args, flags, spinner }) => {
|
|
34
|
+
const spin = spinner('Processing files...')
|
|
35
|
+
spin.start()
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
for (const file of args) {
|
|
39
|
+
if (flags.verbose) {
|
|
40
|
+
logger.info(`Processing ${file}`)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Process logic here
|
|
44
|
+
await processFile(file, {
|
|
45
|
+
input: file,
|
|
46
|
+
output: flags.output,
|
|
47
|
+
format: flags.format,
|
|
48
|
+
verbose: flags.verbose
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
spin.succeed(`Processed ${args.length} files`)
|
|
53
|
+
} catch (error) {
|
|
54
|
+
spin.fail('Processing failed')
|
|
55
|
+
logger.error(error)
|
|
56
|
+
process.exit(1)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
async function processFile(file: string, options: ProcessOptions): Promise<void> {
|
|
62
|
+
// Implementation here
|
|
63
|
+
logger.debug(`Processing ${file} with options:`, options)
|
|
64
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ProcessOptions {
|
|
2
|
+
input: string
|
|
3
|
+
output?: string
|
|
4
|
+
format?: 'json' | 'yaml' | 'text'
|
|
5
|
+
verbose?: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface AnalyzeResult {
|
|
9
|
+
file: string
|
|
10
|
+
metrics: {
|
|
11
|
+
lines: number
|
|
12
|
+
characters: number
|
|
13
|
+
words: number
|
|
14
|
+
}
|
|
15
|
+
issues: Array<{
|
|
16
|
+
type: 'error' | 'warning' | 'info'
|
|
17
|
+
line: number
|
|
18
|
+
column: number
|
|
19
|
+
message: string
|
|
20
|
+
}>
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"composite": true
|
|
9
|
+
},
|
|
10
|
+
"include": ["src/**/*"],
|
|
11
|
+
"exclude": ["node_modules", "dist", "test/**/*"],
|
|
12
|
+
"references": [
|
|
13
|
+
{ "path": "../utils" }
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@{{projectName}}/utils",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Shared utilities for {{projectName}}",
|
|
6
|
+
"author": "{{author}}",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "bun scripts/build.ts && bun run tsc",
|
|
18
|
+
"test": "bun test",
|
|
19
|
+
"type-check": "tsc --noEmit",
|
|
20
|
+
"clean": "rm -rf dist"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/bun": "latest",
|
|
24
|
+
"typescript": "^5.0.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { $ } from 'bun'
|
|
3
|
+
|
|
4
|
+
// Clean dist directory
|
|
5
|
+
await $`rm -rf dist`
|
|
6
|
+
await $`mkdir -p dist`
|
|
7
|
+
|
|
8
|
+
// Build TypeScript files
|
|
9
|
+
await Bun.build({
|
|
10
|
+
entrypoints: ['./src/index.ts'],
|
|
11
|
+
outdir: './dist',
|
|
12
|
+
target: 'bun',
|
|
13
|
+
format: 'esm',
|
|
14
|
+
minify: false
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
console.log('✅ @{{projectName}}/utils built successfully')
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
|
|
7
|
+
// Calculate column widths
|
|
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
|
+
|
|
14
|
+
// Build table
|
|
15
|
+
const lines: string[] = []
|
|
16
|
+
|
|
17
|
+
// Header
|
|
18
|
+
lines.push(headers.map((h, i) => h.padEnd(widths[i])).join(' '))
|
|
19
|
+
lines.push(widths.map(w => '-'.repeat(w)).join(' '))
|
|
20
|
+
|
|
21
|
+
// Rows
|
|
22
|
+
for (const row of rows) {
|
|
23
|
+
lines.push(row.map((cell, i) => cell.padEnd(widths[i])).join(' '))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return lines.join('\\n')
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function parseJSON<T = any>(text: string): T {
|
|
2
|
+
try {
|
|
3
|
+
return JSON.parse(text)
|
|
4
|
+
} catch (error) {
|
|
5
|
+
throw new Error(`Invalid JSON: ${error}`)
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function stringifyJSON(data: any, pretty = false): string {
|
|
10
|
+
return JSON.stringify(data, null, pretty ? 2 : 0)
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const logger = {
|
|
2
|
+
debug: (...args: any[]) => {
|
|
3
|
+
if (process.env.DEBUG) {
|
|
4
|
+
console.log('[DEBUG]', ...args)
|
|
5
|
+
}
|
|
6
|
+
},
|
|
7
|
+
|
|
8
|
+
info: (...args: any[]) => {
|
|
9
|
+
console.log('[INFO]', ...args)
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
warn: (...args: any[]) => {
|
|
13
|
+
console.warn('[WARN]', ...args)
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
error: (...args: any[]) => {
|
|
17
|
+
console.error('[ERROR]', ...args)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"composite": true
|
|
9
|
+
},
|
|
10
|
+
"include": ["src/**/*"],
|
|
11
|
+
"exclude": ["node_modules", "dist", "test/**/*"]
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bunli-monorepo",
|
|
3
|
+
"description": "Monorepo template for multi-package Bunli projects",
|
|
4
|
+
"variables": [
|
|
5
|
+
{
|
|
6
|
+
"name": "projectName",
|
|
7
|
+
"message": "Project name",
|
|
8
|
+
"type": "string",
|
|
9
|
+
"default": "my-bunli-monorepo"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "description",
|
|
13
|
+
"message": "Project description",
|
|
14
|
+
"type": "string",
|
|
15
|
+
"default": "A monorepo CLI project built with Bunli"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "author",
|
|
19
|
+
"message": "Author name",
|
|
20
|
+
"type": "string",
|
|
21
|
+
"default": ""
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"types": ["bun-types"]
|
|
12
|
+
},
|
|
13
|
+
"exclude": ["node_modules", "dist", "build", ".turbo"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://turbo.build/schema.json",
|
|
3
|
+
"globalDependencies": ["**/.env.*local"],
|
|
4
|
+
"pipeline": {
|
|
5
|
+
"build": {
|
|
6
|
+
"dependsOn": ["^build"],
|
|
7
|
+
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
|
|
8
|
+
},
|
|
9
|
+
"test": {
|
|
10
|
+
"dependsOn": ["build"],
|
|
11
|
+
"outputs": ["coverage/**"],
|
|
12
|
+
"cache": false
|
|
13
|
+
},
|
|
14
|
+
"lint": {
|
|
15
|
+
"dependsOn": ["^build"]
|
|
16
|
+
},
|
|
17
|
+
"type-check": {
|
|
18
|
+
"dependsOn": ["^build"]
|
|
19
|
+
},
|
|
20
|
+
"dev": {
|
|
21
|
+
"cache": false,
|
|
22
|
+
"persistent": true
|
|
23
|
+
},
|
|
24
|
+
"clean": {
|
|
25
|
+
"cache": false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|