@zwa73/dev-utils 1.0.55 → 1.0.56

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 @@
1
+ PartialOption,ProperSubset,ProperSubsetCheck,Literal,LiteralCheck,AssignObject,FixedLengthTuple,UnionToIntersection,ExclusiveSub,ExclusiveRecursive,ExclusiveRecord,ExclusiveJObject,Await,FuncPropNames,ComposedClass,Mixinable,IsCtor,RefMixinable,ComposedMixinable,ComposedRefMixinable,ExtendThen,MatchableFlag,ExtractOutcome,AnnotableTuple,bigint,UnionInclude
@@ -75,19 +75,7 @@ const CmdGenI18n = (program) => program
75
75
  .option("-o, --output <path>", "输出的数据目录位置 默认 i18n", 'i18n')
76
76
  .option("-i, --include <glob>", "包含的glob 默认 src/**/*.ts", "src/**/*.ts")
77
77
  .option("-g, --exclude <glob>", "忽略的glob")
78
- .option("-f, --funckey <string|string[]>", "扫描的目标函数名, 默认 t", (i) => {
79
- const v = (0, utils_1.ivk)(() => {
80
- try {
81
- return JSON.parse(i);
82
- }
83
- catch (e) {
84
- return undefined;
85
- }
86
- });
87
- if (Array.isArray(v))
88
- return v;
89
- return i;
90
- }, 't')
78
+ .option("-f, --funckey <string|strings>", "扫描的目标函数名, 可传入逗号分隔数组, 默认 t", (i) => i.split(','), ['t'])
91
79
  .action(async (opt) => {
92
80
  await scanI18n(opt.output, opt.include, opt.exclude, opt.funckey);
93
81
  });
@@ -11,14 +11,16 @@ 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("-t, --type <string>", "若传入则仅输出 type 对应的类型 此时将直接输出至outDir/type.json, 且不会展开")
14
+ .option("-it, --include-types <string[]>", "包含的type名数组, 传入逗号分隔数组", (i) => i.split(','))
15
+ .option("-et, --exclude-types <string[]>", "排除的type名数组, 传入逗号分隔数组", (i) => i.split(','))
15
16
  .action(async (opt) => {
16
17
  await UtilDevTool_1.UtilDT.generateSchema(process.cwd(), {
17
18
  include: opt.include,
18
19
  exclude: opt.exclude,
19
20
  project: opt.project,
20
21
  outDir: opt.outDir,
21
- typeName: opt.type
22
+ includeTypes: opt.includeTypes,
23
+ excludeTypes: opt.excludeTypes
22
24
  });
23
25
  });
24
26
  exports.CmdGenSchema = CmdGenSchema;
@@ -18,19 +18,22 @@ export declare namespace UtilDT {
18
18
  coverDefine: JObject;
19
19
  /**schema输出路径目录 如 ./schema/ */
20
20
  outDir: string;
21
- /**若传入则仅输出 typeName 对应的类型 此时将直接输出至outDir/typeName.json, 且不会展开 */
22
- typeName?: string;
21
+ /**包含的types 支持正则 */
22
+ includeTypes?: string[];
23
+ /**排除的types 支持正则 */
24
+ excludeTypes?: string[];
23
25
  }> & BuildMatchOpt;
24
26
  /**生成匹配的文件的所有type的schema
25
27
  * @async
26
28
  * @param dir - 基础目录
27
29
  * @param opt - 可选参数
28
- * @param opt.include - 包含的glob 默认 **\/\*.schema.ts
29
- * @param opt.exclude - 忽略的glob
30
- * @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
31
- * @param opt.project - tsconfig路径
32
- * @param opt.outDir - schema输出路径目录 默认 ./schema/
33
- * @param opt.typeName - 若传入则仅输出 typeName 对应的类型 此时将直接输出至outDir/typeName.json, 且不会展开
30
+ * @param opt.include - 包含的glob 默认 **\/\*.schema.ts
31
+ * @param opt.exclude - 忽略的glob
32
+ * @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
33
+ * @param opt.project - tsconfig路径
34
+ * @param opt.outDir - schema输出路径目录 默认 ./schema/
35
+ * @param opt.includeTypes - 包含的types 支持正则
36
+ * @param opt.excludeTypes - 排除的types 支持正则
34
37
  */
35
38
  export function generateSchema(dir: string, opt?: BuildSchemaOpt): Promise<void>;
