@amritk/mjst 0.1.0 → 0.3.0
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 -1
- package/dist/cli-config.d.ts +16 -0
- package/dist/cli.js +308 -69
- package/dist/detect-helpers-mode.d.ts +10 -0
- package/package.json +8 -3
- package/src/cli-config.ts +41 -0
- package/src/cli.ts +134 -0
- package/src/detect-helpers-mode.test.ts +45 -0
- package/src/detect-helpers-mode.ts +21 -0
- package/src/load-config.test.ts +69 -0
- package/src/load-config.ts +29 -0
- package/src/parse-cli-args.test.ts +226 -0
- package/src/parse-cli-args.ts +97 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { CliConfig } from './cli-config'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parses command-line arguments into a partial CLI config.
|
|
5
|
+
* Supports --schema, --outDir, and --types-only flags with either `--flag value` or `--flag=value` syntax.
|
|
6
|
+
* Only returns the flags that were explicitly provided so we can layer them on top of config file values.
|
|
7
|
+
*/
|
|
8
|
+
export const parseCliArgs = (args: readonly string[]): Partial<CliConfig> => {
|
|
9
|
+
// Use a mutable local type for building, then return as Partial<CliConfig>
|
|
10
|
+
const config: {
|
|
11
|
+
schema?: string
|
|
12
|
+
outDir?: string
|
|
13
|
+
typesOnly?: boolean
|
|
14
|
+
build?: boolean
|
|
15
|
+
logWarnings?: boolean
|
|
16
|
+
strict?: boolean
|
|
17
|
+
helpers?: 'package' | 'embedded'
|
|
18
|
+
} = {}
|
|
19
|
+
|
|
20
|
+
const parseHelpersValue = (value: string): 'package' | 'embedded' | undefined => {
|
|
21
|
+
if (value === 'package' || value === 'embedded') return value
|
|
22
|
+
return undefined
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < args.length; i++) {
|
|
26
|
+
const arg = args[i]
|
|
27
|
+
|
|
28
|
+
if (!arg) {
|
|
29
|
+
continue
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Handle --flag=value syntax
|
|
33
|
+
if (arg.startsWith('--') && arg.includes('=')) {
|
|
34
|
+
const equalsIndex = arg.indexOf('=')
|
|
35
|
+
const key = arg.slice(2, equalsIndex)
|
|
36
|
+
const value = arg.slice(equalsIndex + 1)
|
|
37
|
+
|
|
38
|
+
if (key === 'schema') {
|
|
39
|
+
config.schema = value
|
|
40
|
+
} else if (key === 'outDir') {
|
|
41
|
+
config.outDir = value
|
|
42
|
+
} else if (key === 'types-only') {
|
|
43
|
+
// Accept --types-only=false to explicitly opt out, otherwise treat as true
|
|
44
|
+
config.typesOnly = value !== 'false'
|
|
45
|
+
} else if (key === 'build') {
|
|
46
|
+
config.build = value !== 'false'
|
|
47
|
+
} else if (key === 'log-warnings') {
|
|
48
|
+
config.logWarnings = value !== 'false'
|
|
49
|
+
} else if (key === 'strict') {
|
|
50
|
+
config.strict = value !== 'false'
|
|
51
|
+
} else if (key === 'helpers') {
|
|
52
|
+
const parsed = parseHelpersValue(value)
|
|
53
|
+
if (parsed) config.helpers = parsed
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
continue
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Handle --flag value syntax
|
|
60
|
+
if (arg === '--schema') {
|
|
61
|
+
const value = args[i + 1]
|
|
62
|
+
|
|
63
|
+
if (value && !value.startsWith('--')) {
|
|
64
|
+
config.schema = value
|
|
65
|
+
i++
|
|
66
|
+
}
|
|
67
|
+
} else if (arg === '--outDir') {
|
|
68
|
+
const value = args[i + 1]
|
|
69
|
+
|
|
70
|
+
if (value && !value.startsWith('--')) {
|
|
71
|
+
config.outDir = value
|
|
72
|
+
i++
|
|
73
|
+
}
|
|
74
|
+
} else if (arg === '--types-only') {
|
|
75
|
+
// Boolean flag: presence alone enables it, no value needed
|
|
76
|
+
config.typesOnly = true
|
|
77
|
+
} else if (arg === '--build') {
|
|
78
|
+
config.build = true
|
|
79
|
+
} else if (arg === '--log-warnings') {
|
|
80
|
+
config.logWarnings = true
|
|
81
|
+
} else if (arg === '--strict') {
|
|
82
|
+
config.strict = true
|
|
83
|
+
} else if (arg === '--helpers') {
|
|
84
|
+
const value = args[i + 1]
|
|
85
|
+
|
|
86
|
+
if (value && !value.startsWith('--')) {
|
|
87
|
+
const parsed = parseHelpersValue(value)
|
|
88
|
+
if (parsed) {
|
|
89
|
+
config.helpers = parsed
|
|
90
|
+
i++
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return config
|
|
97
|
+
}
|