import "@johnlindquist/kit"
const collect = await npm("collect.js")
const directory = await env("RAYCAST_SCRIPTS_DIRECTORY", async () => { return await selectFolder("Select a directory to store the scripts in") })
let scripts = collect(await getScripts())
scripts = scripts.map(script => {
delete script.preview
return script
})
scripts = scripts.where('kenv', '')
scripts.each(async script => {
const scriptContents = `#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title ${script.name}
# @raycast.mode silent
# @raycast.packageName Script Kit Scripts
# Documentation:
# @raycast.description ${script.description}
~/.kit/kar ${script.command}
`
await writeFile(`${directory}/${script.name}.sh`, scriptContents, "utf-8")
})