36
39
  /**运行所有匹配的的js/ts文件
@@ -37,12 +37,13 @@ var UtilDT;
37
37
  * @async
38
38
  * @param dir - 基础目录
39
39
  * @param opt - 可选参数
40
- * @param opt.include - 包含的glob 默认 **\/\*.schema.ts
41
- * @param opt.exclude - 忽略的glob
42
- * @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
43
- * @param opt.project - tsconfig路径
44
- * @param opt.outDir - schema输出路径目录 默认 ./schema/
45
- * @param opt.typeName - 若传入则仅输出 typeName 对应的类型 此时将直接输出至outDir/typeName.json, 且不会展开
40
+ * @param opt.include - 包含的glob 默认 **\/\*.schema.ts
41
+ * @param opt.exclude - 忽略的glob
42
+ * @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
43
+ * @param opt.project - tsconfig路径
44
+ * @param opt.outDir - schema输出路径目录 默认 ./schema/
45
+ * @param opt.includeTypes - 包含的types 支持正则
46
+ * @param opt.excludeTypes - 排除的types 支持正则
46
47
  */
47
48
  async function generateSchema(dir, opt) {
48
49
  //生成
@@ -59,17 +60,23 @@ var UtilDT;
59
60
  Object.assign(compilerOptions, (await utils_1.UtilFT.loadJSONFile(opt.project)).compilerOptions);
60
61
  const files = await utils_1.UtilFT.fileSearchGlob(dir, opt?.include ?? "**/*.schema.ts", { ingore: opt?.exclude });
61
62
  const program = TJS.getProgramFromFiles(files, compilerOptions);
62
- const schema = TJS.generateSchema(program, opt?.typeName ?? "*", settings);
63
+ const gener = TJS.buildGenerator(program, settings);
64
+ //const schema = TJS.generateSchema(program, opt?.typeName??"*", settings,undefined,gener) as JObject;
65
+ const it = opt?.includeTypes?.map(t => new RegExp(t)) ?? [];
66
+ const et = opt?.excludeTypes?.map(t => new RegExp(t)) ?? [];
67
+ const list = gener.getUserSymbols()
68
+ .filter(t => it.some(i => i.test(t)))
69
+ .filter(t => !et.some(i => i.test(t)));
70
+ //await UtilFT.writeJSONFile('testout',list);
71
+ const schema = gener.getSchemaForSymbols(list);
63
72
  const outDir = opt?.outDir ?? pathe_1.default.join(process.cwd(), 'schema');
64
- const schemasPath = opt?.typeName != undefined
65
- ? pathe_1.default.join(outDir, `${opt.typeName}.json`)
66
- : pathe_1.default.join(outDir, 'schemas.json');
73
+ const schemasPath = pathe_1.default.join(outDir, 'schemas.json');
67
74
  //预处理
68
75
  const proced = procSchema(schema, opt?.coverDefine ?? {});
69
76
  await Promise.all([
70
77
  utils_1.UtilFT.writeJSONFile(schemasPath, schema),
71
- //全范围类型则展开
72
- opt?.typeName != undefined ? undefined : expandSchema(proced, schemasPath),
78
+ //展开
79
+ expandSchema(proced, schemasPath),
73
80
  ]);
74
81
  }
75
82
  UtilDT.generateSchema = generateSchema;
@@ -0,0 +1 @@
1
+ export type AASSAA<B, P> = Record<string, 123>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/dev-utils",
3
- "version": "1.0.55",
3
+ "version": "1.0.56",
4
4
  "description": "编译与调试工具",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  "ts-morph": "^23.0.0",
23
23
  "ts-node": "^10.9.2",
24
24
  "tsconfig-paths": "^4.2.0",
25
- "typescript-json-schema": "^0.63.0"
25
+ "typescript-json-schema": "^0.64.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/fluent-ffmpeg": "^2.1.24",
@@ -73,17 +73,8 @@ export const CmdGenI18n = (program:Command) => program
73
73
  .option("-o, --output <path>" , "输出的数据目录位置 默认 i18n",'i18n')
74
74
  .option("-i, --include <glob>", "包含的glob 默认 src/**/*.ts","src/**/*.ts")
75
75
  .option("-g, --exclude <glob>", "忽略的glob")
