import { downloadScript } from "../utils/api.util"; import { confirm } from "@inquirer/prompts"; import { INSTALLING_DEPENDENCIES_MESSAGE, CONFIRM_DOWNLOAD_SCRIPT_MESSAGE, NOW_AGENTQL_IS_INSTALLED_MESSAGE, DOWNLOADING_SAMPLE_SCRIPT_MESSAGE, GET_STARTED_MESSAGE, WOULD_YOU_LIKE_TO_INSTALL_DEPENDENCIES_MESSAGE, } from "../consts/init.const"; import { installPlaywrightDependenciesJavascript, installPlaywrightDependenciesPython, } from "../utils/process.util"; import { Language } from "../enums/language.enum"; import chalk from "chalk"; async function requestInstallDependencies(): Promise { try { const shouldInstall = await confirm({ message: WOULD_YOU_LIKE_TO_INSTALL_DEPENDENCIES_MESSAGE, }); return shouldInstall; } catch (_) { process.exit(1); } } /** * Install dependencies for the projects. */ async function installDependencies(language: Language): Promise { console.log(INSTALLING_DEPENDENCIES_MESSAGE); switch (language) { case Language.PYTHON: await installPlaywrightDependenciesPython(); break; case Language.JAVASCRIPT: await installPlaywrightDependenciesJavascript(); break; } } /** * Download the sample script. Asks the user if they want to download the sample script. * If they do, ask them which language they want to download the script in. * Then download the script and print the command to run the script. */ async function requestDownloadSampleScript(language: Language): Promise { try { const wantToDownload = await confirm({ message: CONFIRM_DOWNLOAD_SCRIPT_MESSAGE, }); if (wantToDownload) { let sampleScriptUrl = ""; let sampleScriptFileName = ""; let sampleCommand = ""; switch (language) { case Language.PYTHON: sampleScriptUrl = "https://raw.githubusercontent.com/tinyfish-io/agentql/refs/heads/main/examples/python/first_steps/main.py"; sampleScriptFileName = "example_script.py"; sampleCommand = "python3 example_script.py"; break; case Language.JAVASCRIPT: sampleScriptUrl = "https://raw.githubusercontent.com/tinyfish-io/agentql/refs/heads/main/examples/js/first-steps/main.js"; sampleScriptFileName = "example-script.js"; sampleCommand = "node example-script.js"; break; } console.log(DOWNLOADING_SAMPLE_SCRIPT_MESSAGE); await downloadScript(sampleScriptUrl, sampleScriptFileName); console.log(chalk.cyan.bold(`${NOW_AGENTQL_IS_INSTALLED_MESSAGE}`)); console.log(chalk.bold(GET_STARTED_MESSAGE(sampleCommand))); } else { console.log(NOW_AGENTQL_IS_INSTALLED_MESSAGE); } } catch (_) { process.exit(1); } } export { requestDownloadSampleScript, requestInstallDependencies, installDependencies, };