agmd 0.0.8 → 0.1.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) <year> <author>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.EN.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- >Enter 'AGMD' in any folder where documents need to be generated, and the directory MD description can be automatically generated
5
+ >If you need to generate documents, enter 'AGMD' in the console under the folder to automatically generate the directory MD description
6
6
 
7
7
 
8
8
 
@@ -10,9 +10,6 @@
10
10
 
11
11
 
12
12
 
13
- English| [中文](https://github.com/majun2232/vue3sketchRuler/blob/master/README.md)
14
-
15
-
16
13
 
17
14
  ### Case
18
15
 
@@ -24,9 +21,9 @@ English| [中文](https://github.com/majun2232/vue3sketchRuler/blob/master/READM
24
21
 
25
22
  ### Method of use
26
23
 
24
+ Node environment is required
27
25
 
28
-
29
- Global installation (Global installation is required, otherwise it will be reported that the "AGMD" item cannot be recognized as the name of cmdlet, function, script file or runnable program)
26
+ 1. Global installation (Global installation is required, otherwise it will be reported that the "AGMD" item cannot be recognized as the name of cmdlet, function, script file or runnable program)
30
27
 
31
28
 
32
29
 
@@ -42,6 +39,26 @@ Example is some of the files I prepared for the demonstration, which is of no ot
42
39
 
43
40
 
44
41
 
42
+ 2. Advanced usage
43
+
44
+ Some need to insert automatically generated documents into an automatically generated MD. the plug-in exports the automatically generated MD data method, and 'getfilenodes' obtains the specific information of all files. You can DIY different documents
45
+
46
+ >const { getFileNodes, getMd } = require('agmd')
47
+
48
+
49
+
50
+ In es:
51
+
52
+ >import {getFileNodes, getMd} from 'agmd'
53
+
54
+
55
+
56
+ -Getfilenodes can obtain information related to specific files
57
+
58
+ -Getmd gets the final output information
59
+
60
+
61
+
45
62
  ### Creative background
46
63
 
47
64
 
@@ -72,8 +89,20 @@ Example is some of the files I prepared for the demonstration, which is of no ot
72
89
 
73
90
 
74
91
 
92
+ ### Related articles
75
93
 
76
94
 
77
- ### Related articles
78
95
 
79
- [Nuggets - auto generate directory MD file](https://juejin.cn/post/7030030599268073508)
96
+ [Nuggets - auto generate directory MD file]https://juejin.cn/post/7030030599268073508 )
97
+
98
+
99
+
100
+ ### Update record
101
+
102
+ 0.1. 0
103
+
104
+ 1. Package with esbuild
105
+
106
+ 2. It is written in eslint and preter specifications
107
+
108
+ 3. Rewrite with TS
package/README.md CHANGED
@@ -1,17 +1,17 @@
1
1
  # agmd(auto generate md)
2
2
 
3
- > 在任何需要生成文档的,文件夹下输入`agmd`, 就能自动生成目录 md 说明
3
+ > 在任何需要生成文档的,文件夹下的控制台中输入`agmd`, 就能自动生成目录 md 说明
4
4
 
5
5
  [![](https://camo.githubusercontent.com/28479a7a834310a667f36760a27283f7389e864a/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f6c2f76322d646174657069636b65722e737667)](https://camo.githubusercontent.com/28479a7a834310a667f36760a27283f7389e864a/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f6c2f76322d646174657069636b65722e737667)
6
6
 
7
- 简体中文 | [English](https://github.com/majun2232/vue3sketchRuler/blob/master/README.EN.md)
7
+ 简体中文 | [English](https://github.com/majun2232/auto-generate-md/blob/master/README.EN.md)
8
8
 
9
9
  ### 案例
10
10
 
11
11
  ![image](https://github.com/majun2232/auto-generate-md/blob/master/md.png)
12
12
 
13
13
  ### 使用方法
14
- 需要有node环境
14
+ 需要有node环境
15
15
  1. 全局安装(必须全局安装,否则会报`无法将“agmd”项识别为 cmdlet、函数、脚本文件或可运行程序的名称`)
16
16
 
17
17
  > npm i agmd -g
@@ -21,10 +21,14 @@
21
21
  example,是我为演示准备的一些文件,并没有其他用
22
22
 
23
23
  2. 高级用法
24
- 有些需要把自动生成的文档插入到某个自动生成的 md 当中, 该插件导出了自动生成的 md 数据方法, 还有`getFileNodes`获得所有文件的具体信息, 可以 DIY 做出不同的文档
25
- > import {getFileNodes, getMd} from agmd
26
- > 其中 getFileNodes 可以获得具体文件相关的信息
27
- > getMd 得到最终输出的信息
24
+ 有些需要把自动生成的文档插入到某个自动生成的 md 当中, 该插件导出了自动生成的 md 数据方法, 还有`getFileNodes`获得所有文件的具体信息, 可以 DIY 做出不同的文档
25
+ >const { getFileNodes, getMd } = require('agmd')
26
+
27
+ es中:
28
+ >import {getFileNodes, getMd} from 'agmd'
29
+
30
+ - 其中 getFileNodes 可以获得具体文件相关的信息
31
+ - getMd 得到最终输出的信息
28
32
 
29
33
  ### 创作背景
30
34
 
@@ -44,3 +48,9 @@ example,是我为演示准备的一些文件,并没有其他用
44
48
  ### 相关文章
45
49
 
46
50
  [掘金-自动生成目录 md 文件](https://juejin.cn/post/7030030599268073508)
51
+
52
+ ### 更新记录
53
+ 0.1.3
54
+ 1. 采用esbuild 进行打包
55
+ 2. 并且用eslint, preter规范写法, 规范
56
+ 3. 用ts进行改写
package/bin/agmd.js CHANGED
@@ -1,49 +1,139 @@
1
1
  #!/usr/bin/env node
2
- // 获取文件的头部注释工具
3
- import path from "path";
4
- import fs from "fs";
5
- const __dirname = path.resolve();
6
- import { getMd } from "../module.js";
7
- /**
8
- * @description: 把结果写入到js文件
9
- * @param {data} 要写的数据
10
- * @return {fileName} 要写入文件地址
11
- */
12
- function wirteJs(data, filePath) {
13
- let file = path.resolve(__dirname, filePath);
14
- const pre = "export default";
15
- // 异步写入数据到文件
16
- fs.writeFile(file, pre + data, { encoding: "utf8" }, (err) => {});
2
+ /*!
3
+ * agmd v0.0.11
4
+ * author:majun <253495832@qq.com>
5
+ * Fri Dec 17 2021 09:30:50 GMT+0800 (中国标准时间)
6
+ */
7
+ var __create = Object.create;
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __getProtoOf = Object.getPrototypeOf;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
13
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
14
+ var __reExport = (target, module2, copyDefault, desc) => {
15
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
16
+ for (let key of __getOwnPropNames(module2))
17
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
18
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
19
+ }
20
+ return target;
21
+ };
22
+ var __toESM = (module2, isNodeMode) => {
23
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
24
+ };
25
+
26
+ // src/agmd.ts
27
+ var import_path2 = __toESM(require("path"));
28
+ var import_fs2 = __toESM(require("fs"));
29
+
30
+ // src/index.ts
31
+ var import_fs = __toESM(require("fs"));
32
+ var import_path = __toESM(require("path"));
33
+ function getFile(file) {
34
+ const str = import_fs.default.readFileSync(file, "utf-8");
35
+ const sarr = str.split(/[\n,]/g);
36
+ const f = sarr[0].indexOf("eslint") === -1 && (sarr[0].indexOf("-->") > -1 || sarr[0].indexOf("*/") > -1 || sarr[0].indexOf("//") > -1) ? sarr[0] : "";
37
+ return f;
38
+ }
39
+ var filterArr = ["img", "styles", "node_modules", "LICENSE", ".git", ".github", "dist", ".husky", ".vscode"];
40
+ var includeArrs = [".js", ".vue", ".ts"];
41
+ function getFileNodes(nodes = [], dir = import_path.default.resolve("./"), level = 0) {
42
+ const files = import_fs.default.readdirSync(dir).map((item) => {
43
+ const fullPath = import_path.default.join(dir, item);
44
+ const isDir = import_fs.default.lstatSync(fullPath).isDirectory();
45
+ return {
46
+ name: item,
47
+ isDir,
48
+ level,
49
+ note: ""
50
+ };
51
+ }).sort((a, b) => {
52
+ if (!a.isDir && b.isDir)
53
+ return 1;
54
+ if (a.isDir && !b.isDir)
55
+ return -1;
56
+ if (a.isDir && b.isDir || !a.isDir && !b.isDir)
57
+ return 0;
58
+ return 0;
59
+ });
60
+ for (let index = 0; index < files.length; index += 1) {
61
+ const item = files[index];
62
+ let note = "";
63
+ const arr = filterArr.findIndex((obj) => obj === item.name);
64
+ if (arr === -1) {
65
+ const fullPath = import_path.default.join(dir, item.name);
66
+ const isDir = import_fs.default.lstatSync(fullPath).isDirectory();
67
+ if (isDir) {
68
+ getFileNodes(item.children = [], fullPath, level + 1);
69
+ } else {
70
+ const i = fullPath.lastIndexOf(".");
71
+ const lastName = fullPath.substring(i);
72
+ if ([".js", ".vue", ".ts"].includes(lastName)) {
73
+ note = getFile(fullPath);
74
+ }
75
+ item.note = note;
76
+ }
77
+ nodes.push(item);
78
+ }
79
+ }
80
+ return nodes;
81
+ }
82
+ function getNote(datas, keys) {
83
+ const nodes = keys || [];
84
+ datas.forEach((obj) => {
85
+ if (obj.children) {
86
+ const md = setMd(obj);
87
+ nodes.push(md);
88
+ getNote(obj.children, nodes);
89
+ } else {
90
+ const md = setMd(obj);
91
+ nodes.push(md);
92
+ }
93
+ });
94
+ return nodes;
95
+ }
96
+ function setMd(obj) {
97
+ let filesString = "";
98
+ const blank = " ".repeat(obj.level);
99
+ if (obj.isDir) {
100
+ filesString += `${blank}+ ${obj.name}
101
+ `;
102
+ } else {
103
+ const index = obj.name.lastIndexOf(".");
104
+ const lastName = obj.name.substring(index);
105
+ if (includeArrs.includes(lastName) || index === -1) {
106
+ filesString += `${blank} ${obj.name} ${obj.note}
107
+ `;
108
+ }
109
+ }
110
+ return filesString;
111
+ }
112
+ function getMd() {
113
+ console.log("%s", "*** run location: ", import_path.default.resolve("./"));
114
+ const nodes = getFileNodes();
115
+ const note = getNote(nodes);
116
+ const md = note.join("");
117
+ if (md.length > 0) {
118
+ console.log("%s", "*** Automatic generation completed ! ");
119
+ }
120
+ return md;
17
121
  }
18
122
 
19
- /**
20
- * @description: 把结果写入到js文件
21
- * @param {data} 要写的数据
22
- * @return {fileName} 要写入文件地址
23
- */
123
+ // src/agmd.ts
124
+ var __dirname = import_path2.default.resolve();
24
125
  function wirteMd(data, filePath) {
25
- let file = path.resolve(__dirname, filePath);
126
+ const file = import_path2.default.resolve(__dirname, filePath);
26
127
  const pre = "```js\n";
27
128
  const last = "```\n";
28
- // 异步写入数据到文件
29
- fs.writeFile(file, pre + data + last, { encoding: "utf8" }, (err) => {});
129
+ import_fs2.default.writeFile(file, pre + data + last, { encoding: "utf8" }, (err) => {
130
+ console.error(err);
131
+ });
30
132
  }
31
-
32
- /**
33
- * @description: 自动生成全流程
34
- * @param {*}
35
- * @return {*}
36
- */
37
133
  function agmd() {
38
134
  const md = getMd();
39
- // 得到md对象
40
- // wirteJs(JSON.stringify(nodes), __dirname + "\\readme-file.js");
41
- // 得到md文档
42
- console.log(
43
- "\x1B[36m%s\x1B[0m",
44
- "*** location: ",
45
- path.resolve("./") + "\\readme-md.md"
46
- );
47
- wirteMd(md, path.resolve("./") + "\\readme-md.md");
135
+ console.log("%s", "*** location: ", `${import_path2.default.resolve("./")}\\readme-md.md`);
136
+ wirteMd(md, `${import_path2.default.resolve("./")}\\readme-md.md`);
48
137
  }
49
138
  agmd();
139
+ //# sourceMappingURL=agmd.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/agmd.ts", "../src/index.ts"],
4
+ "sourcesContent": ["#!/usr/bin/env node\r\n// \u83B7\u53D6\u6587\u4EF6\u7684\u5934\u90E8\u6CE8\u91CA\u5DE5\u5177\r\nimport path from 'path'\r\nimport fs from 'fs'\r\nimport { getMd } from './index'\r\n\r\nconst __dirname = path.resolve()\r\n/**\r\n * @description: \u628A\u7ED3\u679C\u5199\u5165\u5230js\u6587\u4EF6\r\n * @param {data} \u8981\u5199\u7684\u6570\u636E\r\n * @return {fileName} \u8981\u5199\u5165\u6587\u4EF6\u5730\u5740\r\n */\r\n// function wirteJs(data: string, filePath: string) {\r\n// const file = path.resolve(__dirname, filePath)\r\n// const pre = 'export default'\r\n// // \u5F02\u6B65\u5199\u5165\u6570\u636E\u5230\u6587\u4EF6\r\n// fs.writeFile(file, pre + data, { encoding: 'utf8' }, (err) => {\r\n// console.error(err);\r\n// })\r\n// }\r\n\r\n/**\r\n * @description: \u628A\u7ED3\u679C\u5199\u5165\u5230js\u6587\u4EF6\r\n * @param {data} \u8981\u5199\u7684\u6570\u636E\r\n * @return {fileName} \u8981\u5199\u5165\u6587\u4EF6\u5730\u5740\r\n */\r\nfunction wirteMd(data: string, filePath: string) {\r\n const file = path.resolve(__dirname, filePath)\r\n const pre = '```js\\n'\r\n const last = '```\\n'\r\n // \u5F02\u6B65\u5199\u5165\u6570\u636E\u5230\u6587\u4EF6\r\n fs.writeFile(file, pre + data + last, { encoding: 'utf8' }, (err) => { console.error(err);})\r\n}\r\n\r\n/**\r\n * @description: \u81EA\u52A8\u751F\u6210\u5168\u6D41\u7A0B\r\n * @param {*}\r\n * @return {*}\r\n */\r\nfunction agmd() {\r\n const md = getMd()\r\n // \u5F97\u5230md\u5BF9\u8C61\r\n // wirteJs(JSON.stringify(nodes), __dirname + \"\\\\readme-file.js\");\r\n // \u5F97\u5230md\u6587\u6863\r\n console.log('\\x1B[36m%s\\x1B[0m', '*** location: ', `${path.resolve('./')}\\\\readme-md.md`)\r\n wirteMd(md, `${path.resolve('./')}\\\\readme-md.md`)\r\n}\r\nagmd()\r\n", "import fs from 'fs'\nimport path from 'path'\n\n/**\n * @description: \u83B7\u53D6\u6587\u4EF6\u7684\u5934\u90E8\u6CE8\u91CA\n * @param {*} file\n * @return {*}\n */\nfunction getFile(file: fs.PathOrFileDescriptor) {\n const str = fs.readFileSync(file, 'utf-8')\n const sarr = str.split(/[\\n,]/g)\n // console.log(file);\n const f =\n sarr[0].indexOf('eslint') === -1 &&\n (sarr[0].indexOf('-->') > -1 || sarr[0].indexOf('*/') > -1 || sarr[0].indexOf('//') > -1)\n ? sarr[0]\n : ''\n // console.log(f);\n return f\n}\n// \u8FC7\u6EE4\u6587\u4EF6\u5939\nconst filterArr = ['img', 'styles', 'node_modules', 'LICENSE', '.git', '.github', 'dist', '.husky', '.vscode']\n// \u8FD9\u91CC\u53EA\u83B7\u53D6\u67D0\u540E\u7F00\u6587\u4EF6\u7684\u6CE8\u91CA,\u9700\u8981\u5176\u4ED6\u8FD9\u91CC\u52A0\u5165\nconst includeArrs = ['.js', '.vue', '.ts']\n\nexport type ItemType ={\n name: string\n isDir: boolean\n level: number\n note: string\n children?: ItemType[]\n}\n\n/**\n * @description: \u751F\u6210\u6240\u6709\u6587\u4EF6\u7684node\u4FE1\u606F\n * @param {*} nodes\n * @param {*} dir\n * @param {*} level\n * @return {*}\n */\n export function getFileNodes(nodes: Array<ItemType> = [], dir = path.resolve('./'), level = 0): Array<ItemType> {\n const files = fs\n .readdirSync(dir)\n .map((item) => {\n const fullPath = path.join(dir, item)\n const isDir = fs.lstatSync(fullPath).isDirectory()\n return {\n name: item,\n isDir,\n level,\n note: ''\n } as ItemType\n })\n // \u5BF9\u6587\u4EF6\u5939\u548C\u6587\u4EF6\u8FDB\u884C\u6392\u5E8F,\u8981\u4E0D\u7136\u751F\u6210\u7684\u548C\u7F16\u8F91\u5668\u6253\u5F00\u7684\u987A\u5E8F\u4E0D\u5BF9\u5E94\n .sort((a, b) => {\n if (!a.isDir && b.isDir) return 1\n if (a.isDir && !b.isDir) return -1\n if ((a.isDir && b.isDir) || (!a.isDir && !b.isDir)) return 0\n return 0\n })\n for (let index = 0; index < files.length; index += 1) {\n const item = files[index]\n let note = '' // \u6587\u4EF6\u6CE8\u91CA\n const arr = filterArr.findIndex((obj) => obj === item.name)\n if (arr === -1) {\n const fullPath = path.join(dir, item.name)\n const isDir = fs.lstatSync(fullPath).isDirectory()\n if (isDir) {\n // \u9012\u5F52\n getFileNodes((item.children = []), fullPath, level + 1)\n } else {\n const i = fullPath.lastIndexOf('.')\n const lastName = fullPath.substring(i)\n // \u8FD9\u91CC\u53EA\u83B7\u53D6js\u548Cvue,ts\u6587\u4EF6\u7684\u6CE8\u91CA\n if (['.js', '.vue', '.ts'].includes(lastName)) {\n note = getFile(fullPath)\n }\n item.note = note\n }\n nodes.push(item)\n }\n }\n // \u63A7\u5236\u8FD4\u56DE\u65F6\u95F4\u8282\u70B9,\u4E0D\u8BA9\u63D0\u524D\u8FD4\u56DE\n return nodes\n}\n\n/**\n * @description: \u9012\u5F52\u5F97\u5230\u6587\u4EF6\u540D+note\n * @param {*} datas\n * @param {*} keys\n * @return {*}\n */\nfunction getNote(datas: Array<ItemType>, keys?: string[]) {\n const nodes = keys || []\n datas.forEach((obj: ItemType) => {\n if (obj.children) {\n // \u6587\u4EF6\u5939\n const md = setMd(obj)\n nodes.push(md)\n getNote(obj.children, nodes)\n }\n // \u6587\u4EF6\n else {\n const md = setMd(obj)\n nodes.push(md)\n }\n })\n return nodes\n}\n\n/**\n * @description: \u4E00\u4E2Aobj\u751F\u6210\u4E00\u4E2A\u4E00\u884C\u6587\u5B57\n * @param {*} obj\n * @return {*}\n */\nfunction setMd(obj: ItemType): string {\n let filesString = ''\n // \u628A\u6587\u4EF6\u5939\u8F93\u51FA,\u5E76\u4E14level+1\n const blank = ' '.repeat(obj.level) // \u91CD\u590D\u7A7A\u767D\n if (obj.isDir) {\n filesString += `${blank}+ ${obj.name}\\n`\n } else {\n const index = obj.name.lastIndexOf('.')\n const lastName = obj.name.substring(index)\n // \u8FD9\u91CC\u53EA\u83B7\u53D6\u67D0\u540E\u7F00\u6587\u4EF6\u7684\u6CE8\u91CA\n if (includeArrs.includes(lastName) || index === -1) {\n filesString += `${blank} ${obj.name} ${obj.note}\\n`\n }\n }\n return filesString\n}\n\nexport function getMd() {\n console.log('\\x1B[36m%s\\x1B[0m', '*** run location: ', path.resolve('./'))\n const nodes = getFileNodes()\n const note = getNote(nodes) // \u5F97\u5230\u6240\u6709note\u7684\u6570\u7EC4\n const md = note.join('') // \u6570\u7EC4\u8F6C\u5B57\u7B26\u4E32\n if (md.length > 0) {\n console.log('\\x1B[36m%s\\x1B[0m', '*** Automatic generation completed ! ')\n }\n return md\n}\n\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,mBAAiB;AACjB,iBAAe;;;ACHf,gBAAe;AACf,kBAAiB;AAOjB,iBAAiB,MAA+B;AAC9C,QAAM,MAAM,kBAAG,aAAa,MAAM;AAClC,QAAM,OAAO,IAAI,MAAM;AAEvB,QAAM,IACJ,KAAK,GAAG,QAAQ,cAAc,MAC7B,MAAK,GAAG,QAAQ,SAAS,MAAM,KAAK,GAAG,QAAQ,QAAQ,MAAM,KAAK,GAAG,QAAQ,QAAQ,MAClF,KAAK,KACL;AAEN,SAAO;AAAA;AAGT,IAAM,YAAY,CAAC,OAAO,UAAU,gBAAgB,WAAW,QAAQ,WAAW,QAAQ,UAAU;AAEpG,IAAM,cAAc,CAAC,OAAO,QAAQ;AAiB5B,sBAAsB,QAAyB,IAAI,MAAM,oBAAK,QAAQ,OAAO,QAAQ,GAAoB;AAC/G,QAA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;AAQT,eAAe,KAAuB;AACpC,MAAI,cAAc;AAElB,QAAM,QAAQ,KAAK,OAAO,IAAI;AAC9B,MAAI,IAAI,OAAO;AACb,mBAAe,GAAG,UAAU,IAAI;AAAA;AAAA,SAC3B;AACL,UAAM,QAAQ,IAAI,KAAK,YAAY;AACnC,UAAM,WAAW,IAAI,KAAK,UAAU;AAEpC,QAAI,YAAY,SAAS,aAAa,UAAU,IAAI;AAClD,qBAAe,GAAG,UAAU,IAAI,mBAAmB,IAAI;AAAA;AAAA;AAAA;AAG3D,SAAO;AAAA;AAGF,iBAAiB;AACtB,UAAQ,IAAI,eAAqB,sBAAsB,oBAAK,QAAQ;AACpE,QAAM,QAAQ;AACd,QAAM,OAAO,QAAQ;AACrB,QAAM,KAAK,KAAK,KAAK;AACrB,MAAI,GAAG,SAAS,GAAG;AACjB,YAAQ,IAAI,eAAqB;AAAA;AAEnC,SAAO;AAAA;;;ADtIT,IAAM,YAAY,qBAAK;AAoBvB,iBAAiB,MAAc,UAAkB;AAC/C,QAAM,OAAO,qBAAK,QAAQ,WAAW;AACrC,QAAM,MAAM;AACZ,QAAM,OAAO;AAEb,qBAAG,UAAU,MAAM,MAAM,OAAO,MAAM,EAAE,UAAU,UAAU,CAAC,QAAQ;AAAE,YAAQ,MAAM;AAAA;AAAA;AAQvF,gBAAgB;AACd,QAAM,KAAK;AAIX,UAAQ,IAAI,eAAqB,kBAAkB,GAAG,qBAAK,QAAQ;AACnE,UAAQ,IAAI,GAAG,qBAAK,QAAQ;AAAA;AAE9B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,137 @@
1
+ /*!
2
+ * agmd v0.0.11
3
+ * author:majun <253495832@qq.com>
4
+ * Fri Dec 17 2021 09:30:50 GMT+0800 (中国标准时间)
5
+ */
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __reExport = (target, module2, copyDefault, desc) => {
18
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
19
+ for (let key of __getOwnPropNames(module2))
20
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
21
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
22
+ }
23
+ return target;
24
+ };
25
+ var __toESM = (module2, isNodeMode) => {
26
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
27
+ };
28
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
29
+ return (module2, temp) => {
30
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
31
+ };
32
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
33
+
34
+ // src/index.ts
35
+ var src_exports = {};
36
+ __export(src_exports, {
37
+ getFileNodes: () => getFileNodes,
38
+ getMd: () => getMd
39
+ });
40
+ var import_fs = __toESM(require("fs"));
41
+ var import_path = __toESM(require("path"));
42
+ function getFile(file) {
43
+ const str = import_fs.default.readFileSync(file, "utf-8");
44
+ const sarr = str.split(/[\n,]/g);
45
+ const f = sarr[0].indexOf("eslint") === -1 && (sarr[0].indexOf("-->") > -1 || sarr[0].indexOf("*/") > -1 || sarr[0].indexOf("//") > -1) ? sarr[0] : "";
46
+ return f;
47
+ }
48
+ var filterArr = ["img", "styles", "node_modules", "LICENSE", ".git", ".github", "dist", ".husky", ".vscode"];
49
+ var includeArrs = [".js", ".vue", ".ts"];
50
+ function getFileNodes(nodes = [], dir = import_path.default.resolve("./"), level = 0) {
51
+ const files = import_fs.default.readdirSync(dir).map((item) => {
52
+ const fullPath = import_path.default.join(dir, item);
53
+ const isDir = import_fs.default.lstatSync(fullPath).isDirectory();
54
+ return {
55
+ name: item,
56
+ isDir,
57
+ level,
58
+ note: ""
59
+ };
60
+ }).sort((a, b) => {
61
+ if (!a.isDir && b.isDir)
62
+ return 1;
63
+ if (a.isDir && !b.isDir)
64
+ return -1;
65
+ if (a.isDir && b.isDir || !a.isDir && !b.isDir)
66
+ return 0;
67
+ return 0;
68
+ });
69
+ for (let index = 0; index < files.length; index += 1) {
70
+ const item = files[index];
71
+ let note = "";
72
+ const arr = filterArr.findIndex((obj) => obj === item.name);
73
+ if (arr === -1) {
74
+ const fullPath = import_path.default.join(dir, item.name);
75
+ const isDir = import_fs.default.lstatSync(fullPath).isDirectory();
76
+ if (isDir) {
77
+ getFileNodes(item.children = [], fullPath, level + 1);
78
+ } else {
79
+ const i = fullPath.lastIndexOf(".");
80
+ const lastName = fullPath.substring(i);
81
+ if ([".js", ".vue", ".ts"].includes(lastName)) {
82
+ note = getFile(fullPath);
83
+ }
84
+ item.note = note;
85
+ }
86
+ nodes.push(item);
87
+ }
88
+ }
89
+ return nodes;
90
+ }
91
+ function getNote(datas, keys) {
92
+ const nodes = keys || [];
93
+ datas.forEach((obj) => {
94
+ if (obj.children) {
95
+ const md = setMd(obj);
96
+ nodes.push(md);
97
+ getNote(obj.children, nodes);
98
+ } else {
99
+ const md = setMd(obj);
100
+ nodes.push(md);
101
+ }
102
+ });
103
+ return nodes;
104
+ }
105
+ function setMd(obj) {
106
+ let filesString = "";
107
+ const blank = " ".repeat(obj.level);
108
+ if (obj.isDir) {
109
+ filesString += `${blank}+ ${obj.name}
110
+ `;
111
+ } else {
112
+ const index = obj.name.lastIndexOf(".");
113
+ const lastName = obj.name.substring(index);
114
+ if (includeArrs.includes(lastName) || index === -1) {
115
+ filesString += `${blank} ${obj.name} ${obj.note}
116
+ `;
117
+ }
118
+ }
119
+ return filesString;
120
+ }
121
+ function getMd() {
122
+ console.log("%s", "*** run location: ", import_path.default.resolve("./"));
123
+ const nodes = getFileNodes();
124
+ const note = getNote(nodes);
125
+ const md = note.join("");
126
+ if (md.length > 0) {
127
+ console.log("%s", "*** Automatic generation completed ! ");
128
+ }
129
+ return md;
130
+ }
131
+ module.exports = __toCommonJS(src_exports);
132
+ // Annotate the CommonJS export names for ESM import in node:
133
+ 0 && (module.exports = {
134
+ getFileNodes,
135
+ getMd
136
+ });
137
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["import fs from 'fs'\nimport path from 'path'\n\n/**\n * @description: \u83B7\u53D6\u6587\u4EF6\u7684\u5934\u90E8\u6CE8\u91CA\n * @param {*} file\n * @return {*}\n */\nfunction getFile(file: fs.PathOrFileDescriptor) {\n const str = fs.readFileSync(file, 'utf-8')\n const sarr = str.split(/[\\n,]/g)\n // console.log(file);\n const f =\n sarr[0].indexOf('eslint') === -1 &&\n (sarr[0].indexOf('-->') > -1 || sarr[0].indexOf('*/') > -1 || sarr[0].indexOf('//') > -1)\n ? sarr[0]\n : ''\n // console.log(f);\n return f\n}\n// \u8FC7\u6EE4\u6587\u4EF6\u5939\nconst filterArr = ['img', 'styles', 'node_modules', 'LICENSE', '.git', '.github', 'dist', '.husky', '.vscode']\n// \u8FD9\u91CC\u53EA\u83B7\u53D6\u67D0\u540E\u7F00\u6587\u4EF6\u7684\u6CE8\u91CA,\u9700\u8981\u5176\u4ED6\u8FD9\u91CC\u52A0\u5165\nconst includeArrs = ['.js', '.vue', '.ts']\n\nexport type ItemType ={\n name: string\n isDir: boolean\n level: number\n note: string\n children?: ItemType[]\n}\n\n/**\n * @description: \u751F\u6210\u6240\u6709\u6587\u4EF6\u7684node\u4FE1\u606F\n * @param {*} nodes\n * @param {*} dir\n * @param {*} level\n * @return {*}\n */\n export function getFileNodes(nodes: Array<ItemType> = [], dir = path.resolve('./'), level = 0): Array<ItemType> {\n const files = fs\n .readdirSync(dir)\n .map((item) => {\n const fullPath = path.join(dir, item)\n const isDir = fs.lstatSync(fullPath).isDirectory()\n return {\n name: item,\n isDir,\n level,\n note: ''\n } as ItemType\n })\n // \u5BF9\u6587\u4EF6\u5939\u548C\u6587\u4EF6\u8FDB\u884C\u6392\u5E8F,\u8981\u4E0D\u7136\u751F\u6210\u7684\u548C\u7F16\u8F91\u5668\u6253\u5F00\u7684\u987A\u5E8F\u4E0D\u5BF9\u5E94\n .sort((a, b) => {\n if (!a.isDir && b.isDir) return 1\n if (a.isDir && !b.isDir) return -1\n if ((a.isDir && b.isDir) || (!a.isDir && !b.isDir)) return 0\n return 0\n })\n for (let index = 0; index < files.length; index += 1) {\n const item = files[index]\n let note = '' // \u6587\u4EF6\u6CE8\u91CA\n const arr = filterArr.findIndex((obj) => obj === item.name)\n if (arr === -1) {\n const fullPath = path.join(dir, item.name)\n const isDir = fs.lstatSync(fullPath).isDirectory()\n if (isDir) {\n // \u9012\u5F52\n getFileNodes((item.children = []), fullPath, level + 1)\n } else {\n const i = fullPath.lastIndexOf('.')\n const lastName = fullPath.substring(i)\n // \u8FD9\u91CC\u53EA\u83B7\u53D6js\u548Cvue,ts\u6587\u4EF6\u7684\u6CE8\u91CA\n if (['.js', '.vue', '.ts'].includes(lastName)) {\n note = getFile(fullPath)\n }\n item.note = note\n }\n nodes.push(item)\n }\n }\n // \u63A7\u5236\u8FD4\u56DE\u65F6\u95F4\u8282\u70B9,\u4E0D\u8BA9\u63D0\u524D\u8FD4\u56DE\n return nodes\n}\n\n/**\n * @description: \u9012\u5F52\u5F97\u5230\u6587\u4EF6\u540D+note\n * @param {*} datas\n * @param {*} keys\n * @return {*}\n */\nfunction getNote(datas: Array<ItemType>, keys?: string[]) {\n const nodes = keys || []\n datas.forEach((obj: ItemType) => {\n if (obj.children) {\n // \u6587\u4EF6\u5939\n const md = setMd(obj)\n nodes.push(md)\n getNote(obj.children, nodes)\n }\n // \u6587\u4EF6\n else {\n const md = setMd(obj)\n nodes.push(md)\n }\n })\n return nodes\n}\n\n/**\n * @description: \u4E00\u4E2Aobj\u751F\u6210\u4E00\u4E2A\u4E00\u884C\u6587\u5B57\n * @param {*} obj\n * @return {*}\n */\nfunction setMd(obj: ItemType): string {\n let filesString = ''\n // \u628A\u6587\u4EF6\u5939\u8F93\u51FA,\u5E76\u4E14level+1\n const blank = ' '.repeat(obj.level) // \u91CD\u590D\u7A7A\u767D\n if (obj.isDir) {\n filesString += `${blank}+ ${obj.name}\\n`\n } else {\n const index = obj.name.lastIndexOf('.')\n const lastName = obj.name.substring(index)\n // \u8FD9\u91CC\u53EA\u83B7\u53D6\u67D0\u540E\u7F00\u6587\u4EF6\u7684\u6CE8\u91CA\n if (includeArrs.includes(lastName) || index === -1) {\n filesString += `${blank} ${obj.name} ${obj.note}\\n`\n }\n }\n return filesString\n}\n\nexport function getMd() {\n console.log('\\x1B[36m%s\\x1B[0m', '*** run location: ', path.resolve('./'))\n const nodes = getFileNodes()\n const note = getNote(nodes) // \u5F97\u5230\u6240\u6709note\u7684\u6570\u7EC4\n const md = note.join('') // \u6570\u7EC4\u8F6C\u5B57\u7B26\u4E32\n if (md.length > 0) {\n console.log('\\x1B[36m%s\\x1B[0m', '*** Automatic generation completed ! ')\n }\n return md\n}\n\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,kBAAiB;AAOjB,iBAAiB,MAA+B;AAC9C,QAAM,MAAM,kBAAG,aAAa,MAAM;AAClC,QAAM,OAAO,IAAI,MAAM;AAEvB,QAAM,IACJ,KAAK,GAAG,QAAQ,cAAc,MAC7B,MAAK,GAAG,QAAQ,SAAS,MAAM,KAAK,GAAG,QAAQ,QAAQ,MAAM,KAAK,GAAG,QAAQ,QAAQ,MAClF,KAAK,KACL;AAE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Q;AACtB,QAAM,QAAQ,CAAC,QAAkB;AAC/B,QAAI,IAAI,UAAU;AAEhB,YAAM,KAAK,MAAM;AACjB,YAAM,KAAK;AACX,cAAQ,IAAI,UAAU;AAAA,WAGnB;AACH,YAAM,KAAK,MAAM;AACjB,YAAM,KAAK;AAAA;AAAA;AAGf,SAAO;AAAA;AAQT,eAAe,KAAuB;AACpC,MAAI,cAAc;AAElB,QAAM,QAAQ,KAAK,OAAO,IAAI;AAC9B,MAAI,IAAI,OAAO;AACb,mBAAe,GAAG,UAAU,IAAI;AAAA;AAAA,SAC3B;AACL,UAAM,QAAQ,IAAI,KAAK,YAAY;AACnC,UAAM,WAAW,IAAI,KAAK,UAAU;AAEpC,QAAI,YAAY,SAAS,aAAa,UAAU,IAAI;AAClD,qBAAe,GAAG,UAAU,IAAI,mBAAmB,IAAI;AAAA;AAAA;AAAA;AAG3D,SAAO;AAAA;AAGF,iBAAiB;AACtB,UAAQ,IAAI,eAAqB,sBAAsB,oBAAK,QAAQ;AACpE,QAAM,QAAQ;AACd,QAAM,OAAO,QAAQ;AACrB,QAAM,KAAK,KAAK,KAAK;AACrB,MAAI,GAAG,SAAS,GAAG;AACjB,YAAQ,IAAI,eAAqB;AAAA;AAEnC,SAAO;AAAA;",
6
+ "names": []
7
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export declare type ItemType = {
2
+ name: string;
3
+ isDir: boolean;
4
+ level: number;
5
+ note: string;
6
+ children?: ItemType[];
7
+ };
8
+ export declare function getFileNodes(nodes?: Array<ItemType>, dir?: string, level?: number): Array<ItemType>;
9
+ export declare function getMd(): string;
@@ -0,0 +1,102 @@
1
+ /*!
2
+ * agmd v0.0.11
3
+ * author:majun <253495832@qq.com>
4
+ * Fri Dec 17 2021 09:30:50 GMT+0800 (中国标准时间)
5
+ */
6
+ // src/index.ts
7
+ import fs from "fs";
8
+ import path from "path";
9
+ function getFile(file) {
10
+ const str = fs.readFileSync(file, "utf-8");
11
+ const sarr = str.split(/[\n,]/g);
12
+ const f = sarr[0].indexOf("eslint") === -1 && (sarr[0].indexOf("-->") > -1 || sarr[0].indexOf("*/") > -1 || sarr[0].indexOf("//") > -1) ? sarr[0] : "";
13
+ return f;
14
+ }
15
+ var filterArr = ["img", "styles", "node_modules", "LICENSE", ".git", ".github", "dist", ".husky", ".vscode"];
16
+ var includeArrs = [".js", ".vue", ".ts"];
17
+ function getFileNodes(nodes = [], dir = path.resolve("./"), level = 0) {
18
+ const files = fs.readdirSync(dir).map((item) => {
19
+ const fullPath = path.join(dir, item);
20
+ const isDir = fs.lstatSync(fullPath).isDirectory();
21
+ return {
22
+ name: item,
23
+ isDir,
24
+ level,
25
+ note: ""
26
+ };
27
+ }).sort((a, b) => {
28
+ if (!a.isDir && b.isDir)
29
+ return 1;
30
+ if (a.isDir && !b.isDir)
31
+ return -1;
32
+ if (a.isDir && b.isDir || !a.isDir && !b.isDir)
33
+ return 0;
34
+ return 0;
35
+ });
36
+ for (let index = 0; index < files.length; index += 1) {
37
+ const item = files[index];
38
+ let note = "";
39
+ const arr = filterArr.findIndex((obj) => obj === item.name);
40
+ if (arr === -1) {
41
+ const fullPath = path.join(dir, item.name);
42
+ const isDir = fs.lstatSync(fullPath).isDirectory();
43
+ if (isDir) {
44
+ getFileNodes(item.children = [], fullPath, level + 1);
45
+ } else {
46
+ const i = fullPath.lastIndexOf(".");
47
+ const lastName = fullPath.substring(i);
48
+ if ([".js", ".vue", ".ts"].includes(lastName)) {
49
+ note = getFile(fullPath);
50
+ }
51
+ item.note = note;
52
+ }
53
+ nodes.push(item);
54
+ }
55
+ }
56
+ return nodes;
57
+ }
58
+ function getNote(datas, keys) {
59
+ const nodes = keys || [];
60
+ datas.forEach((obj) => {
61
+ if (obj.children) {
62
+ const md = setMd(obj);
63
+ nodes.push(md);
64
+ getNote(obj.children, nodes);
65
+ } else {
66
+ const md = setMd(obj);
67
+ nodes.push(md);
68
+ }
69
+ });
70
+ return nodes;
71
+ }
72
+ function setMd(obj) {
73
+ let filesString = "";
74
+ const blank = " ".repeat(obj.level);
75
+ if (obj.isDir) {
76
+ filesString += `${blank}+ ${obj.name}
77
+ `;
78
+ } else {
79
+ const index = obj.name.lastIndexOf(".");
80
+ const lastName = obj.name.substring(index);
81
+ if (includeArrs.includes(lastName) || index === -1) {
82
+ filesString += `${blank} ${obj.name} ${obj.note}
83
+ `;
84
+ }
85
+ }
86
+ return filesString;
87
+ }
88
+ function getMd() {
89
+ console.log("%s", "*** run location: ", path.resolve("./"));
90
+ const nodes = getFileNodes();
91
+ const note = getNote(nodes);
92
+ const md = note.join("");
93
+ if (md.length > 0) {
94
+ console.log("%s", "*** Automatic generation completed ! ");
95
+ }
96
+ return md;
97
+ }
98
+ export {
99
+ getFileNodes,
100
+ getMd
101
+ };
102
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["import fs from 'fs'\nimport path from 'path'\n\n/**\n * @description: \u83B7\u53D6\u6587\u4EF6\u7684\u5934\u90E8\u6CE8\u91CA\n * @param {*} file\n * @return {*}\n */\nfunction getFile(file: fs.PathOrFileDescriptor) {\n const str = fs.readFileSync(file, 'utf-8')\n const sarr = str.split(/[\\n,]/g)\n // console.log(file);\n const f =\n sarr[0].indexOf('eslint') === -1 &&\n (sarr[0].indexOf('-->') > -1 || sarr[0].indexOf('*/') > -1 || sarr[0].indexOf('//') > -1)\n ? sarr[0]\n : ''\n // console.log(f);\n return f\n}\n// \u8FC7\u6EE4\u6587\u4EF6\u5939\nconst filterArr = ['img', 'styles', 'node_modules', 'LICENSE', '.git', '.github', 'dist', '.husky', '.vscode']\n// \u8FD9\u91CC\u53EA\u83B7\u53D6\u67D0\u540E\u7F00\u6587\u4EF6\u7684\u6CE8\u91CA,\u9700\u8981\u5176\u4ED6\u8FD9\u91CC\u52A0\u5165\nconst includeArrs = ['.js', '.vue', '.ts']\n\nexport type ItemType ={\n name: string\n isDir: boolean\n level: number\n note: string\n children?: ItemType[]\n}\n\n/**\n * @description: \u751F\u6210\u6240\u6709\u6587\u4EF6\u7684node\u4FE1\u606F\n * @param {*} nodes\n * @param {*} dir\n * @param {*} level\n * @return {*}\n */\n export function getFileNodes(nodes: Array<ItemType> = [], dir = path.resolve('./'), level = 0): Array<ItemType> {\n const files = fs\n .readdirSync(dir)\n .map((item) => {\n const fullPath = path.join(dir, item)\n const isDir = fs.lstatSync(fullPath).isDirectory()\n return {\n name: item,\n isDir,\n level,\n note: ''\n } as ItemType\n })\n // \u5BF9\u6587\u4EF6\u5939\u548C\u6587\u4EF6\u8FDB\u884C\u6392\u5E8F,\u8981\u4E0D\u7136\u751F\u6210\u7684\u548C\u7F16\u8F91\u5668\u6253\u5F00\u7684\u987A\u5E8F\u4E0D\u5BF9\u5E94\n .sort((a, b) => {\n if (!a.isDir && b.isDir) return 1\n if (a.isDir && !b.isDir) return -1\n if ((a.isDir && b.isDir) || (!a.isDir && !b.isDir)) return 0\n return 0\n })\n for (let index = 0; index < files.length; index += 1) {\n const item = files[index]\n let note = '' // \u6587\u4EF6\u6CE8\u91CA\n const arr = filterArr.findIndex((obj) => obj === item.name)\n if (arr === -1) {\n const fullPath = path.join(dir, item.name)\n const isDir = fs.lstatSync(fullPath).isDirectory()\n if (isDir) {\n // \u9012\u5F52\n getFileNodes((item.children = []), fullPath, level + 1)\n } else {\n const i = fullPath.lastIndexOf('.')\n const lastName = fullPath.substring(i)\n // \u8FD9\u91CC\u53EA\u83B7\u53D6js\u548Cvue,ts\u6587\u4EF6\u7684\u6CE8\u91CA\n if (['.js', '.vue', '.ts'].includes(lastName)) {\n note = getFile(fullPath)\n }\n item.note = note\n }\n nodes.push(item)\n }\n }\n // \u63A7\u5236\u8FD4\u56DE\u65F6\u95F4\u8282\u70B9,\u4E0D\u8BA9\u63D0\u524D\u8FD4\u56DE\n return nodes\n}\n\n/**\n * @description: \u9012\u5F52\u5F97\u5230\u6587\u4EF6\u540D+note\n * @param {*} datas\n * @param {*} keys\n * @return {*}\n */\nfunction getNote(datas: Array<ItemType>, keys?: string[]) {\n const nodes = keys || []\n datas.forEach((obj: ItemType) => {\n if (obj.children) {\n // \u6587\u4EF6\u5939\n const md = setMd(obj)\n nodes.push(md)\n getNote(obj.children, nodes)\n }\n // \u6587\u4EF6\n else {\n const md = setMd(obj)\n nodes.push(md)\n }\n })\n return nodes\n}\n\n/**\n * @description: \u4E00\u4E2Aobj\u751F\u6210\u4E00\u4E2A\u4E00\u884C\u6587\u5B57\n * @param {*} obj\n * @return {*}\n */\nfunction setMd(obj: ItemType): string {\n let filesString = ''\n // \u628A\u6587\u4EF6\u5939\u8F93\u51FA,\u5E76\u4E14level+1\n const blank = ' '.repeat(obj.level) // \u91CD\u590D\u7A7A\u767D\n if (obj.isDir) {\n filesString += `${blank}+ ${obj.name}\\n`\n } else {\n const index = obj.name.lastIndexOf('.')\n const lastName = obj.name.substring(index)\n // \u8FD9\u91CC\u53EA\u83B7\u53D6\u67D0\u540E\u7F00\u6587\u4EF6\u7684\u6CE8\u91CA\n if (includeArrs.includes(lastName) || index === -1) {\n filesString += `${blank} ${obj.name} ${obj.note}\\n`\n }\n }\n return filesString\n}\n\nexport function getMd() {\n console.log('\\x1B[36m%s\\x1B[0m', '*** run location: ', path.resolve('./'))\n const nodes = getFileNodes()\n const note = getNote(nodes) // \u5F97\u5230\u6240\u6709note\u7684\u6570\u7EC4\n const md = note.join('') // \u6570\u7EC4\u8F6C\u5B57\u7B26\u4E32\n if (md.length > 0) {\n console.log('\\x1B[36m%s\\x1B[0m', '*** Automatic generation completed ! ')\n }\n return md\n}\n\n"],
5
+ "mappings": ";;;;;;AAAA;AACA;AAOA,iBAAiB,MAA+B;AAC9C,QAAM,MAAM,GAAG,aAAa,MAAM;AAClC,QAAM,OAAO,IAAI,MAAM;AAEvB,QAAM,IACJ,KAAK,GAAG,QAAQ,cAAc,MAC7B,MAAK,GAAG,QAAQ,SAAS,MAAM,KAAK,GAAG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AAO;AAAA;AAST,iBAAiB,OAAwB,MAAiB;AACxD,QAAM,QAAQ,QAAQ;AACtB,QAAM,QAAQ,CAAC,QAAkB;AAC/B,QAAI,IAAI,UAAU;AAEhB,YAAM,KAAK,MAAM;AACjB,YAAM,KAAK;AACX,cAAQ,IAAI,UAAU;AAAA,WAGnB;AACH,YAAM,KAAK,MAAM;AACjB,YAAM,KAAK;AAAA;AAAA;AAGf,SAAO;AAAA;AAQT,eAAe,KAAuB;AACpC,MAAI,cAAc;AAElB,QAAM,QAAQ,KAAK,OAAO,IAAI;AAC9B,MAAI,IAAI,OAAO;AACb,mBAAe,GAAG,UAAU,IAAI;AAAA;AAAA,SAC3B;AACL,UAAM,QAAQ,IAAI,KAAK,YAAY;AACnC,UAAM,WAAW,IAAI,KAAK,UAAU;AAEpC,QAAI,YAAY,SAAS,aAAa,UAAU,IAAI;AAClD,qBAAe,GAAG,UAAU,IAAI,mBAAmB,IAAI;AAAA;AAAA;AAAA;AAG3D,SAAO;AAAA;AAGF,iBAAiB;AACtB,UAAQ,IAAI,eAAqB,sBAAsB,KAAK,QAAQ;AACpE,QAAM,QAAQ;AACd,QAAM,OAAO,QAAQ;AACrB,QAAM,KAAK,KAAK,KAAK;AACrB,MAAI,GAAG,SAAS,GAAG;AACjB,YAAQ,IAAI,eAAqB;AAAA;AAEnC,SAAO;AAAA;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,29 +1,58 @@
1
1
  {
2
2
  "name": "agmd",
3
- "version": "0.0.8",
4
- "description": "auto generate md for node",
5
- "type": "module",
3
+ "version": "0.1.3",
4
+ "description": "auto generate markdown for node",
6
5
  "keywords": [
7
- "fs",
6
+ "node",
8
7
  "auto",
9
8
  "generate",
10
- "md"
9
+ "md",
10
+ "markdown"
11
11
  ],
12
- "main": "module.js",
12
+ "main": "lib/index.cjs.js",
13
+ "module": "lib/index.esm.js",
14
+ "typings": "lib/index.d.ts",
13
15
  "bin": {
14
16
  "agmd": "./bin/agmd.js"
15
17
  },
16
- "author": "kakajun <253495832@qq.com>",
18
+ "scripts": {
19
+ "lint": "eslint \"src/**/*.{ts}\" --max-warnings=0",
20
+ "build": "node builder.js",
21
+ "prepare": "husky install",
22
+ "lint-fix": "eslint --fix --ext .js,.ts",
23
+ "test": "npm run build && node bin/agmd"
24
+ },
25
+ "author": "majun <253495832@qq.com>",
17
26
  "repository": {
18
27
  "type": "git",
19
28
  "url": "git@github.com:majun2232/auto-generate-md.git"
20
29
  },
30
+ "devDependencies": {
31
+ "@types/node": "^17.0.0",
32
+ "@typescript-eslint/eslint-plugin": "^4.31.0",
33
+ "@typescript-eslint/parser": "^4.31.0",
34
+ "agmd": "0.1.1",
35
+ "esbuild": "^0.14.5",
36
+ "esbuild-plugin-d.ts": "^1.1.0",
37
+ "eslint": "^7.32.0",
38
+ "eslint-config-prettier": "^8.3.0",
39
+ "fs-extra": "^10.0.0",
40
+ "husky": "^7.0.2",
41
+ "lint-staged": "^11.1.2",
42
+ "prettier": "^2.5.1",
43
+ "typescript": "^4.4.3"
44
+ },
45
+ "lint-staged": {
46
+ "*.{ts,tsx,js}": "prettier --write",
47
+ "*.{ts,tsx}": "eslint --fix"
48
+ },
21
49
  "license": "MIT",
22
50
  "bugs": {
23
51
  "url": "https://github.com/majun2232/auto-generate-md/issues"
24
52
  },
25
53
  "homepage": "https://github.com/majun2232/auto-generate-md",
26
54
  "files": [
27
- "bin"
55
+ "bin",
56
+ "lib"
28
57
  ]
29
58
  }
package/module.js DELETED
@@ -1,145 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- /**
5
- * @description: 获取文件的头部注释
6
- * @param {*} file
7
- * @return {*}
8
- */
9
- function getFile(file) {
10
- var str = fs.readFileSync(file, "utf-8");
11
- let sarr = str.split(/[\n,]/g);
12
- // console.log(file);
13
- let f =
14
- sarr[0].indexOf("eslint") == -1 &&
15
- (sarr[0].indexOf("-->") > -1 ||
16
- sarr[0].indexOf("*/") > -1 ||
17
- sarr[0].indexOf("//") > -1)
18
- ? sarr[0]
19
- : "";
20
- // console.log(f);
21
- return f;
22
- }
23
- // 过滤文件夹
24
- const filterArr = [
25
- "img",
26
- "styles",
27
- "node_modules",
28
- ".git",
29
- ".github",
30
- "dist",
31
- ".husky",
32
- ".vscode",
33
- ];
34
- // 这里只获取某后缀文件的注释,需要其他这里加入
35
- const includeArrs = [".js", ".vue", ".ts"];
36
-
37
- /**
38
- * @description: 生成所有文件的node信息
39
- * @param {*} nodes
40
- * @param {*} dir
41
- * @param {*} level
42
- * @return {*}
43
- */
44
- function getFileNodes(nodes = [], dir = path.resolve("./"), level = 0) {
45
- let files = fs
46
- .readdirSync(dir)
47
- .map((item) => {
48
- const fullPath = path.join(dir, item);
49
- const isDir = fs.lstatSync(fullPath).isDirectory();
50
- return {
51
- name: item,
52
- isDir: isDir,
53
- level,
54
- };
55
- })
56
- // 对文件夹和文件进行排序,要不然生成的和编辑器打开的顺序不对应
57
- .sort((a, b) => {
58
- if (!a.isDir && b.isDir) return 1;
59
- if (a.isDir && !b.isDir) return -1;
60
- if ((a.isDir && b.isDir) || (!a.isDir && !b.isDir)) return 0;
61
- });
62
- for (let index = 0; index < files.length; index++) {
63
- const item = files[index];
64
- let note = ""; // 文件注释
65
- let arr = filterArr.findIndex((obj) => obj === item.name);
66
- if (arr === -1) {
67
- const fullPath = path.join(dir, item.name);
68
- const isDir = fs.lstatSync(fullPath).isDirectory();
69
- if (isDir) {
70
- // 递归
71
- getFileNodes((item.children = []), fullPath, level + 1);
72
- } else {
73
- const index = fullPath.lastIndexOf(".");
74
- const lastName = fullPath.substring(index);
75
- // 这里只获取js和vue,ts文件的注释
76
- if ([".js", ".vue", ".ts"].includes(lastName)) {
77
- note = getFile(fullPath);
78
- }
79
- item.note = note;
80
- }
81
- nodes.push(item);
82
- }
83
- }
84
- // 控制返回时间节点,不让提前返回
85
- return nodes;
86
- }
87
-
88
- /**
89
- * @description: 递归得到文件名+note
90
- * @param {*} datas
91
- * @param {*} keys
92
- * @return {*}
93
- */
94
- function getNote(datas, keys) {
95
- let nodes = keys ? keys : [];
96
- datas.forEach((obj) => {
97
- if (obj.children) {
98
- // 文件夹
99
- let md = setMd(obj);
100
- nodes.push(md);
101
- getNote(obj.children, nodes);
102
- }
103
- // 文件
104
- else {
105
- let md = setMd(obj);
106
- nodes.push(md);
107
- }
108
- });
109
- return nodes;
110
- }
111
-
112
- /**
113
- * @description: 一个obj生成一个一行文字
114
- * @param {*} obj
115
- * @return {*}
116
- */
117
- function setMd(obj) {
118
- let filesString = "";
119
- // 把文件夹输出,并且level+1
120
- const blank = " ".repeat(obj.level); // 重复空白
121
- if (obj.isDir) {
122
- filesString += `${blank}+ ${obj.name}\n`;
123
- } else {
124
- var index = obj.name.lastIndexOf(".");
125
- const lastName = obj.name.substring(index);
126
- // 这里只获取某后缀文件的注释
127
- if ( includeArrs.includes(lastName) || index === -1) {
128
- filesString += `${blank} ${obj.name} ${obj.note}\n`;
129
- }
130
- }
131
- return filesString;
132
- }
133
-
134
- function getMd() {
135
- console.log("\x1B[36m%s\x1B[0m", "*** run location: ", path.resolve("./"));
136
- const nodes = getFileNodes();
137
- const note = getNote(nodes); // 得到所有note的数组
138
- const md = note.join(""); // 数组转字符串
139
- if (md.length > 0) {
140
- console.log("\x1B[36m%s\x1B[0m", "*** Automatic generation completed ! ");
141
- }
142
- return md;
143
- }
144
- /* 导出获取md的getMd方法 */
145
- export { getMd, getFileNodes };