MCPcopy Create free account
hub / github.com/formkit/formkit / exportInput

Function exportInput

packages/cli/src/exportInput.ts:14–45  ·  view source on GitHub ↗
(
  inputOption?: string,
  options: Record<string, string | undefined> = {}
)

Source from the content-addressed store, hash-verified

12 * @internal
13 */
14export 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.

Callers

nothing calls this directly

Calls 8

errorFunction · 0.90
greenFunction · 0.90
requireInputFunction · 0.85
requireLangFunction · 0.85
requireInputCodeFunction · 0.85
transformSourceFunction · 0.85
requireOutputDirFunction · 0.85
upsertDirFunction · 0.85

Tested by

no test coverage detected