@bagelink/vue 1.4.42 → 1.4.44
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/generateFormSchema.ts +1038 -0
- package/bin/utils.ts +230 -0
- package/dist/components/form/inputs/NumberInput.vue.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/style.css +1 -1
- package/dist/utils/BagelFormUtils.d.ts +3 -1
- package/dist/utils/BagelFormUtils.d.ts.map +1 -1
- package/package.json +4 -1
- package/src/components/form/inputs/NumberInput.vue +2 -1
- package/src/utils/BagelFormUtils.ts +3 -3
package/bin/utils.ts
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { cwd as _cwd, env, argv } from 'node:process'
|
|
5
|
+
import { ESLint } from 'eslint'
|
|
6
|
+
import * as prettier from 'prettier'
|
|
7
|
+
import { loadEnv } from 'vite'
|
|
8
|
+
|
|
9
|
+
const cwd = _cwd()
|
|
10
|
+
|
|
11
|
+
export async function formatAndWriteCode(outPath: string, code: string) {
|
|
12
|
+
const prettyCode = await prettier.format(code, { parser: 'typescript' })
|
|
13
|
+
fs.writeFileSync(outPath, prettyCode)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function runEsLintOnDir(dir: string) {
|
|
17
|
+
// ! only run if eslint.config.js exists
|
|
18
|
+
if (!fs.existsSync(join(cwd, 'eslint.config.js'))) {
|
|
19
|
+
console.log('no eslint.config.js found, skipping eslint')
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const eslint = new ESLint({ fix: true, overrideConfigFile: join(cwd, 'eslint.config.js'), cwd })
|
|
24
|
+
const results = await eslint.lintFiles(`${dir}/**/*.ts`)
|
|
25
|
+
|
|
26
|
+
await ESLint.outputFixes(results)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// =============================================================================
|
|
30
|
+
// TYPES
|
|
31
|
+
// =============================================================================
|
|
32
|
+
|
|
33
|
+
interface ParsedConfig {
|
|
34
|
+
readonly baseUrl: string
|
|
35
|
+
readonly baseUrlEnvStr: string
|
|
36
|
+
readonly openApiUrl: string
|
|
37
|
+
readonly schemaId?: string
|
|
38
|
+
readonly outputFile?: string
|
|
39
|
+
readonly useUtilityFunctions?: boolean
|
|
40
|
+
readonly useTableSchema?: boolean
|
|
41
|
+
readonly verbose?: boolean
|
|
42
|
+
readonly cwd: string
|
|
43
|
+
env: Partial<Record<string, string>>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface ConfigOptions {
|
|
47
|
+
readonly schemaId: string | undefined
|
|
48
|
+
readonly defaultOutputFile?: string
|
|
49
|
+
readonly allowedFlags?: readonly string[]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// =============================================================================
|
|
53
|
+
// ARGUMENT PARSING UTILITIES
|
|
54
|
+
// =============================================================================
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Parse command line flags (arguments starting with --)
|
|
58
|
+
*/
|
|
59
|
+
function parseFlags(args: string[]): Set<string> {
|
|
60
|
+
return new Set(
|
|
61
|
+
args
|
|
62
|
+
.filter(arg => arg.startsWith('--'))
|
|
63
|
+
.map(arg => arg.slice(2)) // Remove '--' prefix
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Parse command line arguments that are key-value pairs (--key=value)
|
|
69
|
+
*/
|
|
70
|
+
function parseKeyValueArgs(args: string[]): Record<string, string> {
|
|
71
|
+
const keyValuePairs: Record<string, string> = {}
|
|
72
|
+
|
|
73
|
+
args
|
|
74
|
+
.filter(arg => arg.startsWith('--') && arg.includes('='))
|
|
75
|
+
.forEach((arg) => {
|
|
76
|
+
const [key, ...valueParts] = arg.slice(2).split('=')
|
|
77
|
+
if (key && valueParts.length > 0) {
|
|
78
|
+
keyValuePairs[key] = valueParts.join('=')
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
return keyValuePairs
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// /**
|
|
86
|
+
// * Parse positional arguments (non-flag arguments)
|
|
87
|
+
// */
|
|
88
|
+
// function parsePositionalArgs(args: string[]): string[] {
|
|
89
|
+
// return args.filter(arg => !arg.startsWith('--'))
|
|
90
|
+
// }
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get environment variable with fallback
|
|
94
|
+
*/
|
|
95
|
+
function getEnvVar(key: string, fallback: string): string {
|
|
96
|
+
return env[key] || fallback
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// =============================================================================
|
|
100
|
+
// MAIN PARSING FUNCTION
|
|
101
|
+
// =============================================================================
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Parse command line arguments and environment variables into a structured configuration
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```bash
|
|
108
|
+
* # Basic usage
|
|
109
|
+
* node script.js
|
|
110
|
+
*
|
|
111
|
+
* # With directory
|
|
112
|
+
* node script.js
|
|
113
|
+
*
|
|
114
|
+
* # With flags
|
|
115
|
+
* node script.js --verbose
|
|
116
|
+
*
|
|
117
|
+
* # With key-value pairs
|
|
118
|
+
* node script.js --schema-id=UserResponse --output=src/forms/user.ts
|
|
119
|
+
*
|
|
120
|
+
* # Combined
|
|
121
|
+
* node script.js --schema-id=UserResponse --output=src/forms/user.ts
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export function parseConfig(options: ConfigOptions): ParsedConfig {
|
|
125
|
+
const {
|
|
126
|
+
schemaId,
|
|
127
|
+
defaultOutputFile,
|
|
128
|
+
allowedFlags = [
|
|
129
|
+
'verbose',
|
|
130
|
+
'utility-functions',
|
|
131
|
+
'table-schema'
|
|
132
|
+
]
|
|
133
|
+
} = options
|
|
134
|
+
|
|
135
|
+
// Load environment variables
|
|
136
|
+
const currentCwd = cwd
|
|
137
|
+
const environment = loadEnv('', currentCwd)
|
|
138
|
+
|
|
139
|
+
// Parse command line arguments
|
|
140
|
+
const args = argv.slice(2) // Remove 'node' and script path
|
|
141
|
+
const flags = parseFlags(args)
|
|
142
|
+
const keyValueArgs = parseKeyValueArgs(args)
|
|
143
|
+
// const positionalArgs = parsePositionalArgs(args)
|
|
144
|
+
|
|
145
|
+
// Validate flags
|
|
146
|
+
const invalidFlags = Array.from(flags).filter(flag => !allowedFlags.includes(flag) && !flag.includes('=')
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
if (invalidFlags.length > 0) {
|
|
150
|
+
console.warn(`Warning: Unknown flags detected: ${invalidFlags.join(', ')}`)
|
|
151
|
+
console.warn(`Allowed flags: ${allowedFlags.join(', ')}`)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Build configuration
|
|
155
|
+
const baseUrl = getEnvVar('VITE_BAGEL_BASE_URL', 'http://localhost:8000')
|
|
156
|
+
|
|
157
|
+
const config: ParsedConfig = {
|
|
158
|
+
// URLs and paths
|
|
159
|
+
baseUrl,
|
|
160
|
+
baseUrlEnvStr: 'import.meta.env.VITE_BAGEL_BASE_URL',
|
|
161
|
+
openApiUrl: `${baseUrl}/openapi.json`,
|
|
162
|
+
|
|
163
|
+
// Flags
|
|
164
|
+
useUtilityFunctions: flags.has('utility-functions'),
|
|
165
|
+
useTableSchema: flags.has('table-schema'),
|
|
166
|
+
verbose: flags.has('verbose'),
|
|
167
|
+
|
|
168
|
+
// Key-value arguments with fallbacks
|
|
169
|
+
schemaId: keyValueArgs['schema-id'] || keyValueArgs.schemaId || keyValueArgs.schema || schemaId,
|
|
170
|
+
outputFile: keyValueArgs.output || keyValueArgs.out || defaultOutputFile,
|
|
171
|
+
|
|
172
|
+
// System info
|
|
173
|
+
cwd: currentCwd,
|
|
174
|
+
env: { ...environment, ...env } // Merge loaded env with process.env
|
|
175
|
+
} as const
|
|
176
|
+
|
|
177
|
+
// Log configuration if verbose
|
|
178
|
+
if (config.verbose) {
|
|
179
|
+
console.log('Parsed configuration:', {
|
|
180
|
+
...config,
|
|
181
|
+
env: '[hidden]' // Don't log environment variables
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return config
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// =============================================================================
|
|
189
|
+
// UTILITY HELPERS
|
|
190
|
+
// =============================================================================
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Print help message for command line usage
|
|
194
|
+
*/
|
|
195
|
+
export function printHelp(scriptName: string = 'script'): void {
|
|
196
|
+
console.log(`
|
|
197
|
+
Usage: ${scriptName} [directory] [options]
|
|
198
|
+
|
|
199
|
+
Arguments:
|
|
200
|
+
directory Target directory (default: .bagelink)
|
|
201
|
+
|
|
202
|
+
Options:
|
|
203
|
+
--verbose Enable verbose logging
|
|
204
|
+
--utility-functions Use utility functions in generated code
|
|
205
|
+
--table-schema Generate table schema instead of form schema
|
|
206
|
+
--schema-id=<id> Specify schema ID to process
|
|
207
|
+
--output=<path> Specify output file path
|
|
208
|
+
|
|
209
|
+
Examples:
|
|
210
|
+
${scriptName} # Use defaults
|
|
211
|
+
${scriptName} # Custom directory
|
|
212
|
+
${scriptName} --verbose # With flags
|
|
213
|
+
${scriptName} --schema-id=UserResponse # With schema ID
|
|
214
|
+
${scriptName} --output=forms.ts # Combined usage
|
|
215
|
+
`)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Validate required configuration values
|
|
220
|
+
*/
|
|
221
|
+
export function validateConfig(config: ParsedConfig, required: (keyof ParsedConfig)[] = []): void {
|
|
222
|
+
const missing = required.filter((key) => {
|
|
223
|
+
const value = config[key]
|
|
224
|
+
return value === undefined || value === null || value === ''
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
if (missing.length > 0) {
|
|
228
|
+
throw new Error(`Missing required configuration: ${missing.join(', ')}`)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberInput.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/form/inputs/NumberInput.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NumberInput.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/form/inputs/NumberInput.vue"],"names":[],"mappings":"AAsPA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAI7C,KAAK,YAAY,GAAG,SAAS,GAAG,UAAU,GAAG,YAAY,CAAA;AAEzD,UAAU,gBAAgB;IACzB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,QAAQ,CAAA;IACpB,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,OAAO,CAAA;CACrB;;;;;;AAwWD,wBAQG"}
|