@yunarch/config-web 0.7.4 → 0.7.5

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{a as n,b as a,c as P}from"../chunk-66TS4QAV.js";import{writeFile as B}from"fs/promises";import{styleText as t}from"util";import W from"@inquirer/confirm";async function x(e,o){await n("npx",["openapi-typescript-codegen","--input",e,"--output",o,"--client","fetch"],{shell:!0})}import{writeFile as b}from"fs/promises";var O=`
2
+ import{a as n,b as a,c as w}from"../chunk-66TS4QAV.js";import{writeFile as B}from"fs/promises";import{styleText as o}from"util";import F from"@inquirer/confirm";async function P(e,t){await n("npx",["openapi-typescript-codegen","--input",e,"--output",t,"--client","fetch"],{shell:!0})}import{writeFile as b}from"fs/promises";var x=`
3
3
  import {
4
4
  http as mswHttp,
5
5
  type DefaultBodyType,
@@ -122,22 +122,22 @@ export function http<P extends keyof Paths, M extends Methods<P>>(
122
122
  }
123
123
  return handlers[method as keyof typeof handlers](uri, resolver, options);
124
124
  }
125
- `;async function T(e){await b(`${e}/openapi-msw-http.ts`,O)}import{readFile as C,writeFile as $}from"fs/promises";async function M(e,o){await n("npx",["openapi-typescript",e,"-o",o],{shell:!0});let p=await C(o,"utf8");await $(o,`/* eslint-disable -- Autogenerated file */
126
- ${p}`)}import{existsSync as S}from"fs";import{mkdir as D}from"fs/promises";import h from"path";async function k(e){if(h.extname(e)!=="")throw new Error("Output must be a directory.");let o=process.cwd(),p=h.resolve(e),c=p.startsWith(o)?p:h.resolve(o,h.relative(h.parse(e).root,e));return S(c)||await D(c,{recursive:!0}),c}import{existsSync as I}from"fs";import{readFile as F}from"fs/promises";async function v(e){if(!e.endsWith(".json"))throw new Error(`Input file must be a JSON file: ${e}`);if(e.startsWith("http"))try{let{stdout:o}=await n("curl",["-s",e,"--fail"],{encoding:"utf8"});return o}catch{throw new Error(`Failed to fetch remote OpenAPI file: ${e}`)}if(!I(e))throw new Error(`Input file does not exist: ${e}`);return await F(e,"utf8")}import{existsSync as A}from"fs";import{readFile as q}from"fs/promises";async function R(e){if(!e.endsWith(".json"))throw new Error(`Output file must be a JSON file: ${e}`);return A(e)?await q(e,"utf8"):!1}P().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("-y, --yes","Skip confirmation prompts and proceed with defaults.").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.").option("--verify-openapi-sync","Verifies that the generated output is up to date with the input (e.g., in CI) to catch outdated or mismatched output without making changes.").addHelpText("after",`
125
+ `;async function T(e){await b(`${e}/openapi-msw-http.ts`,x)}import{readFile as C,writeFile as $}from"fs/promises";async function O(e,t){await n("npx",["openapi-typescript",e,"-o",t],{shell:!0});let s=await C(t,"utf8");await $(t,`/* eslint-disable -- Autogenerated file */
126
+ ${s}`)}import{existsSync as S}from"fs";import{mkdir as D}from"fs/promises";import h from"path";async function k(e){if(h.extname(e)!=="")throw new Error("Output must be a directory.");let t=process.cwd(),s=h.resolve(e),d=s.startsWith(t)?s:h.resolve(t,h.relative(h.parse(e).root,e));return S(d)||await a({name:"Generating output directory",command:async()=>{await D(d,{recursive:!0})}}),d}import{existsSync as M}from"fs";import{readFile as v}from"fs/promises";async function I(e){if(!e.endsWith(".json"))throw new Error(`Input file must be a JSON file: ${e}`);if(e.startsWith("http"))try{let{stdout:t}=await n("curl",["-s",e,"--fail"],{encoding:"utf8"});return t}catch{throw new Error(`Failed to fetch remote OpenAPI file: ${e}`)}if(!M(e))throw new Error(`Input file does not exist: ${e}`);return await v(e,"utf8")}async function A(e){if(!e.endsWith(".json"))throw new Error(`Output file must be a JSON file: ${e}`);return M(e)?await v(e,"utf8"):!1}async function R(e,t){return await a({name:"Reading OpenAPI schemas",command:async()=>{let[s,r]=await Promise.all([I(e),A(t)]);return[JSON.stringify(JSON.parse(s)),r?JSON.stringify(JSON.parse(r)):!1]}})}w().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("-y, --yes","Skip confirmation prompts and proceed with defaults.").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.").option("--verify-openapi-sync","Verifies that the generated output is up to date with the input (e.g., in CI) to catch outdated or mismatched output without making changes.").addHelpText("after",`
127
127
  Example usage:
