@povio/openapi-codegen-cli 2.0.8-rc.31 → 2.0.8-rc.33

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
- import { a as deepMerge, p as DEFAULT_GENERATE_OPTIONS, r as writeGenerateFileData, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-DkNqNy-S.mjs";
2
- import fs from "fs";
1
+ import { S as Profiler, i as writeGenerateFileData, m as DEFAULT_GENERATE_OPTIONS, o as deepMerge, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-D_spaAd2.mjs";
2
+ import path from "path";
3
3
  import SwaggerParser from "@apidevtools/swagger-parser";
4
4
 
5
5
  //#region src/generators/core/resolveConfig.ts
@@ -23,10 +23,11 @@ async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler =
23
23
  }));
24
24
  const openApiDoc = await getOpenApiDoc(config.input, profiler);
25
25
  const filesData = profiler.runSync("generate.total", () => generateCodeFromOpenAPIDoc(openApiDoc, config, profiler));
26
- if (config.clearOutput) profiler.runSync("files.clearOutput", () => {
27
- fs.rmSync(config.output, {
28
- force: true,
29
- recursive: true
26
+ if (config.clearOutput) profiler.runSync("files.removeStaleGenerated", () => {
27
+ removeStaleGeneratedFiles({
28
+ output: config.output,
29
+ filesData,
30
+ options: config
30
31
  });
31
32
  });
32
33
  await profiler.runAsync("files.write", async () => {
@@ -3076,6 +3076,51 @@ async function writeFile({ fileName, content }, options) {
3076
3076
  async function writeGenerateFileData(filesData, options) {
3077
3077
  for (const file of filesData) await writeFile(file, options);
3078
3078
  }
3079
+ function removeStaleGeneratedFiles({ output, filesData, options }) {
3080
+ if (!fs.existsSync(output)) return;
3081
+ const expectedFiles = new Set(filesData.map((file) => path.resolve(file.fileName)));
3082
+ const generatedSuffixes = new Set(Object.values(options.configs).map((config) => config.outputFileNameSuffix));
3083
+ const staleFiles = [];
3084
+ const visit = (dirPath) => {
3085
+ for (const dirent of fs.readdirSync(dirPath, { withFileTypes: true })) {
3086
+ const entryPath = path.join(dirPath, dirent.name);
3087
+ if (dirent.isDirectory()) {
3088
+ visit(entryPath);
3089
+ continue;
3090
+ }
3091
+ if (isGeneratedFile(entryPath, output, generatedSuffixes) && !expectedFiles.has(path.resolve(entryPath))) staleFiles.push(entryPath);
3092
+ }
3093
+ };
3094
+ visit(output);
3095
+ staleFiles.forEach((filePath) => fs.rmSync(filePath, { force: true }));
3096
+ removeEmptyDirectories(output);
3097
+ }
3098
+ function isGeneratedFile(filePath, output, generatedSuffixes) {
3099
+ const relativePath = path.relative(output, filePath);
3100
+ if (relativePath === ".openapi-codegen-cache.json") return true;
3101
+ const normalizedRelativePath = relativePath.split(path.sep).join("/");
3102
+ if ([
3103
+ "app-rest-client.ts",
3104
+ "queryModules.ts",
3105
+ "acl/app.ability.ts"
3106
+ ].includes(normalizedRelativePath)) return true;
3107
+ if (path.parse(filePath).ext !== ".ts") return false;
3108
+ const segments = relativePath.split(path.sep).filter(Boolean);
3109
+ if (segments.length < 2) return false;
3110
+ const moduleName = segments[0];
3111
+ const fileName = segments[segments.length - 1];
3112
+ if (!fileName.startsWith(`${moduleName}.`)) return false;
3113
+ const suffix = fileName.slice(moduleName.length + 1).replace(/\.tsx?$/, "");
3114
+ return generatedSuffixes.has(suffix);
3115
+ }
3116
+ function removeEmptyDirectories(root) {
3117
+ if (!fs.existsSync(root)) return;
3118
+ const removeIfEmpty = (dirPath) => {
3119
+ for (const dirent of fs.readdirSync(dirPath, { withFileTypes: true })) if (dirent.isDirectory()) removeIfEmpty(path.join(dirPath, dirent.name));
3120
+ if (dirPath !== root && fs.readdirSync(dirPath).length === 0) fs.rmdirSync(dirPath);
3121
+ };
3122
+ removeIfEmpty(root);
3123
+ }
3079
3124
 
3080
3125
  //#endregion
3081
3126
  //#region src/generators/generate/generateAcl.ts
@@ -4624,4 +4669,4 @@ function generateCodeFromOpenAPIDoc(openApiDoc, options, profiler) {
4624
4669
  }
4625
4670
 
4626
4671
  //#endregion
4627
- export { VALIDATION_ERROR_TYPE_TITLE as S, isMediaTypeAllowed as _, deepMerge as a, formatTag as b, getSchemaTsMetaType as c, getTagImportPath as d, getQueryName as f, groupByType as g, GenerateType as h, getDataFromOpenAPIDoc as i, getTsTypeBase as l, getNamespaceName as m, getOutputFileName as n, isMutation as o, DEFAULT_GENERATE_OPTIONS as p, writeGenerateFileData as r, isQuery as s, generateCodeFromOpenAPIDoc as t, getTagFileName as u, isParamMediaTypeAllowed as v, Profiler as x, invalidVariableNameCharactersToCamel as y };
4672
+ export { VALIDATION_ERROR_TYPE_TITLE as C, Profiler as S, groupByType as _, getDataFromOpenAPIDoc as a, invalidVariableNameCharactersToCamel as b, isQuery as c, getTagFileName as d, getTagImportPath as f, GenerateType as g, getNamespaceName as h, writeGenerateFileData as i, getSchemaTsMetaType as l, DEFAULT_GENERATE_OPTIONS as m, getOutputFileName as n, deepMerge as o, getQueryName as p, removeStaleGeneratedFiles as r, isMutation as s, generateCodeFromOpenAPIDoc as t, getTsTypeBase as u, isMediaTypeAllowed as v, formatTag as x, isParamMediaTypeAllowed as y };
@@ -1,4 +1,4 @@
1
- import { _ as isMediaTypeAllowed, b as formatTag, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, h as GenerateType, i as getDataFromOpenAPIDoc, l as getTsTypeBase, m as getNamespaceName, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as isParamMediaTypeAllowed, y as invalidVariableNameCharactersToCamel } from "./generateCodeFromOpenAPIDoc-DkNqNy-S.mjs";
1
+ import { a as getDataFromOpenAPIDoc, b as invalidVariableNameCharactersToCamel, c as isQuery, f as getTagImportPath, g as GenerateType, h as getNamespaceName, l as getSchemaTsMetaType, m as DEFAULT_GENERATE_OPTIONS, p as getQueryName, s as isMutation, t as generateCodeFromOpenAPIDoc, u as getTsTypeBase, v as isMediaTypeAllowed, x as formatTag, y as isParamMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-D_spaAd2.mjs";
2
2
  import SwaggerParser from "@apidevtools/swagger-parser";
3
3
 
4
4
  //#region src/generators/core/getMetadataFromOpenAPIDoc.ts
package/dist/sh.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { S as VALIDATION_ERROR_TYPE_TITLE, g as groupByType, h as GenerateType, i as getDataFromOpenAPIDoc, n as getOutputFileName, u as getTagFileName, x as Profiler } from "./generateCodeFromOpenAPIDoc-DkNqNy-S.mjs";
3
- import { n as resolveConfig, t as runGenerate } from "./generate.runner-CXsHkwM7.mjs";
2
+ import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, _ as groupByType, a as getDataFromOpenAPIDoc, d as getTagFileName, g as GenerateType, n as getOutputFileName } from "./generateCodeFromOpenAPIDoc-D_spaAd2.mjs";
3
+ import { n as resolveConfig, t as runGenerate } from "./generate.runner-DUGWfT_G.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import yargs from "yargs";
6
6
  import { hideBin } from "yargs/helpers";
@@ -39,7 +39,7 @@ function logBanner(message) {
39
39
  * Fetch the version from package.json
40
40
  */
41
41
  function getVersion() {
42
- return "2.0.8-rc.31";
42
+ return "2.0.8-rc.33";
43
43
  }
44
44
 
45
45
  //#endregion
package/dist/vite.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { x as Profiler } from "./generateCodeFromOpenAPIDoc-DkNqNy-S.mjs";
2
- import { t as runGenerate } from "./generate.runner-CXsHkwM7.mjs";
1
+ import { S as Profiler } from "./generateCodeFromOpenAPIDoc-D_spaAd2.mjs";
2
+ import { t as runGenerate } from "./generate.runner-DUGWfT_G.mjs";
3
3
  import path from "path";
4
4
 
5
5
  //#region src/vite/openapi-codegen.plugin.ts
@@ -18,6 +18,7 @@ function openApiCodegen(config) {
18
18
  profiler: new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1")
19
19
  });
20
20
  });
21
+ return queue;
21
22
  };
22
23
  const setupWatcher = (server) => {
23
24
  if (!isLocalInput || !config.input) return;
@@ -32,10 +33,11 @@ function openApiCodegen(config) {
32
33
  configResolved(config) {
33
34
  resolvedViteConfig = config;
34
35
  },
35
- buildStart() {
36
- enqueueGenerate();
36
+ async buildStart() {
37
+ await enqueueGenerate();
37
38
  },
38
- configureServer(server) {
39
+ async configureServer(server) {
40
+ await enqueueGenerate();
39
41
  setupWatcher(server);
40
42
  }
41
43
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/openapi-codegen-cli",
3
- "version": "2.0.8-rc.31",
3
+ "version": "2.0.8-rc.33",
4
4
  "keywords": [
5
5
  "codegen",
6
6
  "openapi",