@biuxiu/codegen 0.2.7 → 0.2.8

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
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biuxiu/codegen",
3
- "version": "0.2.7",
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
  }