UNPKG

@yunarch/config-web

Version:

Shared configurations for web projects.

10 lines (9 loc) 1.6 kB
#!/usr/bin/env node import{c as a}from"../chunk-LXZC4N54.js";import{execSync as u}from"child_process";import{styleText as t}from"util";import{execSync as p}from"child_process";import i from"@inquirer/select";async function c(){let n=p("npx turbo ls",{encoding:"utf8",stdio:"pipe"}).split(` `).slice(1).map(e=>e.trim()).filter(Boolean).map(e=>e.split(" ")[0]);return await i({message:"Select a package to run the script:",choices:n.map(e=>({name:e,value:e}))})}async function s(){return await i({message:"Select a mode to load different env files:",choices:[{name:"development",value:"development"},{name:"staging",value:"staging"},{name:"production",value:"production"}]})}a().name("turbo-select").description(`A CLI tool to filter and select a single package from the Turborepo package list and run a script command. Additionally, allow to prompt environment mode (development, staging, production), for example, when using Vite.`).requiredOption("--run <script>","The package script command to execute (e.g., --run=dev).").option("--select-env","An environment mode (development, staging, production) If using for example vite.").addHelpText("after",` Example usage: ${t("dim","$")} ${t("cyan","turbo-select")} ${t("green","--run")} ${t("yellow","dev")} ${t("green","--select-env")} `).action(async({run:o,selectEnv:n})=>{try{console.log(t("magenta",` \u{1F680} Turbo-Select `));let e=await c(),r=n?await s():void 0;u(`turbo run ${o} --ui stream ${e?`--filter=${e}`:""} ${r?`-- --mode ${r}`:""}`,{encoding:"utf8",stdio:"inherit"})}catch(e){console.error(e),process.exit(1)}}).parseAsync(process.argv);