@sqldoc/sqldoc 0.0.2 → 0.0.4
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/package.json +10 -10
- package/src/index.ts +67 -17
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@sqldoc/sqldoc",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"description": "Global CLI shim for sqldoc -- finds .sqldoc/ and delegates to project-local @sqldoc/cli",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -20,19 +20,19 @@
|
|
|
20
20
|
"!src/__tests__",
|
|
21
21
|
"package.json"
|
|
22
22
|
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "node --test 'src/__tests__/**/*.test.ts'",
|
|
25
|
+
"typecheck": "tsgo -noEmit"
|
|
26
|
+
},
|
|
23
27
|
"engines": {
|
|
24
28
|
"node": ">=18"
|
|
25
29
|
},
|
|
26
30
|
"dependencies": {
|
|
27
|
-
"picocolors": "
|
|
31
|
+
"picocolors": "1.1.1"
|
|
28
32
|
},
|
|
29
33
|
"devDependencies": {
|
|
30
|
-
"@
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
},
|
|
34
|
-
"scripts": {
|
|
35
|
-
"test": "vitest run",
|
|
36
|
-
"typecheck": "tsc --noEmit"
|
|
34
|
+
"@sqldoc/test-utils": "0.0.1",
|
|
35
|
+
"@types/node": "22",
|
|
36
|
+
"@typescript/native-preview": "latest"
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { execSync } from 'node:child_process'
|
|
|
2
2
|
import * as fs from 'node:fs'
|
|
3
3
|
import * as path from 'node:path'
|
|
4
4
|
import pc from 'picocolors'
|
|
5
|
+
import packageJson from '../package.json' with { type: 'json' }
|
|
5
6
|
import { addCommand } from './commands/add.ts'
|
|
6
7
|
import { initCommand } from './commands/init.ts'
|
|
7
8
|
import { upgradeCommand } from './commands/upgrade.ts'
|
|
@@ -10,26 +11,75 @@ import { findSqldocDir } from './find-sqldoc.ts'
|
|
|
10
11
|
import { getPackageManagerCommand } from './runtime.ts'
|
|
11
12
|
|
|
12
13
|
// Version is set at build time — the compiled binary can't read package.json
|
|
13
|
-
const VERSION =
|
|
14
|
+
const VERSION = packageJson.version
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
type CommandInfo = {
|
|
17
|
+
name: string
|
|
18
|
+
description: string
|
|
19
|
+
subcommands?: CommandInfo[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Discover commands from the project-local @sqldoc/cli via --help-json. */
|
|
23
|
+
function discoverCliCommands(sqldocDir: string): CommandInfo[] | null {
|
|
24
|
+
let localCli = path.join(sqldocDir, 'node_modules', '@sqldoc', 'cli', 'src', 'index.ts')
|
|
25
|
+
if (!fs.existsSync(localCli)) {
|
|
26
|
+
localCli = path.join(sqldocDir, 'node_modules', '@sqldoc', 'cli', 'dist', 'index.js')
|
|
27
|
+
}
|
|
28
|
+
if (!fs.existsSync(localCli)) return null
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const output = execSync(`"${process.execPath}" "${localCli}" --help-json`, {
|
|
32
|
+
env: {
|
|
33
|
+
...process.env,
|
|
34
|
+
NODE_PATH: path.join(sqldocDir, 'node_modules'),
|
|
35
|
+
BUN_BE_BUN: '1',
|
|
36
|
+
},
|
|
37
|
+
timeout: 10000,
|
|
38
|
+
encoding: 'utf-8',
|
|
39
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
40
|
+
})
|
|
41
|
+
return JSON.parse(output)
|
|
42
|
+
} catch {
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
}
|
|
17
46
|
|
|
18
|
-
|
|
19
|
-
|
|
47
|
+
function buildHelp(): string {
|
|
48
|
+
const sqldocDir = findSqldocDir()
|
|
20
49
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
50
|
+
const lines: string[] = [
|
|
51
|
+
`${pc.bold('sqldoc')} - SQL documentation and code generation`,
|
|
52
|
+
'',
|
|
53
|
+
`${pc.dim('Usage:')}`,
|
|
54
|
+
' sqldoc <command> [options]',
|
|
55
|
+
'',
|
|
56
|
+
`${pc.dim('Commands:')}`,
|
|
57
|
+
' init Initialize .sqldoc/ in the current directory',
|
|
58
|
+
' add <packages...> Install packages into .sqldoc/',
|
|
59
|
+
' upgrade Update all packages in .sqldoc/',
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
const cliCommands = sqldocDir ? discoverCliCommands(sqldocDir) : null
|
|
63
|
+
if (cliCommands) {
|
|
64
|
+
for (const cmd of cliCommands) {
|
|
65
|
+
lines.push(` ${cmd.name.padEnd(19)} ${cmd.description}`)
|
|
66
|
+
if (cmd.subcommands) {
|
|
67
|
+
for (const sub of cmd.subcommands) {
|
|
68
|
+
lines.push(`··${`${cmd.name}·${sub.name}`.padEnd(19)}·${sub.description}`)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
25
73
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
74
|
+
lines.push(
|
|
75
|
+
'',
|
|
76
|
+
`${pc.dim('Options:')}`,
|
|
77
|
+
' --version, -V Show version',
|
|
78
|
+
' --help, -h Show this help',
|
|
79
|
+
)
|
|
29
80
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
`.trim()
|
|
81
|
+
return lines.join('\n')
|
|
82
|
+
}
|
|
33
83
|
|
|
34
84
|
/** Run install in .sqldoc/ to ensure node_modules is up to date */
|
|
35
85
|
function ensureDeps(sqldocDir: string): void {
|
|
@@ -85,7 +135,7 @@ async function main(): Promise<void> {
|
|
|
85
135
|
}
|
|
86
136
|
|
|
87
137
|
if (command === '--help' || command === '-h') {
|
|
88
|
-
console.log(
|
|
138
|
+
console.log(buildHelp())
|
|
89
139
|
return
|
|
90
140
|
}
|
|
91
141
|
|
|
@@ -111,7 +161,7 @@ async function main(): Promise<void> {
|
|
|
111
161
|
|
|
112
162
|
// No command given → show help
|
|
113
163
|
if (!command) {
|
|
114
|
-
console.log(
|
|
164
|
+
console.log(buildHelp())
|
|
115
165
|
return
|
|
116
166
|
}
|
|
117
167
|
|