@yunarch/config-web 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ import{f as r,g as d,h as n,i as h}from"../chunk-OOETI6RK.js";r();import{existsSync as y}from"fs";import{mkdir as I,readFile as T,writeFile as b}from"fs/promises";import m from"path";import{styleText as l}from"util";import N from"@inquirer/confirm";r();async function x(e,t){await n({name:"Generating models",command:`npx openapi-typescript-codegen --input ${e} --output ${t} --client fetch`})}r();import{copyFile as k}from"fs/promises";import w from"path";import{fileURLToPath as v}from"url";async function O(e){await n({name:"Generating openapi MSW utils",command:async()=>{let t=v(import.meta.url),o=w.dirname(t),a=w.join(o,"openapi-msw-http.ts");await k(a,w.join(e,"openapi-msw-http.ts"))}})}r();import{readFile as E,writeFile as F}from"fs/promises";async function $(e,t){await n({name:"Generating schema types",command:async()=>{await d(`npx openapi-typescript ${e} -o ${t}`);let o=await E(t,"utf8");await F(t,`/* eslint-disable -- Autogenerated file */
3
+ ${o}`)}})}async function j(e){if(m.extname(e)!=="")throw new Error("Output must be a directory.");let t=process.cwd(),o=m.resolve(e),i=o.startsWith(t)?o:m.resolve(t,m.relative(m.parse(e).root,e));return y(i)||await n({name:"Generating output directory",command:async()=>{await I(i,{recursive:!0})}}),i}async function J(e,t){let[o,a]=await Promise.all([n({name:"Reading input openapi schema",command:async()=>{if(!e.endsWith(".json"))throw new Error(`Input file must be a JSON file: ${e}`);if(e.startsWith("http"))try{let{stdout:i}=await d(`curl -s ${e} --fail`);return i}catch{throw new Error(`Failed to fetch remote OpenAPI file: ${e}`)}if(!y(e))throw new Error(`Input file does not exist: ${e}`);return await T(e,"utf8")}}),n({name:"Reading output openapi schema",command:async()=>{if(!t.endsWith(".json"))throw new Error(`Output file must be a JSON file: ${t}`);return y(t)?await T(t,"utf8"):!1}})]);return[JSON.stringify(JSON.parse(o)),a?JSON.stringify(JSON.parse(a)):!1]}h().name("openapi-sync").description("A CLI tool to convert OpenAPI 3.0/3.1 schemas to TypeScript types and create type-safe fetching based on a openapi file and keep them in sync.").requiredOption("-i, --input <path>","The input (local or remote) openapi schema (JSON).").requiredOption("-o, --output <folder>","The output folder to save the generated models and openapi schema and type definitions.").option("-f, --force-gen","Force generation of typescript schemas and fetching code even if the input and output schemas are identical.").option("--include-msw-utils","Include MSW mocking utilities based on the generated typescript types.").option("--post-script <script>","A package.json script to run after the code generation.").addHelpText("after",`
4
+ Example usage:
5
+
6
+ $ openapi-sync -i ./input.json -o ./src/api/gen --include-msw-utils`).action(async({input:e,output:t,forceGen:o,includeMswUtils:a,postScript:i})=>{try{console.log(l("magenta",`
7
+ \u{1F680} openapi-sync
8
+ `));let s=await j(t),c=`${s}/openapi.json`,S=`${s}/schema.d.ts`,[u,p]=await J(e,c);p&&u===p&&!o?(console.log(l("blue",`
9
+ No updates required.
10
+ `)),process.exit(0)):p?p&&u!==p&&(console.log(l("yellow",`
11
+ \u26A0\uFE0F Local and remote schemas does not match!
12
+ `)),await N({message:"Do you want to use the remote schema? (y/n)?"})?await n({name:"Replacing local schema with input schema",command:b(c,u)}):(console.log(l("yellow",`
13
+ \u26A0\uFE0F Sync remote schemas skipped.
14
+ `)),o||process.exit(0))):await n({name:"Creating local schema",command:b(c,u)}),await Promise.all([$(c,S),x(c,s)]),a&&await O(s),i&&await n({name:"Running post script",command:`node --run ${i}`}),console.log(l("green",`
15
+ \u2705 openapi-sync process completed!
16
+ `))}catch(s){console.error(s),process.exit(1)}}).parseAsync(process.argv);
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import{f as t,i as a}from"../chunk-OOETI6RK.js";t();import{execSync as u}from"child_process";import{styleText as d}from"util";t();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(`
3
+ `).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.
4
+ 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",`
5
+ Example usage:
6
+
7
+ $ turbo-select --run dev --select-env`).action(async({run:o,selectEnv:n})=>{try{console.log(d("magenta",`
8
+ \u{1F680} Turbo-Select
9
+ `));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);