@aiao/rxdb-client-generator 0.0.2 → 0.0.3

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.
@@ -0,0 +1,3 @@
1
+ import { RxDBClientCLIentGeneratorOptions } from './cli.interface';
2
+ declare const _default: (options: RxDBClientCLIentGeneratorOptions) => Promise<void>;
3
+ export default _default;
package/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ export declare function main(): Promise<void>;
@@ -0,0 +1,5 @@
1
+ import { RxDBClientGeneratorOptions } from './RxDBClientGenerator';
2
+ export interface RxDBClientCLIentGeneratorOptions extends RxDBClientGeneratorOptions {
3
+ entities: string[];
4
+ outDir: string;
5
+ }
package/cli.js CHANGED
@@ -1,94 +1,62 @@
1
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) {
2
+ import { existsSync as f } from "node:fs";
3
+ import { resolve as c, dirname as a } from "node:path";
4
+ import { b as g } from "./build_rxdb_client_lib-BPIw_COZ.js";
5
+ async function u(s) {
33
6
  try {
34
- console.log(`
35
- 📄 分析文件: ${o}`);
36
- const s = t.addSourceFileAtPath(o).getClasses();
37
- if (s.length === 0) {
38
- console.log(" ⚠️ 文件中没有找到类声明");
39
- return;
7
+ if (!f(s))
8
+ throw new Error(`配置文件不存在: ${s}`);
9
+ const t = c(s), i = a(t), r = await import(t);
10
+ let e;
11
+ if (r.default)
12
+ e = r.default;
13
+ else if (r.config)
14
+ e = r.config;
15
+ else if (r.rxdbConfig)
16
+ e = r.rxdbConfig;
17
+ else {
18
+ const o = Object.keys(r);
19
+ if (o.length === 0)
20
+ throw new Error("配置文件中没有找到有效的配置导出");
21
+ e = r[o[0]];
40
22
  }
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);
23
+ return Array.isArray(e) || (e = [e]), e.forEach((o, l) => {
24
+ if (!o.entities || !Array.isArray(o.entities))
25
+ throw new Error(`配置项 ${l}: entities 必须是字符串数组`);
26
+ if (!o.outDir || typeof o.outDir != "string")
27
+ throw new Error(`配置项 ${l}: outDir 必须是字符串`);
28
+ o.entities = o.entities.map((n) => n.startsWith(".") ? c(i, n) : n), o.outDir.startsWith(".") && (o.outDir = c(i, o.outDir));
29
+ }), e;
30
+ } catch (t) {
31
+ throw new Error(`加载配置文件失败: ${t instanceof Error ? t.message : String(t)}`);
62
32
  }
63
33
  }
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) {
34
+ async function d() {
89
35
  try {
90
- return new Function("PropertyType", `return ${t}`)(m);
91
- } catch (o) {
92
- console.error(o);
36
+ const s = process.argv.slice(2);
37
+ s.length === 0 && (console.error("❌ 请提供配置文件路径"), console.log("使用方法: node cli.js <配置文件路径>"), console.log("示例: node cli.js ./rxdb.config.ts"), console.log("示例: node cli.js packages/rxdb-test/rxdb.config.ts"), process.exit(1));
38
+ const t = s[0];
39
+ console.log("📁 正在加载配置文件:", t);
40
+ const i = await u(t);
41
+ console.log(`✅ 成功加载 ${i.length} 个配置项`);
42
+ for (let r = 0; r < i.length; r++) {
43
+ const e = i[r];
44
+ console.log(`🚀 正在执行配置项 ${r + 1}/${i.length}:`), console.log(` - 实体文件: ${e.entities.join(", ")}`), console.log(` - 输出目录: ${e.outDir}`);
45
+ try {
46
+ await g(e), console.log(`✅ 配置项 ${r + 1} 执行成功`);
47
+ } catch (o) {
48
+ throw console.error(`❌ 配置项 ${r + 1} 执行失败:`, o), o;
49
+ }
50
+ }
51
+ console.log("🎉 所有配置项执行完成!");
52
+ } catch (s) {
53
+ console.error("❌ 程序执行出错:", s), process.exit(1);
93
54
  }
94
55
  }
56
+ const h = import.meta.url === `file://${process.argv[1]}`;
57
+ h && d().catch((s) => {
58
+ console.error("❌ 程序执行出错:", s), process.exit(1);
59
+ });
60
+ export {
61
+ d as main
62
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: (filePaths: string[]) => Promise<string[]>;
2
+ export default _default;
@@ -1,6 +1,6 @@
1
1
  import { RxDBClientGenerator } from './RxDBClientGenerator';
2
2
  /**
3
- * 生成所有 entity 的定义到 types.d.ts 文件里
3
+ * 生成所有 entity 的定义到 index.d.ts 文件里
4
4
  */
5
5
  declare const _default: (generator: RxDBClientGenerator) => void;
6
6
  export default _default;
@@ -1,6 +1,6 @@
1
1
  import { EntityMetadata } from '@aiao/rxdb';
2
2
  import { RxDBClientGenerator } from './RxDBClientGenerator';
3
- import { SourceFile } from './ts-morph-browser';
3
+ import { SourceFile } from './ts_morph_browser';
4
4
  /**
5
5
  * 生成一个实体的类型文件
6
6
  */
@@ -1,11 +1,12 @@
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
  */
6
- declare const _default: ({ classProperties, metadata, file }: {
6
+ declare const _default: ({ classProperties, metadata, file, rxdbNamedImports }: {
7
7
  metadata: EntityMetadata;
8
8
  file: SourceFile;
9
9
  classProperties: OptionalKind<PropertyDeclarationStructure>[];
10
+ rxdbNamedImports: Set<string>;
10
11
  }) => void;
11
12
  export default _default;
@@ -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
2
  import { RxDBClientGenerator } from './RxDBClientGenerator';
3
- interface RuleTypeData {
3
+ export interface RuleTypeData {
4
4
  rule: string;
5
5
  entity: string;
6
6
  key: string;
@@ -1,6 +1,8 @@
1
1
  import { EntityMetadata } from '@aiao/rxdb';
2
+ import { RuleTypeData } from './generator_entity_rules';
2
3
  import { RxDBClientGenerator } from './RxDBClientGenerator';
3
- import { MethodDeclarationStructure, OptionalKind, SourceFile } from './ts-morph-browser';
4
+ import { MethodDeclarationStructure, OptionalKind, SourceFile } from './ts_morph_browser';
5
+ export declare const build_rules: (entityRules: RuleTypeData[], rxdbNamedImports: Set<string>) => string[];
4
6
  /**
5
7
  * 生成 repository 方法
6
8
  */
@@ -1,6 +1,6 @@
1
1
  import { EntityMetadata } from '@aiao/rxdb';
2
2
  import { RxDBClientGenerator } from './RxDBClientGenerator';
3
- import { MethodDeclarationStructure, OptionalKind, SourceFile } from './ts-morph-browser';
3
+ import { MethodDeclarationStructure, OptionalKind, SourceFile } from './ts_morph_browser';
4
4
  /**
5
5
  * 生成 tree repository 方法
6
6
  */
package/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from './cli.interface';
1
2
  export * from './RxDBClientGenerator';
2
3
  export * from './vite';