128
- ${t("dim","$")} ${t("cyan","openapi-sync")} ${t("green","-i")} ${t("yellow","./openapi.json")} ${t("green","-o")} ${t("yellow","./src/api/gen")} ${t("green","--include-msw-utils")}
129
- `).action(async({input:e,output:o,yes:p,forceGen:u,verifyOpenapiSync:c,includeMswUtils:E,postScript:f})=>{try{console.log(t("magenta",`
128
+ ${o("dim","$")} ${o("cyan","openapi-sync")} ${o("green","-i")} ${o("yellow","./openapi.json")} ${o("green","-o")} ${o("yellow","./src/api/gen")} ${o("green","--include-msw-utils")}
129
+ `).action(async({input:e,output:t,yes:s,forceGen:r,verifyOpenapiSync:d,includeMswUtils:E,postScript:f})=>{try{console.log(o("magenta",`
130
130
  \u{1F680} openapi-sync
131
- `));let i=await a({name:"Preparing output directory",command:async()=>await k(o)}),d=`${i}/openapi.json`,H=`${i}/schema.d.ts`,[y,g]=await a({name:"Reading OpenAPI schemas",command:async()=>{let[m,w]=await Promise.all([v(e),R(d)]);return[JSON.stringify(JSON.parse(m)),w?JSON.stringify(JSON.parse(w)):!1]}}),l=y!==g;c&&(console.log(l?t("yellow",`
131
+ `));let p=await k(t),m=`${p}/openapi.json`,H=`${p}/schema.d.ts`,[u,g]=await R(e,m),l=u!==g;d&&(console.log(l?o("yellow",`
132
132
  \u26A0\uFE0F Local and remote schemas does not match!
133
- `):t("green",`
133
+ `):o("green",`
134
134
  \u2705 Local and remote schemas match!
135
- `)),process.exit(l?1:0)),g===!1&&await a({name:"Creating local schema",command:B(d,y)}),!l&&!u?(console.log(t("blue",`
135
+ `)),process.exit(l?1:0)),g===!1&&await a({name:"Creating local schema",command:B(m,u)}),!l&&!r?(console.log(o("blue",`
136
136
  No updates required.
137
- `)),process.exit(0)):l&&(console.log(t("yellow",`
137
+ `)),process.exit(0)):l&&(console.log(o("yellow",`
138
138
  \u26A0\uFE0F Local and remote schemas does not match!
139
- `)),p||await W({message:"Do you want to use the remote schema? (y/n)?"})?await a({name:"Replacing local schema with input schema",command:B(d,y)}):(console.log(t("yellow",`
139
+ `)),s||await F({message:"Do you want to use the remote schema? (y/n)?"})?await a({name:"Replacing local schema with input schema",command:B(m,u)}):(console.log(o("yellow",`
140
140
  \u26A0\uFE0F Sync remote schemas skipped.
141
- `)),u||process.exit(0))),await a({name:"Generating code from OpenAPI schema",command:async()=>{let m=[M(d,H),x(d,i)];E&&m.push(T(i)),await Promise.all(m)}}),f&&await a({name:"Running post script",command:async()=>{try{await(typeof Bun<"u"?n("bun",["run",f]):n("node",["--run",f]))}catch{await n("npm",["run",f],{shell:!0})}}}),console.log(t("green",`
141
+ `)),r||process.exit(0))),await a({name:"Generating code from OpenAPI schema",command:async()=>{let y=[O(m,H),P(m,p)];E&&y.push(T(p)),await Promise.all(y)}}),f&&await a({name:"Running post script",command:async()=>{try{await(typeof Bun<"u"?n("bun",["run",f]):n("node",["--run",f]))}catch{await n("npm",["run",f],{shell:!0})}}}),console.log(o("green",`
142
142
  \u2705 openapi-sync process completed!
143
- `))}catch(i){console.error(i),process.exit(1)}}).parseAsync(process.argv);
143
+ `))}catch(p){console.error(p),process.exit(1)}}).parseAsync(process.argv);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@yunarch/config-web",
4
- "version": "0.7.4",
4
+ "version": "0.7.5",
5
5
  "description": "Shared configurations for web projects.",
6
6
  "license": "MIT",
7
7
  "keywords": [