import { select } from "@inquirer/prompts"; import { downloadScript } from "../utils/api.util"; import { CHOOSE_SCRIPT_TYPE_MESSAGE, DOWNLOADING_SCRIPT_MESSAGE, } from "../consts/new-script.const"; import { Language } from "../enums/language.enum"; /** * Gets whether the user wants a sync or async exmaple script. * @returns The script type. */ async function getSyncAsync(): Promise { const syncType: string = await select({ message: CHOOSE_SCRIPT_TYPE_MESSAGE, choices: ["sync", "async"], }); return syncType; } async function downloadExampleScript( language: Language, isAsync: boolean ): Promise { const prefix = isAsync ? "async" : "sync"; let scriptUrl = ""; let fileName = ""; switch (language) { case Language.PYTHON: scriptUrl = `https://raw.githubusercontent.com/tinyfish-io/agentql/main/.templates/python/template_${prefix}.py`; fileName = `template_script.py`; break; case Language.JAVASCRIPT: scriptUrl = `https://raw.githubusercontent.com/tinyfish-io/agentql/main/.templates/js/template.js`; fileName = `template-script.js`; break; } console.log(DOWNLOADING_SCRIPT_MESSAGE); await downloadScript(scriptUrl, fileName); } export { getSyncAsync as getScriptType, downloadExampleScript };