js-code-detector 0.0.3 → 0.0.4

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/README.md CHANGED
@@ -21,9 +21,9 @@ $ npm run build
21
21
 
22
22
  ## 使用
23
23
 
24
- 项目安装 js-code-detector
25
- package.json 中添加 scripts 命令 ```npx detect```
26
- 执行该命令可在当前项目目录下生成报告
24
+ 1.项目安装 **js-code-detector**
25
+ 2.package.json 中添加 scripts 命令 ```detect```
26
+ 3.执行该命令可在当前项目目录下生成报告
27
27
 
28
28
  ## 报告说明
29
29
  - filePath 文件路径
package/dist/cjs/index.js CHANGED
@@ -43,7 +43,8 @@ var import_fs2 = require("fs");
43
43
  var import_report_util = require("./util/report_util");
44
44
  var import_utils = require("@umijs/utils");
45
45
  var import_dayjs = __toESM(require("dayjs"));
46
- var jsonName = "git_diff_report.json";
46
+ var import_createMdByJson = require("./util/report_util/createMdByJson");
47
+ var jsonName = "git_diff_report.md";
47
48
  async function umiPluginCallback(api) {
48
49
  const diff_txt = (0, import_fs.readFileSync)((0, import_path.join)(api.cwd, "git_diff.txt"), "utf-8");
49
50
  const gitDiffDetail = (0, import_format_git_diff_content.formatGitDiffContent)(diff_txt);
@@ -57,7 +58,8 @@ async function umiPluginCallback(api) {
57
58
  const usingFileNoPrefix = usingFiles.map((item) => item.filePath.replace(absPathPrefix, ""));
58
59
  const groupGitDiffLines = gitDiffDetail.filter((item) => usingFileNoPrefix.includes(item.filePath));
59
60
  const reports = (0, import_report_util.createDetectReport)({ groupGitDiffLines, tree, absPathPrefix });
60
- (0, import_fs2.writeFileSync)((0, import_path.join)(api.cwd, jsonName), JSON.stringify(reports, null, 2), { encoding: "utf-8", flag: "w" });
61
+ const mdContent = (0, import_createMdByJson.createMdByJson)(reports);
62
+ (0, import_fs2.writeFileSync)((0, import_path.join)(api.cwd, jsonName), mdContent, { encoding: "utf-8", flag: "w" });
61
63
  }
62
64
  var shellFileContent = `#!/bin/sh
63
65
  time=$(date "+%Y%-m%d")
@@ -0,0 +1,2 @@
1
+ import { createDetectReport } from "../report_util";
2
+ export declare function createMdByJson(report: ReturnType<typeof createDetectReport>): string;
@@ -0,0 +1,74 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/util/report_util/createMdByJson.ts
20
+ var createMdByJson_exports = {};
21
+ __export(createMdByJson_exports, {
22
+ createMdByJson: () => createMdByJson
23
+ });
24
+ module.exports = __toCommonJS(createMdByJson_exports);
25
+ var mapReportType = {
26
+ modify: "修改",
27
+ add: "新增",
28
+ delete: "删除"
29
+ };
30
+ function createMdByJson(report) {
31
+ return report.map(reportItemToMd).join("\n\n\n");
32
+ }
33
+ function reportItemToMd(report) {
34
+ const { filePath, filesDependsOnMe, type, dangerIdentifiers, blockReports } = report;
35
+ return [
36
+ `## ${filePath}`,
37
+ `- 类型: ${mapReportType[type]}`,
38
+ filesDependsOnMe.length > 0 ? `- 依赖${filePath}的文件` : "",
39
+ ...filesDependsOnMe.map((file, i) => `${i + 1}. ${file}`),
40
+ dangerIdentifiers.length > 0 ? `- 重点检查使用的变量` : "",
41
+ dangerIdentifiers.length > 0 ? `> ${dangerIdentifiers.join(", ")}` : "",
42
+ blockReports.length > 0 ? `### 代码块分析` : "",
43
+ ...blockReports.map(blockReportToMd)
44
+ ].filter(Boolean).join("\n\n");
45
+ }
46
+ function blockReportToMd(block) {
47
+ const {
48
+ kind,
49
+ diff_txt,
50
+ added,
51
+ addedEffects,
52
+ removed,
53
+ removedEffects
54
+ } = block;
55
+ return [
56
+ `#### 修改分类: ${kind}`,
57
+ `- 原始diff内容`,
58
+ `\`\`\`txt
59
+ ${diff_txt.join("\n")}
60
+ \`\`\``,
61
+ added.length > 0 ? `- 新增标识符` : "",
62
+ added.length > 0 ? `> ${added.join(", ")}` : "",
63
+ addedEffects.length > 0 ? `- 新增标识符影响` : "",
64
+ addedEffects.map(({ causeBy, effects }) => `> ${causeBy}相关: ${effects.join()}`).join("\n\n"),
65
+ removed.length > 0 ? `- 删除标识符` : "",
66
+ removed.length > 0 ? `> ${removed.join(", ")}` : "",
67
+ removedEffects.length > 0 ? `- 删除标识符影响` : "",
68
+ removedEffects.map(({ causeBy, effects }) => `> ${causeBy}相关: ${effects.join()}`).join("\n\n")
69
+ ].filter(Boolean).join("\n\n");
70
+ }
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ createMdByJson
74
+ });
@@ -1,4 +1,12 @@
1
1
  import { GitDiffDetail } from "./format_git_diff_content";
2
+ import { BlockReport } from "./report_util/code_block_detect";
3
+ export type DetectReport = {
4
+ filePath: string;
5
+ type: "modify" | "add" | "delete";
6
+ filesDependsOnMe: string[];
7
+ dangerIdentifiers: string[];
8
+ blockReports: BlockReport[];
9
+ };
2
10
  type Arg = {
3
11
  groupGitDiffLines: GitDiffDetail[];
4
12
  tree: Record<string, string[]>;
@@ -23,7 +31,7 @@ export declare function createDetectReport(arg: Arg): {
23
31
  kind: "Import" | "Declaration" | "Assignment" | "SelfUpdate" | "Invoke" | "Other" | "Never";
24
32
  }[];
25
33
  filePath: string;
26
- type: "add" | "delete" | "modify";
34
+ type: "modify" | "add" | "delete";
27
35
  filesDependsOnMe: string[];
28
36
  dangerIdentifiers: string[];
29
37
  }[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-code-detector",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",