Skip to content

Commit

Permalink
refactor: add named exports
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Sep 1, 2021
1 parent 4200177 commit f3297ac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/__tests__/comment-parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import commentParser from '../utils/comment-parser';
import { parseComment } from '../utils/comment-parser';

const template = `/*
* @vuepress
Expand All @@ -9,8 +9,8 @@ const template = `/*
* ---
*/`;

describe('commentParser', () => {
const { attributes } = commentParser(template);
describe('parseComment()', () => {
const { attributes } = parseComment(template);

test('Title to be "Your custom title"', () => {
expect(attributes?.title).toBe('Your custom title');
Expand All @@ -23,9 +23,9 @@ describe('commentParser', () => {
});
});

describe('commentParser fail', () => {
describe('parseComment() fail', () => {
// @ts-expect-error check empty method
const { frontmatter } = commentParser();
const { frontmatter } = parseComment();

test('fontmatter should be null', () => {
expect(frontmatter).toBe(null);
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/sidebar.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import vueSidebar from '../utils/vue-sidebar';
import { generateVueSidebar } from '../utils/vue-sidebar';

describe('test sidebar', () => {
test('vueSidebar should return valid vue config', () => {
test('generateVueSidebar should return valid vue config', () => {
const codeFolder = 'test_folder';
const title = 'test_folder';
const fileTree = [
Expand All @@ -25,7 +25,7 @@ describe('test sidebar', () => {
{ name: 'tests', children: [] }
];

const sidebar = vueSidebar({ fileTree, codeFolder, title });
const sidebar = generateVueSidebar({ fileTree, codeFolder, title });

const result = {
[`/${codeFolder}/`]: [
Expand Down
4 changes: 1 addition & 3 deletions src/utils/comment-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fm from 'front-matter';

import { DirectoryFile } from '../interfaces';

const parseComment = (fileContent: string) => {
export const parseComment = (fileContent: string) => {
try {
const allCommentBlocks = fileContent.match(/\/*[\s\S]*\/.*/g);
const vuepressBlock = allCommentBlocks?.filter((block: string) => {
Expand Down Expand Up @@ -60,5 +60,3 @@ export const parseVuepressFileHeader = (content: string, file: DirectoryFile) =>

return fileContent;
};

export default parseComment;
10 changes: 9 additions & 1 deletion src/utils/vue-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ interface Node {
children: any[];
}

export default ({ fileTree, codeFolder, title }: { fileTree: any; codeFolder: string; title: string }) => {
export const generateVueSidebar = ({
fileTree,
codeFolder,
title
}: {
fileTree: any;
codeFolder: string;
title: string;
}) => {
let rootFiles = [['', '::vuepress-jsdoc-title::']];
rootFiles = rootFiles.concat(fileTree.filter((file: Node) => !file.children).map((file: Node) => file.name));

Expand Down

0 comments on commit f3297ac

Please sign in to comment.