@zwa73/dev-utils 1.0.56 → 1.0.58

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.
@@ -11,8 +11,8 @@ const CmdGenSchema = (program) => program
11
11
  .option("-g, --exclude <glob>", "忽略的glob")
12
12
  .option("-p, --project <path>", "tsconfig路径 默认tsconfig.json", "tsconfig.json")
13
13
  .option("-o, --out <dir>", "schema输出路径目录 默认 ./schema/")
14
- .option("-it, --include-types <string[]>", "包含的type名数组, 传入逗号分隔数组", (i) => i.split(','))
15
- .option("-et, --exclude-types <string[]>", "排除的type名数组, 传入逗号分隔数组", (i) => i.split(','))
14
+ .option("-it, --include-types <regexp[]>", "包含的types正则匹配数组, 传入逗号分隔数组", (i) => i.split(','))
15
+ .option("-et, --exclude-types <regexp[]>", "排除的types正则匹配数组, 传入逗号分隔数组", (i) => i.split(','))
16
16
  .action(async (opt) => {
17
17
  await UtilDevTool_1.UtilDT.generateSchema(process.cwd(), {
18
18
  include: opt.include,
@@ -18,9 +18,9 @@ export declare namespace UtilDT {
18
18
  coverDefine: JObject;
19
19
  /**schema输出路径目录 如 ./schema/ */
20
20
  outDir: string;
21
- /**包含的types 支持正则 */
21
+ /**包含的types正则匹配数组 默认 [/.*\/] */
22
22
  includeTypes?: string[];
23
- /**排除的types 支持正则 */
23
+ /**排除的types正则匹配数组 */
24
24
  excludeTypes?: string[];
25
25
  }> & BuildMatchOpt;
26
26
  /**生成匹配的文件的所有type的schema
@@ -32,8 +32,8 @@ export declare namespace UtilDT {
32
32
  * @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
33
33
  * @param opt.project - tsconfig路径
34
34
  * @param opt.outDir - schema输出路径目录 默认 ./schema/
35
- * @param opt.includeTypes - 包含的types 支持正则
36
- * @param opt.excludeTypes - 排除的types 支持正则
35
+ * @param opt.includeTypes - 包含的types正则匹配数组 默认 [/.*\/]
36
+ * @param opt.excludeTypes - 排除的types正则匹配数组
37
37
  */
38
38
  export function generateSchema(dir: string, opt?: BuildSchemaOpt): Promise<void>;
39
39
  /**运行所有匹配的的js/ts文件
@@ -31,6 +31,7 @@ const pathe_1 = __importDefault(require("pathe"));
31
31
  const TJS = __importStar(require("typescript-json-schema"));
32
32
  const fs = __importStar(require("fs"));
33
33
  const utils_1 = require("@zwa73/utils");
34
+ const ts_morph_1 = require("ts-morph");
34
35
  var UtilDT;
35
36
  (function (UtilDT) {
36
37
  /**生成匹配的文件的所有type的schema
@@ -42,8 +43,8 @@ var UtilDT;
42
43
  * @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
43
44
  * @param opt.project - tsconfig路径
44
45
  * @param opt.outDir - schema输出路径目录 默认 ./schema/
45
- * @param opt.includeTypes - 包含的types 支持正则
46
- * @param opt.excludeTypes - 排除的types 支持正则
46
+ * @param opt.includeTypes - 包含的types正则匹配数组 默认 [/.*\/]
47
+ * @param opt.excludeTypes - 排除的types正则匹配数组
47
48
  */
48
49
  async function generateSchema(dir, opt) {
49
50
  //生成
@@ -62,11 +63,20 @@ var UtilDT;
62
63
  const program = TJS.getProgramFromFiles(files, compilerOptions);
63
64
  const gener = TJS.buildGenerator(program, settings);
64
65
  //const schema = TJS.generateSchema(program, opt?.typeName??"*", settings,undefined,gener) as JObject;
65
- const it = opt?.includeTypes?.map(t => new RegExp(t)) ?? [];
66
+ const it = opt?.includeTypes?.map(t => new RegExp(t)) ?? [/.*/];
66
67
  const et = opt?.excludeTypes?.map(t => new RegExp(t)) ?? [];
68
+ const p = new ts_morph_1.Project();
69
+ const types = files.map(fp => {
70
+ const sf = p.addSourceFileAtPath(fp);
71
+ const ds = sf.getDescendantsOfKind(ts_morph_1.SyntaxKind.TypeAliasDeclaration);
72
+ return ds.map(d => d.getName());
73
+ }).flat();
74
+ //console.log(types)
67
75
  const list = gener.getUserSymbols()
76
+ .filter(t => types.some(i => i === t))
68
77
  .filter(t => it.some(i => i.test(t)))
69
78
  .filter(t => !et.some(i => i.test(t)));
79
+ //console.log(list)
70
80
  //await UtilFT.writeJSONFile('testout',list);
71
81
  const schema = gener.getSchemaForSymbols(list);
72
82
  const outDir = opt?.outDir ?? pathe_1.default.join(process.cwd(), 'schema');
@@ -0,0 +1,4 @@
1
+ export type ASD<A, B> = {
2
+ a: 123;
3
+ b: 223;
4
+ };
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ let c = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/dev-utils",
3
- "version": "1.0.56",
3
+ "version": "1.0.58",
4
4
  "description": "编译与调试工具",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,8 +10,8 @@ export const CmdGenSchema = (program:Command) => program
10
10
  .option("-g, --exclude <glob>", "忽略的glob")
11
11
  .option("-p, --project <path>", "tsconfig路径 默认tsconfig.json","tsconfig.json")
12
12
  .option("-o, --out <dir>", "schema输出路径目录 默认 ./schema/")
13
- .option("-it, --include-types <string[]>", "包含的type名数组, 传入逗号分隔数组",(i:string)=>i.split(','))
14
- .option("-et, --exclude-types <string[]>", "排除的type名数组, 传入逗号分隔数组",(i:string)=>i.split(','))
13
+ .option("-it, --include-types <regexp[]>", "包含的types正则匹配数组, 传入逗号分隔数组",(i:string)=>i.split(','))
14
+ .option("-et, --exclude-types <regexp[]>", "排除的types正则匹配数组, 传入逗号分隔数组",(i:string)=>i.split(','))
15
15
  .action(async (opt) => {
16
16
  await UtilDT.generateSchema(process.cwd(), {
17
17
  include : opt.include,
@@ -2,6 +2,7 @@ import path from 'pathe';
2
2
  import * as TJS from 'typescript-json-schema';
3
3
  import * as fs from 'fs';
4
4
  import { JObject, SLogger, UtilFT, UtilFunc, dedent, throwError } from '@zwa73/utils';
5
+ import { Project, SyntaxKind } from 'ts-morph';
5
6
 
6
7
  export namespace UtilDT{
7
8
 
@@ -25,9 +26,9 @@ type BuildSchemaOpt = Partial<{
25
26
  coverDefine:JObject;
26
27
  /**schema输出路径目录 如 ./schema/ */
27
28
  outDir:string;
28
- /**包含的types 支持正则 */
29
+ /**包含的types正则匹配数组 默认 [/.*\/] */
29
30
  includeTypes?:string[];
30
- /**排除的types 支持正则 */
31
+ /**排除的types正则匹配数组 */
31
32
  excludeTypes?:string[];
32
33
  }>&BuildMatchOpt;
33
34
 
@@ -42,8 +43,8 @@ type BuildSchemaOpt = Partial<{
42
43
  * @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
43
44
  * @param opt.project - tsconfig路径
44
45
  * @param opt.outDir - schema输出路径目录 默认 ./schema/
45
- * @param opt.includeTypes - 包含的types 支持正则
46
- * @param opt.excludeTypes - 排除的types 支持正则
46
+ * @param opt.includeTypes - 包含的types正则匹配数组 默认 [/.*\/]
47
+ * @param opt.excludeTypes - 排除的types正则匹配数组
47
48
  */
48
49
  export async function generateSchema(dir:string,opt?:BuildSchemaOpt){
49
50
  //生成
@@ -65,11 +66,20 @@ export async function generateSchema(dir:string,opt?:BuildSchemaOpt){
65
66
  );
66
67
  const gener = TJS.buildGenerator(program,settings)!;
67
68
  //const schema = TJS.generateSchema(program, opt?.typeName??"*", settings,undefined,gener) as JObject;
68
- const it = opt?.includeTypes?.map(t=>new RegExp(t))??[];
69
+ const it = opt?.includeTypes?.map(t=>new RegExp(t))??[/.*/];
69
70
  const et = opt?.excludeTypes?.map(t=>new RegExp(t))??[];
71
+ const p = new Project();
72
+ const types = files.map(fp=>{
73
+ const sf = p.addSourceFileAtPath(fp);
74
+ const ds = sf.getDescendantsOfKind(SyntaxKind.TypeAliasDeclaration);
75
+ return ds.map(d=>d.getName());
76
+ }).flat();
77
+ //console.log(types)
70
78
  const list = gener.getUserSymbols()
79
+ .filter(t=>types.some(i=>i===t))
71
80
  .filter(t=>it.some(i=>i.test(t)))
72
81
  .filter(t=>!et.some(i=>i.test(t)));
82
+ //console.log(list)
73
83
  //await UtilFT.writeJSONFile('testout',list);
74
84
  const schema = gener.getSchemaForSymbols(list) as JObject;
75
85
  const outDir = opt?.outDir ?? path.join(process.cwd(),'schema');
@@ -0,0 +1,5 @@
1
+ import { PartialOption } from "@zwa73/utils";
2
+
3
+ let c:PartialOption<{},{}>=null as any;
4
+
5
+ export type ASD<A,B> = {a:123,b:223}
@@ -1 +0,0 @@
1
- export type AASSAA<B, P> = Record<string, 123>;
@@ -1,23 +0,0 @@
1
- {
2
- "base_lang": "zh-CN",
3
- "texts": [
4
- {
5
- "original": "你好?%0,吗?",
6
- "scan_time": "2024-07-22T04:08:33.552Z",
7
- "position": "F:/Sosarciel/SosarcielCore/NodeJs/dev-utils/jest/UtilI18n/test.ts:6:13",
8
- "source": "Ast"
9
- },
10
- {
11
- "original": "abcdefg %0rst",
12
- "scan_time": "2024-07-22T04:08:33.552Z",
13
- "position": "F:/Sosarciel/SosarcielCore/NodeJs/dev-utils/jest/UtilI18n/test.ts:7:13",
14
- "source": "Ast"
15
- },
16
- {
17
- "original": "higklmn%0",
18
- "scan_time": "2024-07-22T04:08:33.552Z",
19
- "position": "F:/Sosarciel/SosarcielCore/NodeJs/dev-utils/jest/UtilI18n/test.ts:7:25",
20
- "source": "Ast"
21
- }
22
- ]
23
- }
package/i18n/lang/en.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "base_lang": "zh-CN",
3
- "modify_time": "2024-07-22T04:08:33.570Z",
4
- "target_lang": "en",
5
- "translate_table": {
6
- "你好?%0,吗?": "hello? %0 \\%0",
7
- "abcdefg %0rst": "ABCDEFG %0RST",
8
- "higklmn%0": "HIJKLMN%0"
9
- }
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- "base_lang": "zh-CN",
3
- "modify_time": "2024-07-22T04:08:33.570Z",
4
- "target_lang": "template",
5
- "translate_table": {
6
- "你好?%0,吗?": null,
7
- "abcdefg %0rst": null,
8
- "higklmn%0": null
9
- }
10
- }