UNPKG

constatic

Version:
4 lines (3 loc) 1.56 kB
import{divider as t,instructions as l,json as m,log as d,sleep as u,uiMessage as i}from"#helpers";import{menus as g}from"#menus";import{checkbox as h}from"@inquirer/prompts";import r from"chalk";import{withDefaults as w}from"#prompts";import P from"node:path";import{formatPresets as k}from"./actions/format.js";import{applyScriptPresets as S}from"#shared/presets/scripts/apply.js";import{noSelect as j}from"./actions/noselect.js";import{packageJsonHasDeps as y}from"#shared/presets/scripts/deps.js";async function O(s,a){const n=await h(w({message:i({"en-US":"Select the presets you want to apply","pt-BR":"Selecione as predefini\xE7\xF5es que deseja aplicar"}),instructions:l.checkbox,choices:k(a,!0),required:!1}));if(t(),n.length<1){await j(s);return}const c=a.filter(e=>n.includes(e.id)),p=P.join(s.cwd,"package.json"),o=await m.read(p).catch(()=>null),f=c.some(e=>y(e.packageJson??{}));if(!o&&f){const e=r.underline("package.json");d.warn(i({"en-US":[`The file ${e} was not found in the root or is incorrect!`,"The preset dependencies cannot be applied."].join(` `),"pt-BR":[`O arquivo ${e} n\xE3o foi encontrado na raiz ou est\xE1 incorreto!`,"As depend\xEAncias das predefini\xE7\xF5es n\xE3o podem ser aplicadas."].join(` `)},r.yellow)),t()}await S({configdir:s.configdir,presets:c,packageJson:o,distPath:s.cwd}),o&&await m.write(p,o),d.success(i({"en-US":"Selected presets applied successfully!","pt-BR":"Predefini\xE7\xF5es selecionadas aplicadas com sucesso!"},r.green)),t(),await u(400),g.presets.scripts.main(s)}export{O as presetsScriptsApplyMenu};