agmd 0.1.4 → 0.2.9
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 +21 -21
- package/README.EN.md +175 -108
- package/README.md +103 -57
- package/bin/agmd.js +19 -134
- package/bin/agmd.js.map +3 -3
- package/bin/readme-file.js +1 -0
- package/lib/index.cjs.js +116 -34
- package/lib/index.cjs.js.map +2 -2
- package/lib/index.d.ts +14 -3
- package/lib/index.esm.js +114 -33
- package/lib/index.esm.js.map +2 -2
- package/package.json +11 -6
package/bin/agmd.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
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": "
|
|
3
|
+
"sources": ["../node_modules/arg/index.js", "../src/agmd.ts", "../src/index.ts", "../script/cli/index.ts", "../script/help/index.ts", "../script/cli/handle.ts"],
|
|
4
|
+
"sourcesContent": ["const flagSymbol = Symbol('arg flag');\n\nclass ArgError extends Error {\n\tconstructor(msg, code) {\n\t\tsuper(msg);\n\t\tthis.name = 'ArgError';\n\t\tthis.code = code;\n\n\t\tObject.setPrototypeOf(this, ArgError.prototype);\n\t}\n}\n\nfunction arg(\n\topts,\n\t{\n\t\targv = process.argv.slice(2),\n\t\tpermissive = false,\n\t\tstopAtPositional = false\n\t} = {}\n) {\n\tif (!opts) {\n\t\tthrow new ArgError(\n\t\t\t'argument specification object is required',\n\t\t\t'ARG_CONFIG_NO_SPEC'\n\t\t);\n\t}\n\n\tconst result = { _: [] };\n\n\tconst aliases = {};\n\tconst handlers = {};\n\n\tfor (const key of Object.keys(opts)) {\n\t\tif (!key) {\n\t\t\tthrow new ArgError(\n\t\t\t\t'argument key cannot be an empty string',\n\t\t\t\t'ARG_CONFIG_EMPTY_KEY'\n\t\t\t);\n\t\t}\n\n\t\tif (key[0] !== '-') {\n\t\t\tthrow new ArgError(\n\t\t\t\t`argument key must start with '-' but found: '${key}'`,\n\t\t\t\t'ARG_CONFIG_NONOPT_KEY'\n\t\t\t);\n\t\t}\n\n\t\tif (key.length === 1) {\n\t\t\tthrow new ArgError(\n\t\t\t\t`argument key must have a name; singular '-' keys are not allowed: ${key}`,\n\t\t\t\t'ARG_CONFIG_NONAME_KEY'\n\t\t\t);\n\t\t}\n\n\t\tif (typeof opts[key] === 'string') {\n\t\t\taliases[key] = opts[key];\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet type = opts[key];\n\t\tlet isFlag = false;\n\n\t\tif (\n\t\t\tArray.isArray(type) &&\n\t\t\ttype.length === 1 &&\n\t\t\ttypeof type[0] === 'function'\n\t\t) {\n\t\t\tconst [fn] = type;\n\t\t\ttype = (value, name, prev = []) => {\n\t\t\t\tprev.push(fn(value, name, prev[prev.length - 1]));\n\t\t\t\treturn prev;\n\t\t\t};\n\t\t\tisFlag = fn === Boolean || fn[flagSymbol] === true;\n\t\t} else if (typeof type === 'function') {\n\t\t\tisFlag = type === Boolean || type[flagSymbol] === true;\n\t\t} else {\n\t\t\tthrow new ArgError(\n\t\t\t\t`type missing or not a function or valid array type: ${key}`,\n\t\t\t\t'ARG_CONFIG_VAD_TYPE'\n\t\t\t);\n\t\t}\n\n\t\tif (key[1] !== '-' && key.length > 2) {\n\t\t\tthrow new ArgError(\n\t\t\t\t`short argument keys (with a single hyphen) must have only one character: ${key}`,\n\t\t\t\t'ARG_CONFIG_SHORTOPT_TOOLONG'\n\t\t\t);\n\t\t}\n\n\t\thandlers[key] = [type, isFlag];\n\t}\n\n\tfor (let i = 0, len = argv.length; i < len; i++) {\n\t\tconst wholeArg = argv[i];\n\n\t\tif (stopAtPositional && result._.length > 0) {\n\t\t\tresult._ = result._.concat(argv.slice(i));\n\t\t\tbreak;\n\t\t}\n\n\t\tif (wholeArg === '--') {\n\t\t\tresult._ = result._.concat(argv.slice(i + 1));\n\t\t\tbreak;\n\t\t}\n\n\t\tif (wholeArg.length > 1 && wholeArg[0] === '-') {\n\t\t\t/* eslint-disable operator-linebreak */\n\t\t\tconst separatedArguments =\n\t\t\t\twholeArg[1] === '-' || wholeArg.length === 2\n\t\t\t\t\t? [wholeArg]\n\t\t\t\t\t: wholeArg\n\t\t\t\t\t\t\t.slice(1)\n\t\t\t\t\t\t\t.split('')\n\t\t\t\t\t\t\t.map((a) => `-${a}`);\n\t\t\t/* eslint-enable operator-linebreak */\n\n\t\t\tfor (let j = 0; j < separatedArguments.length; j++) {\n\t\t\t\tconst arg = separatedArguments[j];\n\t\t\t\tconst [originalArgName, argStr] =\n\t\t\t\t\targ[1] === '-' ? arg.split(/=(.*)/, 2) : [arg, undefined];\n\n\t\t\t\tlet argName = originalArgName;\n\t\t\t\twhile (argName in aliases) {\n\t\t\t\t\targName = aliases[argName];\n\t\t\t\t}\n\n\t\t\t\tif (!(argName in handlers)) {\n\t\t\t\t\tif (permissive) {\n\t\t\t\t\t\tresult._.push(arg);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new ArgError(\n\t\t\t\t\t\t\t`unknown or unexpected option: ${originalArgName}`,\n\t\t\t\t\t\t\t'ARG_UNKNOWN_OPTION'\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst [type, isFlag] = handlers[argName];\n\n\t\t\t\tif (!isFlag && j + 1 < separatedArguments.length) {\n\t\t\t\t\tthrow new ArgError(\n\t\t\t\t\t\t`option requires argument (but was followed by another short argument): ${originalArgName}`,\n\t\t\t\t\t\t'ARG_MISSING_REQUIRED_SHORTARG'\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (isFlag) {\n\t\t\t\t\tresult[argName] = type(true, argName, result[argName]);\n\t\t\t\t} else if (argStr === undefined) {\n\t\t\t\t\tif (\n\t\t\t\t\t\targv.length < i + 2 ||\n\t\t\t\t\t\t(argv[i + 1].length > 1 &&\n\t\t\t\t\t\t\targv[i + 1][0] === '-' &&\n\t\t\t\t\t\t\t!(\n\t\t\t\t\t\t\t\targv[i + 1].match(/^-?\\d*(\\.(?=\\d))?\\d*$/) &&\n\t\t\t\t\t\t\t\t(type === Number ||\n\t\t\t\t\t\t\t\t\t// eslint-disable-next-line no-undef\n\t\t\t\t\t\t\t\t\t(typeof BigInt !== 'undefined' && type === BigInt))\n\t\t\t\t\t\t\t))\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst extended =\n\t\t\t\t\t\t\toriginalArgName === argName ? '' : ` (alias for ${argName})`;\n\t\t\t\t\t\tthrow new ArgError(\n\t\t\t\t\t\t\t`option requires argument: ${originalArgName}${extended}`,\n\t\t\t\t\t\t\t'ARG_MISSING_REQUIRED_LONGARG'\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tresult[argName] = type(argv[i + 1], argName, result[argName]);\n\t\t\t\t\t++i;\n\t\t\t\t} else {\n\t\t\t\t\tresult[argName] = type(argStr, argName, result[argName]);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tresult._.push(wholeArg);\n\t\t}\n\t}\n\n\treturn result;\n}\n\narg.flag = (fn) => {\n\tfn[flagSymbol] = true;\n\treturn fn;\n};\n\n// Utility types\narg.COUNT = arg.flag((v, name, existingCount) => (existingCount || 0) + 1);\n\n// Expose error class\narg.ArgError = ArgError;\n\nmodule.exports = arg;\n", "#!/usr/bin/env node\r\n'use strict'\r\nimport path from 'path'\r\nimport { getMd, wirteMd } from './index'\r\nimport stringToArgs from '../script/cli'\r\nimport handle from '../script/cli/handle'\r\nconst options = stringToArgs(process.argv)\r\nconst { ignores: ignore, includes: include } = handle(options)\r\n/**\r\n * @description:Automatic generation of the whole process \u81EA\u52A8\u751F\u6210\u5168\u6D41\u7A0B\r\n * @param {*}\r\n * @return {*}\r\n */\r\nfunction agmd() {\r\n const md = getMd({ ignore, include })\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'\r\nimport path from 'path'\r\n\r\n/**\r\n * @description:Gets the header comment of the file \u83B7\u53D6\u6587\u4EF6\u7684\u5934\u90E8\u6CE8\u91CA\r\n * @param {*} file\r\n * @return {*}\r\n */\r\nfunction getFile(file: fs.PathOrFileDescriptor) {\r\n const str = fs.readFileSync(file, 'utf-8')\r\n const size = str.length\r\n const sarr = str.split(/[\\n,]/g)\r\n const rowSize = sarr.length\r\n const f =\r\n sarr[0].indexOf('eslint') === -1 &&\r\n (sarr[0].indexOf('-->') > -1 || sarr[0].indexOf('*/') > -1 || sarr[0].indexOf('//') > -1)\r\n ? sarr[0]\r\n : ''\r\n return { note: f, size, rowSize }\r\n}\r\n\r\ntype ItemType = {\r\n name: string\r\n isDir: boolean\r\n level: number\r\n note: string\r\n size: number\r\n suffix: string\r\n rowSize: number\r\n children?: ItemType[]\r\n}\r\n\r\ntype secoutType = { rowTotleNumber: number; sizeTotleNumber: number; coutObj: { [key: string]: number } }\r\n\r\n/**\r\n * @description:Generate node information for all files \u751F\u6210\u6240\u6709\u6587\u4EF6\u7684node\u4FE1\u606F\r\n * @param {Array} nodes\r\n * @param {*} dir\r\n * @param {Number} level\r\n * @return {*}\r\n */\r\nexport function getFileNodes(\r\n option: { ignore: string[] | undefined; include: string[] | undefined } | undefined,\r\n nodes: Array<ItemType> = [],\r\n dir = path.resolve('./'),\r\n level = 0\r\n): Array<ItemType> {\r\n //File filtering -- full name with suffix required \u6587\u4EF6\u8FC7\u6EE4--\u9700\u8981\u5168\u79F0\u5E26\u540E\u7F00\r\n let ignore = [\r\n 'img',\r\n 'styles',\r\n 'node_modules',\r\n 'LICENSE',\r\n '.git',\r\n '.github',\r\n 'dist',\r\n '.husky',\r\n '.vscode',\r\n 'readme-file.js',\r\n 'readme-md.js'\r\n ]\r\n //File suffix contains only \u6587\u4EF6\u540E\u7F00\u53EA\u5305\u542B\r\n let include = ['.js', '.vue', '.ts']\r\n\r\n if (option) {\r\n ignore = option.ignore || ignore\r\n include = option.include || include\r\n }\r\n const files = fs\r\n .readdirSync(dir)\r\n .map((item) => {\r\n const fullPath = path.join(dir, item)\r\n const isDir = fs.lstatSync(fullPath).isDirectory()\r\n return {\r\n name: item,\r\n isDir,\r\n level,\r\n note: ''\r\n } as ItemType\r\n })\r\n //Sort folders and files, otherwise the generated will not correspond to the opening order of the editor \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\r\n .sort((a, b) => {\r\n if (!a.isDir && b.isDir) return 1\r\n if (a.isDir && !b.isDir) return -1\r\n if ((a.isDir && b.isDir) || (!a.isDir && !b.isDir)) return 0\r\n return 0\r\n })\r\n for (let index = 0; index < files.length; index += 1) {\r\n const item = files[index]\r\n //Folder filtering is handled here \u8FD9\u91CC\u5904\u7406\u6587\u4EF6\u5939\u8FC7\u6EE4\r\n const foldFlag = ignore.findIndex((obj: string) => obj === item.name)\r\n if (foldFlag === -1) {\r\n const fullPath = path.join(dir, item.name)\r\n const isDir = fs.lstatSync(fullPath).isDirectory()\r\n if (isDir) {\r\n //recursion \u9012\u5F52\r\n getFileNodes(option, (item.children = []), fullPath, level + 1)\r\n nodes.push(item)\r\n } else {\r\n const i = fullPath.lastIndexOf('.')\r\n const lastName = fullPath.substring(i)\r\n //File filtering is handled here \u8FD9\u91CC\u5904\u7406\u6587\u4EF6\u8FC7\u6EE4\r\n if (include.includes(lastName)) {\r\n const obj = getFile(fullPath)\r\n Object.assign(item, obj)\r\n item.suffix = lastName\r\n nodes.push(item)\r\n }\r\n }\r\n }\r\n }\r\n return nodes\r\n}\r\n\r\n/**\r\n * @description:Recursive file name + note \u9012\u5F52\u5F97\u5230\u6587\u4EF6\u540D+note\r\n * @param {Array} datas\r\n * @param {string} keys\r\n * @return {*}\r\n */\r\nfunction getNote(datas: Array<ItemType>, keys?: string[]) {\r\n const nodes = keys || []\r\n datas.forEach((obj: ItemType, index: Number) => {\r\n const last = index === datas.length - 1\r\n if (obj.children) {\r\n //fold\r\n const md = setMd(obj, last)\r\n nodes.push(md)\r\n getNote(obj.children, nodes)\r\n }\r\n // file\r\n else {\r\n const md = setMd(obj, last)\r\n nodes.push(md)\r\n }\r\n })\r\n return nodes\r\n}\r\n\r\n/**\r\n * @description:One obj generates one line of text \u4E00\u4E2Aobj\u751F\u6210\u4E00\u4E2A\u4E00\u884C\u6587\u5B57\r\n * @param {ItemType} obj\r\n * @param {Boolean} last Is it the last one \u662F\u4E0D\u662F\u6700\u540E\u4E00\u4E2A\r\n * @return {*}\r\n */\r\nfunction setMd(obj: ItemType, last: Boolean): string {\r\n let filesString = ''\r\n const blank = '\u2502 '.repeat(obj.level) // \u91CD\u590D\u7A7A\u767D\r\n const pre = `${blank}${last ? '\u2514\u2500\u2500' : '\u251C\u2500\u2500'} ${obj.name}`\r\n if (obj.isDir) {\r\n filesString += `${pre}\\n`\r\n } else {\r\n filesString += `${pre} ${obj.note}\\n`\r\n }\r\n return filesString\r\n}\r\n\r\n/**\r\n * @description: Write the result to JS file \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 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 * @description:Thousands format \u5343\u5206\u4F4D\u683C\u5F0F\u5316\r\n * @param {num} To format a number \u8981\u683C\u5F0F\u5316\u6570\u5B57\r\n * @return {string}\r\n */\r\nfunction format(num: number) {\r\n var reg = /\\d{1,3}(?=(\\d{3})+$)/g\r\n return (num + '').replace(reg, '$&,')\r\n}\r\n/**\r\n * @description: Generate statistics MD \u751F\u6210\u7EDF\u8BA1md\r\n * @param {object} option\r\n * @return {*}\r\n */\r\nfunction setCountMd(obj: secoutType) {\r\n const { rowTotleNumber, sizeTotleNumber, coutObj } = obj\r\n let countMd = ''\r\n let totle=0\r\n for (const key in coutObj) {\r\n const ele = coutObj[key]\r\n totle += ele\r\n countMd += `The suffix is ${key} has ${ele} files\\n`\r\n }\r\n countMd += `The totle has ${totle} files\\n`\r\n let md = `Total number of file lines: ${format(rowTotleNumber)},\r\nTotal number of codes: ${format(sizeTotleNumber)} \\n`\r\n md = countMd + md\r\n return md\r\n // wirteMd(md, `${path.resolve('./')}\\\\count-md.md`)\r\n}\r\n/**\r\n * @description: Get statistics \u5F97\u5230\u7EDF\u8BA1\r\n * @param {Array} nodes\r\n * @return {*}\r\n */\r\nfunction getCountMd(datas: Array<ItemType>) {\r\n let rowTotleNumber = 0\r\n let sizeTotleNumber = 0\r\n const coutObj: { [key: string]: number } = {}\r\n function getDeatle(nodes: Array<ItemType>) {\r\n nodes.forEach((obj: ItemType) => {\r\n if (obj.children) getDeatle(obj.children)\r\n else {\r\n if (!coutObj.hasOwnProperty(obj.suffix)) coutObj[obj.suffix] = 0\r\n coutObj[obj.suffix]++\r\n rowTotleNumber += obj.rowSize\r\n sizeTotleNumber += obj.size\r\n }\r\n })\r\n }\r\n getDeatle(datas)\r\n return {\r\n rowTotleNumber,\r\n sizeTotleNumber,\r\n coutObj\r\n }\r\n}\r\n\r\n/**\r\n * @description: Generate MD \u751F\u6210md\r\n * @param {object} option\r\n * @return {*}\r\n */\r\nexport function getMd(option?: { ignore: string[] | undefined; include: string[] | undefined } | undefined) {\r\n console.log('\\x1B[36m%s\\x1B[0m', '*** run location: ', path.resolve('./'))\r\n const nodes = getFileNodes(option)\r\n // \u5F97\u5230md\u5BF9\u8C61\r\n wirteJs(JSON.stringify(nodes), __dirname + '\\\\readme-file.js')\r\n const countMdObj = getCountMd(nodes)\r\n const coutMd= setCountMd(countMdObj)\r\n const note = getNote(nodes) // \u5F97\u5230\u6240\u6709note\u7684\u6570\u7EC4\r\n const md = note.join('')+'\\n' // \u6570\u7EC4\u8F6C\u5B57\u7B26\u4E32\r\n if (md.length > 0) {\r\n console.log('\\x1B[36m%s\\x1B[0m', '*** Automatic generation completed ! ')\r\n }\r\n console.log('\\x1B[33m%s\\x1b[0m:', coutMd)\r\n return md + coutMd\r\n}\r\n\r\n/**\r\n * @description:Write the result to JS file \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\nexport function wirteMd(data: string, filePath: string) {\r\n const file = path.resolve(__dirname, filePath)\r\n // \u5F02\u6B65\u5199\u5165\u6570\u636E\u5230\u6587\u4EF6\r\n fs.writeFile(file, data, { encoding: 'utf8' }, (err) => {\r\n console.error(err)\r\n })\r\n}\r\n", "import arg from 'arg'\r\nconst stringToArgs = (rawArgs: string[]) => {\r\n const args = arg(\r\n {\r\n '--ignore': String,\r\n '--include': String,\r\n '--version': Boolean,\r\n '--help': Boolean,\r\n '-h': '--help',\r\n '-i': '--ignore',\r\n '-in': '--include',\r\n '-v': '--version'\r\n },\r\n {\r\n argv: rawArgs.slice(2)\r\n }\r\n )\r\n return {\r\n help: args['--help'],\r\n ignore: args['--ignore'],\r\n include: args['--include'],\r\n version: args['--version']\r\n }\r\n}\r\n\r\nexport default stringToArgs\r\n", "const st = `Usage: agmd--include str--ignore str\r\n\r\n Options:\r\n --include string / -i string.......... include file extension\r\n --ignore string / -in string........... ignore file or fold\r\n --version / -v ........... seach vesion\r\n Str deafult:\r\n --ignore img,styles,node_modules,LICENSE,.git,.github,dist,.husky,.vscode,readme-file.js,readme-md.js\r\n --include .js,.vue,.ts\r\n\r\n Note:\r\n There should be no space between strings in a configuration\r\n\r\n Examples:\r\n $ agmd --ignore lib,node_modules,dist --include .js,.ts,.vue`\r\n\r\nfunction help() {\r\n console.log(st)\r\n process.exit(0)\r\n}\r\nexport default help\r\n", "import help from '../help'\r\nimport pkg from '../../package.json'\r\ninterface parseType {\r\n version?: Boolean | undefined\r\n includes?: string[]\r\n ignores?: string[]\r\n help: Boolean | undefined\r\n ignore: string | undefined\r\n include: string | undefined\r\n}\r\nfunction handle(settings: parseType) {\r\n if (settings.help) {\r\n help()\r\n }\r\n if (settings.version) {\r\n console.log(`agmd version is: ` + '\\x1B[36m%s\\x1B[0m', pkg.version)\r\n process.exit(0)\r\n }\r\n if (settings.ignore) {\r\n settings.ignores = settings.ignore.split(' ')\r\n }\r\n if (settings.include) {\r\n settings.includes = settings.include.split(' ')\r\n }\r\n return settings\r\n}\r\n\r\nexport default handle\r\n"],
|
|
5
|
+
"mappings": ";+lBAAA,oBAAM,GAAa,OAAO,YAE1B,eAAuB,MAAM,CAC5B,YAAY,EAAK,EAAM,CACtB,MAAM,GACN,KAAK,KAAO,WACZ,KAAK,KAAO,EAEZ,OAAO,eAAe,KAAM,EAAS,aAIvC,WACC,EACA,CACC,OAAO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,QAAU,EAAS,OAAO,MAAM,MAEvC,EAAS,SACX,GAAS,SAAW,EAAS,QAAQ,MAAM,MAEtC,EAGT,GAAO,GAAQ,GJrBf,GAAM,IAAU,EAAa,QAAQ,MAC/B,CAAE,QAAS,GAAQ,SAAU,IAAY,EAAO,IAMtD,aAAgB,CACd,GAAM,GAAK,EAAM,CAAE,UAAQ,aAE3B,QAAQ,IAAI,oBAAqB,iBAAkB,GAAG,UAAK,QAAQ,uBACnE,EAAQ,EAAI,GAAG,UAAK,QAAQ,uBAE9B",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default[{"name":"bin","isDir":true,"level":0,"note":"","children":[{"name":"agmd.js","isDir":false,"level":1,"note":"","noteText":"","size":8211,"rowSize":290,"suffix":".js"}]},{"name":"lib","isDir":true,"level":0,"note":"","children":[{"name":"index.cjs.js","isDir":false,"level":1,"note":"","noteText":"","size":6805,"rowSize":305,"suffix":".js"},{"name":"index.d.ts","isDir":false,"level":1,"note":"","noteText":"","size":630,"rowSize":25,"suffix":".ts"},{"name":"index.esm.js","isDir":false,"level":1,"note":"","noteText":"","size":4825,"rowSize":240,"suffix":".js"}]},{"name":"script","isDir":true,"level":0,"note":"","children":[{"name":"cli","isDir":true,"level":1,"note":"","children":[{"name":"handle.ts","isDir":false,"level":2,"note":"","noteText":"","size":681,"rowSize":30,"suffix":".ts"},{"name":"index.ts","isDir":false,"level":2,"note":"","noteText":"","size":539,"rowSize":38,"suffix":".ts"}]},{"name":"help","isDir":true,"level":1,"note":"","children":[{"name":"index.ts","isDir":false,"level":2,"note":"","noteText":"","size":640,"rowSize":38,"suffix":".ts"}]},{"name":"build.js","isDir":false,"level":1,"note":"","noteText":"","size":172,"rowSize":8,"suffix":".js"},{"name":"builder.js","isDir":false,"level":1,"note":"","noteText":"","size":1239,"rowSize":74,"suffix":".js"}]},{"name":"src","isDir":true,"level":0,"note":"","children":[{"name":"agmd.ts","isDir":false,"level":1,"note":"","noteText":"","size":635,"rowSize":27,"suffix":".ts"},{"name":"index.ts","isDir":false,"level":1,"note":"","noteText":"","size":7116,"rowSize":317,"suffix":".ts"}]},{"name":"test","isDir":true,"level":0,"note":"","children":[{"name":"index.js","isDir":false,"level":1,"note":"","noteText":"","size":88,"rowSize":4,"suffix":".js"}]},{"name":"unuse","isDir":true,"level":0,"note":"","children":[{"name":"assets","isDir":true,"level":1,"note":"","children":[]},{"name":"components","isDir":true,"level":1,"note":"","children":[{"name":"user-ruler.vue","isDir":false,"level":2,"note":"","noteText":"/* 这是vue2.0写法 */\r","size":3652,"rowSize":204,"suffix":".vue"},{"name":"user-rulerts.vue","isDir":false,"level":2,"note":"","noteText":"/* 这是ts写法 */\r","size":4219,"rowSize":239,"suffix":".vue"}]},{"name":"App.vue","isDir":false,"level":1,"note":"","noteText":"/* App主入口 */\r","size":695,"rowSize":31,"suffix":".vue"},{"name":"main.js","isDir":false,"level":1,"note":"","noteText":"/* 入口 */\r","size":340,"rowSize":13,"suffix":".js"}]},{"name":".eslintrc.js","isDir":false,"level":0,"note":"","noteText":"","size":938,"rowSize":67,"suffix":".js"}]
|
package/lib/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* agmd v0.
|
|
3
|
-
* author:
|
|
4
|
-
* Sun
|
|
2
|
+
* agmd v0.2.8
|
|
3
|
+
* author:kakajun <253495832@qq.com>
|
|
4
|
+
* Sun Mar 20 2022 22:57:02 GMT+0800 (中国标准时间)
|
|
5
5
|
*/
|
|
6
6
|
var __create = Object.create;
|
|
7
7
|
var __defProp = Object.defineProperty;
|
|
@@ -35,19 +35,38 @@ var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
|
35
35
|
var src_exports = {};
|
|
36
36
|
__export(src_exports, {
|
|
37
37
|
getFileNodes: () => getFileNodes,
|
|
38
|
-
getMd: () => getMd
|
|
38
|
+
getMd: () => getMd,
|
|
39
|
+
wirteMd: () => wirteMd
|
|
39
40
|
});
|
|
40
41
|
var import_fs = __toESM(require("fs"));
|
|
41
42
|
var import_path = __toESM(require("path"));
|
|
42
43
|
function getFile(file) {
|
|
43
44
|
const str = import_fs.default.readFileSync(file, "utf-8");
|
|
45
|
+
const size = str.length;
|
|
44
46
|
const sarr = str.split(/[\n,]/g);
|
|
47
|
+
const rowSize = sarr.length;
|
|
45
48
|
const f = sarr[0].indexOf("eslint") === -1 && (sarr[0].indexOf("-->") > -1 || sarr[0].indexOf("*/") > -1 || sarr[0].indexOf("//") > -1) ? sarr[0] : "";
|
|
46
|
-
return f;
|
|
49
|
+
return { note: f, size, rowSize };
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
function getFileNodes(option, nodes = [], dir = import_path.default.resolve("./"), level = 0) {
|
|
52
|
+
let ignore = [
|
|
53
|
+
"img",
|
|
54
|
+
"styles",
|
|
55
|
+
"node_modules",
|
|
56
|
+
"LICENSE",
|
|
57
|
+
".git",
|
|
58
|
+
".github",
|
|
59
|
+
"dist",
|
|
60
|
+
".husky",
|
|
61
|
+
".vscode",
|
|
62
|
+
"readme-file.js",
|
|
63
|
+
"readme-md.js"
|
|
64
|
+
];
|
|
65
|
+
let include = [".js", ".vue", ".ts"];
|
|
66
|
+
if (option) {
|
|
67
|
+
ignore = option.ignore || ignore;
|
|
68
|
+
include = option.include || include;
|
|
69
|
+
}
|
|
51
70
|
const files = import_fs.default.readdirSync(dir).map((item) => {
|
|
52
71
|
const fullPath = import_path.default.join(dir, item);
|
|
53
72
|
const isDir = import_fs.default.lstatSync(fullPath).isDirectory();
|
|
@@ -68,70 +87,133 @@ function getFileNodes(nodes = [], dir = import_path.default.resolve("./"), level
|
|
|
68
87
|
});
|
|
69
88
|
for (let index = 0; index < files.length; index += 1) {
|
|
70
89
|
const item = files[index];
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (arr === -1) {
|
|
90
|
+
const foldFlag = ignore.findIndex((obj) => obj === item.name);
|
|
91
|
+
if (foldFlag === -1) {
|
|
74
92
|
const fullPath = import_path.default.join(dir, item.name);
|
|
75
93
|
const isDir = import_fs.default.lstatSync(fullPath).isDirectory();
|
|
76
94
|
if (isDir) {
|
|
77
|
-
getFileNodes(item.children = [], fullPath, level + 1);
|
|
95
|
+
getFileNodes(option, item.children = [], fullPath, level + 1);
|
|
96
|
+
nodes.push(item);
|
|
78
97
|
} else {
|
|
79
98
|
const i = fullPath.lastIndexOf(".");
|
|
80
99
|
const lastName = fullPath.substring(i);
|
|
81
|
-
if (
|
|
82
|
-
|
|
100
|
+
if (include.includes(lastName)) {
|
|
101
|
+
const obj = getFile(fullPath);
|
|
102
|
+
Object.assign(item, obj);
|
|
103
|
+
item.suffix = lastName;
|
|
104
|
+
nodes.push(item);
|
|
83
105
|
}
|
|
84
|
-
item.note = note;
|
|
85
106
|
}
|
|
86
|
-
nodes.push(item);
|
|
87
107
|
}
|
|
88
108
|
}
|
|
89
109
|
return nodes;
|
|
90
110
|
}
|
|
91
111
|
function getNote(datas, keys) {
|
|
92
112
|
const nodes = keys || [];
|
|
93
|
-
datas.forEach((obj) => {
|
|
113
|
+
datas.forEach((obj, index) => {
|
|
114
|
+
const last = index === datas.length - 1;
|
|
94
115
|
if (obj.children) {
|
|
95
|
-
const md = setMd(obj);
|
|
116
|
+
const md = setMd(obj, last);
|
|
96
117
|
nodes.push(md);
|
|
97
118
|
getNote(obj.children, nodes);
|
|
98
119
|
} else {
|
|
99
|
-
const md = setMd(obj);
|
|
120
|
+
const md = setMd(obj, last);
|
|
100
121
|
nodes.push(md);
|
|
101
122
|
}
|
|
102
123
|
});
|
|
103
124
|
return nodes;
|
|
104
125
|
}
|
|
105
|
-
function setMd(obj) {
|
|
126
|
+
function setMd(obj, last) {
|
|
106
127
|
let filesString = "";
|
|
107
|
-
const blank = "
|
|
128
|
+
const blank = "\u2502 ".repeat(obj.level);
|
|
129
|
+
const pre = `${blank}${last ? "\u2514\u2500\u2500" : "\u251C\u2500\u2500"} ${obj.name}`;
|
|
108
130
|
if (obj.isDir) {
|
|
109
|
-
filesString += `${
|
|
131
|
+
filesString += `${pre}
|
|
110
132
|
`;
|
|
111
133
|
} else {
|
|
112
|
-
|
|
113
|
-
const lastName = obj.name.substring(index);
|
|
114
|
-
if (includeArrs.includes(lastName) || index === -1) {
|
|
115
|
-
filesString += `${blank} ${obj.name} ${obj.note}
|
|
134
|
+
filesString += `${pre} ${obj.note}
|
|
116
135
|
`;
|
|
117
|
-
}
|
|
118
136
|
}
|
|
119
137
|
return filesString;
|
|
120
138
|
}
|
|
121
|
-
function
|
|
122
|
-
|
|
123
|
-
const
|
|
139
|
+
function wirteJs(data, filePath) {
|
|
140
|
+
const file = import_path.default.resolve(__dirname, filePath);
|
|
141
|
+
const pre = "export default";
|
|
142
|
+
import_fs.default.writeFile(file, pre + data, { encoding: "utf8" }, (err) => {
|
|
143
|
+
console.error(err);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function format(num) {
|
|
147
|
+
var reg = /\d{1,3}(?=(\d{3})+$)/g;
|
|
148
|
+
return (num + "").replace(reg, "$&,");
|
|
149
|
+
}
|
|
150
|
+
function setCountMd(obj) {
|
|
151
|
+
const { rowTotleNumber, sizeTotleNumber, coutObj } = obj;
|
|
152
|
+
let countMd = "";
|
|
153
|
+
let totle = 0;
|
|
154
|
+
for (const key in coutObj) {
|
|
155
|
+
const ele = coutObj[key];
|
|
156
|
+
totle += ele;
|
|
157
|
+
countMd += `The suffix is ${key} has ${ele} files
|
|
158
|
+
`;
|
|
159
|
+
}
|
|
160
|
+
countMd += `The totle has ${totle} files
|
|
161
|
+
`;
|
|
162
|
+
let md = `Total number of file lines: ${format(rowTotleNumber)},
|
|
163
|
+
Total number of codes: ${format(sizeTotleNumber)}
|
|
164
|
+
`;
|
|
165
|
+
md = countMd + md;
|
|
166
|
+
return md;
|
|
167
|
+
}
|
|
168
|
+
function getCountMd(datas) {
|
|
169
|
+
let rowTotleNumber = 0;
|
|
170
|
+
let sizeTotleNumber = 0;
|
|
171
|
+
const coutObj = {};
|
|
172
|
+
function getDeatle(nodes) {
|
|
173
|
+
nodes.forEach((obj) => {
|
|
174
|
+
if (obj.children)
|
|
175
|
+
getDeatle(obj.children);
|
|
176
|
+
else {
|
|
177
|
+
if (!coutObj.hasOwnProperty(obj.suffix))
|
|
178
|
+
coutObj[obj.suffix] = 0;
|
|
179
|
+
coutObj[obj.suffix]++;
|
|
180
|
+
rowTotleNumber += obj.rowSize;
|
|
181
|
+
sizeTotleNumber += obj.size;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
getDeatle(datas);
|
|
186
|
+
return {
|
|
187
|
+
rowTotleNumber,
|
|
188
|
+
sizeTotleNumber,
|
|
189
|
+
coutObj
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function getMd(option) {
|
|
193
|
+
console.log("\x1B[36m%s\x1B[0m", "*** run location: ", import_path.default.resolve("./"));
|
|
194
|
+
const nodes = getFileNodes(option);
|
|
195
|
+
wirteJs(JSON.stringify(nodes), __dirname + "\\readme-file.js");
|
|
196
|
+
const countMdObj = getCountMd(nodes);
|
|
197
|
+
const coutMd = setCountMd(countMdObj);
|
|
124
198
|
const note = getNote(nodes);
|
|
125
|
-
const md = note.join("");
|
|
199
|
+
const md = note.join("") + "\n";
|
|
126
200
|
if (md.length > 0) {
|
|
127
|
-
console.log("
|
|
201
|
+
console.log("\x1B[36m%s\x1B[0m", "*** Automatic generation completed ! ");
|
|
128
202
|
}
|
|
129
|
-
|
|
203
|
+
console.log("\x1B[33m%s\x1B[0m:", coutMd);
|
|
204
|
+
return md + coutMd;
|
|
205
|
+
}
|
|
206
|
+
function wirteMd(data, filePath) {
|
|
207
|
+
const file = import_path.default.resolve(__dirname, filePath);
|
|
208
|
+
import_fs.default.writeFile(file, data, { encoding: "utf8" }, (err) => {
|
|
209
|
+
console.error(err);
|
|
210
|
+
});
|
|
130
211
|
}
|
|
131
212
|
module.exports = __toCommonJS(src_exports);
|
|
132
213
|
// Annotate the CommonJS export names for ESM import in node:
|
|
133
214
|
0 && (module.exports = {
|
|
134
215
|
getFileNodes,
|
|
135
|
-
getMd
|
|
216
|
+
getMd,
|
|
217
|
+
wirteMd
|
|
136
218
|
});
|
|
137
219
|
//# sourceMappingURL=index.cjs.js.map
|
package/lib/index.cjs.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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
|
|
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;
|
|
4
|
+
"sourcesContent": ["import fs from 'fs'\r\nimport path from 'path'\r\n\r\n/**\r\n * @description:Gets the header comment of the file \u83B7\u53D6\u6587\u4EF6\u7684\u5934\u90E8\u6CE8\u91CA\r\n * @param {*} file\r\n * @return {*}\r\n */\r\nfunction getFile(file: fs.PathOrFileDescriptor) {\r\n const str = fs.readFileSync(file, 'utf-8')\r\n const size = str.length\r\n const sarr = str.split(/[\\n,]/g)\r\n const rowSize = sarr.length\r\n const f =\r\n sarr[0].indexOf('eslint') === -1 &&\r\n (sarr[0].indexOf('-->') > -1 || sarr[0].indexOf('*/') > -1 || sarr[0].indexOf('//') > -1)\r\n ? sarr[0]\r\n : ''\r\n return { note: f, size, rowSize }\r\n}\r\n\r\ntype ItemType = {\r\n name: string\r\n isDir: boolean\r\n level: number\r\n note: string\r\n size: number\r\n suffix: string\r\n rowSize: number\r\n children?: ItemType[]\r\n}\r\n\r\ntype secoutType = { rowTotleNumber: number; sizeTotleNumber: number; coutObj: { [key: string]: number } }\r\n\r\n/**\r\n * @description:Generate node information for all files \u751F\u6210\u6240\u6709\u6587\u4EF6\u7684node\u4FE1\u606F\r\n * @param {Array} nodes\r\n * @param {*} dir\r\n * @param {Number} level\r\n * @return {*}\r\n */\r\nexport function getFileNodes(\r\n option: { ignore: string[] | undefined; include: string[] | undefined } | undefined,\r\n nodes: Array<ItemType> = [],\r\n dir = path.resolve('./'),\r\n level = 0\r\n): Array<ItemType> {\r\n //File filtering -- full name with suffix required \u6587\u4EF6\u8FC7\u6EE4--\u9700\u8981\u5168\u79F0\u5E26\u540E\u7F00\r\n let ignore = [\r\n 'img',\r\n 'styles',\r\n 'node_modules',\r\n 'LICENSE',\r\n '.git',\r\n '.github',\r\n 'dist',\r\n '.husky',\r\n '.vscode',\r\n 'readme-file.js',\r\n 'readme-md.js'\r\n ]\r\n //File suffix contains only \u6587\u4EF6\u540E\u7F00\u53EA\u5305\u542B\r\n let include = ['.js', '.vue', '.ts']\r\n\r\n if (option) {\r\n ignore = option.ignore || ignore\r\n include = option.include || include\r\n }\r\n const files = fs\r\n .readdirSync(dir)\r\n .map((item) => {\r\n const fullPath = path.join(dir, item)\r\n const isDir = fs.lstatSync(fullPath).isDirectory()\r\n return {\r\n name: item,\r\n isDir,\r\n level,\r\n note: ''\r\n } as ItemType\r\n })\r\n //Sort folders and files, otherwise the generated will not correspond to the opening order of the editor \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\r\n .sort((a, b) => {\r\n if (!a.isDir && b.isDir) return 1\r\n if (a.isDir && !b.isDir) return -1\r\n if ((a.isDir && b.isDir) || (!a.isDir && !b.isDir)) return 0\r\n return 0\r\n })\r\n for (let index = 0; index < files.length; index += 1) {\r\n const item = files[index]\r\n //Folder filtering is handled here \u8FD9\u91CC\u5904\u7406\u6587\u4EF6\u5939\u8FC7\u6EE4\r\n const foldFlag = ignore.findIndex((obj: string) => obj === item.name)\r\n if (foldFlag === -1) {\r\n const fullPath = path.join(dir, item.name)\r\n const isDir = fs.lstatSync(fullPath).isDirectory()\r\n if (isDir) {\r\n //recursion \u9012\u5F52\r\n getFileNodes(option, (item.children = []), fullPath, level + 1)\r\n nodes.push(item)\r\n } else {\r\n const i = fullPath.lastIndexOf('.')\r\n const lastName = fullPath.substring(i)\r\n //File filtering is handled here \u8FD9\u91CC\u5904\u7406\u6587\u4EF6\u8FC7\u6EE4\r\n if (include.includes(lastName)) {\r\n const obj = getFile(fullPath)\r\n Object.assign(item, obj)\r\n item.suffix = lastName\r\n nodes.push(item)\r\n }\r\n }\r\n }\r\n }\r\n return nodes\r\n}\r\n\r\n/**\r\n * @description:Recursive file name + note \u9012\u5F52\u5F97\u5230\u6587\u4EF6\u540D+note\r\n * @param {Array} datas\r\n * @param {string} keys\r\n * @return {*}\r\n */\r\nfunction getNote(datas: Array<ItemType>, keys?: string[]) {\r\n const nodes = keys || []\r\n datas.forEach((obj: ItemType, index: Number) => {\r\n const last = index === datas.length - 1\r\n if (obj.children) {\r\n //fold\r\n const md = setMd(obj, last)\r\n nodes.push(md)\r\n getNote(obj.children, nodes)\r\n }\r\n // file\r\n else {\r\n const md = setMd(obj, last)\r\n nodes.push(md)\r\n }\r\n })\r\n return nodes\r\n}\r\n\r\n/**\r\n * @description:One obj generates one line of text \u4E00\u4E2Aobj\u751F\u6210\u4E00\u4E2A\u4E00\u884C\u6587\u5B57\r\n * @param {ItemType} obj\r\n * @param {Boolean} last Is it the last one \u662F\u4E0D\u662F\u6700\u540E\u4E00\u4E2A\r\n * @return {*}\r\n */\r\nfunction setMd(obj: ItemType, last: Boolean): string {\r\n let filesString = ''\r\n const blank = '\u2502 '.repeat(obj.level) // \u91CD\u590D\u7A7A\u767D\r\n const pre = `${blank}${last ? '\u2514\u2500\u2500' : '\u251C\u2500\u2500'} ${obj.name}`\r\n if (obj.isDir) {\r\n filesString += `${pre}\\n`\r\n } else {\r\n filesString += `${pre} ${obj.note}\\n`\r\n }\r\n return filesString\r\n}\r\n\r\n/**\r\n * @description: Write the result to JS file \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 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 * @description:Thousands format \u5343\u5206\u4F4D\u683C\u5F0F\u5316\r\n * @param {num} To format a number \u8981\u683C\u5F0F\u5316\u6570\u5B57\r\n * @return {string}\r\n */\r\nfunction format(num: number) {\r\n var reg = /\\d{1,3}(?=(\\d{3})+$)/g\r\n return (num + '').replace(reg, '$&,')\r\n}\r\n/**\r\n * @description: Generate statistics MD \u751F\u6210\u7EDF\u8BA1md\r\n * @param {object} option\r\n * @return {*}\r\n */\r\nfunction setCountMd(obj: secoutType) {\r\n const { rowTotleNumber, sizeTotleNumber, coutObj } = obj\r\n let countMd = ''\r\n let totle=0\r\n for (const key in coutObj) {\r\n const ele = coutObj[key]\r\n totle += ele\r\n countMd += `The suffix is ${key} has ${ele} files\\n`\r\n }\r\n countMd += `The totle has ${totle} files\\n`\r\n let md = `Total number of file lines: ${format(rowTotleNumber)},\r\nTotal number of codes: ${format(sizeTotleNumber)} \\n`\r\n md = countMd + md\r\n return md\r\n // wirteMd(md, `${path.resolve('./')}\\\\count-md.md`)\r\n}\r\n/**\r\n * @description: Get statistics \u5F97\u5230\u7EDF\u8BA1\r\n * @param {Array} nodes\r\n * @return {*}\r\n */\r\nfunction getCountMd(datas: Array<ItemType>) {\r\n let rowTotleNumber = 0\r\n let sizeTotleNumber = 0\r\n const coutObj: { [key: string]: number } = {}\r\n function getDeatle(nodes: Array<ItemType>) {\r\n nodes.forEach((obj: ItemType) => {\r\n if (obj.children) getDeatle(obj.children)\r\n else {\r\n if (!coutObj.hasOwnProperty(obj.suffix)) coutObj[obj.suffix] = 0\r\n coutObj[obj.suffix]++\r\n rowTotleNumber += obj.rowSize\r\n sizeTotleNumber += obj.size\r\n }\r\n })\r\n }\r\n getDeatle(datas)\r\n return {\r\n rowTotleNumber,\r\n sizeTotleNumber,\r\n coutObj\r\n }\r\n}\r\n\r\n/**\r\n * @description: Generate MD \u751F\u6210md\r\n * @param {object} option\r\n * @return {*}\r\n */\r\nexport function getMd(option?: { ignore: string[] | undefined; include: string[] | undefined } | undefined) {\r\n console.log('\\x1B[36m%s\\x1B[0m', '*** run location: ', path.resolve('./'))\r\n const nodes = getFileNodes(option)\r\n // \u5F97\u5230md\u5BF9\u8C61\r\n wirteJs(JSON.stringify(nodes), __dirname + '\\\\readme-file.js')\r\n const countMdObj = getCountMd(nodes)\r\n const coutMd= setCountMd(countMdObj)\r\n const note = getNote(nodes) // \u5F97\u5230\u6240\u6709note\u7684\u6570\u7EC4\r\n const md = note.join('')+'\\n' // \u6570\u7EC4\u8F6C\u5B57\u7B26\u4E32\r\n if (md.length > 0) {\r\n console.log('\\x1B[36m%s\\x1B[0m', '*** Automatic generation completed ! ')\r\n }\r\n console.log('\\x1B[33m%s\\x1b[0m:', coutMd)\r\n return md + coutMd\r\n}\r\n\r\n/**\r\n * @description:Write the result to JS file \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\nexport function wirteMd(data: string, filePath: string) {\r\n const file = path.resolve(__dirname, filePath)\r\n // \u5F02\u6B65\u5199\u5165\u6570\u636E\u5230\u6587\u4EF6\r\n fs.writeFile(file, data, { encoding: 'utf8' }, (err) => {\r\n console.error(err)\r\n })\r\n}\r\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,kBAAiB;AAOjB,iBAAiB,MAA+B;AAC9C,QAAM,MAAM,kBAAG,aAAa,MAAM;AAClC,QAAM,OAAO,IAAI;AACjB,QAAM,OAAO,IAAI,MAAM;AACvB,QAAM,UAAU,KAAK;AACrB,QAAM,IACJ,KAAK,GAAG,QAAQ,cAAc,MAC7B,MAAK,GAAG,QAAQ,SAAS,MAAM,KAAK,GAAG,QAAQ,QAAQ,MAAM,KAAK,GAAG,QAAQ,QAAQ,MAClF,KAAK,KACL;AACN,SAAO,EAAE,MAAM,GAAG,MAAM;AAAA;AAuBnB,sBACL,QACA,QAAyB,IACzB,MAAM,oBAAK,QAAQ,OACnB,QAAQ,GACS;AAEjB,MAAI,SAAS;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAGF,MAAI,UAAU,CAAC,OAAO,QAAQ;AAE9B,MAAI,QAAQ;AACV,aAAS,OAAO,UAAU;AAC1B,cAAU,OAAO,WAAW;AAAA;AAE9B,QAAM,QAAQ,kBACX,YAAY,KACZ,IAAI,CAAC,SAAS;AACb,UAAM,WAAW,oBAAK,KAAK,KAAK;AAChC,UAAM,QAAQ,kBAAG,UAAU,UAAU;AACrC,WAAO;AAAA,MACL,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA,MAAM;AAAA;AAAA,KAIT,KAAK,CAAC,GAAG,MAAM;AACd,QA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3C,QAAM,aAAa,WAAW;AAC/B,QAAM,SAAQ,WAAW;AACxB,QAAM,OAAO,QAAQ;AACrB,QAAM,KAAK,KAAK,KAAK,MAAI;AACzB,MAAI,GAAG,SAAS,GAAG;AACjB,YAAQ,IAAI,qBAAqB;AAAA;AAElC,UAAQ,IAAI,sBAAsB;AACnC,SAAO,KAAK;AAAA;AAQP,iBAAiB,MAAc,UAAkB;AACtD,QAAM,OAAO,oBAAK,QAAQ,WAAW;AAErC,oBAAG,UAAU,MAAM,MAAM,EAAE,UAAU,UAAU,CAAC,QAAQ;AACtD,YAAQ,MAAM;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
declare type ItemType = {
|
|
2
2
|
name: string;
|
|
3
3
|
isDir: boolean;
|
|
4
4
|
level: number;
|
|
5
5
|
note: string;
|
|
6
|
+
size: number;
|
|
7
|
+
suffix: string;
|
|
8
|
+
rowSize: number;
|
|
6
9
|
children?: ItemType[];
|
|
7
10
|
};
|
|
8
|
-
export declare function getFileNodes(
|
|
9
|
-
|
|
11
|
+
export declare function getFileNodes(option: {
|
|
12
|
+
ignore: string[] | undefined;
|
|
13
|
+
include: string[] | undefined;
|
|
14
|
+
} | undefined, nodes?: Array<ItemType>, dir?: string, level?: number): Array<ItemType>;
|
|
15
|
+
export declare function getMd(option?: {
|
|
16
|
+
ignore: string[] | undefined;
|
|
17
|
+
include: string[] | undefined;
|
|
18
|
+
} | undefined): string;
|
|
19
|
+
export declare function wirteMd(data: string, filePath: string): void;
|
|
20
|
+
export {};
|
package/lib/index.esm.js
CHANGED
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* agmd v0.
|
|
3
|
-
* author:
|
|
4
|
-
* Sun
|
|
2
|
+
* agmd v0.2.8
|
|
3
|
+
* author:kakajun <253495832@qq.com>
|
|
4
|
+
* Sun Mar 20 2022 22:57:02 GMT+0800 (中国标准时间)
|
|
5
5
|
*/
|
|
6
6
|
// src/index.ts
|
|
7
7
|
import fs from "fs";
|
|
8
8
|
import path from "path";
|
|
9
9
|
function getFile(file) {
|
|
10
10
|
const str = fs.readFileSync(file, "utf-8");
|
|
11
|
+
const size = str.length;
|
|
11
12
|
const sarr = str.split(/[\n,]/g);
|
|
13
|
+
const rowSize = sarr.length;
|
|
12
14
|
const f = sarr[0].indexOf("eslint") === -1 && (sarr[0].indexOf("-->") > -1 || sarr[0].indexOf("*/") > -1 || sarr[0].indexOf("//") > -1) ? sarr[0] : "";
|
|
13
|
-
return f;
|
|
15
|
+
return { note: f, size, rowSize };
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
function getFileNodes(option, nodes = [], dir = path.resolve("./"), level = 0) {
|
|
18
|
+
let ignore = [
|
|
19
|
+
"img",
|
|
20
|
+
"styles",
|
|
21
|
+
"node_modules",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
".git",
|
|
24
|
+
".github",
|
|
25
|
+
"dist",
|
|
26
|
+
".husky",
|
|
27
|
+
".vscode",
|
|
28
|
+
"readme-file.js",
|
|
29
|
+
"readme-md.js"
|
|
30
|
+
];
|
|
31
|
+
let include = [".js", ".vue", ".ts"];
|
|
32
|
+
if (option) {
|
|
33
|
+
ignore = option.ignore || ignore;
|
|
34
|
+
include = option.include || include;
|
|
35
|
+
}
|
|
18
36
|
const files = fs.readdirSync(dir).map((item) => {
|
|
19
37
|
const fullPath = path.join(dir, item);
|
|
20
38
|
const isDir = fs.lstatSync(fullPath).isDirectory();
|
|
@@ -35,68 +53,131 @@ function getFileNodes(nodes = [], dir = path.resolve("./"), level = 0) {
|
|
|
35
53
|
});
|
|
36
54
|
for (let index = 0; index < files.length; index += 1) {
|
|
37
55
|
const item = files[index];
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (arr === -1) {
|
|
56
|
+
const foldFlag = ignore.findIndex((obj) => obj === item.name);
|
|
57
|
+
if (foldFlag === -1) {
|
|
41
58
|
const fullPath = path.join(dir, item.name);
|
|
42
59
|
const isDir = fs.lstatSync(fullPath).isDirectory();
|
|
43
60
|
if (isDir) {
|
|
44
|
-
getFileNodes(item.children = [], fullPath, level + 1);
|
|
61
|
+
getFileNodes(option, item.children = [], fullPath, level + 1);
|
|
62
|
+
nodes.push(item);
|
|
45
63
|
} else {
|
|
46
64
|
const i = fullPath.lastIndexOf(".");
|
|
47
65
|
const lastName = fullPath.substring(i);
|
|
48
|
-
if (
|
|
49
|
-
|
|
66
|
+
if (include.includes(lastName)) {
|
|
67
|
+
const obj = getFile(fullPath);
|
|
68
|
+
Object.assign(item, obj);
|
|
69
|
+
item.suffix = lastName;
|
|
70
|
+
nodes.push(item);
|
|
50
71
|
}
|
|
51
|
-
item.note = note;
|
|
52
72
|
}
|
|
53
|
-
nodes.push(item);
|
|
54
73
|
}
|
|
55
74
|
}
|
|
56
75
|
return nodes;
|
|
57
76
|
}
|
|
58
77
|
function getNote(datas, keys) {
|
|
59
78
|
const nodes = keys || [];
|
|
60
|
-
datas.forEach((obj) => {
|
|
79
|
+
datas.forEach((obj, index) => {
|
|
80
|
+
const last = index === datas.length - 1;
|
|
61
81
|
if (obj.children) {
|
|
62
|
-
const md = setMd(obj);
|
|
82
|
+
const md = setMd(obj, last);
|
|
63
83
|
nodes.push(md);
|
|
64
84
|
getNote(obj.children, nodes);
|
|
65
85
|
} else {
|
|
66
|
-
const md = setMd(obj);
|
|
86
|
+
const md = setMd(obj, last);
|
|
67
87
|
nodes.push(md);
|
|
68
88
|
}
|
|
69
89
|
});
|
|
70
90
|
return nodes;
|
|
71
91
|
}
|
|
72
|
-
function setMd(obj) {
|
|
92
|
+
function setMd(obj, last) {
|
|
73
93
|
let filesString = "";
|
|
74
|
-
const blank = "
|
|
94
|
+
const blank = "\u2502 ".repeat(obj.level);
|
|
95
|
+
const pre = `${blank}${last ? "\u2514\u2500\u2500" : "\u251C\u2500\u2500"} ${obj.name}`;
|
|
75
96
|
if (obj.isDir) {
|
|
76
|
-
filesString += `${
|
|
97
|
+
filesString += `${pre}
|
|
77
98
|
`;
|
|
78
99
|
} else {
|
|
79
|
-
|
|
80
|
-
const lastName = obj.name.substring(index);
|
|
81
|
-
if (includeArrs.includes(lastName) || index === -1) {
|
|
82
|
-
filesString += `${blank} ${obj.name} ${obj.note}
|
|
100
|
+
filesString += `${pre} ${obj.note}
|
|
83
101
|
`;
|
|
84
|
-
}
|
|
85
102
|
}
|
|
86
103
|
return filesString;
|
|
87
104
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
const
|
|
105
|
+
function wirteJs(data, filePath) {
|
|
106
|
+
const file = path.resolve(__dirname, filePath);
|
|
107
|
+
const pre = "export default";
|
|
108
|
+
fs.writeFile(file, pre + data, { encoding: "utf8" }, (err) => {
|
|
109
|
+
console.error(err);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function format(num) {
|
|
113
|
+
var reg = /\d{1,3}(?=(\d{3})+$)/g;
|
|
114
|
+
return (num + "").replace(reg, "$&,");
|
|
115
|
+
}
|
|
116
|
+
function setCountMd(obj) {
|
|
117
|
+
const { rowTotleNumber, sizeTotleNumber, coutObj } = obj;
|
|
118
|
+
let countMd = "";
|
|
119
|
+
let totle = 0;
|
|
120
|
+
for (const key in coutObj) {
|
|
121
|
+
const ele = coutObj[key];
|
|
122
|
+
totle += ele;
|
|
123
|
+
countMd += `The suffix is ${key} has ${ele} files
|
|
124
|
+
`;
|
|
125
|
+
}
|
|
126
|
+
countMd += `The totle has ${totle} files
|
|
127
|
+
`;
|
|
128
|
+
let md = `Total number of file lines: ${format(rowTotleNumber)},
|
|
129
|
+
Total number of codes: ${format(sizeTotleNumber)}
|
|
130
|
+
`;
|
|
131
|
+
md = countMd + md;
|
|
132
|
+
return md;
|
|
133
|
+
}
|
|
134
|
+
function getCountMd(datas) {
|
|
135
|
+
let rowTotleNumber = 0;
|
|
136
|
+
let sizeTotleNumber = 0;
|
|
137
|
+
const coutObj = {};
|
|
138
|
+
function getDeatle(nodes) {
|
|
139
|
+
nodes.forEach((obj) => {
|
|
140
|
+
if (obj.children)
|
|
141
|
+
getDeatle(obj.children);
|
|
142
|
+
else {
|
|
143
|
+
if (!coutObj.hasOwnProperty(obj.suffix))
|
|
144
|
+
coutObj[obj.suffix] = 0;
|
|
145
|
+
coutObj[obj.suffix]++;
|
|
146
|
+
rowTotleNumber += obj.rowSize;
|
|
147
|
+
sizeTotleNumber += obj.size;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
getDeatle(datas);
|
|
152
|
+
return {
|
|
153
|
+
rowTotleNumber,
|
|
154
|
+
sizeTotleNumber,
|
|
155
|
+
coutObj
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function getMd(option) {
|
|
159
|
+
console.log("\x1B[36m%s\x1B[0m", "*** run location: ", path.resolve("./"));
|
|
160
|
+
const nodes = getFileNodes(option);
|
|
161
|
+
wirteJs(JSON.stringify(nodes), __dirname + "\\readme-file.js");
|
|
162
|
+
const countMdObj = getCountMd(nodes);
|
|
163
|
+
const coutMd = setCountMd(countMdObj);
|
|
91
164
|
const note = getNote(nodes);
|
|
92
|
-
const md = note.join("");
|
|
165
|
+
const md = note.join("") + "\n";
|
|
93
166
|
if (md.length > 0) {
|
|
94
|
-
console.log("
|
|
167
|
+
console.log("\x1B[36m%s\x1B[0m", "*** Automatic generation completed ! ");
|
|
95
168
|
}
|
|
96
|
-
|
|
169
|
+
console.log("\x1B[33m%s\x1B[0m:", coutMd);
|
|
170
|
+
return md + coutMd;
|
|
171
|
+
}
|
|
172
|
+
function wirteMd(data, filePath) {
|
|
173
|
+
const file = path.resolve(__dirname, filePath);
|
|
174
|
+
fs.writeFile(file, data, { encoding: "utf8" }, (err) => {
|
|
175
|
+
console.error(err);
|
|
176
|
+
});
|
|
97
177
|
}
|
|
98
178
|
export {
|
|
99
179
|
getFileNodes,
|
|
100
|
-
getMd
|
|
180
|
+
getMd,
|
|
181
|
+
wirteMd
|
|
101
182
|
};
|
|
102
183
|
//# sourceMappingURL=index.esm.js.map
|