@zwa73/dev-utils 1.0.19 → 1.0.21

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.
@@ -7,6 +7,7 @@ exports.CmdScanDups = void 0;
7
7
  const utils_1 = require("@zwa73/utils");
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const crypto_1 = __importDefault(require("crypto"));
10
+ const path_1 = __importDefault(require("path"));
10
11
  async function calculateHash(filePath) {
11
12
  return new Promise((resolve, reject) => {
12
13
  const hash = crypto_1.default.createHash('md5');
@@ -25,7 +26,8 @@ const CmdScanDups = (program) => program
25
26
  .option("-r, --recursive", "是否处理子目录, 默认 true", true)
26
27
  .action(async (options) => {
27
28
  const regex = new RegExp(options.regex);
28
- const pList = utils_1.UtilFT.fileSearchRegex(__dirname.replaceAll("\\", "/"), regex.source, {
29
+ const basePath = process.cwd().replaceAll("\\", "/");
30
+ const pList = utils_1.UtilFT.fileSearchRegex(basePath, regex.source, {
29
31
  relative: options.recursive,
30
32
  normalize: "posix",
31
33
  }).map(async (filePath) => ({ filePath, hash: await calculateHash(filePath) }));
@@ -43,6 +45,6 @@ const CmdScanDups = (program) => program
43
45
  if (options.out === "console")
44
46
  utils_1.SLogger.info(out);
45
47
  else
46
- await utils_1.UtilFT.writeJSONFile(options.out, out);
48
+ await utils_1.UtilFT.writeJSONFile(path_1.default.join(basePath, options.out), out);
47
49
  });
48
50
  exports.CmdScanDups = CmdScanDups;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/dev-utils",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "编译与调试工具",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,6 +2,7 @@ import { SLogger, UtilFT } from "@zwa73/utils";
2
2
  import { Command } from "commander";
3
3
  import fs from "fs";
4
4
  import crypto from 'crypto';
5
+ import path from "path";
5
6
 
6
7
  async function calculateHash(filePath:string) {
7
8
  return new Promise<string>((resolve, reject) => {
@@ -23,7 +24,8 @@ export const CmdScanDups = (program: Command) => program
23
24
  .option("-r, --recursive", "是否处理子目录, 默认 true", true)
24
25
  .action(async (options) => {
25
26
  const regex = new RegExp(options.regex);
26
- const pList = UtilFT.fileSearchRegex(__dirname.replaceAll("\\", "/"), regex.source, {
27
+ const basePath = process.cwd().replaceAll("\\", "/")
28
+ const pList = UtilFT.fileSearchRegex(basePath, regex.source, {
27
29
  relative: options.recursive,
28
30
  normalize: "posix",
29
31
  }).map(async (filePath) => ({ filePath, hash: await calculateHash(filePath) }));
@@ -41,5 +43,5 @@ export const CmdScanDups = (program: Command) => program
41
43
  if(options.out==="console")
42
44
  SLogger.info(out);
43
45
  else
44
- await UtilFT.writeJSONFile(options.out,out);
46
+ await UtilFT.writeJSONFile(path.join(basePath,options.out),out);
45
47
  });