@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.
- package/bin/zen-build.ts +2 -0
- package/bin/zen-dev.ts +2 -0
- package/bin/zen-preview.ts +2 -0
- package/bin/zenith.ts +2 -0
- package/cli/main.ts +101 -0
- package/cli/utils/project.ts +10 -4
- package/dist/cli.js +5 -0
- package/dist/zen-build.js +11663 -0
- package/dist/zen-dev.js +11663 -0
- package/dist/zen-preview.js +11663 -0
- package/dist/zenith.js +11663 -0
- package/package.json +7 -7
- package/bin/cli-source.ts +0 -81
package/bin/zen-build.ts
ADDED
package/bin/zen-dev.ts
ADDED
package/bin/zenith.ts
ADDED
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/cli/utils/project.ts
CHANGED
|
@@ -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(
|
|
57
|
-
distDir: path.join(
|
|
62
|
+
pagesDir: path.join(appDir, 'pages'),
|
|
63
|
+
distDir: path.join(appDir, 'dist'),
|
|
58
64
|
hasZenithDeps: true
|
|
59
65
|
}
|
|
60
66
|
}
|