vuepress-jsdoc 4.3.0 → 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.
@@ -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;
@@ -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,58 +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 __read = (this && this.__read) || function (o, n) {
50
- var m = typeof Symbol === "function" && o[Symbol.iterator];
51
- if (!m) return o;
52
- var i = m.call(o), r, ar = [], e;
53
- try {
54
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
- }
56
- catch (error) { e = { error: error }; }
57
- finally {
58
- try {
59
- if (r && !r.done && (m = i["return"])) m.call(i);
60
- }
61
- finally { if (e) throw e.error; }
62
- }
63
- return ar;
64
- };
65
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
66
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
67
- if (ar || !(i in from)) {
68
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
69
- ar[i] = from[i];
70
- }
71
- }
72
- return to.concat(ar || Array.prototype.slice.call(from));
73
- };
74
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
75
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
76
13
  };
@@ -82,14 +19,14 @@ exports.writeContentToFile = exports.parseVueFile = exports.parseFile = void 0;
82
19
  * headline: lib/parser.ts
83
20
  * ---
84
21
  */
85
- var promises_1 = __importDefault(require("fs/promises"));
86
- var jsdoc_to_markdown_1 = __importDefault(require("jsdoc-to-markdown"));
87
- var mkdirp_1 = __importDefault(require("mkdirp"));
88
- var path_1 = require("path");
89
- var compileTemplates_1 = __importDefault(require("vue-docgen-cli/lib/compileTemplates"));
90
- var docgen_1 = require("vue-docgen-cli/lib/docgen");
91
- var constants_1 = require("../constants");
92
- var comment_parser_1 = require("./comment-parser");
22
+ const jsdoc_to_markdown_1 = __importDefault(require("jsdoc-to-markdown"));
23
+ const mkdirp_1 = require("mkdirp");
24
+ const promises_1 = __importDefault(require("node:fs/promises"));
25
+ const node_path_1 = require("node:path");
26
+ const compileTemplates_1 = __importDefault(require("vue-docgen-cli/lib/compileTemplates"));
27
+ const docgen_1 = require("vue-docgen-cli/lib/docgen");
28
+ const constants_1 = require("../constants");
29
+ const comment_parser_1 = require("./comment-parser");
93
30
  /**
94
31
  * Parse a typescript or javascript file
95
32
  * @param file {DirectoryFile}
@@ -99,69 +36,57 @@ var comment_parser_1 = require("./comment-parser");
99
36
  * @param partials {string | string[]}
100
37
  * @returns {object} file data
101
38
  */
102
- var parseFile = function (file, srcFolder, destFolder, configPath, partials) { return __awaiter(void 0, void 0, void 0, function () {
103
- var root, relativePathDest, folderInDest, folderInSrc, success, empty, excluded, fileContent, content, fileName, _a, e_1;
104
- return __generator(this, function (_b) {
105
- switch (_b.label) {
106
- case 0:
107
- if (!file.folder)
108
- return [2 /*return*/, null];
109
- root = process.cwd();
110
- relativePathDest = (0, path_1.join)(destFolder, file.folder.replace(srcFolder, ''));
111
- folderInDest = (0, path_1.join)(root, relativePathDest);
112
- folderInSrc = (0, path_1.join)(root, file.folder);
113
- success = true;
114
- empty = false;
115
- excluded = false;
116
- fileContent = '';
117
- _b.label = 1;
118
- case 1:
119
- _b.trys.push([1, 4, , 5]);
120
- content = '';
121
- fileName = file.name;
122
- if (fileName === '__index__') {
123
- fileName = 'index';
124
- }
125
- return [4 /*yield*/, jsdoc_to_markdown_1.default.render({
126
- 'no-cache': configPath ? true : false,
127
- files: [(0, path_1.join)(process.cwd(), file.folder, fileName + file.ext)],
128
- configure: configPath,
129
- partial: __spreadArray([
130
- (0, path_1.resolve)(__filename, '../../../template/header.hbs'),
131
- (0, path_1.resolve)(__filename, '../../../template/main.hbs')
132
- ], __read(partials), false)
133
- })];
134
- case 2:
135
- content = _b.sent();
136
- _a = comment_parser_1.parseVuepressFileHeader;
137
- return [4 /*yield*/, promises_1.default.readFile("".concat((0, path_1.join)(folderInSrc, fileName + file.ext)), 'utf-8')];
138
- case 3:
139
- fileContent = _a.apply(void 0, [_b.sent(), file]);
140
- if (content) {
141
- fileContent += content;
142
- }
143
- else {
144
- empty = true;
145
- }
146
- return [3 /*break*/, 5];
147
- case 4:
148
- e_1 = _b.sent();
149
- success = false;
150
- excluded = true;
151
- return [3 /*break*/, 5];
152
- case 5: return [2 /*return*/, {
153
- success: success,
154
- file: file,
155
- empty: empty,
156
- excluded: excluded,
157
- relativePathDest: relativePathDest,
158
- relativePathSrc: file.folder,
159
- dest: folderInDest,
160
- content: fileContent
161
- }];
39
+ const parseFile = (file, srcFolder, destFolder, configPath, partials) => __awaiter(void 0, void 0, void 0, function* () {
40
+ if (!file.folder)
41
+ return null;
42
+ const root = process.cwd();
43
+ const relativePathDest = (0, node_path_1.join)(destFolder, file.folder.replace(srcFolder, ''));
44
+ const folderInDest = (0, node_path_1.join)(root, relativePathDest);
45
+ const folderInSrc = (0, node_path_1.join)(root, file.folder);
46
+ let success = true;
47
+ let empty = false;
48
+ let excluded = false;
49
+ let fileContent = '';
50
+ // parse file
51
+ try {
52
+ let content = '';
53
+ let fileName = file.name;
54
+ if (fileName.endsWith('index')) {
55
+ fileName = 'index';
162
56
  }
163
- });
164
- }); };
57
+ content = yield jsdoc_to_markdown_1.default.render({
58
+ 'no-cache': configPath ? true : false,
59
+ files: [(0, node_path_1.join)(process.cwd(), file.folder, fileName + file.ext)],
60
+ configure: configPath,
61
+ partial: [
62
+ (0, node_path_1.resolve)(__filename, '../../../template/header.hbs'),
63
+ (0, node_path_1.resolve)(__filename, '../../../template/main.hbs'),
64
+ ...partials
65
+ ]
66
+ });
67
+ fileContent = (0, comment_parser_1.parseVuepressFileHeader)(yield promises_1.default.readFile(`${(0, node_path_1.join)(folderInSrc, fileName + file.ext)}`, 'utf-8'), file);
68
+ if (content) {
69
+ fileContent += content;
70
+ }
71
+ else {
72
+ empty = true;
73
+ }
74
+ }
75
+ catch (e) {
76
+ success = false;
77
+ excluded = true;
78
+ }
79
+ return {
80
+ success,
81
+ file,
82
+ empty,
83
+ excluded,
84
+ relativePathDest,
85
+ relativePathSrc: file.folder,
86
+ dest: folderInDest,
87
+ content: fileContent
88
+ };
89
+ });
165
90
  exports.parseFile = parseFile;
166
91
  /**
167
92
  * Parse a vue file
@@ -170,59 +95,47 @@ exports.parseFile = parseFile;
170
95
  * @param {string} destFolder
171
96
  * @returns {object} file data
172
97
  */
173
- var parseVueFile = function (file, srcFolder, destFolder) { return __awaiter(void 0, void 0, void 0, function () {
174
- var root, relativePathDest, folderInDest, folderInSrc, config, success, empty, fileContent, fileName, data, _a, e_2;
175
- return __generator(this, function (_b) {
176
- switch (_b.label) {
177
- case 0:
178
- if (!file.folder)
179
- return [2 /*return*/, null];
180
- root = process.cwd();
181
- relativePathDest = (0, path_1.join)(destFolder, file.folder.replace(srcFolder, ''));
182
- folderInDest = (0, path_1.join)(root, relativePathDest);
183
- folderInSrc = (0, path_1.join)(root, file.folder);
184
- config = __assign(__assign({}, (0, docgen_1.extractConfig)((0, path_1.join)(root, file.folder))), { components: file.name + file.ext });
185
- success = true;
186
- empty = false;
187
- fileContent = '';
188
- _b.label = 1;
189
- case 1:
190
- _b.trys.push([1, 4, , 5]);
191
- fileName = file.name;
192
- if (fileName === '__index__') {
193
- fileName = 'index';
194
- }
195
- return [4 /*yield*/, (0, compileTemplates_1.default)((0, path_1.join)(config.componentsRoot, fileName + file.ext), config, fileName + file.ext)];
196
- case 2:
197
- data = _b.sent();
198
- _a = comment_parser_1.parseVuepressFileHeader;
199
- return [4 /*yield*/, promises_1.default.readFile("".concat((0, path_1.join)(folderInSrc, fileName + file.ext)), 'utf-8')];
200
- case 3:
201
- fileContent = _a.apply(void 0, [_b.sent(), file]);
202
- if (data.content) {
203
- fileContent += data.content;
204
- }
205
- else {
206
- empty = true;
207
- }
208
- return [3 /*break*/, 5];
209
- case 4:
210
- e_2 = _b.sent();
211
- console.log(e_2);
212
- success = false;
213
- return [3 /*break*/, 5];
214
- case 5: return [2 /*return*/, {
215
- success: success,
216
- file: file,
217
- empty: empty,
218
- relativePathDest: relativePathDest,
219
- relativePathSrc: file.folder,
220
- dest: folderInDest,
221
- content: fileContent
222
- }];
98
+ const parseVueFile = (file, srcFolder, destFolder) => __awaiter(void 0, void 0, void 0, function* () {
99
+ if (!file.folder)
100
+ return null;
101
+ const root = process.cwd();
102
+ const relativePathDest = (0, node_path_1.join)(destFolder, file.folder.replace(srcFolder, ''));
103
+ const folderInDest = (0, node_path_1.join)(root, relativePathDest);
104
+ const folderInSrc = (0, node_path_1.join)(root, file.folder);
105
+ const vueDocGenCliConf = yield (0, docgen_1.extractConfig)((0, node_path_1.join)(root, file.folder));
106
+ const config = Object.assign(Object.assign({}, vueDocGenCliConf), { components: file.name + file.ext });
107
+ let success = true;
108
+ let empty = false;
109
+ let fileContent = '';
110
+ try {
111
+ let fileName = file.name;
112
+ if (fileName.endsWith('index')) {
113
+ fileName = 'index';
223
114
  }
224
- });
225
- }); };
115
+ // parse file
116
+ const data = yield (0, compileTemplates_1.default)('add', (0, node_path_1.join)(config.componentsRoot, fileName + file.ext), config, fileName + file.ext);
117
+ fileContent = (0, comment_parser_1.parseVuepressFileHeader)(yield promises_1.default.readFile(`${(0, node_path_1.join)(folderInSrc, fileName + file.ext)}`, 'utf-8'), file);
118
+ if (data.content) {
119
+ fileContent += data.content;
120
+ }
121
+ else {
122
+ empty = true;
123
+ }
124
+ }
125
+ catch (e) {
126
+ console.log(e);
127
+ success = false;
128
+ }
129
+ return {
130
+ success,
131
+ file,
132
+ empty,
133
+ relativePathDest,
134
+ relativePathSrc: file.folder,
135
+ dest: folderInDest,
136
+ content: fileContent
137
+ };
138
+ });
226
139
  exports.parseVueFile = parseVueFile;
227
140
  /**
228
141
  * Write content on disk
@@ -230,36 +143,23 @@ exports.parseVueFile = parseVueFile;
230
143
  * @param {string} dest
231
144
  * @returns {Promise | null} null or type with some data of the saved file
232
145
  */
233
- var writeContentToFile = function (parseData, dest) { return __awaiter(void 0, void 0, void 0, function () {
234
- var root, type, path, _a;
235
- return __generator(this, function (_b) {
236
- switch (_b.label) {
237
- case 0:
238
- root = process.cwd();
239
- dest = (0, path_1.join)(root, dest);
240
- type = constants_1.StatisticType.ERROR;
241
- if (parseData === null || parseData === void 0 ? void 0 : parseData.excluded) {
242
- type = constants_1.StatisticType.EXCLUDE;
243
- }
244
- _b.label = 1;
245
- case 1:
246
- _b.trys.push([1, 5, , 6]);
247
- if (!(parseData === null || parseData === void 0 ? void 0 : parseData.content)) return [3 /*break*/, 4];
248
- path = "".concat((0, path_1.join)(dest, parseData.file.name), ".md");
249
- return [4 /*yield*/, (0, mkdirp_1.default)(dest)];
250
- case 2:
251
- _b.sent();
252
- return [4 /*yield*/, promises_1.default.writeFile(path, parseData.content, 'utf-8')];
253
- case 3:
254
- _b.sent();
255
- type = (parseData === null || parseData === void 0 ? void 0 : parseData.empty) ? constants_1.StatisticType.EMPTY : constants_1.StatisticType.SUCCESS;
256
- _b.label = 4;
257
- case 4: return [2 /*return*/, __assign(__assign({}, parseData), { type: type })];
258
- case 5:
259
- _a = _b.sent();
260
- return [3 /*break*/, 6];
261
- case 6: return [2 /*return*/, null];
146
+ const writeContentToFile = (parseData, dest) => __awaiter(void 0, void 0, void 0, function* () {
147
+ const root = process.cwd();
148
+ dest = (0, node_path_1.join)(root, dest);
149
+ let type = constants_1.StatisticType.ERROR;
150
+ if (parseData === null || parseData === void 0 ? void 0 : parseData.excluded) {
151
+ type = constants_1.StatisticType.EXCLUDE;
152
+ }
153
+ try {
154
+ if (parseData === null || parseData === void 0 ? void 0 : parseData.content) {
155
+ const path = `${(0, node_path_1.join)(dest, parseData.file.name)}.md`;
156
+ yield (0, mkdirp_1.mkdirp)(dest);
157
+ yield promises_1.default.writeFile(path, parseData.content, 'utf-8');
158
+ type = (parseData === null || parseData === void 0 ? void 0 : parseData.empty) ? constants_1.StatisticType.EMPTY : constants_1.StatisticType.INCLUDE;
262
159
  }
263
- });
264
- }); };
160
+ return Object.assign(Object.assign({}, parseData), { type });
161
+ }
162
+ catch (_a) { }
163
+ return null;
164
+ });
265
165
  exports.writeContentToFile = writeContentToFile;
package/dist/lib/utils.js CHANGED
@@ -12,9 +12,7 @@ exports.getFilename = exports.checkExtension = exports.getExtension = void 0;
12
12
  * @param {string} path
13
13
  * @returns {string} extension of file
14
14
  */
15
- var getExtension = function (path) {
16
- return path && typeof path === 'string' ? path.substring(path.length, path.lastIndexOf('.')) : '';
17
- };
15
+ const getExtension = (path) => path && typeof path === 'string' ? path.substring(path.length, path.lastIndexOf('.')) : '';
18
16
  exports.getExtension = getExtension;
19
17
  /**
20
18
  * Check if extension ist correct
@@ -22,7 +20,7 @@ exports.getExtension = getExtension;
22
20
  * @param {string[]} extensions
23
21
  * @returns {boolean}
24
22
  */
25
- var checkExtension = function (path, extensions) {
23
+ const checkExtension = (path, extensions) => {
26
24
  if (!extensions || !path || typeof path !== 'string')
27
25
  return false;
28
26
  return extensions.indexOf((0, exports.getExtension)(path)) >= 0;
@@ -33,11 +31,11 @@ exports.checkExtension = checkExtension;
33
31
  * @param {string} path
34
32
  * @returns {string} filename
35
33
  */
36
- var getFilename = function (path) {
34
+ const getFilename = (path) => {
37
35
  var _a;
38
36
  if (!path || (path && typeof path !== 'string'))
39
37
  return '';
40
- var splitted = (_a = path.split('/').pop()) !== null && _a !== void 0 ? _a : path;
38
+ const splitted = (_a = path.split('/').pop()) !== null && _a !== void 0 ? _a : path;
41
39
  return splitted.substring(0, splitted.lastIndexOf('.'));
42
40
  };
43
41
  exports.getFilename = getFilename;