@zwa73/dev-utils 1.0.41 → 1.0.43
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.
- package/dist/Command/MapPath.js +2 -2
- package/dist/Command/ScanDups.js +2 -2
- package/dist/UtilDevTool.js +5 -5
- package/dist/UtilMacro.js +2 -2
- package/package.json +2 -2
- package/src/Command/MapPath.ts +2 -2
- package/src/Command/ScanDups.ts +3 -3
- package/src/UtilDevTool.ts +6 -6
- package/src/UtilMacro.ts +3 -3
package/dist/Command/MapPath.js
CHANGED
@@ -27,9 +27,9 @@ const CmdMapPath = (program) => program
|
|
27
27
|
if (!DupMethodList.includes(options.duplicateHandling))
|
28
28
|
(0, utils_1.throwError)(`${options.duplicateHandling} 不是有效的 duplicate-handling`);
|
29
29
|
const duplicateHandling = options.duplicateHandling;
|
30
|
-
const basePath = process.cwd()
|
30
|
+
const basePath = process.cwd();
|
31
31
|
// 遍历当前目录下的所有文件
|
32
|
-
const filePaths = utils_1.UtilFT.fileSearchRegex(basePath, regex.source, { relative: options.recursive,
|
32
|
+
const filePaths = utils_1.UtilFT.fileSearchRegex(basePath, regex.source, { relative: options.recursive, style: "posix" })
|
33
33
|
.map((filePath) => path_1.default.posix.relative(basePath, filePath))
|
34
34
|
.filter((filePath) => excludeRegex ? (!excludeRegex.test(filePath)) : true);
|
35
35
|
//对单个路径映射
|
package/dist/Command/ScanDups.js
CHANGED
@@ -27,10 +27,10 @@ const CmdScanDups = (program) => program
|
|
27
27
|
.option("-r, --recursive", "是否处理子目录, 默认 true", true)
|
28
28
|
.action(async (options) => {
|
29
29
|
const regex = new RegExp(options.regex);
|
30
|
-
const basePath = process.cwd()
|
30
|
+
const basePath = (0, utils_1.posixizePath)(process.cwd());
|
31
31
|
const pList = utils_1.UtilFT.fileSearchRegex(basePath, regex.source, {
|
32
32
|
relative: options.recursive,
|
33
|
-
|
33
|
+
style: "posix",
|
34
34
|
}).map(async (filePath) => ({ filePath, hash: await calculateHash(filePath) }));
|
35
35
|
const hashMap = (await Promise.all(pList)).reduce((obj, cur) => {
|
36
36
|
obj[cur.hash] = (obj[cur.hash] ?? []).concat(cur.filePath);
|
package/dist/UtilDevTool.js
CHANGED
@@ -124,7 +124,7 @@ var UtilDT;
|
|
124
124
|
if (!Array.isArray(filepath))
|
125
125
|
filepath = [filepath];
|
126
126
|
// 将所有的相对路径转换为绝对路径
|
127
|
-
const absolutePaths = filepath.map(fp => path.resolve(process.cwd(), fp)
|
127
|
+
const absolutePaths = filepath.map(fp => (0, utils_1.posixizePath)(path.resolve(process.cwd(), fp)));
|
128
128
|
// 创建一个字符串,其中包含所有文件的 require 语句
|
129
129
|
const requires = absolutePaths.map(fp => `require('${fp}')`).join(';');
|
130
130
|
// 创建并执行 ts-node 命令
|
@@ -140,11 +140,11 @@ var UtilDT;
|
|
140
140
|
const basePath = loc?.filePath;
|
141
141
|
return opt?.filePath
|
142
142
|
? opt.glob
|
143
|
-
? utils_1.UtilFT.fileSearchGlob(process.cwd(), opt.filePath, {
|
143
|
+
? utils_1.UtilFT.fileSearchGlob(process.cwd(), opt.filePath, { style: "posix" })
|
144
144
|
: typeof opt?.filePath === "string"
|
145
|
-
? [
|
146
|
-
: opt?.filePath.map((filepath) =>
|
147
|
-
: [basePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/, "$1.$2")
|
145
|
+
? [(0, utils_1.posixizePath)(opt?.filePath)]
|
146
|
+
: opt?.filePath.map((filepath) => (0, utils_1.posixizePath)(filepath))
|
147
|
+
: [(0, utils_1.posixizePath)(basePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/, "$1.$2"))];
|
148
148
|
};
|
149
149
|
const readFile = async (basePath) => (await fs.promises.readFile(basePath, 'utf-8')).replaceAll("\r\n", "\n");
|
150
150
|
const parseCodeText = async (codeText, opt) => {
|
package/dist/UtilMacro.js
CHANGED
@@ -15,8 +15,8 @@ var UtilMacro;
|
|
15
15
|
*/
|
16
16
|
function exportComment(glob) {
|
17
17
|
(0, QuickFunc_1.commentMacro)(/export (\S*)/, ({ filePath, matchId, execArr }) => {
|
18
|
-
const basedir = path_1.default.dirname(filePath)
|
19
|
-
const result = utils_1.UtilFT.fileSearchGlob(basedir, execArr[1], {
|
18
|
+
const basedir = (0, utils_1.posixizePath)(path_1.default.dirname(filePath));
|
19
|
+
const result = utils_1.UtilFT.fileSearchGlob(basedir, execArr[1], { style: 'posix' })
|
20
20
|
.map((file) => path_1.default.posix.relative(basedir, file))
|
21
21
|
.map((file) => path_1.default.parse(file).name)
|
22
22
|
.filter((file) => file != path_1.default.parse(filePath).name)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zwa73/dev-utils",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.43",
|
4
4
|
"description": "编译与调试工具",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -16,7 +16,7 @@
|
|
16
16
|
"author": "zwa73",
|
17
17
|
"license": "ISC",
|
18
18
|
"dependencies": {
|
19
|
-
"@zwa73/utils": "^1.0.
|
19
|
+
"@zwa73/utils": "^1.0.119",
|
20
20
|
"commander": "^11.1.0",
|
21
21
|
"ts-node": "^10.9.2",
|
22
22
|
"tsconfig-paths": "^4.2.0",
|
package/src/Command/MapPath.ts
CHANGED
@@ -25,9 +25,9 @@ export const CmdMapPath = (program: Command) => program
|
|
25
25
|
if(!DupMethodList.includes(options.duplicateHandling))
|
26
26
|
throwError(`${options.duplicateHandling} 不是有效的 duplicate-handling`);
|
27
27
|
const duplicateHandling = options.duplicateHandling as DupMethod;
|
28
|
-
const basePath = process.cwd()
|
28
|
+
const basePath = process.cwd();
|
29
29
|
// 遍历当前目录下的所有文件
|
30
|
-
const filePaths = UtilFT.fileSearchRegex(basePath, regex.source,{relative:options.recursive,
|
30
|
+
const filePaths = UtilFT.fileSearchRegex(basePath, regex.source,{relative:options.recursive,style:"posix"})
|
31
31
|
.map((filePath)=>path.posix.relative(basePath, filePath))
|
32
32
|
.filter((filePath)=>excludeRegex ? (!excludeRegex.test(filePath)) : true);
|
33
33
|
|
package/src/Command/ScanDups.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { SLogger, UtilFT } from "@zwa73/utils";
|
1
|
+
import { SLogger, UtilFT, posixizePath, stylizePath } from "@zwa73/utils";
|
2
2
|
import { Command } from "commander";
|
3
3
|
import fs from "fs";
|
4
4
|
import crypto from 'crypto';
|
@@ -25,10 +25,10 @@ export const CmdScanDups = (program: Command) => program
|
|
25
25
|
.option("-r, --recursive", "是否处理子目录, 默认 true", true)
|
26
26
|
.action(async (options) => {
|
27
27
|
const regex = new RegExp(options.regex);
|
28
|
-
const basePath = process.cwd()
|
28
|
+
const basePath = posixizePath(process.cwd());
|
29
29
|
const pList = UtilFT.fileSearchRegex(basePath, regex.source, {
|
30
30
|
relative: options.recursive,
|
31
|
-
|
31
|
+
style: "posix",
|
32
32
|
}).map(async (filePath) => ({ filePath, hash: await calculateHash(filePath) }));
|
33
33
|
|
34
34
|
const hashMap = (await Promise.all(pList)).reduce((obj,cur)=>{
|
package/src/UtilDevTool.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as path from 'path';
|
2
2
|
import * as TJS from 'typescript-json-schema';
|
3
3
|
import * as fs from 'fs';
|
4
|
-
import { JObject, SLogger, UtilFT, UtilFunc, dedent, throwError } from '@zwa73/utils';
|
4
|
+
import { JObject, SLogger, UtilFT, UtilFunc, dedent, posixizePath, stylizePath, throwError } from '@zwa73/utils';
|
5
5
|
|
6
6
|
export namespace UtilDT{
|
7
7
|
|
@@ -123,7 +123,7 @@ export async function batchNode(filepath:string|string[],opt?:BatchNodeOpt) {
|
|
123
123
|
// 确保 filepath 总是一个数组
|
124
124
|
if (!Array.isArray(filepath)) filepath = [filepath];
|
125
125
|
// 将所有的相对路径转换为绝对路径
|
126
|
-
const absolutePaths = filepath.map(fp => path.resolve(process.cwd(), fp)
|
126
|
+
const absolutePaths = filepath.map(fp => posixizePath(path.resolve(process.cwd(), fp)));
|
127
127
|
// 创建一个字符串,其中包含所有文件的 require 语句
|
128
128
|
const requires = absolutePaths.map(fp => `require('${fp}')`).join(';');
|
129
129
|
// 创建并执行 ts-node 命令
|
@@ -158,11 +158,11 @@ const parseMacroPaths = (opt?:MacroOpt)=>{
|
|
158
158
|
const basePath = loc?.filePath!;
|
159
159
|
return opt?.filePath
|
160
160
|
? opt.glob
|
161
|
-
? UtilFT.fileSearchGlob(process.cwd(),opt.filePath,{
|
161
|
+
? UtilFT.fileSearchGlob(process.cwd(),opt.filePath,{style:"posix"})
|
162
162
|
: typeof opt?.filePath==="string"
|
163
|
-
? [opt?.filePath
|
164
|
-
: opt?.filePath.map((filepath)=>filepath
|
165
|
-
: [basePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/,"$1.$2")
|
163
|
+
? [posixizePath(opt?.filePath)]
|
164
|
+
: opt?.filePath.map((filepath)=>posixizePath(filepath))
|
165
|
+
: [posixizePath(basePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/,"$1.$2"))];
|
166
166
|
}
|
167
167
|
const readFile = async (basePath:string)=>
|
168
168
|
(await fs.promises.readFile(basePath,'utf-8')).replaceAll("\r\n","\n");
|
package/src/UtilMacro.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { UtilFT } from "@zwa73/utils";
|
1
|
+
import { UtilFT, posixizePath, stylizePath } from "@zwa73/utils";
|
2
2
|
import { commentMacro } from "./QuickFunc"
|
3
3
|
import path from "path";
|
4
4
|
|
@@ -10,8 +10,8 @@ export namespace UtilMacro{
|
|
10
10
|
*/
|
11
11
|
export function exportComment(glob:string){
|
12
12
|
commentMacro(/export (\S*)/,({filePath,matchId,execArr})=>{
|
13
|
-
const basedir = path.dirname(filePath)
|
14
|
-
const result = UtilFT.fileSearchGlob(basedir,execArr[1],{
|
13
|
+
const basedir = posixizePath(path.dirname(filePath));
|
14
|
+
const result = UtilFT.fileSearchGlob(basedir,execArr[1],{style:'posix'})
|
15
15
|
.map((file)=>path.posix.relative(basedir,file))
|
16
16
|
.map((file)=>path.parse(file).name)
|
17
17
|
.filter((file)=>file!=path.parse(filePath).name)
|