Skip to content

Commit

Permalink
refactor(smells): fix some code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Sep 2, 2021
1 parent 1b8870e commit 45370ea
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# vuepress-jsdoc

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/9ec565a85a134df2a0f6bdf905e438d4)](https://app.codacy.com/app/ph1p/vuepress-jsdoc?utm_source=github.com&utm_medium=referral&utm_content=ph1p/vuepress-jsdoc&utm_campaign=Badge_Grade_Settings)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ph1p_vuepress-jsdoc&metric=alert_status)](https://sonarcloud.io/dashboard?id=ph1p_vuepress-jsdoc)
[![npm](https://img.shields.io/npm/v/vuepress-jsdoc.svg)](https://www.npmjs.com/package/vuepress-jsdoc)
[![vercel](https://img.shields.io/badge/vercel-demo-black)](https://vuepress-jsdoc-example.vercel.app)

This npm package is a command line script, which scans your JavaScript, Vue or Typescript source code and generates markdown files for vuepress with the help of [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown) and [vue-docgen-cli](https://github.com/vue-styleguidist/vue-styleguidist/tree/dev/packages/vue-docgen-cli).

![CLI ./example](https://user-images.githubusercontent.com/15351728/131877824-0124e47f-9080-4976-88d0-84ad04b64f24.gif)

## How to

```bash
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const parseArguments = (argv: CLIArguments) => {
* @param {object} argv passed arguments
*/
export const generate = async (argv: CLIArguments) => {
const { exclude, srcFolder, codeFolder, docsFolder, title, readme, rmPattern, partials } = parseArguments(argv);
const { exclude, srcFolder, codeFolder, docsFolder, title, readme, rmPattern } = parseArguments(argv);

const startTime = +new Date();

Expand All @@ -77,7 +77,7 @@ export const generate = async (argv: CLIArguments) => {
if (!file.isDir) {
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0);
process.stdout.write(`${chalk.dim(` ${file.path} `)}`);
process.stdout.write(chalk.dim(` ${file.path} `));
await new Promise(resolve => setTimeout(resolve, 20));
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ export interface CLIArguments {
readme: string;
watch: boolean;
}

export interface ParseReturn {
success: boolean;
dest: string;
file: DirectoryFile;
content: string;
empty: boolean;
excluded?: boolean;
relativePathSrc: string;
relativePathDest: string;
}
1 change: 0 additions & 1 deletion src/lib/list-folder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import chalk from 'chalk';
import fs from 'fs/promises';
import mm from 'micromatch';
import path from 'path';
Expand Down
14 changes: 1 addition & 13 deletions src/lib/parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import chalk from 'chalk';
import fs from 'fs/promises';
import jsdoc2md from 'jsdoc-to-markdown';
import mkdirp from 'mkdirp';
Expand All @@ -7,21 +6,10 @@ import compileTemplates from 'vue-docgen-cli/lib/compileTemplates';
import { extractConfig } from 'vue-docgen-cli/lib/docgen';

import { StatisticType } from '../constants';
import { DirectoryFile } from '../interfaces';
import { DirectoryFile, ParseReturn } from '../interfaces';

import { parseVuepressFileHeader } from './comment-parser';

interface ParseReturn {
success: boolean;
dest: string;
file: DirectoryFile;
content: string;
empty: boolean;
excluded?: boolean;
relativePathSrc: string;
relativePathDest: string;
}

export const parseFile = async (
file: DirectoryFile,
srcFolder: string,
Expand Down
22 changes: 11 additions & 11 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
/**
* Get extension of file
*
* @param {string} path
* @param path
* @returns extension of file
*/
export const getExtension = (path: string) => path.substring(path.length, path.lastIndexOf('.'));

/**
* Check if extension ist correct
*
* @param {string} path
* @param {array} extensions
* @returns a boolean
* @param path
* @param extensions
* @returns boolean
*/
export const checkExtension = (path: string, extensions: string[]) => extensions.indexOf(getExtension(path)) >= 0;

/**
* Get filename without extension
*
* @param {string} path
* @param path
* @returns filename
*/
export const getFilename = (path: string) =>
Expand All @@ -29,10 +26,13 @@ export const getFilename = (path: string) =>

/**
* Async foreach loop
* @param {array} array
* @param {function} callback
* @param array
* @param callback
*/
export const asyncForEach = async (array: any[], callback: (result: any, index: number, array: any[]) => void) => {
export const asyncForEach = async (
array: any[],
callback: (result: any, index: number, array: any[]) => Promise<void>
) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
Expand Down

0 comments on commit 45370ea

Please sign in to comment.