vuepress-jsdoc 4.3.1 → 5.0.0

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.
@@ -10,17 +10,17 @@ exports.parseVuepressFileHeader = exports.parseComment = void 0;
10
10
  * headline: lib/comment-parser.ts
11
11
  * ---
12
12
  */
13
- var front_matter_1 = __importDefault(require("front-matter"));
13
+ const front_matter_1 = __importDefault(require("front-matter"));
14
14
  /**
15
15
  * Search in file for @vuepress comment
16
16
  * @param {string} fileContent content of given file
17
17
  * @returns {object} object of found frontmatter data
18
18
  */
19
- var parseComment = function (fileContent) {
19
+ const parseComment = (fileContent) => {
20
20
  try {
21
- var allCommentBlocks = fileContent.match(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/g);
22
- var vuepressBlock = allCommentBlocks === null || allCommentBlocks === void 0 ? void 0 : allCommentBlocks.filter(function (block) {
23
- return block.split('\n').filter(function (line) { return line.indexOf('@vuepress') >= 0; }).length;
21
+ const allCommentBlocks = fileContent.match(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/g);
22
+ const vuepressBlock = allCommentBlocks === null || allCommentBlocks === void 0 ? void 0 : allCommentBlocks.filter((block) => {
23
+ return block.split('\n').filter(line => line.indexOf('@vuepress') >= 0).length;
24
24
  })[0];
25
25
  if (!vuepressBlock) {
26
26
  return {
@@ -50,24 +50,24 @@ exports.parseComment = parseComment;
50
50
  * @param {object} file file object
51
51
  * @returns {string} markdown header
52
52
  */
53
- var parseVuepressFileHeader = function (content, file) {
54
- var _a = (0, exports.parseComment)(content), frontmatter = _a.frontmatter, attributes = _a.attributes;
55
- var fileContent = '---\n';
56
- fileContent += !(attributes === null || attributes === void 0 ? void 0 : attributes.title) ? "title: ".concat(file.name) : '';
53
+ const parseVuepressFileHeader = (content, file) => {
54
+ const { frontmatter, attributes } = (0, exports.parseComment)(content);
55
+ let fileContent = '---\n';
56
+ fileContent += !(attributes === null || attributes === void 0 ? void 0 : attributes.title) ? `title: ${file.name}` : '';
57
57
  if (frontmatter) {
58
58
  fileContent += !(attributes === null || attributes === void 0 ? void 0 : attributes.title) ? '\n' : '';
59
- fileContent += "".concat(frontmatter);
59
+ fileContent += `${frontmatter}`;
60
60
  }
61
61
  fileContent += '\n---\n';
62
62
  if ((attributes === null || attributes === void 0 ? void 0 : attributes.title) || file.ext !== '.vue') {
63
- var headline = file.name;
63
+ let headline = file.name;
64
64
  if (attributes === null || attributes === void 0 ? void 0 : attributes.headline) {
65
65
  headline = attributes.headline;
66
66
  }
67
67
  else if (attributes === null || attributes === void 0 ? void 0 : attributes.title) {
68
68
  headline = attributes.title;
69
69
  }
70
- fileContent += "\n# ".concat(headline, "\n\n");
70
+ fileContent += `\n# ${headline}\n\n`;
71
71
  }
72
72
  return fileContent;
73
73
  };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Get extension of file
3
+ * @param {string} path
4
+ * @returns {string} extension of file
5
+ */
6
+ export declare const getExtension: (path: string) => string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getExtension = void 0;
4
+ /*
5
+ * @vuepress
6
+ * ---
7
+ * headline: lib/utils.ts
8
+ * ---
9
+ */
10
+ /**
11
+ * Get extension of file
12
+ * @param {string} path
13
+ * @returns {string} extension of file
14
+ */
15
+ const getExtension = (path) => path && typeof path === 'string' ? path.substring(path.length, path.lastIndexOf('.')) : '';
16
+ exports.getExtension = getExtension;
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,69 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20
9
  });
21
10
  };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __values = (this && this.__values) || function(o) {
50
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
51
- if (m) return m.call(o);
52
- if (o && typeof o.length === "number") return {
53
- next: function () {
54
- if (o && i >= o.length) o = void 0;
55
- return { value: o && o[i++], done: !o };
56
- }
57
- };
58
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
59
- };
60
- var __read = (this && this.__read) || function (o, n) {
61
- var m = typeof Symbol === "function" && o[Symbol.iterator];
62
- if (!m) return o;
63
- var i = m.call(o), r, ar = [], e;
64
- try {
65
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
66
- }
67
- catch (error) { e = { error: error }; }
68
- finally {
69
- try {
70
- if (r && !r.done && (m = i["return"])) m.call(i);
71
- }
72
- finally { if (e) throw e.error; }
73
- }
74
- return ar;
75
- };
76
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
77
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
78
- if (ar || !(i in from)) {
79
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
80
- ar[i] = from[i];
81
- }
82
- }
83
- return to.concat(ar || Array.prototype.slice.call(from));
84
- };
85
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
86
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
87
13
  };
@@ -93,9 +19,9 @@ exports.listFolder = void 0;
93
19
  * headline: lib/list-folder.ts
94
20
  * ---
95
21
  */
96
- var promises_1 = __importDefault(require("fs/promises"));
97
- var micromatch_1 = __importDefault(require("micromatch"));
98
- var path_1 = __importDefault(require("path"));
22
+ const micromatch_1 = __importDefault(require("micromatch"));
23
+ const promises_1 = __importDefault(require("node:fs/promises"));
24
+ const node_path_1 = __importDefault(require("node:path"));
99
25
  /**
100
26
  * Recursively traverse folders and return exluded files, a file list and a file tree.
101
27
  * @param {string} srcPath path to source dir
@@ -105,98 +31,56 @@ var path_1 = __importDefault(require("path"));
105
31
  * @param {object} tree tree array
106
32
  * @returns {object} paths array, tree, excluded array
107
33
  */
108
- var listFolder = function (srcPath, exclude, include, mainPath, tree) {
109
- if (tree === void 0) { tree = []; }
110
- return __awaiter(void 0, void 0, void 0, function () {
111
- var paths, excluded, dirs, _a, dirs_1, dirs_1_1, dirent, filePath, isDir, ext, name_1, folder, file, baseSrc, treeEntry, _b, _c, _d, _e, e_1_1;
112
- var e_1, _f;
113
- return __generator(this, function (_g) {
114
- switch (_g.label) {
115
- case 0:
116
- if (!Boolean(exclude) || !Array.isArray(exclude)) {
117
- exclude = [];
118
- }
119
- if (!Boolean(include) || !Array.isArray(include)) {
120
- include = [];
121
- }
122
- exclude = exclude.filter(Boolean);
123
- include = include.filter(Boolean);
124
- paths = [];
125
- excluded = [];
126
- if (!srcPath) return [3 /*break*/, 2];
127
- return [4 /*yield*/, promises_1.default.readdir(srcPath, {
128
- withFileTypes: true
129
- })];
130
- case 1:
131
- _a = _g.sent();
132
- return [3 /*break*/, 3];
133
- case 2:
134
- _a = [];
135
- _g.label = 3;
136
- case 3:
137
- dirs = _a;
138
- _g.label = 4;
139
- case 4:
140
- _g.trys.push([4, 12, 13, 14]);
141
- dirs_1 = __values(dirs), dirs_1_1 = dirs_1.next();
142
- _g.label = 5;
143
- case 5:
144
- if (!!dirs_1_1.done) return [3 /*break*/, 11];
145
- dirent = dirs_1_1.value;
146
- filePath = path_1.default.join(srcPath, dirent.name);
147
- isDir = dirent.isDirectory();
148
- ext = path_1.default.extname(filePath);
149
- name_1 = path_1.default.basename(filePath).replace(ext, '');
150
- folder = filePath.replace(name_1, '').replace(ext, '');
151
- if (name_1 === 'index') {
152
- name_1 = '__index__';
153
- }
154
- file = __assign({ isDir: isDir, name: name_1, path: filePath }, (!isDir ? { ext: ext, folder: folder } : {}));
155
- // skip readmes as they are automatically resolved
156
- if (name_1.toLowerCase() === 'readme')
157
- return [3 /*break*/, 10];
158
- baseSrc = mainPath || srcPath;
159
- if (!(micromatch_1.default.every(path_1.default.join(srcPath.replace(baseSrc, ''), dirent.name), __spreadArray(__spreadArray([], __read(include), false), __read(exclude.map(function (e) { return '!' + e; })), false)) ||
160
- isDir)) return [3 /*break*/, 9];
161
- treeEntry = {
162
- name: name_1
163
- };
164
- if (!isDir) return [3 /*break*/, 7];
165
- treeEntry.children = [];
166
- _c = (_b = paths.push).apply;
167
- _d = [paths];
168
- _e = [[]];
169
- return [4 /*yield*/, (0, exports.listFolder)(filePath, exclude, include, baseSrc, treeEntry.children)];
170
- case 6:
171
- _c.apply(_b, _d.concat([__spreadArray.apply(void 0, _e.concat([__read.apply(void 0, [(_g.sent()).paths]), false]))]));
172
- return [3 /*break*/, 8];
173
- case 7:
174
- treeEntry = __assign(__assign({}, treeEntry), { path: "/".concat(name_1), fullPath: path_1.default.join(srcPath, name_1), ext: ext });
175
- _g.label = 8;
176
- case 8:
177
- tree.push(treeEntry);
178
- paths.push(file);
179
- return [3 /*break*/, 10];
180
- case 9:
181
- excluded.push(file);
182
- _g.label = 10;
183
- case 10:
184
- dirs_1_1 = dirs_1.next();
185
- return [3 /*break*/, 5];
186
- case 11: return [3 /*break*/, 14];
187
- case 12:
188
- e_1_1 = _g.sent();
189
- e_1 = { error: e_1_1 };
190
- return [3 /*break*/, 14];
191
- case 13:
192
- try {
193
- if (dirs_1_1 && !dirs_1_1.done && (_f = dirs_1.return)) _f.call(dirs_1);
194
- }
195
- finally { if (e_1) throw e_1.error; }
196
- return [7 /*endfinally*/];
197
- case 14: return [2 /*return*/, { paths: paths, tree: tree, excluded: excluded }];
34
+ const listFolder = (srcPath, exclude, include, mainPath, tree = []) => __awaiter(void 0, void 0, void 0, function* () {
35
+ if (!Boolean(exclude) || !Array.isArray(exclude)) {
36
+ exclude = [];
37
+ }
38
+ if (!Boolean(include) || !Array.isArray(include)) {
39
+ include = [];
40
+ }
41
+ exclude = exclude.filter(Boolean);
42
+ include = include.filter(Boolean);
43
+ const paths = [];
44
+ const excluded = [];
45
+ const dirs = srcPath
46
+ ? yield promises_1.default.readdir(srcPath, {
47
+ withFileTypes: true
48
+ })
49
+ : [];
50
+ for (const dirent of dirs) {
51
+ const filePath = node_path_1.default.join(srcPath, dirent.name);
52
+ const isDir = dirent.isDirectory();
53
+ const ext = node_path_1.default.extname(filePath);
54
+ let name = node_path_1.default.basename(filePath).replace(ext, '');
55
+ const folder = filePath.replace(name, '').replace(ext, '');
56
+ if (name.endsWith('index')) {
57
+ name = srcPath.replace(/\//g, '-') + '-' + name;
58
+ }
59
+ const file = Object.assign({ isDir,
60
+ name, path: filePath }, (!isDir ? { ext, folder } : {}));
61
+ // skip readmes as they are automatically resolved
62
+ if (name.toLowerCase() === 'readme')
63
+ continue;
64
+ const baseSrc = mainPath || srcPath;
65
+ if (micromatch_1.default.every(node_path_1.default.join(srcPath.replace(baseSrc, ''), dirent.name), [...include, ...exclude.map((e) => '!' + e)]) ||
66
+ isDir) {
67
+ let treeEntry = {
68
+ name
69
+ };
70
+ if (isDir) {
71
+ treeEntry.children = [];
72
+ paths.push(...(yield (0, exports.listFolder)(filePath, exclude, include, baseSrc, treeEntry.children)).paths);
198
73
  }
199
- });
200
- });
201
- };
74
+ else {
75
+ treeEntry = Object.assign(Object.assign({}, treeEntry), { path: `/${name}`, fullPath: node_path_1.default.join(srcPath, name), ext });
76
+ }
77
+ tree.push(treeEntry);
78
+ paths.push(file);
79
+ }
80
+ else {
81
+ excluded.push(file);
82
+ }
83
+ }
84
+ return { paths, tree, excluded };
85
+ });
202
86
  exports.listFolder = listFolder;