(
inputOption?: string,
options: Record<string, string | undefined> = {}
)
| 12 | * @internal |
| 13 | */ |
| 14 | export async function exportInput( |
| 15 | inputOption?: string, |
| 16 | options: Record<string, string | undefined> = {} |
| 17 | ): Promise<void> { |
| 18 | const input = await requireInput(inputOption) |
| 19 | const lang = await requireLang(options.lang) |
| 20 | const exportData = await requireInputCode(input, lang) |
| 21 | const sourceCode = transformSource(exportData, input) |
| 22 | const [absoluteDir, relativeDir] = await requireOutputDir(options.dir) |
| 23 | const validDir = await upsertDir(absoluteDir) |
| 24 | |
| 25 | if (validDir === false) |
| 26 | return error(`${relativeDir} is not a writable directory.`) |
| 27 | if (!validDir) return |
| 28 | const outFile = resolve(absoluteDir, `${input}.${lang}`) |
| 29 | if (!existsSync(outFile)) { |
| 30 | await writeFile(outFile, sourceCode) |
| 31 | } else { |
| 32 | return error('Did not export input because that file already exists.') |
| 33 | } |
| 34 | green(`Success! Exported ${relativeDir}/${input}.${lang}`) |
| 35 | console.log(`To use it pass it to your FormKit configuration: |
| 36 | // ... |
| 37 | import { ${input} } from '${relativeDir}/${input}' |
| 38 | // ... |
| 39 | const config = defaultConfig({ |
| 40 | inputs: { |
| 41 | ${input} |
| 42 | } |
| 43 | }) |
| 44 | `) |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Checks if a given directory is writable, if it doesn't exist, create it. |
nothing calls this directly
no test coverage detected