/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@vtex/fsp-cli@0.17.8/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import{Args,Command,Flags}from"@oclif/core";import{start}from"@vtex/fsp-local";import{readFileSync}from"fs";import path from"path";import{loadConfig}from"@vtex/fsp-config";var moduleCliMap={checkout:"@vtex/checkout",discovery:"@faststore/cli","sales-app":"@vtex/sales-app"},moduleCLIPathMap={"@vtex/checkout":"@vtex/checkout/cli","@faststore/cli":"@faststore/cli","@vtex/sales-app":"@vtex/sales-app/cli"},availableModules=Object.keys(moduleCliMap);async function loadModules(t,e=()=>!0){const{stores:o}=await loadConfig(),a=o[t];if(!a){const e=Object.keys(o).join(", ");throw new Error(`Could not find account "${t}". Found accounts: ${e}`)}const s=Object.keys(a).filter(e).map((t=>{const e=a[t],o=e?.cli??moduleCliMap[t];if(!o)throw new Error("CLI not found! Provide a valid module or a CLI");return{...a[t],cli:o}}));return await Promise.all(s.map((t=>loadModule(t))))}async function loadModule(t){if(!path.join(process.cwd(),t.path))throw new Error("Module not found");const e=await load(t);return{...t,loadedCli:e}}async function load(t){let e={};try{e=JSON.parse(readFileSync(path.join(process.cwd(),"package.json")).toString())}catch{throw new Error("Could not find package.json")}if(!e.devDependencies?.[t.cli])throw new Error(`You must add ${t.cli} to your devDependencies and install it`);try{const e=await import(moduleCLIPathMap[t.cli]);return!!e.__esModule?e.default:e}catch{throw new Error(`Could not import module ${t.cli}`)}}var Dev=class t extends Command{static args={account:Args.string({required:!0,description:"Store name key to be considered. It must match the keys on faststore.json, otherwise the first one found will be used."})};static description="Runs the development server for the local storefront environment.";static examples=["<%= config.bin %> <%= command.id %>"];static flags={"proxy-port":Flags.integer({required:!1,description:"Port used for the proxy server",default:3e3})};async run(){this.log("Running faststore dev  🚀");const{args:{account:e},flags:{"proxy-port":o}}=await this.parse(t),a=await loadModules(e);try{await this.runPreTasks({modules:a,account:e}),await this.runMainTasks({modules:a,account:e}),await this.runPostTasks({modules:a,account:e}),await start(e,o)}catch(t){this.logToStderr("Something went wrong."),console.log(t)}}async runMainTasks({modules:t,account:e}){try{await Promise.all(t.map((({loadedCli:t,path:o,port:a})=>{const{dev:s}=t.commands;return s.run([e,o,a?.toString()??""])})))}catch(t){console.log(t)}}async runPostTasks({modules:t}){try{await Promise.all(t.map((({loadedCli:t})=>{const e=t.hooks?.postDev;return e?e():Promise.resolve()})))}catch(t){console.log(t)}}async runPreTasks({modules:t}){try{await Promise.all(t.map((({loadedCli:t})=>{const e=t.hooks?.preDev;return e?e():Promise.resolve()})))}catch(t){this.logToStderr("Something went wrong."),console.log(t)}}};import{Args as Args2,Command as Command2}from"@oclif/core";var Build=class t extends Command2{static args={account:Args2.string({required:!0,description:"Store name key to be considered. It must match the keys on faststore.json, otherwise the first one found will be used."}),moduleList:Args2.string({required:!1,description:"Modules to build. Separated by comma (,)"})};static description="Initiates the build process for the storefront project.";static examples=["<%= config.bin %> <%= command.id %>"];async run(){this.log("Running faststore build  🚀");const{args:{account:e,moduleList:o},flags:a}=await this.parse(t),s=await loadModules(e,o?t=>o.split(",").includes(t):()=>!0);try{await this.runPreTasks({modules:s,account:e}),await this.runMainTasks({modules:s,account:e}),await this.runPostTasks({modules:s,account:e})}catch(t){this.logToStderr("Something went wrong."),console.log(t)}}async runMainTasks({modules:t,account:e}){try{await Promise.all(t.map((({loadedCli:t,path:o})=>{const{build:a}=t.commands;return a.run([e,o])})))}catch(t){console.log(t)}}async runPostTasks({modules:t}){try{await Promise.all(t.map((({loadedCli:t})=>{const e=t.hooks?.postBuild;return e?e():Promise.resolve()})))}catch(t){console.log(t)}}async runPreTasks({modules:t}){try{await Promise.all(t.map((({loadedCli:t})=>{const e=t.hooks?.preBuild;return e?e():Promise.resolve()})))}catch(t){this.logToStderr("Something went wrong."),console.log(t)}}};import{writeFile}from"fs/promises";import path2 from"path";import{cwd}from"process";import{input,select}from"@inquirer/prompts";import{Args as Args3,Command as Command3}from"@oclif/core";import{loadConfig as loadConfig2}from"@vtex/fsp-config";var Create=class t extends Command3{static ACCOUNT_PROMPT="What is the account name?";static MODULE_PROMPT="Which module do you want to initialize?";static PATH_PROMPT=t=>`What should be the path to initialize ${t}?`;static args={account:Args3.string({required:!1,description:"Name of the account to be initialized"}),moduleName:Args3.string({required:!1,description:"Name of the module to be initialized"}),path:Args3.string({required:!1,description:"Path of where to initialize the module"})};static description="Add a new faststore module on the monorepo.";static examples=["<%= config.bin %> <%= command.id %>"];static flags={};async run(){const{args:e}=await this.parse(t);let o=e.account;o||(o=await input({message:t.ACCOUNT_PROMPT}));let a=e.moduleName;a||(a=await select({message:t.MODULE_PROMPT,choices:availableModules.map((t=>({name:t,value:t})))}));let s=e.path;s||(s=await input({message:t.PATH_PROMPT(a),default:`./packages/${a}`}));const i=await loadConfig2();i.stores=i.stores??{},i.stores?.[o]?.[a]&&this.error(`${a} has already been initialized for ${o}.`,{code:"Already Initialized Module",exit:1});const r=i.stores[o]??{};let n=3001;if(Object.keys(r).length>0){let t=n;for(const e of Object.keys(r)){const o=r[e].port;o&&o>t&&(t=o)}n=t+1}i.stores[o]={...r,[a]:{path:s,port:n}},this.log(`Initializing ${a} for ${o} in ${s}`);const c=await load({cli:moduleCliMap[a],path:s});await c.commands.create.run([s]),await writeFile(path2.join(cwd(),"faststore.json"),`${JSON.stringify(i,void 0,2)}\n`)}};import{Args as Args4,Command as Command4}from"@oclif/core";var Serve=class t extends Command4{static args={account:Args4.string({required:!0,description:"Store name key to be considered. It must match the keys on faststore.json, otherwise the first one found will be used."})};static description="Runs the local server for the storefront environment.";static examples=["<%= config.bin %> <%= command.id %>"];static flags={};async run(){this.log("Running faststore serve  🚀");const{args:{account:e}}=await this.parse(t),o=await loadModules(e);try{await this.runPreTasks({modules:o,account:e}),await this.runMainTasks({modules:o,account:e}),await this.runPostTasks({modules:o,account:e})}catch(t){this.logToStderr("Something went wrong."),console.log(t)}}async runMainTasks({modules:t,account:e}){try{await Promise.all(t.map((({loadedCli:t,path:o,port:a})=>{const{serve:s}=t.commands;return s.run([e,o,a?.toString()??""])})))}catch(t){console.log(t)}}async runPostTasks({modules:t}){try{await Promise.all(t.map((({loadedCli:t})=>{const e=t.hooks?.postServe;return e?e():Promise.resolve()})))}catch(t){console.log(t)}}async runPreTasks({modules:t}){try{await Promise.all(t.map((({loadedCli:t})=>{const e=t.hooks?.preServe;return e?e():Promise.resolve()})))}catch(t){this.logToStderr("Something went wrong."),console.log(t)}}};import{existsSync as existsSync2,mkdirSync as mkdirSync2,readFileSync as readFileSync2,readdirSync,renameSync,unlinkSync,writeFileSync}from"fs";import path5 from"path";import{cwd as cwd2}from"process";import{fileURLToPath}from"url";import{checkbox,input as input2}from"@inquirer/prompts";import{Command as Command5,Flags as Flags2}from"@oclif/core";import{loadConfig as loadConfig3}from"@vtex/fsp-config";import merge from"deepmerge";import Handlebars from"handlebars";import ora from"ora";import*as prettier from"prettier";import{cpSync,existsSync,mkdirSync}from"fs";import path3 from"path";function copyFile(t,e,o,a){existsSync(e)||mkdirSync(e,{recursive:!0});const s=path3.join(t,o),i=path3.join(e,a??o);try{cpSync(s,i,{recursive:!0})}catch(t){console.error(t)}}import path4 from"path";function getFileInfo(t){const e=path4.extname(t);return{name:path4.basename(t,e),extension:e}}async function getPackageLatestVersion(t){try{const e=await fetch(`https://registry.npmjs.org/${t}`),{"dist-tags":o}=await e.json();return o.latest}catch{return"latest"}}var Init=class t extends Command5{static args={};static description="Initialize a new FastStore monorepo project from scratch.";static examples=["<%= config.bin %> <%= command.id %>"];static flags={"from-discovery":Flags2.boolean({required:!1,description:"Migrates the current faststore discovery to the monorepo structure"})};async run(){const e=await loadConfig3();e?.stores&&this.error("Already initialized");const{flags:o}=await this.parse(t);o["from-discovery"]?await this.migrate():this.freshStart()}async freshStart(){const t=await input2({message:"What is the application name?",default:"faststore-app"});0===t.length&&this.error("App name is required"),await this.execTemplate({templateName:"default",destination:path5.join(process.cwd(),t),aditionalDependencies:["@biomejs/biome","turbo"],optionalTemplateData:{package:{name:t}}})}async execTemplate(t){const{templateName:e,destination:o,aditionalDependencies:a=[],optionalTemplateData:s={}}=t;try{this.log("Copying template files");const t=await this.fetchDevDependencies(a),i=merge({package:{name:"faststore-monorepo",devDependencies:t}},s);Handlebars.registerHelper("json",(t=>JSON.stringify(t,void 0,2)));const r=path5.dirname(fileURLToPath(import.meta.url)),n=path5.join(r,"../src/templates",e),c=readdirSync(n);for(const t of c){const e=getFileInfo(t),a=path5.join(n,t);if(".hbs"!==e.extension){copyFile(n,o,t);continue}const s={".json":"json",".js":"babel",".ts":"babel-ts"},r=readFileSync2(a);let c=Handlebars.compile(r.toString())(i);const l=s[path5.extname(e.name)];if(l)try{c=await prettier.format(c,{semi:!1,singleQuote:!0,trailingComma:"es5",parser:l})}catch(t){console.error(t)}writeFileSync(path5.join(o,e.name),c)}this.log("All files copied")}catch(t){this.log("Could not copy files")}}async fetchDevDependencies(t=[]){const e={},o=ora("Fetching dependencies");try{o.start();const a=["@vtex/fsp-cli",...Object.values(moduleCliMap),...t],s=await Promise.all(a.map(getPackageLatestVersion));return a.forEach(((t,o)=>{e[t]=s[o]})),e}catch{return o.fail("Could not fetch dependencies"),e}finally{o.succeed("All dependencies fetched")}}async migrate(){this.log("⚡ Starting the migration of your store");const t=cwd2(),e=path5.join(cwd2(),"packages/discovery"),o=readdirSync(t);if(0===o.length)return;const a={".git":!0,".github":!0,"yarn.lock":!0},s={src:!0,"vtex.env":!0,"vercel.json":!0,packages:!0,public:!0,"next-env.d.ts":!0,"package.json":!0,"faststore.config.js":!0,"discovery.config.js":!0,".gitignore":!0},i={"faststore.config.js":"discovery.config.js"},r={"vercel.json":!0},n=await checkbox({message:"Choose the files that should remain on the repository",choices:o.filter((t=>!a[t]&&!s[t])).map((t=>({name:t,value:t})))});for(const t of n)a[t]=!0;let c="";for(const s of o)if(!a[s])if(r[s])try{unlinkSync(path5.join(t,s)),this.log(`✅ ${s} deleted`)}catch{this.log(`❌ Could not delete ${s}`)}else{if("package.json"===s){const{name:t=""}=JSON.parse(readFileSync2(s).toString());c=String(t).replace(".store","")}this.moveFile(t,e,s,i[s])}await this.execTemplate({templateName:"from-discovery",destination:t,aditionalDependencies:["turbo"],optionalTemplateData:{accountName:c}}),this.log("🦄 Store migrated. You can install your packages with yarn.")}moveFile(t,e,o,a){existsSync2(e)||mkdirSync2(e,{recursive:!0});const s=path5.join(t,o),i=path5.join(e,a??o);try{renameSync(s,i),this.log(`✅ Moved: ${o}`)}catch{this.log(`❌ Could not move the file: ${o}`)}}};import fs from"fs";import path6 from"path";import{Args as Args5,Command as Command6,Flags as Flags3}from"@oclif/core";import{FastStoreSandboxAnalyzer}from"@vtex/fsp-analyzer";import{glob}from"glob";var Analyze=class t extends Command6{static description="Run static analysis on modules to ensure they follow FastStore Platform security guidelines";static examples=["<%= config.bin %> <%= command.id %> --account=myStore"];static flags={path:Flags3.string({description:"Path to analyze (supports glob patterns)",default:"src/**/*.{js,jsx,ts,tsx}"}),verbose:Flags3.boolean({description:"Show detailed information about each violation",default:!1,char:"v"})};static args={account:Args5.string({required:!0,description:"Store account to analyze"})};async run(){const{flags:e,args:o}=await this.parse(t);this.log(`Running static analysis for ${o.account} 🔍`);const a=new FastStoreSandboxAnalyzer,s=e.path,i=await glob(s,{ignore:["node_modules/**"]});0===i.length&&this.error(`No files found matching pattern: ${s}`);for(const t of i){const e=path6.resolve(t),o=fs.readFileSync(e,"utf-8"),s=a.analyzeCode(o,t),i=s.violations.length,r=s.warnings.length;this.logJson(s),(i>0||r>0)&&this.error("We found some issues in your code. Please address them and try again."),this.log(`✅ All good! No issues found in ${t}.`)}}},COMMANDS={build:Build,create:Create,dev:Dev,init:Init,serve:Serve};export{COMMANDS};
//# sourceMappingURL=/sm/54fad868f8beaaefc3a5534cb59780a24a55fbe60ad7760ebd1af86ffefffd5d.map