@biuxiu/codegen 0.2.9 → 0.2.11

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.
package/dist/code/nest.js CHANGED
@@ -30,29 +30,9 @@ class RenderNest {
30
30
  }
31
31
  constructor(name, path) {
32
32
  this.#path = path ? path.endsWith("/") ? `${this.#formatPath(path)}/${name}` : this.#formatPath(path) : name;
33
- let basePath = "";
34
33
  const apiDir = getApiDir();
35
- if (this.#path.includes("/")) {
36
- const pathArr = this.#path.split("/");
37
- for (let i = 0; i < pathArr.length; i++) {
38
- const curPath = pathArr[i];
39
- if (i === 0) {
40
- basePath = join(apiDir, curPath);
41
- } else {
42
- basePath = join(basePath, curPath);
43
- }
44
- if (!existsSync(basePath)) {
45
- mkdirSync(basePath);
46
- }
47
- }
48
- } else {
49
- basePath = join(apiDir, this.#path);
50
- if (!existsSync(basePath)) {
51
- mkdirSync(basePath);
52
- }
53
- }
54
34
  this.#name = name;
55
- this.#moduleDir = basePath;
35
+ this.#moduleDir = join(apiDir, this.#path);
56
36
  }
57
37
  async #deleteDir(path) {
58
38
  const files = await readdir(path);
@@ -60,7 +40,6 @@ class RenderNest {
60
40
  const filePath = join(path, files[i]);
61
41
  if (statSync(filePath).isDirectory()) {
62
42
  await this.#deleteDir(filePath);
63
- await rmdir(filePath);
64
43
  } else {
65
44
  await unlink(filePath);
66
45
  }
@@ -74,6 +53,29 @@ class RenderNest {
74
53
  this.editAppModule(true);
75
54
  }
76
55
  editAppModule(isDelete = false) {
56
+ if (!isDelete) {
57
+ let basePath = "";
58
+ const apiDir = getApiDir();
59
+ if (this.#path.includes("/")) {
60
+ const pathArr = this.#path.split("/");
61
+ for (let i = 0; i < pathArr.length; i++) {
62
+ const curPath = pathArr[i];
63
+ if (i === 0) {
64
+ basePath = join(apiDir, curPath);
65
+ } else {
66
+ basePath = join(basePath, curPath);
67
+ }
68
+ if (!existsSync(basePath)) {
69
+ mkdirSync(basePath);
70
+ }
71
+ }
72
+ } else {
73
+ basePath = join(apiDir, this.#path);
74
+ if (!existsSync(basePath)) {
75
+ mkdirSync(basePath);
76
+ }
77
+ }
78
+ }
77
79
  editFileQueue.push(async () => {
78
80
  const moudleName = `${this.#name[0].toUpperCase() + this.#name.slice(1)}Module`;
79
81
  const appModuleFile = join(getApiDir(), "app.module.ts");
package/dist/config.d.ts CHANGED
@@ -3,8 +3,9 @@ declare const CodegenConfig: {
3
3
  apiDir: string;
4
4
  reverse: boolean;
5
5
  };
6
- export type ConfigType = Partial<typeof CodegenConfig>;
6
+ export type ConfigType = Omit<Partial<typeof CodegenConfig>, 'reverse'>;
7
7
  export declare function setConfig(config: ConfigType): void;
8
+ export declare const setReverse: (reverse: boolean) => boolean;
8
9
  export declare const getWebDir: () => string;
9
10
  export declare const getApiDir: () => string;
10
11
  export declare const isReverse: () => boolean;
package/dist/config.js CHANGED
@@ -11,10 +11,8 @@ function setConfig(config) {
11
11
  if (config.apiDir) {
12
12
  CodegenConfig.apiDir = config.apiDir;
13
13
  }
14
- if (config.reverse !== void 0) {
15
- CodegenConfig.reverse = config.reverse;
16
- }
17
14
  }
15
+ const setReverse = (reverse) => CodegenConfig.reverse = reverse;
18
16
  const getWebDir = () => CodegenConfig.webDir;
19
17
  const getApiDir = () => CodegenConfig.apiDir;
20
18
  const isReverse = () => CodegenConfig.reverse;
@@ -22,5 +20,6 @@ export {
22
20
  getApiDir,
23
21
  getWebDir,
24
22
  isReverse,
25
- setConfig
23
+ setConfig,
24
+ setReverse
26
25
  };
package/dist/gen-type.js CHANGED
@@ -33,7 +33,7 @@ const genLuaTypes = async (path) => {
33
33
  writeFormatFile(
34
34
  settingPath,
35
35
  JSON.stringify({
36
- "Lua.workspace.library": types.map((t) => `./${t}-type.lua`)
36
+ "Lua.workspace.library": types.map((t) => `.vscode/${t}-type.lua`)
37
37
  }),
38
38
  true
39
39
  );
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { genLuaTypes } from './gen-type';
2
2
  import { ConfigType } from './config';
3
- declare function startRun(filePath: string, config?: ConfigType): Promise<undefined>;
4
- export { startRun, genLuaTypes };
3
+ declare const startGen: (filePath: string, config?: ConfigType) => Promise<undefined>;
4
+ declare const startRemove: (filePath: string, config?: ConfigType) => Promise<undefined>;
5
+ export { startGen, startRemove, genLuaTypes };
package/dist/index.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import { compileToByte } from "./compile";
2
2
  import { existsSync } from "fs";
3
3
  import { genLuaTypes } from "./gen-type";
4
- import { setConfig } from "./config";
5
- async function startRun(filePath, config) {
4
+ import { setConfig, setReverse } from "./config";
5
+ async function startRun(filePath, isReverse, config) {
6
6
  if (config) setConfig(config);
7
+ setReverse(isReverse);
7
8
  if (existsSync(filePath)) {
8
9
  try {
9
10
  const data = await compileToByte(filePath);
10
11
  const { run } = await import("./lua_codegen");
11
- run(new Uint8Array(data), filePath);
12
+ run(new Uint8Array(data), filePath);
12
13
  } catch (error) {
13
14
  return Promise.reject(error);
14
15
  }
@@ -16,7 +17,14 @@ run(new Uint8Array(data), filePath);
16
17
  return Promise.reject(`${filePath}\u6587\u4EF6\u5B58\u5728`);
17
18
  }
18
19
  }
20
+ const startGen = (filePath, config) => {
21
+ return startRun(filePath, true, config);
22
+ };
23
+ const startRemove = (filePath, config) => {
24
+ return startRun(filePath, false, config);
25
+ };
19
26
  export {
20
27
  genLuaTypes,
21
- startRun
28
+ startGen,
29
+ startRemove
22
30
  };
@@ -1,5 +1,5 @@
1
1
  import { ApiServiceField, DtoField, EntityField } from '../types';
2
- export declare function renderNestCode(config: {
2
+ export declare function renderNestCode(entity: EntityField[], dto: DtoField[], apiService: ApiServiceField[], config: {
3
3
  name: string;
4
4
  path?: string;
5
- }, dto: DtoField[], entity: EntityField[], apiService: ApiServiceField[]): void;
5
+ }): void;
@@ -1,6 +1,6 @@
1
1
  import { RenderNest } from "../code/nest";
2
2
  import { isReverse } from "../config";
3
- function renderNestCode(config, dto, entity, apiService) {
3
+ function renderNestCode(entity, dto, apiService, config) {
4
4
  const api = new RenderNest(config.name, config.path);
5
5
  if (isReverse()) {
6
6
  api.remove();
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biuxiu/codegen",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "代码生成工具",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {