@aiao/rxdb-client-generator 0.0.1 → 0.0.2

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,6 @@
1
1
  import { EntityMetadataOptions, EntityType } from '@aiao/rxdb';
2
- import { Project } from 'ts-morph-browser';
2
+ import { SetRequired } from 'type-fest';
3
+ import { Project } from './ts-morph-browser';
3
4
  export interface RxDBClientGeneratorOptions {
4
5
  /**
5
6
  * 关系查询深度
@@ -10,6 +11,12 @@ export interface RxDBClientGeneratorOptions {
10
11
  */
11
12
  relationQueryDeep?: number;
12
13
  }
14
+ /**
15
+ * 生成时使用的 metadata
16
+ * ‘extends’ 必填,因为 json 并不能算出继承关系
17
+ *
18
+ */
19
+ export type GeneratorEntityMetadataOptions = SetRequired<EntityMetadataOptions, 'extends'>;
13
20
  /**
14
21
  * RxDB Client 生成器
15
22
  */
@@ -23,11 +30,7 @@ export declare class RxDBClientGenerator {
23
30
  * 添加实体配置
24
31
  * @param value 实体
25
32
  */
26
- addEntity(value: EntityMetadataOptions | EntityType): void;
27
- /**
28
- * 执行生成器
29
- */
30
- execSync(): void;
33
+ addEntity(value: GeneratorEntityMetadataOptions | EntityType): void;
31
34
  /**
32
35
  * 执行生成器
33
36
  */
@@ -1,9 +1,9 @@
1
1
  import { EntityMetadata, EntityPropertyMetadata } from '@aiao/rxdb';
2
- import { OptionalKind, PropertyDeclarationStructure } from 'ts-morph-browser';
2
+ import { PropertyDeclarationStructure } from './ts-morph-browser';
3
3
  /**
4
4
  * 获取属性配置
5
5
  */
6
- export declare const getPropertyTypeConfig: (property: EntityPropertyMetadata) => Partial<OptionalKind<PropertyDeclarationStructure>> & {
6
+ export declare const getPropertyTypeConfig: (property: EntityPropertyMetadata) => Partial<PropertyDeclarationStructure> & {
7
7
  type: string;
8
8
  name: string;
9
9
  };
package/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/cli.js ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env node
2
+ import { PropertyType as m } from "@aiao/rxdb";
3
+ import { glob as p } from "glob";
4
+ import { resolve as d } from "path";
5
+ import { Project as h, Node as f } from "ts-morph";
6
+ const i = process.argv.slice(2);
7
+ i.length === 0 && (console.error("❌ 请提供要分析的文件路径或通配符模式"), console.log("使用方法: node cli.js <文件路径1> [文件路径2] ..."), console.log("示例: node cli.js ./entities/Todo.ts"), console.log("示例: node cli.js packages/rxdb-test/entities/*.ts"), console.log("示例: node cli.js packages/rxdb-test/entities/Todo.ts packages/rxdb-test/entities/Menu.ts"), process.exit(1));
8
+ async function x(t) {
9
+ const o = [];
10
+ for (const s of t)
11
+ try {
12
+ if (s.includes("*") || s.includes("?")) {
13
+ console.log(`🔍 搜索模式: ${s}`);
14
+ const e = await p(s, {
15
+ absolute: !0,
16
+ ignore: ["**/node_modules/**", "**/dist/**", "**/build/**", "**/.git/**"]
17
+ });
18
+ e.length === 0 ? console.log(`⚠️ 模式 ${s} 没有找到匹配的文件`) : (console.log(`📁 模式 ${s} 找到 ${e.length} 个文件:`), e.forEach((l) => console.log(` - ${l}`)), o.push(...e));
19
+ } else {
20
+ const e = d(s);
21
+ console.log(`🔍 分析文件: ${e}`), o.push(e);
22
+ }
23
+ } catch (e) {
24
+ console.error(`❌ 处理路径 ${s} 时出错:`, e);
25
+ }
26
+ if (o.length === 0)
27
+ return console.log("⚠️ 没有找到任何可分析的文件"), [];
28
+ const n = [...new Set(o)];
29
+ return console.log(`
30
+ 📋 总共找到 ${n.length} 个唯一文件:`), n.forEach((s) => console.log(` - ${s}`)), n;
31
+ }
32
+ function $(t, o) {
33
+ try {
34
+ console.log(`
35
+ 📄 分析文件: ${o}`);
36
+ const s = t.addSourceFileAtPath(o).getClasses();
37
+ if (s.length === 0) {
38
+ console.log(" ⚠️ 文件中没有找到类声明");
39
+ return;
40
+ }
41
+ const e = {};
42
+ s.forEach((l) => {
43
+ const r = b(l);
44
+ if (console.log(" classDecorators", r), r.length) {
45
+ const c = r[0].metadata;
46
+ console.log(" metadata", c);
47
+ }
48
+ const a = l.getName() || "AnonymousClass";
49
+ e[a] = [];
50
+ const g = l.getBaseClass();
51
+ if (g) {
52
+ const c = g.getName() || "AnonymousBaseClass";
53
+ e[a].push(`extends ${c}`);
54
+ }
55
+ l.getImplements().forEach((c) => {
56
+ const u = c.getText();
57
+ e[a].push(`implements ${u}`);
58
+ });
59
+ }), console.log(" 类继承关系:", e);
60
+ } catch (n) {
61
+ console.error(" ❌ 分析文件时出错:", n);
62
+ }
63
+ }
64
+ async function y() {
65
+ console.log("args", i);
66
+ const t = await x(i);
67
+ console.log("files", t), t.length === 0 && process.exit(1);
68
+ const o = new h();
69
+ for (const n of t)
70
+ $(o, n);
71
+ console.log(`
72
+ ✅ 所有文件分析完成`);
73
+ }
74
+ y().catch((t) => {
75
+ console.error("❌ 程序执行出错:", t), process.exit(1);
76
+ });
77
+ function b(t) {
78
+ return f.isDecoratable(t) ? t.getDecorators().map((o) => {
79
+ const n = o.getExpression(), s = f.isCallExpression(n);
80
+ let e = [], l;
81
+ return s && (e = n.getArguments().map((r) => r.getText()), e.length && (l = C(e[0]))), {
82
+ name: o.getName(),
83
+ args: e,
84
+ metadata: l
85
+ };
86
+ }) : [];
87
+ }
88
+ function C(t) {
89
+ try {
90
+ return new Function("PropertyType", `return ${t}`)(m);
91
+ } catch (o) {
92
+ console.error(o);
93
+ }
94
+ }
@@ -1,6 +1,6 @@
1
1
  import { EntityMetadata } from '@aiao/rxdb';
2
- import { SourceFile } from 'ts-morph-browser';
3
2
  import { RxDBClientGenerator } from './RxDBClientGenerator';
3
+ import { SourceFile } from './ts-morph-browser';
4
4
  /**
5
5
  * 生成一个实体的类型文件
6
6
  */
@@ -1,5 +1,5 @@
1
1
  import { EntityMetadata } from '@aiao/rxdb';
2
- import { OptionalKind, PropertyDeclarationStructure, SourceFile } from 'ts-morph-browser';
2
+ import { OptionalKind, PropertyDeclarationStructure, SourceFile } from './ts-morph-browser';
3
3
  /**
4
4
  * 生成实体的属性
5
5
  */
@@ -1,5 +1,5 @@
1
1
  import { EntityMetadata } from '@aiao/rxdb';
2
- import { OptionalKind, PropertyDeclarationStructure } from 'ts-morph-browser';
2
+ import { OptionalKind, PropertyDeclarationStructure } from './ts-morph-browser';
3
3
  /**
4
4
  * 生成实体的关系属性
5
5
  *
@@ -1,6 +1,6 @@
1
1
  import { EntityMetadata } from '@aiao/rxdb';
2
- import { MethodDeclarationStructure, OptionalKind, SourceFile } from 'ts-morph-browser';
3
2
  import { RxDBClientGenerator } from './RxDBClientGenerator';
3
+ import { MethodDeclarationStructure, OptionalKind, SourceFile } from './ts-morph-browser';
4
4
  /**
5
5
  * 生成 repository 方法
6
6
  */
@@ -1,6 +1,6 @@
1
1
  import { EntityMetadata } from '@aiao/rxdb';
2
- import { MethodDeclarationStructure, OptionalKind, SourceFile } from 'ts-morph-browser';
3
2
  import { RxDBClientGenerator } from './RxDBClientGenerator';
3
+ import { MethodDeclarationStructure, OptionalKind, SourceFile } from './ts-morph-browser';
4
4
  /**
5
5
  * 生成 tree repository 方法
6
6
  */
package/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './RxDBClientGenerator';
2
+ export * from './vite';