Skip to content

Commit

Permalink
fix(config): exclude files by jsdoc config
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Sep 2, 2021
1 parent 0e2fc24 commit af706c5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion example/documentation/code/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/jsdoc.json
Expand Up @@ -22,6 +22,6 @@
"recurseDepth": 10,
"source": {
"includePattern": ".+\\.(js|ts)(doc|x)?$",
"excludePattern": ".+\\.(test|spec).ts"
"excludePattern": ".+\\.(test|spec).js"
}
}
2 changes: 1 addition & 1 deletion example/package.json
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"docs": "../bin/vuepress-jsdoc.js -c ./jsdoc.json --source=./src --dist=./documentation --title=API --exclude=**/*/*.test.js,class.js --partials=./partials/*.hbs --readme=./README.md",
"docs": "../bin/vuepress-jsdoc.js --jsDocConfigPath ./jsdoc.json --source=./src --dist=./documentation --title=API --exclude=class.js --partials=./partials/*.hbs --readme=./README.md",
"dev": "vuepress dev documentation",
"build": "vuepress build documentation"
},
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Expand Up @@ -92,7 +92,8 @@ export const generate = async (argv: Record<string, string>) => {
const color = {
[StatisticType.SUCCESS]: 'green',
[StatisticType.ERROR]: 'red',
[StatisticType.EMPTY]: 'yellow'
[StatisticType.EMPTY]: 'yellow',
[StatisticType.EXCLUDE]: 'blue'
}[entry.type];

console.log(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/list-folder.ts
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 '), `${chalk.dim('src')}/${chalk.bold(name + ext)}`);
console.log(chalk.reset.inverse.bold.blue(' EXCLUDE '), `${chalk.dim('src')}/${chalk.bold(name + ext)}`);
}
}

Expand Down
34 changes: 22 additions & 12 deletions src/lib/parser.ts
@@ -1,3 +1,4 @@
import chalk from 'chalk';
import fs from 'fs/promises';
import jsdoc2md from 'jsdoc-to-markdown';
import mkdirp from 'mkdirp';
Expand All @@ -15,7 +16,8 @@ interface ParseReturn {
dest: string;
file: DirectoryFile;
content: string;
isEmpty: boolean;
empty: boolean;
excluded?: boolean;
relativePathSrc: string;
relativePathDest: string;
}
Expand All @@ -35,14 +37,17 @@ export const parseFile = async (
const folderInSrc = join(root, file.folder);

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

// parse file
try {
const content = await jsdoc2md.render({
files: [`${join(folderInSrc, file.name + file.ext)}`],
configure: join(root, configPath),
let content = '';

content = await jsdoc2md.render({
files: [join(file.folder, file.name + file.ext)],
configure: configPath,
partial: [
resolve(__filename, '../../../template/header.hbs'),
resolve(__filename, '../../../template/main.hbs'),
Expand All @@ -58,17 +63,18 @@ export const parseFile = async (
if (content) {
fileContent += content;
} else {
isEmpty = true;
empty = true;
}
} catch (e) {
console.log(e);
success = false;
excluded = true;
}

return {
success,
file,
isEmpty,
empty,
excluded,
relativePathDest,
relativePathSrc: file.folder,
dest: folderInDest,
Expand All @@ -94,7 +100,7 @@ export const parseVueFile = async (
};

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

try {
Expand All @@ -113,7 +119,7 @@ export const parseVueFile = async (
if (data.content) {
fileContent += data.content;
} else {
isEmpty = true;
empty = true;
}
} catch (e) {
console.log(e);
Expand All @@ -123,7 +129,7 @@ export const parseVueFile = async (
return {
success,
file,
isEmpty,
empty,
relativePathDest,
relativePathSrc: file.folder,
dest: folderInDest,
Expand All @@ -137,14 +143,18 @@ export const writeContentToFile = async (parseData: ParseReturn | null, dest: st

let type = StatisticType.ERROR;

if (parseData?.excluded) {
type = StatisticType.EXCLUDE;
}

try {
if (parseData?.content) {
const path = `${join(dest, parseData.file.name)}.md`;

await mkdirp(dest);
await fs.writeFile(path, parseData.content, 'utf-8');

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

return {
Expand Down

0 comments on commit af706c5

Please sign in to comment.