@nuasite/cli 0.0.36 → 0.0.38
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 +3 -3
- package/dist/index.js +77 -2390
- package/dist/types/build.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/build.ts +1 -1
- package/src/index.ts +88 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuasite/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"prepack": "bun run ../../scripts/workspace-deps/resolve-deps.ts"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@nuasite/agent-summary": "0.0.
|
|
26
|
+
"@nuasite/agent-summary": "0.0.38",
|
|
27
27
|
"astro": "5.15.1",
|
|
28
28
|
"stacktracey": "2.1.8"
|
|
29
29
|
},
|
package/src/build.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,35 +1,107 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { agentsSummary } from '@nuasite/agent-summary'
|
|
3
|
-
import { dev, preview } from 'astro'
|
|
4
|
-
import {
|
|
3
|
+
import { type AstroInlineConfig, build as astroBuild, dev, preview } from 'astro'
|
|
4
|
+
import { spawn } from 'node:child_process'
|
|
5
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
6
|
+
import { join } from 'node:path'
|
|
5
7
|
|
|
6
|
-
const command = process.argv
|
|
8
|
+
const [, , command, ...args] = process.argv
|
|
9
|
+
|
|
10
|
+
function hasNuaIntegration(configPath: string): boolean {
|
|
11
|
+
try {
|
|
12
|
+
const content = readFileSync(configPath, 'utf-8')
|
|
13
|
+
return content.includes('@nuasite/agent-summary') || content.includes('agentsSummary')
|
|
14
|
+
} catch {
|
|
15
|
+
return false
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function findAstroConfig(): string | null {
|
|
20
|
+
const possibleConfigs = [
|
|
21
|
+
'astro.config.mjs',
|
|
22
|
+
'astro.config.js',
|
|
23
|
+
'astro.config.ts',
|
|
24
|
+
'astro.config.mts',
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
for (const config of possibleConfigs) {
|
|
28
|
+
const configPath = join(process.cwd(), config)
|
|
29
|
+
if (existsSync(configPath)) {
|
|
30
|
+
return configPath
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function proxyToAstroCLI(command: string, args: string[]) {
|
|
37
|
+
const astro = spawn('npx', ['astro', command, ...args], {
|
|
38
|
+
stdio: 'inherit',
|
|
39
|
+
shell: true,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
astro.on('close', (code) => {
|
|
43
|
+
process.exit(code || 0)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
astro.on('error', (error) => {
|
|
47
|
+
console.error('Error running astro command:', error)
|
|
48
|
+
process.exit(1)
|
|
49
|
+
})
|
|
50
|
+
}
|
|
7
51
|
|
|
8
52
|
function printUsage() {
|
|
9
|
-
console.log('Usage: nua <command>')
|
|
53
|
+
console.log('Usage: nua <command> [options]')
|
|
10
54
|
console.log('\nCommands:')
|
|
11
55
|
console.log(' build Run astro build with the Nua defaults')
|
|
12
56
|
console.log(' preview Run astro preview with the Nua defaults')
|
|
13
57
|
console.log(' dev Run astro dev with the Nua defaults')
|
|
14
|
-
console.log(' help Show this message
|
|
58
|
+
console.log(' help Show this message')
|
|
59
|
+
console.log('\nAll Astro CLI options are supported.\n')
|
|
15
60
|
}
|
|
16
61
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
integrations: [agentsSummary()],
|
|
20
|
-
}
|
|
62
|
+
const configPath = findAstroConfig()
|
|
63
|
+
const canProxyDirectly = configPath && hasNuaIntegration(configPath)
|
|
21
64
|
|
|
22
|
-
|
|
65
|
+
if (canProxyDirectly && command && ['build', 'dev', 'preview'].includes(command)) {
|
|
66
|
+
proxyToAstroCLI(command, args)
|
|
67
|
+
} else {
|
|
23
68
|
switch (command) {
|
|
24
69
|
case 'build':
|
|
25
|
-
|
|
70
|
+
astroBuild({
|
|
71
|
+
root: process.cwd(),
|
|
72
|
+
integrations: [agentsSummary()],
|
|
73
|
+
}).catch((error) => {
|
|
74
|
+
console.error('Error:', error)
|
|
75
|
+
process.exit(1)
|
|
76
|
+
})
|
|
26
77
|
break
|
|
27
78
|
case 'dev':
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
79
|
+
case 'preview': {
|
|
80
|
+
const options: AstroInlineConfig = {
|
|
81
|
+
root: process.cwd(),
|
|
82
|
+
integrations: [agentsSummary()],
|
|
83
|
+
vite: {
|
|
84
|
+
server: {},
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (let i = 0; i < args.length; i++) {
|
|
89
|
+
if (args[i] === '--port' && args[i + 1]) {
|
|
90
|
+
options.vite!.server!.port = parseInt(args[i + 1] ?? '', 10)
|
|
91
|
+
i++
|
|
92
|
+
} else if (args[i] === '--host' && args[i + 1]) {
|
|
93
|
+
options.vite!.server!.host = args[i + 1]
|
|
94
|
+
i++
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const runner = command === 'dev' ? dev : preview
|
|
99
|
+
runner(options).catch((error) => {
|
|
100
|
+
console.error('Error:', error)
|
|
101
|
+
process.exit(1)
|
|
102
|
+
})
|
|
32
103
|
break
|
|
104
|
+
}
|
|
33
105
|
case 'help':
|
|
34
106
|
case '--help':
|
|
35
107
|
case '-h':
|
|
@@ -40,7 +112,4 @@ const options = {
|
|
|
40
112
|
printUsage()
|
|
41
113
|
process.exit(1)
|
|
42
114
|
}
|
|
43
|
-
}
|
|
44
|
-
console.error('Error:', error)
|
|
45
|
-
process.exit(1)
|
|
46
|
-
})
|
|
115
|
+
}
|