Skip to content

Commit

Permalink
fix(type): handle empty type
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Sep 2, 2021
1 parent b2a7481 commit 0e2fc24
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const generate = async (argv: Record<string, string>) => {
const deletedPaths = await del([`${docsFolder}/**/*`, ...rmPattern]);

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

await mkdirp(docsFolder);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/list-folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const listFolder = async (srcPath: string, exclude: string[] = [], mainPa
});
} else {
// excluded
console.log(chalk.reset.inverse.bold.blue('EXCLUDE BY CONFIG '), `${chalk.dim('src')}/${chalk.bold(name + ext)}`);
console.log(chalk.reset.inverse.bold.blue('EXCLUDE '), `${chalk.dim('src')}/${chalk.bold(name + ext)}`);
}
}

Expand Down
27 changes: 20 additions & 7 deletions src/lib/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface ParseReturn {
dest: string;
file: DirectoryFile;
content: string;
isEmpty: boolean;
relativePathSrc: string;
relativePathDest: string;
}
Expand All @@ -34,16 +35,17 @@ export const parseFile = async (
const folderInSrc = join(root, file.folder);

let success = true;
let isEmpty = false;
let fileContent = '';

// parse file
try {
const content = await jsdoc2md.render({
files: [`${join(folderInSrc, file.name + file.ext)}`],
configure: configPath,
configure: join(root, configPath),
partial: [
resolve(__filename, '../../template/header.hbs'),
resolve(__filename, '../../template/main.hbs'),
resolve(__filename, '../../../template/header.hbs'),
resolve(__filename, '../../../template/main.hbs'),
...partials
]
});
Expand All @@ -53,7 +55,11 @@ export const parseFile = async (
file
);

fileContent += content;
if (content) {
fileContent += content;
} else {
isEmpty = true;
}
} catch (e) {
console.log(e);
success = false;
Expand All @@ -62,6 +68,7 @@ export const parseFile = async (
return {
success,
file,
isEmpty,
relativePathDest,
relativePathSrc: file.folder,
dest: folderInDest,
Expand All @@ -87,6 +94,7 @@ export const parseVueFile = async (
};

let success = true;
let isEmpty = false;
let fileContent = '';

try {
Expand All @@ -102,7 +110,11 @@ export const parseVueFile = async (
file
);

fileContent += data.content;
if (data.content) {
fileContent += data.content;
} else {
isEmpty = true;
}
} catch (e) {
console.log(e);
success = false;
Expand All @@ -111,6 +123,7 @@ export const parseVueFile = async (
return {
success,
file,
isEmpty,
relativePathDest,
relativePathSrc: file.folder,
dest: folderInDest,
Expand All @@ -122,7 +135,7 @@ export const writeContentToFile = async (parseData: ParseReturn | null, dest: st
const root = process.cwd();
dest = join(root, dest);

let type = parseData?.success ? StatisticType.EMPTY : StatisticType.ERROR;
let type = StatisticType.ERROR;

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

type = StatisticType.SUCCESS;
type = parseData?.isEmpty ? StatisticType.EMPTY : StatisticType.SUCCESS;
}

return {
Expand Down

0 comments on commit 0e2fc24

Please sign in to comment.