@biuxiu/codegen 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ import { ApiServiceField, DtoField, EntityField } from '../types';
2
2
  export declare class RenderNest {
3
3
  #private;
4
4
  constructor(name: string, path?: string);
5
- remove(): Promise<void>;
5
+ remove(): void;
6
6
  editAppModule(isDelete?: boolean): Promise<void>;
7
7
  genModule(): Promise<void>;
8
8
  genApiService(apiService: ApiServiceField[]): Promise<void>;
package/dist/code/nest.js CHANGED
@@ -1,14 +1,13 @@
1
1
  import xiu from "../render";
2
2
  import { join } from "path";
3
- import { writeFormatFile } from "../util";
4
- import { existsSync, mkdirSync, statSync } from "fs";
3
+ import { deleteDir, writeFormatFile } from "../util";
4
+ import { existsSync, mkdirSync } 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 { readdir, rmdir, unlink } from "fs/promises";
12
11
  const editFileQueue = [];
13
12
  let isRunning = false;
14
13
  const runEditTask = async () => {
@@ -34,21 +33,9 @@ class RenderNest {
34
33
  this.#name = name;
35
34
  this.#moduleDir = join(apiDir, this.#path);
36
35
  }
37
- async #deleteDir(path) {
38
- const files = await readdir(path);
39
- for (let i = 0; i < files.length; i++) {
40
- const filePath = join(path, files[i]);
41
- if (statSync(filePath).isDirectory()) {
42
- await this.#deleteDir(filePath);
43
- } else {
44
- await unlink(filePath);
45
- }
46
- }
47
- await rmdir(path);
48
- }
49
- async remove() {
36
+ remove() {
50
37
  if (existsSync(this.#moduleDir)) {
51
- await this.#deleteDir(this.#moduleDir);
38
+ deleteDir(this.#moduleDir);
52
39
  }
53
40
  }
54
41
  async editAppModule(isDelete = false) {
@@ -2,7 +2,7 @@ import { ApiServiceField, FieldSchema, ModuleConfig, ModuleRoute } from '../type
2
2
  export declare class RenderVue {
3
3
  #private;
4
4
  constructor(name: string, path?: string);
5
- editDir(isDelete?: boolean): Promise<void>;
5
+ editDir(isDelete?: boolean): void;
6
6
  genRoute(route: ModuleRoute): Promise<void>;
7
7
  genVueTable({ name, comment }: ModuleConfig, fields: FieldSchema[]): Promise<void>;
8
8
  genVueForm(config: ModuleConfig, fields: FieldSchema[]): Promise<void>;
package/dist/code/vue.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import { getWebDir } from "../config";
2
2
  import xiu from "../render";
3
- import { writeFormatFile } from "../util";
4
- import { existsSync, mkdirSync, statSync } from "fs";
5
- import { readdir, rmdir, unlink } from "fs/promises";
3
+ import { deleteDir, writeFormatFile } from "../util";
4
+ import { existsSync, mkdirSync } from "fs";
6
5
  import { join } from "path";
7
6
  class RenderVue {
8
7
  #moduleDir;
@@ -17,22 +16,10 @@ class RenderVue {
17
16
  this.#name = name;
18
17
  this.#moduleDir = join(webDir, this.#path);
19
18
  }
20
- async #deleteDir(path) {
21
- const files = await readdir(path);
22
- for (let i = 0; i < files.length; i++) {
23
- const filePath = join(path, files[i]);
24
- if (statSync(filePath).isDirectory()) {
25
- await this.#deleteDir(filePath);
26
- } else {
27
- await unlink(filePath);
28
- }
29
- }
30
- await rmdir(path);
31
- }
32
- async editDir(isDelete = false) {
19
+ editDir(isDelete = false) {
33
20
  if (isDelete) {
34
21
  if (existsSync(this.#moduleDir)) {
35
- await this.#deleteDir(this.#moduleDir);
22
+ deleteDir(this.#moduleDir);
36
23
  }
37
24
  } else {
38
25
  let basePath = "";
package/dist/libs.js CHANGED
@@ -6,7 +6,8 @@ function renderNestCode(config, entity, dto, apiService) {
6
6
  setTask(async () => {
7
7
  const nest = new RenderNest(config.name, config.path);
8
8
  if (isReverse()) {
9
- await Promise.all([nest.remove(), nest.editAppModule(true)]);
9
+ nest.remove();
10
+ await nest.editAppModule(true);
10
11
  } else {
11
12
  await nest.editAppModule();
12
13
  await Promise.all([
@@ -29,7 +30,7 @@ function renderVueCode(config, route, fieldList, api) {
29
30
  if (isReverse()) {
30
31
  vue.editDir(true);
31
32
  } else {
32
- await vue.editDir();
33
+ vue.editDir();
33
34
  await Promise.all([
34
35
  vue.genTsFile(fields, api),
35
36
  vue.genRoute(route),
package/dist/task.js CHANGED
@@ -1,13 +1,14 @@
1
- const TaskQueue = [];
1
+ let taskQueue = [];
2
2
  function setTask(fn) {
3
- TaskQueue.push(fn);
3
+ taskQueue.push(fn);
4
4
  }
5
5
  function runTask() {
6
6
  const currentTask = [];
7
- for (let i = 0; i < TaskQueue.length; i++) {
8
- const fn = TaskQueue[i];
7
+ for (let i = 0; i < taskQueue.length; i++) {
8
+ const fn = taskQueue[i];
9
9
  currentTask.push(fn);
10
10
  }
11
+ taskQueue = [];
11
12
  return Promise.all(currentTask.map((f) => f()));
12
13
  }
13
14
  export {
package/dist/util.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { BuiltInParserName, LiteralUnion } from 'prettier';
2
2
  export declare const writeFormatFile: (filePath: string, content: string, parser?: LiteralUnion<BuiltInParserName>) => Promise<undefined>;
3
+ export declare function deleteDir(path: string): void;
package/dist/util.js CHANGED
@@ -1,4 +1,6 @@
1
+ import { readdirSync, rmdirSync, statSync, unlinkSync } from "fs";
1
2
  import { writeFile } from "fs/promises";
3
+ import { join } from "path";
2
4
  import {
3
5
  format,
4
6
  resolveConfig,
@@ -17,6 +19,22 @@ const writeFormatFile = async (filePath, content, parser = "typescript") => {
17
19
  return Promise.reject(error);
18
20
  }
19
21
  };
22
+ function deleteDir(path) {
23
+ if (!statSync(path).isDirectory()) {
24
+ return;
25
+ }
26
+ const files = readdirSync(path);
27
+ for (let i = 0; i < files.length; i++) {
28
+ const filePath = join(path, files[i]);
29
+ if (statSync(filePath).isDirectory()) {
30
+ deleteDir(filePath);
31
+ } else {
32
+ unlinkSync(filePath);
33
+ }
34
+ }
35
+ rmdirSync(path);
36
+ }
20
37
  export {
38
+ deleteDir,
21
39
  writeFormatFile
22
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biuxiu/codegen",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "代码生成工具",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {