@biuxiu/codegen 0.2.6 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
package/dist/code/nest.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import xiu from "../render";
2
2
  import { join } from "path";
3
3
  import { reFromatFile, writeFormatFile } from "../util";
4
- import { existsSync, mkdirSync } from "fs";
4
+ import { existsSync, mkdirSync, statSync } from "fs";
5
5
  import { DTOFromat } from "../format/dto";
6
6
  import { EntityFormat } from "../format/entity";
7
7
  import { ApiFormat } from "../format/api";
8
8
  import { ServiceFormat } from "../format/service";
9
9
  import { getApiDir } from "../config";
10
10
  import { Project, SyntaxKind } from "ts-morph";
11
- import { exec } from "shelljs";
11
+ import { readdir, rmdir, unlink } from "fs/promises";
12
12
  const editFileQueue = [];
13
13
  let isRunning = false;
14
14
  const runEditTask = async () => {
@@ -54,9 +54,21 @@ class RenderNest {
54
54
  this.#name = name;
55
55
  this.#moduleDir = basePath;
56
56
  }
57
+ async #deleteDir(path) {
58
+ const files = await readdir(path);
59
+ for (let i = 0; i < files.length; i++) {
60
+ const filePath = join(path, files[i]);
61
+ if (statSync(filePath).isDirectory()) {
62
+ await this.#deleteDir(filePath);
63
+ await rmdir(filePath);
64
+ } else {
65
+ await unlink(filePath);
66
+ }
67
+ }
68
+ }
57
69
  remove() {
58
70
  if (existsSync(this.#moduleDir)) {
59
- exec(`rm -rf ${this.#moduleDir}`);
71
+ this.#deleteDir(this.#moduleDir);
60
72
  }
61
73
  this.editAppModule(true);
62
74
  }
package/dist/compile.js CHANGED
@@ -1,6 +1,6 @@
1
- import { exec } from "shelljs";
2
1
  import { resolve } from "path";
3
2
  import { platform } from "os";
3
+ import { spawn } from "child_process";
4
4
  const getPathName = () => {
5
5
  switch (platform()) {
6
6
  case "win32":
@@ -16,17 +16,21 @@ const getPathName = () => {
16
16
  function compileToByte(filePath) {
17
17
  const bin = resolve(__dirname, "../lua/bin", getPathName());
18
18
  return new Promise((resolve2, reject) => {
19
- exec(
20
- `${bin} -s -o - ${filePath}`,
21
- { silent: true, encoding: "buffer" },
22
- (code, out, err) => {
23
- if (code === 0) {
24
- resolve2(out);
25
- } else {
26
- reject(err.toString());
27
- }
19
+ const binaryData = [];
20
+ const child = spawn(bin, ["-s", "-o", "-", filePath]);
21
+ child.stdout.on("data", (data) => {
22
+ binaryData.push(data);
23
+ });
24
+ child.on("close", (code) => {
25
+ if (code !== 0) {
26
+ reject(`\u5B50\u8FDB\u7A0B\u9000\u51FA,code=${code}`);
27
+ } else {
28
+ resolve2(Buffer.concat(binaryData));
28
29
  }
29
- );
30
+ });
31
+ child.on("error", (err) => {
32
+ reject(err.toString());
33
+ });
30
34
  });
31
35
  }
32
36
  export {
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { compileToByte } from "./compile";
2
2
  import { existsSync } from "fs";
3
- import { run } from "./lua_codegen";
4
3
  import { genLuaTypes } from "./gen-type";
5
4
  import { setConfig } from "./config";
6
5
  async function startRun(filePath, config) {
@@ -8,7 +7,8 @@ async function startRun(filePath, config) {
8
7
  if (existsSync(filePath)) {
9
8
  try {
10
9
  const data = await compileToByte(filePath);
11
- run(new Uint8Array(data), filePath);
10
+ const { run } = await import("./lua_codegen");
11
+ run(new Uint8Array(data), filePath);
12
12
  } catch (error) {
13
13
  return Promise.reject(error);
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biuxiu/codegen",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "代码生成工具",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -23,6 +23,7 @@
23
23
  "@types/shelljs": "^0.8.15",
24
24
  "esbuild": "^0.21.5",
25
25
  "esbuild-plugin-d.ts": "^1.2.3",
26
+ "shelljs": "^0.8.5",
26
27
  "tsx": "^4.15.1",
27
28
  "typescript": "^5.4.5"
28
29
  },
@@ -30,7 +31,6 @@
30
31
  "@biuxiu/template": "^1.2.3",
31
32
  "module-alias": "^2.2.3",
32
33
  "prettier": "^3.3.2",
33
- "shelljs": "^0.8.5",
34
34
  "ts-morph": "^22.0.0"
35
35
  }
36
36
  }