Skip to content

Commit 0e2fc24

Browse files
committed
fix(type): handle empty type
1 parent b2a7481 commit 0e2fc24

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const generate = async (argv: Record<string, string>) => {
2929
const deletedPaths = await del([`${docsFolder}/**/*`, ...rmPattern]);
3030

3131
const { tree, paths } = await listFolder(srcFolder, exclude);
32+
console.log();
3233

3334
await mkdirp(docsFolder);
3435

src/lib/list-folder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const listFolder = async (srcPath: string, exclude: string[] = [], mainPa
5353
});
5454
} else {
5555
// excluded
56-
console.log(chalk.reset.inverse.bold.blue('EXCLUDE BY CONFIG '), `${chalk.dim('src')}/${chalk.bold(name + ext)}`);
56+
console.log(chalk.reset.inverse.bold.blue('EXCLUDE '), `${chalk.dim('src')}/${chalk.bold(name + ext)}`);
5757
}
5858
}
5959

src/lib/parser.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface ParseReturn {
1515
dest: string;
1616
file: DirectoryFile;
1717
content: string;
18+
isEmpty: boolean;
1819
relativePathSrc: string;
1920
relativePathDest: string;
2021
}
@@ -34,16 +35,17 @@ export const parseFile = async (
3435
const folderInSrc = join(root, file.folder);
3536

3637
let success = true;
38+
let isEmpty = false;
3739
let fileContent = '';
3840

3941
// parse file
4042
try {
4143
const content = await jsdoc2md.render({
4244
files: [`${join(folderInSrc, file.name + file.ext)}`],
43-
configure: configPath,
45+
configure: join(root, configPath),
4446
partial: [
45-
resolve(__filename, '../../template/header.hbs'),
46-
resolve(__filename, '../../template/main.hbs'),
47+
resolve(__filename, '../../../template/header.hbs'),
48+
resolve(__filename, '../../../template/main.hbs'),
4749
...partials
4850
]
4951
});
@@ -53,7 +55,11 @@ export const parseFile = async (
5355
file
5456
);
5557

56-
fileContent += content;
58+
if (content) {
59+
fileContent += content;
60+
} else {
61+
isEmpty = true;
62+
}
5763
} catch (e) {
5864
console.log(e);
5965
success = false;
@@ -62,6 +68,7 @@ export const parseFile = async (
6268
return {
6369
success,
6470
file,
71+
isEmpty,
6572
relativePathDest,
6673
relativePathSrc: file.folder,
6774
dest: folderInDest,
@@ -87,6 +94,7 @@ export const parseVueFile = async (
8794
};
8895

8996
let success = true;
97+
let isEmpty = false;
9098
let fileContent = '';
9199

92100
try {
@@ -102,7 +110,11 @@ export const parseVueFile = async (
102110
file
103111
);
104112

105-
fileContent += data.content;
113+
if (data.content) {
114+
fileContent += data.content;
115+
} else {
116+
isEmpty = true;
117+
}
106118
} catch (e) {
107119
console.log(e);
108120
success = false;
@@ -111,6 +123,7 @@ export const parseVueFile = async (
111123
return {
112124
success,
113125
file,
126+
isEmpty,
114127
relativePathDest,
115128
relativePathSrc: file.folder,
116129
dest: folderInDest,
@@ -122,7 +135,7 @@ export const writeContentToFile = async (parseData: ParseReturn | null, dest: st
122135
const root = process.cwd();
123136
dest = join(root, dest);
124137

125-
let type = parseData?.success ? StatisticType.EMPTY : StatisticType.ERROR;
138+
let type = StatisticType.ERROR;
126139

127140
try {
128141
if (parseData?.content) {
@@ -131,7 +144,7 @@ export const writeContentToFile = async (parseData: ParseReturn | null, dest: st
131144
await mkdirp(dest);
132145
await fs.writeFile(path, parseData.content, 'utf-8');
133146

134-
type = StatisticType.SUCCESS;
147+
type = parseData?.isEmpty ? StatisticType.EMPTY : StatisticType.SUCCESS;
135148
}
136149

137150
return {

0 commit comments

Comments
 (0)