76
- .option("-f, --funckey <string|string[]>", "扫描的目标函数名, 默认 t",(i:string)=>{
77
- const v = ivk(()=>{
78
- try{
79
- return JSON.parse(i);
80
- } catch(e){
81
- return undefined;
82
- }
83
- })
84
- if(Array.isArray(v)) return v;
85
- return i;
86
- },'t')
76
+ .option("-f, --funckey <string|strings>", "扫描的目标函数名, 可传入逗号分隔数组, 默认 t",
77
+ (i:string)=>i.split(','),['t'])
87
78
  .action(async (opt) => {
88
79
  await scanI18n(
89
80
  opt.output ,
@@ -10,13 +10,15 @@ 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("-t, --type <string>", "若传入则仅输出 type 对应的类型 此时将直接输出至outDir/type.json, 且不会展开")
13
+ .option("-it, --include-types <string[]>", "包含的type名数组, 传入逗号分隔数组",(i:string)=>i.split(','))
14
+ .option("-et, --exclude-types <string[]>", "排除的type名数组, 传入逗号分隔数组",(i:string)=>i.split(','))
14
15
  .action(async (opt) => {
15
16
  await UtilDT.generateSchema(process.cwd(), {
16
17
  include : opt.include,
17
18
  exclude : opt.exclude,
18
19
  project : opt.project,
19
20
  outDir : opt.outDir,
20
- typeName: opt.type
21
+ includeTypes: opt.includeTypes,
22
+ excludeTypes: opt.excludeTypes
21
23
  });
22
24
  });
@@ -25,8 +25,10 @@ type BuildSchemaOpt = Partial<{
25
25
  coverDefine:JObject;
26
26
  /**schema输出路径目录 如 ./schema/ */
27
27
  outDir:string;
28
- /**若传入则仅输出 typeName 对应的类型 此时将直接输出至outDir/typeName.json, 且不会展开 */
29
- typeName?:string;
28
+ /**包含的types 支持正则 */
29
+ includeTypes?:string[];
30
+ /**排除的types 支持正则 */
31
+ excludeTypes?:string[];
30
32
  }>&BuildMatchOpt;
31
33
 
32
34
 
@@ -35,12 +37,13 @@ type BuildSchemaOpt = Partial<{
35
37
  * @async
36
38
  * @param dir - 基础目录
37
39
  * @param opt - 可选参数
38
- * @param opt.include - 包含的glob 默认 **\/\*.schema.ts
39
- * @param opt.exclude - 忽略的glob
40
- * @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
41
- * @param opt.project - tsconfig路径
42
- * @param opt.outDir - schema输出路径目录 默认 ./schema/
43
- * @param opt.typeName - 若传入则仅输出 typeName 对应的类型 此时将直接输出至outDir/typeName.json, 且不会展开
40
+ * @param opt.include - 包含的glob 默认 **\/\*.schema.ts
41
+ * @param opt.exclude - 忽略的glob
42
+ * @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
43
+ * @param opt.project - tsconfig路径
44
+ * @param opt.outDir - schema输出路径目录 默认 ./schema/
45
+ * @param opt.includeTypes - 包含的types 支持正则
46
+ * @param opt.excludeTypes - 排除的types 支持正则
44
47
  */
45
48
  export async function generateSchema(dir:string,opt?:BuildSchemaOpt){
46
49
  //生成
@@ -60,17 +63,23 @@ export async function generateSchema(dir:string,opt?:BuildSchemaOpt){
60
63
  files,
61
64
  compilerOptions,
62
65
  );
63
- const schema = TJS.generateSchema(program, opt?.typeName??"*", settings) as JObject;
66
+ const gener = TJS.buildGenerator(program,settings)!;
67
+ //const schema = TJS.generateSchema(program, opt?.typeName??"*", settings,undefined,gener) as JObject;
68
+ const it = opt?.includeTypes?.map(t=>new RegExp(t))??[];
69
+ const et = opt?.excludeTypes?.map(t=>new RegExp(t))??[];
70
+ const list = gener.getUserSymbols()
71
+ .filter(t=>it.some(i=>i.test(t)))
72
+ .filter(t=>!et.some(i=>i.test(t)));
73
+ //await UtilFT.writeJSONFile('testout',list);
74
+ const schema = gener.getSchemaForSymbols(list) as JObject;
64
75
  const outDir = opt?.outDir ?? path.join(process.cwd(),'schema');
65
- const schemasPath = opt?.typeName !=undefined
66
- ? path.join(outDir,`${opt.typeName}.json`)
67
- : path.join(outDir,'schemas.json');
76
+ const schemasPath = path.join(outDir,'schemas.json');
68
77
  //预处理
69
78
  const proced = procSchema(schema,opt?.coverDefine??{});
70
79
  await Promise.all([
71
80
  UtilFT.writeJSONFile(schemasPath,schema),
72
- //全范围类型则展开
73
- opt?.typeName !=undefined ? undefined : expandSchema(proced,schemasPath),
81
+ //展开
82
+ expandSchema(proced,schemasPath),
74
83
  ]);
75
84
  }
76
85
  function procSchema(schema:JObject,coverDefine:JObject){