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.
Files changed (96) hide show
  1. package/README.md +302 -0
  2. package/dist/cli.d.ts +2 -0
  3. package/dist/cli.js +310 -0
  4. package/dist/create-project.d.ts +13 -0
  5. package/dist/create.d.ts +13 -0
  6. package/dist/index.d.ts +4 -0
  7. package/dist/index.js +217 -0
  8. package/dist/template-engine.d.ts +27 -0
  9. package/dist/templates/advanced/README.md +114 -0
  10. package/dist/templates/advanced/package.json +36 -0
  11. package/dist/templates/advanced/src/commands/config.ts +145 -0
  12. package/dist/templates/advanced/src/commands/init.ts +153 -0
  13. package/dist/templates/advanced/src/commands/serve.ts +176 -0
  14. package/dist/templates/advanced/src/commands/validate.ts +116 -0
  15. package/dist/templates/advanced/src/index.ts +44 -0
  16. package/dist/templates/advanced/src/utils/config.ts +83 -0
  17. package/dist/templates/advanced/src/utils/constants.ts +12 -0
  18. package/dist/templates/advanced/src/utils/glob.ts +49 -0
  19. package/dist/templates/advanced/src/utils/validator.ts +131 -0
  20. package/dist/templates/advanced/template.json +37 -0
  21. package/dist/templates/advanced/test/commands.test.ts +34 -0
  22. package/dist/templates/advanced/tsconfig.json +23 -0
  23. package/dist/templates/basic/README.md +41 -0
  24. package/dist/templates/basic/package.json +29 -0
  25. package/dist/templates/basic/src/commands/hello.ts +29 -0
  26. package/dist/templates/basic/src/index.ts +13 -0
  27. package/dist/templates/basic/template.json +31 -0
  28. package/dist/templates/basic/test/hello.test.ts +26 -0
  29. package/dist/templates/basic/tsconfig.json +19 -0
  30. package/dist/templates/monorepo/README.md +74 -0
  31. package/dist/templates/monorepo/package.json +28 -0
  32. package/dist/templates/monorepo/packages/cli/package.json +34 -0
  33. package/dist/templates/monorepo/packages/cli/src/index.ts +22 -0
  34. package/dist/templates/monorepo/packages/cli/tsconfig.json +15 -0
  35. package/dist/templates/monorepo/packages/core/package.json +32 -0
  36. package/dist/templates/monorepo/packages/core/scripts/build.ts +18 -0
  37. package/dist/templates/monorepo/packages/core/src/commands/analyze.ts +84 -0
  38. package/dist/templates/monorepo/packages/core/src/commands/process.ts +64 -0
  39. package/dist/templates/monorepo/packages/core/src/index.ts +3 -0
  40. package/dist/templates/monorepo/packages/core/src/types.ts +21 -0
  41. package/dist/templates/monorepo/packages/core/tsconfig.json +15 -0
  42. package/dist/templates/monorepo/packages/utils/package.json +26 -0
  43. package/dist/templates/monorepo/packages/utils/scripts/build.ts +17 -0
  44. package/dist/templates/monorepo/packages/utils/src/format.ts +27 -0
  45. package/dist/templates/monorepo/packages/utils/src/index.ts +3 -0
  46. package/dist/templates/monorepo/packages/utils/src/json.ts +11 -0
  47. package/dist/templates/monorepo/packages/utils/src/logger.ts +19 -0
  48. package/dist/templates/monorepo/packages/utils/tsconfig.json +12 -0
  49. package/dist/templates/monorepo/template.json +24 -0
  50. package/dist/templates/monorepo/tsconfig.json +14 -0
  51. package/dist/templates/monorepo/turbo.json +28 -0
  52. package/dist/types.d.ts +48 -0
  53. package/package.json +57 -0
  54. package/templates/advanced/README.md +114 -0
  55. package/templates/advanced/package.json +36 -0
  56. package/templates/advanced/src/commands/config.ts +145 -0
  57. package/templates/advanced/src/commands/init.ts +153 -0
  58. package/templates/advanced/src/commands/serve.ts +176 -0
  59. package/templates/advanced/src/commands/validate.ts +116 -0
  60. package/templates/advanced/src/index.ts +44 -0
  61. package/templates/advanced/src/utils/config.ts +83 -0
  62. package/templates/advanced/src/utils/constants.ts +12 -0
  63. package/templates/advanced/src/utils/glob.ts +49 -0
  64. package/templates/advanced/src/utils/validator.ts +131 -0
  65. package/templates/advanced/template.json +37 -0
  66. package/templates/advanced/test/commands.test.ts +34 -0
  67. package/templates/advanced/tsconfig.json +23 -0
  68. package/templates/basic/README.md +41 -0
  69. package/templates/basic/package.json +29 -0
  70. package/templates/basic/src/commands/hello.ts +29 -0
  71. package/templates/basic/src/index.ts +13 -0
  72. package/templates/basic/template.json +31 -0
  73. package/templates/basic/test/hello.test.ts +26 -0
  74. package/templates/basic/tsconfig.json +19 -0
  75. package/templates/monorepo/README.md +74 -0
  76. package/templates/monorepo/package.json +28 -0
  77. package/templates/monorepo/packages/cli/package.json +34 -0
  78. package/templates/monorepo/packages/cli/src/index.ts +22 -0
  79. package/templates/monorepo/packages/cli/tsconfig.json +15 -0
  80. package/templates/monorepo/packages/core/package.json +32 -0
  81. package/templates/monorepo/packages/core/scripts/build.ts +18 -0
  82. package/templates/monorepo/packages/core/src/commands/analyze.ts +84 -0
  83. package/templates/monorepo/packages/core/src/commands/process.ts +64 -0
  84. package/templates/monorepo/packages/core/src/index.ts +3 -0
  85. package/templates/monorepo/packages/core/src/types.ts +21 -0
  86. package/templates/monorepo/packages/core/tsconfig.json +15 -0
  87. package/templates/monorepo/packages/utils/package.json +26 -0
  88. package/templates/monorepo/packages/utils/scripts/build.ts +17 -0
  89. package/templates/monorepo/packages/utils/src/format.ts +27 -0
  90. package/templates/monorepo/packages/utils/src/index.ts +3 -0
  91. package/templates/monorepo/packages/utils/src/json.ts +11 -0
  92. package/templates/monorepo/packages/utils/src/logger.ts +19 -0
  93. package/templates/monorepo/packages/utils/tsconfig.json +12 -0
  94. package/templates/monorepo/template.json +24 -0
  95. package/templates/monorepo/tsconfig.json +14 -0
  96. 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,3 @@
1
+ export { processCommand } from './commands/process.js'
2
+ export { analyzeCommand } from './commands/analyze.js'
3
+ export type { ProcessOptions, AnalyzeResult } from './types.js'
@@ -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,3 @@
1
+ export { logger } from './logger.js'
2
+ export { formatTable } from './format.js'
3
+ export { parseJSON, stringifyJSON } from './json.js'
@@ -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
+ }