@zenithbuild/core 0.3.0 → 0.3.3

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
+ }
@@ -28,8 +28,8 @@ export function findProjectRoot(startDir: string = process.cwd()): string | null
28
28
  const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
29
29
  const deps = { ...pkg.dependencies, ...pkg.devDependencies }
30
30
 
31
- // Check for any @zenith/* dependency
32
- const hasZenith = Object.keys(deps).some(d => d.startsWith('@zenith/'))
31
+ // Check for any @zenith/* or @zenithbuild/* dependency
32
+ const hasZenith = Object.keys(deps).some(d => d.startsWith('@zenith/') || d.startsWith('@zenithbuild/'))
33
33
  if (hasZenith) {
34
34
  return current
35
35
  }
@@ -51,10 +51,16 @@ export function getProject(cwd: string = process.cwd()): ZenithProject | null {
51
51
  const root = findProjectRoot(cwd)
52
52
  if (!root) return null
53
53
 
54
+ // Support both app/ and src/ directory structures
55
+ let appDir = path.join(root, 'app')
56
+ if (!fs.existsSync(appDir)) {
57
+ appDir = path.join(root, 'src')
58
+ }
59
+
54
60
  return {
55
61
  root,
56
- pagesDir: path.join(root, 'app/pages'),
57
- distDir: path.join(root, 'app/dist'),
62
+ pagesDir: path.join(appDir, 'pages'),
63
+ distDir: path.join(appDir, 'dist'),
58
64
  hasZenithDeps: true
59
65
  }
60
66
  }
package/dist/cli.js CHANGED
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env bun
2
+ #!/usr/bin/env bun
3
+ #!/usr/bin/env bun
4
+ #!/usr/bin/env bun
5
+ #!/usr/bin/env bun
6
+ #!/usr/bin/env bun
2
7
  // @bun
3
8
  var __create = Object.create;
4
9
  var __getProtoOf = Object.getPrototypeOf;