@zenithbuild/core 0.3.0 → 0.3.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.
@@ -0,0 +1,2 @@
1
+ import { runCLI } from '../cli/main'
2
+ runCLI({ defaultCommand: 'build' })
package/bin/zen-dev.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { runCLI } from '../cli/main'
2
+ runCLI({ defaultCommand: 'dev' })
@@ -0,0 +1,2 @@
1
+ import { runCLI } from '../cli/main'
2
+ runCLI({ defaultCommand: 'preview' })
package/bin/zenith.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { runCLI } from '../cli/main'
2
+ runCLI()
package/cli/main.ts ADDED
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @zenith/cli - Shared CLI Execution Logic
3
+ */
4
+
5
+ import process from 'node:process'
6
+ import { getCommand, showHelp, placeholderCommands } from './commands/index'
7
+ import * as logger from './utils/logger'
8
+ import { execSync } from 'node:child_process'
9
+
10
+ /**
11
+ * Check if Bun is available in the environment
12
+ */
13
+ function checkBun() {
14
+ try {
15
+ execSync('bun --version', { stdio: 'pipe' })
16
+ return true
17
+ } catch {
18
+ return false
19
+ }
20
+ }
21
+
22
+ export interface CLIOptions {
23
+ defaultCommand?: string
24
+ }
25
+
26
+ /**
27
+ * Main CLI execution entry point
28
+ */
29
+ export async function runCLI(options: CLIOptions = {}) {
30
+ // 1. Check for Bun
31
+ if (!checkBun()) {
32
+ logger.error('Bun is required to run Zenith.')
33
+ logger.info('Please install Bun: https://bun.sh/install')
34
+ process.exit(1)
35
+ }
36
+
37
+ const args = process.argv.slice(2)
38
+ const VERSION = '0.3.0'
39
+
40
+ // 2. Handle global version flag
41
+ if (args.includes('--version') || args.includes('-v')) {
42
+ console.log(`Zenith CLI v${VERSION}`)
43
+ process.exit(0)
44
+ }
45
+
46
+ // Determine command name: either from args or default (for aliases)
47
+ let commandName = args[0]
48
+ let commandArgs = args.slice(1)
49
+
50
+ if (options.defaultCommand) {
51
+ if (!commandName || commandName.startsWith('-')) {
52
+ commandName = options.defaultCommand
53
+ commandArgs = args
54
+ }
55
+ }
56
+
57
+ // Handle help
58
+ if (!commandName || ((commandName === '--help' || commandName === '-h') && !options.defaultCommand)) {
59
+ showHelp()
60
+ process.exit(0)
61
+ }
62
+
63
+ // Parse options (--key value format) for internal use if needed
64
+ const cliOptions: Record<string, string> = {}
65
+ for (let i = 0; i < commandArgs.length; i++) {
66
+ const arg = commandArgs[i]!
67
+ if (arg.startsWith('--')) {
68
+ const key = arg.slice(2)
69
+ const value = commandArgs[i + 1]
70
+ if (value && !value.startsWith('--')) {
71
+ cliOptions[key] = value
72
+ i++
73
+ } else {
74
+ cliOptions[key] = 'true'
75
+ }
76
+ }
77
+ }
78
+
79
+ // Check for placeholder commands
80
+ if (placeholderCommands.includes(commandName)) {
81
+ logger.warn(`Command "${commandName}" is not yet implemented.`)
82
+ logger.info('This feature is planned for a future release.')
83
+ process.exit(0)
84
+ }
85
+
86
+ const command = getCommand(commandName)
87
+
88
+ if (!command) {
89
+ logger.error(`Unknown command: ${commandName}`)
90
+ showHelp()
91
+ process.exit(1)
92
+ }
93
+
94
+ try {
95
+ await command!.run(commandArgs, cliOptions)
96
+ } catch (err: unknown) {
97
+ const message = err instanceof Error ? err.message : String(err)
98
+ logger.error(message)
99
+ process.exit(1)
100
+ }
101
+ }
package/dist/cli.js CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env bun
2
+ #!/usr/bin/env bun
3
+ #!/usr/bin/env bun
4
+ #!/usr/bin/env bun
2
5
  // @bun
3
6
  var __create = Object.create;
4
7
  var __getProtoOf = Object.getPrototypeOf;