@zwa73/utils 1.0.103 → 1.0.105

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,4 +1,28 @@
1
1
  import { JToken } from "./UtilInterfaces";
2
+ /**创建文件选项 */
3
+ type CreatePathOpt = Partial<{
4
+ /**创建一个目录 默认 false
5
+ * 默认仅在以path.sep结尾时创建文件夹
6
+ */
7
+ dir: boolean;
8
+ }>;
9
+ /**验证文件选项 */
10
+ type EnsurePathExistsOpt = Partial<{
11
+ /**验证一个目录 默认 false
12
+ * 默认仅在以path.sep结尾时创建文件夹
13
+ */
14
+ dir: boolean;
15
+ }>;
16
+ /**glob搜索选项 */
17
+ type FileSearchGlobOpt = Partial<{
18
+ /**忽略的文件 默认 undefined */
19
+ ingore: string | string[];
20
+ }>;
21
+ /**regex搜索选项 */
22
+ type FileSearchRegexOpt = Partial<{
23
+ /**搜索子目录 默认 true */
24
+ relative: boolean;
25
+ }>;
2
26
  /**文件工具 */
3
27
  export declare namespace UtilFT {
4
28
  /**验证路径 文件或文件夹 是否存在 异步
@@ -15,28 +39,33 @@ export declare namespace UtilFT {
15
39
  /**路径不存在时创建路径 以path.sep结尾时创建文件夹 异步
16
40
  * @async
17
41
  * @param filePath - 待创建的路径
18
- * @param isDir - 强制创建一个文件夹
42
+ * @param opt - 可选参数
43
+ * @param opt.dir - 创建一个目录
19
44
  * @returns 是否成功创建
20
45
  */
21
- function createPath(filePath: string, isDir?: boolean): Promise<boolean>;
46
+ function createPath(filePath: string, opt?: CreatePathOpt): Promise<boolean>;
22
47
  /**路径不存在时创建路径 以path.sep结尾时创建文件夹 同步
23
48
  * @param filePath - 待创建的路径
24
- * @param isDir - 强制验证一个文件夹
49
+ * @param opt - 可选参数
50
+ * @param opt.dir - 创建一个目录
25
51
  * @returns 是否成功创建
26
52
  */
27
- function createPathSync(filePath: string, isDir?: boolean): boolean;
53
+ function createPathSync(filePath: string, opt?: CreatePathOpt): boolean;
28
54
  /**确保路径存在 不存在时创建 异步
29
55
  * @async
30
56
  * @param filePath - 待验证的路径
31
- * @param isDir - 强制验证一个文件夹
57
+ * @param opt - 可选参数
58
+ * @param opt.dir - 强制验证一个文件夹
32
59
  * @returns 是否成功执行 创建或已存在
33
60
  */
34
- function ensurePathExists(filePath: string, isDir?: boolean): Promise<boolean>;
61
+ function ensurePathExists(filePath: string, opt?: EnsurePathExistsOpt): Promise<boolean>;
35
62
  /**确保路径存在 不存在时创建 同步
36
63
  * @param filePath - 待验证的路径
64
+ * @param opt - 可选参数
65
+ * @param opt.dir - 强制验证一个文件夹
37
66
  * @returns 是否成功执行 创建或已存在
38
67
  */
39
- function ensurePathExistsSync(filePath: string, isDir?: boolean): boolean;
68
+ function ensurePathExistsSync(filePath: string, opt?: EnsurePathExistsOpt): boolean;
40
69
  /**加载json文件 同步
41
70
  * @param filePath - 文件路径
42
71
  * @returns 加载完成的对象或空{}
@@ -69,17 +98,21 @@ export declare namespace UtilFT {
69
98
  */
70
99
  function writeJSONFile(filePath: string, token: JToken): Promise<void>;
71
100
  /**搜索路径符合正则表达式的文件
72
- * @param folder - 文件夹路径
73
- * @param traitRegex - 正则表达式
101
+ * @param folder - 文件夹路径
102
+ * @param traitRegex - 正则表达式
103
+ * @param opt - 可选参数
104
+ * @param opt.relative - 搜索子目录
74
105
  * @returns 文件名路径数组
75
106
  */
76
- function fileSearchRegex(folder: string, traitRegex: string): string[];
107
+ function fileSearchRegex(folder: string, traitRegex: string, opt?: FileSearchRegexOpt): string[];
77
108
  /**搜索符合Glob匹配的文件
109
+ * @param folder - 文件夹路径
78
110
  * @param globPattern - glob匹配
79
- * @param ignore - 忽略的文件
111
+ * @param opt - 可选参数
112
+ * @param opt.ignore - 忽略的文件
80
113
  * @returns 文件绝对路径数组
81
114
  */
82
- function fileSearchGlob(globPattern: string | string[], ignore?: string | string[]): string[];
115
+ function fileSearchGlob(folder: string, globPattern: string | string[], opt?: FileSearchGlobOpt): string[];
83
116
  /**
84
117
  * @deprecated 请使用 fileSearchRegex 或 fileSearchGlob
85
118
  */
@@ -89,3 +122,4 @@ export declare namespace UtilFT {
89
122
  */
90
123
  function isValidFilePath(filePath: string): boolean;
91
124
  }
125
+ export {};
@@ -66,11 +66,12 @@ var UtilFT;
66
66
  /**路径不存在时创建路径 以path.sep结尾时创建文件夹 异步
67
67
  * @async
68
68
  * @param filePath - 待创建的路径
69
- * @param isDir - 强制创建一个文件夹
69
+ * @param opt - 可选参数
70
+ * @param opt.dir - 创建一个目录
70
71
  * @returns 是否成功创建
71
72
  */
72
- async function createPath(filePath, isDir) {
73
- if (isDir == true)
73
+ async function createPath(filePath, opt) {
74
+ if (opt?.dir == true)
74
75
  filePath = path.join(filePath, path.sep);
75
76
  try {
76
77
  if (filePath.endsWith(path.sep)) {
@@ -90,11 +91,12 @@ var UtilFT;
90
91
  UtilFT.createPath = createPath;
91
92
  /**路径不存在时创建路径 以path.sep结尾时创建文件夹 同步
92
93
  * @param filePath - 待创建的路径
93
- * @param isDir - 强制验证一个文件夹
94
+ * @param opt - 可选参数
95
+ * @param opt.dir - 创建一个目录
94
96
  * @returns 是否成功创建
95
97
  */
96
- function createPathSync(filePath, isDir) {
97
- if (isDir == true)
98
+ function createPathSync(filePath, opt) {
99
+ if (opt?.dir == true)
98
100
  filePath = path.join(filePath, path.sep);
99
101
  try {
100
102
  if (filePath.endsWith(path.sep)) {
@@ -114,23 +116,26 @@ var UtilFT;
114
116
  /**确保路径存在 不存在时创建 异步
115
117
  * @async
116
118
  * @param filePath - 待验证的路径
117
- * @param isDir - 强制验证一个文件夹
119
+ * @param opt - 可选参数
120
+ * @param opt.dir - 强制验证一个文件夹
118
121
  * @returns 是否成功执行 创建或已存在
119
122
  */
120
- async function ensurePathExists(filePath, isDir) {
123
+ async function ensurePathExists(filePath, opt) {
121
124
  if (await pathExists(filePath))
122
125
  return true;
123
- return await createPath(filePath, isDir);
126
+ return await createPath(filePath, opt);
124
127
  }
125
128
  UtilFT.ensurePathExists = ensurePathExists;
126
129
  /**确保路径存在 不存在时创建 同步
127
130
  * @param filePath - 待验证的路径
131
+ * @param opt - 可选参数
132
+ * @param opt.dir - 强制验证一个文件夹
128
133
  * @returns 是否成功执行 创建或已存在
129
134
  */
130
- function ensurePathExistsSync(filePath, isDir) {
135
+ function ensurePathExistsSync(filePath, opt) {
131
136
  if (pathExistsSync(filePath))
132
137
  return true;
133
- return createPathSync(filePath, isDir);
138
+ return createPathSync(filePath, opt);
134
139
  }
135
140
  UtilFT.ensurePathExistsSync = ensurePathExistsSync;
136
141
  function loadJSONFileSync(filePath, def) {
@@ -189,20 +194,23 @@ var UtilFT;
189
194
  }
190
195
  UtilFT.writeJSONFile = writeJSONFile;
191
196
  /**搜索路径符合正则表达式的文件
192
- * @param folder - 文件夹路径
193
- * @param traitRegex - 正则表达式
197
+ * @param folder - 文件夹路径
198
+ * @param traitRegex - 正则表达式
199
+ * @param opt - 可选参数
200
+ * @param opt.relative - 搜索子目录
194
201
  * @returns 文件名路径数组
195
202
  */
196
- function fileSearchRegex(folder, traitRegex) {
197
- let outArray = [];
198
- let subFiles = fs.readdirSync(folder);
199
- let regex = new RegExp(traitRegex);
200
- for (let subFile of subFiles) {
201
- let subFilePath = path.join(folder, subFile);
202
- let stat = fs.lstatSync(subFilePath);
203
+ function fileSearchRegex(folder, traitRegex, opt) {
204
+ const relative = opt?.relative ?? true;
205
+ const outArray = [];
206
+ const subFiles = fs.readdirSync(folder, { withFileTypes: true });
207
+ const regex = new RegExp(traitRegex);
208
+ for (const subFile of subFiles) {
209
+ const subFilePath = path.join(folder, subFile.name);
203
210
  //判断是否是文件夹,递归调用
204
- if (stat.isDirectory()) {
205
- outArray.push(...fileSearchRegex(path.join(subFilePath, path.sep), traitRegex));
211
+ if (subFile.isDirectory()) {
212
+ if (relative)
213
+ outArray.push(...fileSearchRegex(path.join(subFilePath, path.sep), traitRegex));
206
214
  continue;
207
215
  }
208
216
  if (regex.test(subFilePath))
@@ -212,15 +220,17 @@ var UtilFT;
212
220
  }
213
221
  UtilFT.fileSearchRegex = fileSearchRegex;
214
222
  /**搜索符合Glob匹配的文件
223
+ * @param folder - 文件夹路径
215
224
  * @param globPattern - glob匹配
216
- * @param ignore - 忽略的文件
225
+ * @param opt - 可选参数
226
+ * @param opt.ignore - 忽略的文件
217
227
  * @returns 文件绝对路径数组
218
228
  */
219
- function fileSearchGlob(globPattern, ignore) {
229
+ function fileSearchGlob(folder, globPattern, opt) {
220
230
  const fixedPath = typeof globPattern === "string"
221
- ? path.posix.normalize(globPattern)
222
- : globPattern.map((p) => path.posix.normalize(p));
223
- return (0, glob_1.globSync)(fixedPath, { ignore, absolute: true });
231
+ ? path.join(folder, path.posix.normalize(globPattern))
232
+ : globPattern.map((p) => path.join(folder, path.posix.normalize(p)));
233
+ return (0, glob_1.globSync)(fixedPath, { ignore: opt?.ingore, absolute: true });
224
234
  }
225
235
  UtilFT.fileSearchGlob = fileSearchGlob;
226
236
  /**
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.103",
3
+ "version": "1.0.105",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "call npm run compile && jest",
7
+ "test": "jest",
8
8
  "postinstall": "start node ./scripts/postinstall.js",
9
9
  "release": "powershell scripts/release",
10
10
  "compile": "powershell scripts/compile",
@@ -1,5 +1,5 @@
1
- Write-Output 开始删除原dist
2
- Remove-Item -Recurse -Force dist
3
- Write-Output 开始编译
4
- tsc -p tsconfig.compile.json
1
+ Write-Output 开始删除原dist
2
+ Remove-Item -Recurse -Force dist
3
+ Write-Output 开始编译
4
+ tsc -p tsconfig.compile.json
5
5
  tsc-alias -p tsconfig.compile.json
@@ -1,53 +1,69 @@
1
- const currentVersion = require('../package.json').version;
2
- const path = require('path');
3
- const { UtilFT } = require("../index");
4
- const readline = require('readline');
5
-
6
- // 将版本号转换为可以比较的数字
7
- function versionToNumber(version) {
8
- if(version==undefined) return 0;
9
- return version.split('.').map(Number).reduce((acc, val) => acc * 1000 + val);
10
- }
11
-
12
- //显示提示
13
- function showUpgradeMessages(prevVersion, currentVersion, infoTable) {
14
- let prevVersionNumber = versionToNumber(prevVersion);
15
- let currentVersionNumber = versionToNumber(currentVersion);
16
- // 遍历infoTable中的所有版本
17
- for (let version in infoTable) {
18
- let versionNumber = versionToNumber(version);
19
- // 如果用户的上一个版本低于这个版本,而当前版本高于或等于这个版本
20
- if (versionNumber > prevVersionNumber && versionNumber <= currentVersionNumber) {
21
- // 显示这个版本的提示信息
22
- console.log(infoTable[version]);
23
- }
24
- }
25
- }
26
-
27
- //提示表
28
- const infoTable = {
29
- "1.0.47":"UtilFT.fileSearch 函数与返回值发生变动, 请使用fileSearchRegex 或 fileSearchGlob"
30
- }
31
-
32
- async function main(){
33
- const dataPath = path.join(__dirname,"..","..","version.json");
34
- UtilFT.ensurePathExists(dataPath);
35
- const dataTable = UtilFT.loadJSONFileSync(dataPath,{});
36
- dataTable.utils = dataTable.utils??{};
37
- const prevVersion = dataTable.utils.version;
38
- dataTable.utils.version = currentVersion;
39
-
40
- console.log(`${currentVersion} 版本已安装`);
41
- // 使用这个函数来显示升级信息
42
- showUpgradeMessages(prevVersion, currentVersion, infoTable);
43
-
44
- await UtilFT.writeJSONFile(dataPath, dataTable);
45
-
46
- const rl = readline.createInterface({
47
- input: process.stdin,
48
- output: process.stdout
49
- });
50
-
51
- rl.question('按任意键继续...', () => rl.close());
52
- }
53
- main()
1
+ const path = require('path');
2
+ const { UtilFT, SLogger } = require("../index");
3
+ const readline = require('readline');
4
+
5
+ const PACKAGE_PATH = path.join(__dirname,'..','package.json');
6
+ const VERSION_PATH = path.join(__dirname,"..","..","version.json");
7
+ //提示表
8
+ const INFO_TABLE = {
9
+ "1.0.47":"UtilFT.fileSearch 函数与返回值发生变动, 请使用fileSearchRegex fileSearchGlob",
10
+ "1.0.104":
11
+ "UtilFT.fleSearchGlob 更改参数 floder作为第一个参数 ingore 移入 可选参数对象 \n" +
12
+ "UtilFT.fleSearchRegex 添加了一个可选参数 \n" +
13
+ "UtilFT.createPath 更改参数 dir 移入 可选参数对象 \n" +
14
+ "UtilFT.createPathSync 更改参数 dir 移入 可选参数对象 \n" +
15
+ "UtilFT.ensurePathExists 更改参数 dir 移入 可选参数对象 \n" +
16
+ "UtilFT.ensurePathExistsSync 更改参数 dir 移入 可选参数对象 \n"
17
+ }
18
+
19
+ // 将版本号转换为可以比较的数字
20
+ function versionToNumber(version) {
21
+ if(version==undefined) return 0;
22
+ return version.split('.').map(Number).reduce((acc, val) => acc * 1000 + val);
23
+ }
24
+
25
+ //显示提示
26
+ function showUpgradeMessages(prevVersion, currentVersion) {
27
+ const prevVersionNumber = versionToNumber(prevVersion);
28
+ const currentVersionNumber = versionToNumber(currentVersion);
29
+ let hasOut = false;
30
+ // 遍历infoTable中的所有版本
31
+ for (const version in INFO_TABLE) {
32
+ const versionNumber = versionToNumber(version);
33
+ // 如果用户的上一个版本低于这个版本,而当前版本高于或等于这个版本
34
+ if (versionNumber > prevVersionNumber && versionNumber <= currentVersionNumber) {
35
+ // 显示这个版本的提示信息
36
+ SLogger.info(INFO_TABLE[version]);
37
+ hasOut=true;
38
+ }
39
+ }
40
+ return hasOut;
41
+ }
42
+
43
+
44
+
45
+ async function main(){
46
+ const packageTable = await UtilFT.loadJSONFile(PACKAGE_PATH);
47
+ const currentVersion = packageTable.version;
48
+ await UtilFT.ensurePathExists(versionTable);
49
+ const versionTable = Object.assign({},
50
+ await UtilFT.loadJSONFile(VERSION_PATH,{}),
51
+ {utils:{version:currentVersion}});
52
+ const prevVersion = versionTable.utils.version;
53
+
54
+ SLogger.info(`${currentVersion} 版本已安装`);
55
+ // 使用这个函数来显示升级信息
56
+ const hasOut = showUpgradeMessages(prevVersion, currentVersion);
57
+
58
+ versionTable.utils.version = currentVersion;
59
+ await UtilFT.writeJSONFile(dataPath, versionTable);
60
+
61
+ if(!hasOut) return;
62
+ const rl = readline.createInterface({
63
+ input: process.stdin,
64
+ output: process.stdout
65
+ });
66
+ setTimeout(()=>rl.close(),10000);
67
+ rl.question('按任意键继续...', () => rl.close());
68
+ }
69
+ main()
@@ -1,4 +1,4 @@
1
- Write-Output 开始编译
2
- npm run compile
3
- Write-Output 开始发布
1
+ Write-Output 开始编译
2
+ npm run compile
3
+ Write-Output 开始发布
4
4
  npx zcli release
package/scripts/watch.ps1 CHANGED
@@ -1,10 +1,10 @@
1
- # 定义一个函数来运行脚本
2
- function New-Script {
3
- param($command)
4
- # 在后台运行命令
5
- Start-Process -NoNewWindow -FilePath "powershell" -ArgumentList "-Command", $command
6
- }
7
-
8
- # 开始运行脚本
9
- New-Script "tsc -w -p tsconfig.compile.json"
1
+ # 定义一个函数来运行脚本
2
+ function New-Script {
3
+ param($command)
4
+ # 在后台运行命令
5
+ Start-Process -NoNewWindow -FilePath "powershell" -ArgumentList "-Command", $command
6
+ }
7
+
8
+ # 开始运行脚本
9
+ New-Script "tsc -w -p tsconfig.compile.json"
10
10
  New-Script "tsc-alias -w -p tsconfig.compile.json"
@@ -6,6 +6,33 @@ import * as JSON5 from 'json5';
6
6
  import { globSync } from "glob";
7
7
  import { UtilFunc } from "./UtilFunctions";
8
8
 
9
+ /**创建文件选项 */
10
+ type CreatePathOpt = Partial<{
11
+ /**创建一个目录 默认 false
12
+ * 默认仅在以path.sep结尾时创建文件夹
13
+ */
14
+ dir:boolean
15
+ }>
16
+ /**验证文件选项 */
17
+ type EnsurePathExistsOpt = Partial<{
18
+ /**验证一个目录 默认 false
19
+ * 默认仅在以path.sep结尾时创建文件夹
20
+ */
21
+ dir:boolean
22
+ }>
23
+
24
+ /**glob搜索选项 */
25
+ type FileSearchGlobOpt = Partial<{
26
+ /**忽略的文件 默认 undefined */
27
+ ingore:string|string[];
28
+ }>
29
+
30
+ /**regex搜索选项 */
31
+ type FileSearchRegexOpt = Partial<{
32
+ /**搜索子目录 默认 true */
33
+ relative:boolean;
34
+ }>
35
+
9
36
  /**文件工具 */
10
37
  export namespace UtilFT{
11
38
 
@@ -40,11 +67,12 @@ export function pathExistsSync(filePath: string):boolean{
40
67
  /**路径不存在时创建路径 以path.sep结尾时创建文件夹 异步
41
68
  * @async
42
69
  * @param filePath - 待创建的路径
43
- * @param isDir - 强制创建一个文件夹
70
+ * @param opt - 可选参数
71
+ * @param opt.dir - 创建一个目录
44
72
  * @returns 是否成功创建
45
73
  */
46
- export async function createPath(filePath: string, isDir?:boolean):Promise<boolean>{
47
- if(isDir==true)
74
+ export async function createPath(filePath: string, opt?:CreatePathOpt):Promise<boolean>{
75
+ if(opt?.dir==true)
48
76
  filePath = path.join(filePath,path.sep);
49
77
 
50
78
  try{
@@ -65,11 +93,12 @@ export async function createPath(filePath: string, isDir?:boolean):Promise<boole
65
93
 
66
94
  /**路径不存在时创建路径 以path.sep结尾时创建文件夹 同步
67
95
  * @param filePath - 待创建的路径
68
- * @param isDir - 强制验证一个文件夹
96
+ * @param opt - 可选参数
97
+ * @param opt.dir - 创建一个目录
69
98
  * @returns 是否成功创建
70
99
  */
71
- export function createPathSync(filePath: string, isDir?:boolean):boolean{
72
- if(isDir==true)
100
+ export function createPathSync(filePath: string, opt?:CreatePathOpt):boolean{
101
+ if(opt?.dir==true)
73
102
  filePath = path.join(filePath,path.sep);
74
103
 
75
104
  try{
@@ -90,23 +119,26 @@ export function createPathSync(filePath: string, isDir?:boolean):boolean{
90
119
  /**确保路径存在 不存在时创建 异步
91
120
  * @async
92
121
  * @param filePath - 待验证的路径
93
- * @param isDir - 强制验证一个文件夹
122
+ * @param opt - 可选参数
123
+ * @param opt.dir - 强制验证一个文件夹
94
124
  * @returns 是否成功执行 创建或已存在
95
125
  */
96
- export async function ensurePathExists(filePath: string, isDir?:boolean):Promise<boolean>{
126
+ export async function ensurePathExists(filePath: string, opt?:EnsurePathExistsOpt):Promise<boolean>{
97
127
  if(await pathExists(filePath))
98
128
  return true;
99
- return await createPath(filePath,isDir);
129
+ return await createPath(filePath,opt);
100
130
  }
101
131
 
102
132
  /**确保路径存在 不存在时创建 同步
103
133
  * @param filePath - 待验证的路径
134
+ * @param opt - 可选参数
135
+ * @param opt.dir - 强制验证一个文件夹
104
136
  * @returns 是否成功执行 创建或已存在
105
137
  */
106
- export function ensurePathExistsSync(filePath: string, isDir?:boolean):boolean{
138
+ export function ensurePathExistsSync(filePath: string, opt?:EnsurePathExistsOpt):boolean{
107
139
  if(pathExistsSync(filePath))
108
140
  return true;
109
- return createPathSync(filePath,isDir);
141
+ return createPathSync(filePath,opt);
110
142
  }
111
143
 
112
144
  /**加载json文件 同步
@@ -196,20 +228,22 @@ export async function writeJSONFile(
196
228
  }
197
229
 
198
230
  /**搜索路径符合正则表达式的文件
199
- * @param folder - 文件夹路径
200
- * @param traitRegex - 正则表达式
231
+ * @param folder - 文件夹路径
232
+ * @param traitRegex - 正则表达式
233
+ * @param opt - 可选参数
234
+ * @param opt.relative - 搜索子目录
201
235
  * @returns 文件名路径数组
202
236
  */
203
- export function fileSearchRegex(folder: string, traitRegex: string) {
204
- let outArray: string[] = [];
205
- let subFiles = fs.readdirSync(folder);
206
- let regex = new RegExp(traitRegex);
207
- for (let subFile of subFiles) {
208
- let subFilePath = path.join(folder, subFile);
209
- let stat = fs.lstatSync(subFilePath);
237
+ export function fileSearchRegex(folder: string, traitRegex: string, opt?:FileSearchRegexOpt) {
238
+ const relative = opt?.relative ?? true;
239
+ const outArray: string[] = [];
240
+ const subFiles = fs.readdirSync(folder,{withFileTypes:true});
241
+ const regex = new RegExp(traitRegex);
242
+ for (const subFile of subFiles) {
243
+ const subFilePath = path.join(folder, subFile.name);
210
244
  //判断是否是文件夹,递归调用
211
- if (stat.isDirectory()) {
212
- outArray.push(...fileSearchRegex(path.join(subFilePath, path.sep), traitRegex));
245
+ if (subFile.isDirectory()) {
246
+ if(relative) outArray.push(...fileSearchRegex(path.join(subFilePath, path.sep), traitRegex));
213
247
  continue;
214
248
  }
215
249
  if (regex.test(subFilePath)) outArray.push(subFilePath);
@@ -217,15 +251,17 @@ export function fileSearchRegex(folder: string, traitRegex: string) {
217
251
  return outArray;
218
252
  }
219
253
  /**搜索符合Glob匹配的文件
254
+ * @param folder - 文件夹路径
220
255
  * @param globPattern - glob匹配
221
- * @param ignore - 忽略的文件
256
+ * @param opt - 可选参数
257
+ * @param opt.ignore - 忽略的文件
222
258
  * @returns 文件绝对路径数组
223
259
  */
224
- export function fileSearchGlob(globPattern:string|string[],ignore?:string|string[]){
260
+ export function fileSearchGlob(folder: string, globPattern:string|string[],opt?:FileSearchGlobOpt){
225
261
  const fixedPath = typeof globPattern === "string"
226
- ? path.posix.normalize(globPattern)
227
- : globPattern.map((p)=>path.posix.normalize(p));
228
- return globSync(fixedPath,{ignore,absolute:true});
262
+ ? path.join(folder,path.posix.normalize(globPattern))
263
+ : globPattern.map((p)=>path.join(folder,path.posix.normalize(p)));
264
+ return globSync(fixedPath,{ignore:opt?.ingore,absolute:true});
229
265
  }
230
266
  /**
231
267
  * @deprecated 请使用 fileSearchRegex 或 fileSearchGlob