Skip to content

Commit

Permalink
refactor: update dependencies, split files and switch to kebab-case
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Feb 2, 2019
1 parent 3dda693 commit 0992836
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 71 deletions.
44 changes: 15 additions & 29 deletions cmds/generate.js → cmds/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// const fs = require('fs/promises');
'use strict';

const fs = require('fs.promised/promisify')(require('bluebird'));
const path = require('path');
const mkdirp = require('mkdirp');
Expand All @@ -8,8 +9,9 @@ const del = require('del');
const mm = require('micromatch');
const chalk = require('chalk');

const vueSidebar = require('../helpers/vueSidebar');
const parseVuepressComment = require('../helpers/commentParser');
const vueSidebar = require('../helpers/vue-sidebar');
const parseVuepressComment = require('../helpers/comment-parser');
const { checkExtension, getFilename } = require('../helpers/utils');

const fileTree = [];

Expand All @@ -19,8 +21,8 @@ const extensions = ['.ts', '.js', '.vue'];
* Default command that generate md files
* @param {Object} argv Arguments passed by yargs
*/
async function generate(argv) {
const exclude = argv.exclude && (argv.exclude.split(',') || [argv.exclude]);
async function generate(argv, ctx) {
const exclude = (argv.exclude && argv.exclude.split(',')) || [argv.exclude || ''];
const srcFolder = argv.source;
const codeFolder = argv.folder;
const docsFolder = `${argv.dist}/${codeFolder}`;
Expand Down Expand Up @@ -69,28 +71,6 @@ async function generate(argv) {
console.log(`\n${chalk.green.bold(`Finished! 👍 `)}`);
});

/**
* Check if extension ist correct
*
* @param {string} path
* @param {array} extensions
* @returns extension of file
*/
const checkExtension = (path, extensions) =>
extensions.indexOf(path.substring(path.length, path.lastIndexOf('.'))) >= 0;

/**
* Get filename without extension
*
* @param {string} path
* @returns filename
*/
const getFilename = path =>
path
.split('/')
.pop()
.substring(0, path.lastIndexOf('.')) || '';

/**
* Read all files in directory
*
Expand All @@ -113,7 +93,7 @@ async function generate(argv) {

// iterate through all files in folder
await asyncForEach(files, async file => {
if (mm.contains(`${folder}/${file}`, exclude)) {
if (exclude && mm.contains(`${folder}/${file}`, exclude)) {
console.log(chalk.black.bgBlue('exclude'), `${folder}/${file}`);
return;
}
Expand Down Expand Up @@ -215,4 +195,10 @@ async function asyncForEach(array, callback) {
}
}

module.exports = generate;
module.exports = {
generate,
plugin: (options, ctx) => ({
name: 'vuepress-plugin-jsdoc',
generate: generate(options, ctx)
})
};
File renamed without changes.
25 changes: 25 additions & 0 deletions helpers/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

/**
* Check if extension ist correct
*
* @param {string} path
* @param {array} extensions
* @returns extension of file
*/
exports.checkExtension = (path, extensions) =>
extensions.indexOf(path.substring(path.length, path.lastIndexOf('.'))) >= 0;

/**
* Get filename without extension
*
* @param {string} path
* @returns filename
*/
exports.getFilename = path =>
(path &&
path
.split('/')
.pop()
.substring(0, path.lastIndexOf('.'))) ||
'';
File renamed without changes.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const yargs = require('yargs');
const generate = require('./cmds/generate');
const { generate } = require('./cmds');

function main() {
yargs
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"devDependencies": {
"husky": "^1.3.1",
"jest": "^24.0.0",
"lint-staged": "^8.1.0"
"lint-staged": "^8.1.2"
},
"lint-staged": {
"**/*.{js,jsx,css,scss,json,ts,vue}": [
Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const commentParser = require('../helpers/commentParser');
const commentParser = require('../helpers/comment-parser');

const template = `/*
* @vuepress
Expand Down
19 changes: 19 additions & 0 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const { checkExtension, getFilename } = require('../helpers/utils');

describe('test utils', () => {
test('checkExtension should return true', () => {
expect(checkExtension('./dir/test.jpg', ['.jpg'])).toBe(true);
});
test('checkExtension should return false', () => {
expect(checkExtension('test.jpg', ['.vue'])).toBe(false);
});
test('getFilename should return only filename', () => {
expect(getFilename('../path/to/test-file.js')).toBe('test-file.js');
});
test('getFilename should return empty string', () => {
expect(getFilename(undefined)).toBe('');
expect(getFilename()).toBe('');
});
});
90 changes: 51 additions & 39 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/runtime@7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.0.0.tgz#adeb78fedfc855aa05bc041640f3f6f98e85424c"
integrity sha512-7hGhzlcmg01CvH1EHdSPVXYX1aJ8KCEyz6I9xYIi/asDtzBPMyMhVibhM/K6g/5qnKBwjZtp10bNZIEFTRW1MA==
dependencies:
regenerator-runtime "^0.12.0"

"@babel/template@^7.0.0", "@babel/template@^7.1.0", "@babel/template@^7.1.2", "@babel/template@^7.2.2":
version "7.2.2"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.2.2.tgz#005b3fdf0ed96e88041330379e0da9a708eb2907"
Expand Down Expand Up @@ -887,16 +894,7 @@ core-util-is@1.0.2, core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=

cosmiconfig@5.0.6:
version "5.0.6"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.6.tgz#dca6cf680a0bd03589aff684700858c81abeeb39"
integrity sha512-6DWfizHriCrFWURP1/qyhsiFvYdlJzbCzmtFWh744+KyWsJo5+kPzUZZaMRSSItoYc0pxFX7gEO7ZC1/gN/7AQ==
dependencies:
is-directory "^0.3.1"
js-yaml "^3.9.0"
parse-json "^4.0.0"

cosmiconfig@^5.0.7:
cosmiconfig@^5.0.2, cosmiconfig@^5.0.7:
version "5.0.7"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.7.tgz#39826b292ee0d78eda137dfa3173bd1c21a43b04"
integrity sha512-PcLqxTKiDmNT6pSpy4N6KtuPwb53W+2tzNvwOZw0WH9N6O0vLIBq0x8aj8Oj75ere4YcGi48bDFCL+3fRJdlNA==
Expand Down Expand Up @@ -1437,6 +1435,11 @@ find-up@^3.0.0:
dependencies:
locate-path "^3.0.0"

fn-name@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/fn-name/-/fn-name-2.0.1.tgz#5214d7537a4d06a4a301c0cc262feb84188002e7"
integrity sha1-UhTXU3pNBqSjAcDMJi/rhBiAAuc=

for-in@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
Expand Down Expand Up @@ -2294,11 +2297,6 @@ jest-environment-node@^24.0.0:
jest-mock "^24.0.0"
jest-util "^24.0.0"

jest-get-type@^22.1.0:
version "22.4.3"
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.4.3.tgz#e3a8504d8479342dd4420236b322869f18900ce4"
integrity sha512-/jsz0Y+V29w1chdXVygEKSz2nBoHoYqNShPe+QgxSNjAuP1i8+k4LbQNrfoliKej0P45sivkSCh7yiD6ubHS3w==

jest-get-type@^24.0.0:
version "24.0.0"
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-24.0.0.tgz#36e72930b78e33da59a4f63d44d332188278940b"
Expand Down Expand Up @@ -2472,16 +2470,6 @@ jest-util@^24.0.0:
slash "^2.0.0"
source-map "^0.6.0"

jest-validate@^23.5.0:
version "23.6.0"
resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-23.6.0.tgz#36761f99d1ed33fcd425b4e4c5595d62b6597474"
integrity sha512-OFKapYxe72yz7agrDAWi8v2WL8GIfVqcbKRCLbRG9PAxtzF9b1SEDdTpytNDN12z2fJynoBwpMpvj2R39plI2A==
dependencies:
chalk "^2.0.1"
jest-get-type "^22.1.0"
leven "^2.1.0"
pretty-format "^23.6.0"

jest-validate@^24.0.0:
version "24.0.0"
resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-24.0.0.tgz#aa8571a46983a6538328fef20406b4a496b6c020"
Expand Down Expand Up @@ -2737,15 +2725,15 @@ levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"

lint-staged@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-8.1.0.tgz#dbc3ae2565366d8f20efb9f9799d076da64863f2"
integrity sha512-yfSkyJy7EuVsaoxtUSEhrD81spdJOe/gMTGea3XaV7HyoRhTb9Gdlp6/JppRZERvKSEYXP9bjcmq6CA5oL2lYQ==
lint-staged@^8.1.2:
version "8.1.2"
resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-8.1.2.tgz#3f486d438bec9fb61bedf4b49559b66c72ee94ab"
integrity sha512-n0693jPSCv3K5TbQu1NCXGQ3oRRw/gZbL1yLBmEgitNCYBGhDYUZBXPzljh2vopckGrZ8pVWbuIHfJCRR31O4A==
dependencies:
"@iamstarkov/listr-update-renderer" "0.4.1"
chalk "^2.3.1"
commander "^2.14.1"
cosmiconfig "5.0.6"
cosmiconfig "^5.0.2"
debug "^3.1.0"
dedent "^0.7.0"
del "^3.0.0"
Expand All @@ -2754,7 +2742,6 @@ lint-staged@^8.1.0:
g-status "^2.0.2"
is-glob "^4.0.0"
is-windows "^1.0.2"
jest-validate "^23.5.0"
listr "^0.14.2"
lodash "^4.17.5"
log-symbols "^2.2.0"
Expand All @@ -2767,6 +2754,7 @@ lint-staged@^8.1.0:
staged-git-files "1.1.2"
string-argv "^0.0.2"
stringify-object "^3.2.2"
yup "^0.26.10"

listr-silent-renderer@^1.1.1:
version "1.1.1"
Expand Down Expand Up @@ -3572,14 +3560,6 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=

pretty-format@^23.6.0:
version "23.6.0"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-23.6.0.tgz#5eaac8eeb6b33b987b7fe6097ea6a8a146ab5760"
integrity sha512-zf9NV1NSlDLDjycnwm6hpFATCGl/K1lt0R/GdkAK2O5LN/rwJoB+Mh93gGJjut4YbmecbfgLWVGSTCr0Ewvvbw==
dependencies:
ansi-regex "^3.0.0"
ansi-styles "^3.2.0"

pretty-format@^24.0.0:
version "24.0.0"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-24.0.0.tgz#cb6599fd73ac088e37ed682f61291e4678f48591"
Expand All @@ -3601,6 +3581,11 @@ prompts@^2.0.1:
kleur "^3.0.0"
sisteransi "^1.0.0"

property-expr@^1.5.0:
version "1.5.1"
resolved "https://registry.yarnpkg.com/property-expr/-/property-expr-1.5.1.tgz#22e8706894a0c8e28d58735804f6ba3a3673314f"
integrity sha512-CGuc0VUTGthpJXL36ydB6jnbyOf/rAHFvmVrJlH+Rg0DqqLFQGAP6hIaxD/G0OAmBJPhXDHuEJigrp0e0wFV6g==

psl@^1.1.24, psl@^1.1.28:
version "1.1.31"
resolved "https://registry.yarnpkg.com/psl/-/psl-1.1.31.tgz#e9aa86d0101b5b105cbe93ac6b784cd547276184"
Expand Down Expand Up @@ -3718,6 +3703,11 @@ reduce-without@^1.0.1:
dependencies:
test-value "^2.0.0"

regenerator-runtime@^0.12.0:
version "0.12.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz#fa1a71544764c036f8c49b13a08b2594c9f8a0de"
integrity sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==

regex-not@^1.0.0, regex-not@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/regex-not/-/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c"
Expand Down Expand Up @@ -4341,6 +4331,11 @@ symbol-tree@^3.2.2:
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"
integrity sha1-rifbOPZgp64uHDt9G8KQgZuFGeY=

synchronous-promise@^2.0.5:
version "2.0.6"
resolved "https://registry.yarnpkg.com/synchronous-promise/-/synchronous-promise-2.0.6.tgz#de76e0ea2b3558c1e673942e47e714a930fa64aa"
integrity sha512-TyOuWLwkmtPL49LHCX1caIwHjRzcVd62+GF6h8W/jHOeZUFHpnd2XJDVuUlaTaLPH1nuu2M69mfHr5XbQJnf/g==

table-layout@^0.4.2:
version "0.4.4"
resolved "https://registry.yarnpkg.com/table-layout/-/table-layout-0.4.4.tgz#bc5398b2a05e58b67b05dd9238354b89ef27be0f"
Expand Down Expand Up @@ -4449,6 +4444,11 @@ to-regex@^3.0.1, to-regex@^3.0.2:
regex-not "^1.0.2"
safe-regex "^1.1.0"

toposort@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/toposort/-/toposort-2.0.2.tgz#ae21768175d1559d48bef35420b2f4962f09c330"
integrity sha1-riF2gXXRVZ1IvvNUILL0li8JwzA=

tough-cookie@>=2.3.3:
version "3.0.0"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-3.0.0.tgz#d2bceddebde633153ff20a52fa844a0dc71dacef"
Expand Down Expand Up @@ -4899,3 +4899,15 @@ yargs@^12.0.2, yargs@^12.0.5:
which-module "^2.0.0"
y18n "^3.2.1 || ^4.0.0"
yargs-parser "^11.1.1"

yup@^0.26.10:
version "0.26.10"
resolved "https://registry.yarnpkg.com/yup/-/yup-0.26.10.tgz#3545839663289038faf25facfc07e11fd67c0cb1"
integrity sha512-keuNEbNSnsOTOuGCt3UJW69jDE3O4P+UHAakO7vSeFMnjaitcmlbij/a3oNb9g1Y1KvSKH/7O1R2PQ4m4TRylw==
dependencies:
"@babel/runtime" "7.0.0"
fn-name "~2.0.1"
lodash "^4.17.10"
property-expr "^1.5.0"
synchronous-promise "^2.0.5"
toposort "^2.0.2"

0 comments on commit 0992836

Please sign in to comment.