Socket
Socket
Sign inDemoInstall

vue-docgen-cli

Package Overview
Dependencies
Maintainers
3
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-docgen-cli - npm Package Compare versions

Comparing version 3.20.3 to 3.20.4

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [3.20.4](https://github.com/vue-styleguidist/vue-styleguidist/compare/v3.20.3...v3.20.4) (2019-08-12)
### Bug Fixes
* watcher looking at md files ([536157d](https://github.com/vue-styleguidist/vue-styleguidist/commit/536157d))
## [3.20.3](https://github.com/vue-styleguidist/vue-styleguidist/compare/v3.20.2...v3.20.3) (2019-08-12)

@@ -8,0 +19,0 @@

23

lib/docgen.js

@@ -37,5 +37,2 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {

@@ -48,8 +45,12 @@ if (mod && mod.__esModule) return mod;

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var path = __importStar(require("path"));
var globby_1 = __importDefault(require("globby"));
var path = __importStar(require("path"));
var singleMd_1 = __importDefault(require("./singleMd"));
var multiMd_1 = __importDefault(require("./multiMd"));
var utils_1 = require("./utils");
function hasComponents(config) {

@@ -59,3 +60,3 @@ return !!config.components;

exports.default = (function (config) { return __awaiter(_this, void 0, void 0, function () {
var files;
var files, watcher, docMap;
return __generator(this, function (_a) {

@@ -75,12 +76,18 @@ switch (_a.label) {

config.outFile = config.outFile ? path.resolve(config.outDir, config.outFile) : undefined;
return [4 /*yield*/, globby_1.default(config.components, { cwd: config.componentsRoot })];
return [4 /*yield*/, globby_1.default(config.components, { cwd: config.componentsRoot })
// then create the watcher if necessary
];
case 1:
files = _a.sent();
if (config.watch) {
watcher = utils_1.getWatcher(config.components, config.componentsRoot, files.map(function (f) { return path.relative(config.componentsRoot, config.getDocFileName(f)); }));
}
docMap = utils_1.getDocMap(files, config.getDocFileName, config.componentsRoot);
if (config.outFile) {
// create one combined documentation file
singleMd_1.default(files, config);
singleMd_1.default(files, watcher, config, docMap);
}
else {
// create one documentation file per component
multiMd_1.default(files, config);
multiMd_1.default(files, watcher, config, docMap);
}

@@ -87,0 +94,0 @@ return [2 /*return*/];

@@ -0,1 +1,2 @@

import { FSWatcher } from 'chokidar';
import { DocgenCLIConfigWithComponents } from './docgen';

@@ -9,3 +10,5 @@ /**

*/
export default function (files: string[], config: DocgenCLIConfigWithComponents): void;
export default function (files: string[], watcher: FSWatcher | undefined, config: DocgenCLIConfigWithComponents, docMap: {
[filepath: string]: string;
}, _compile?: typeof compile): void;
/**

@@ -12,0 +15,0 @@ * /**

@@ -56,9 +56,8 @@ "use strict";

*/
function default_1(files, config) {
var docMap = utils_1.getDocMap(files, config.getDocFileName);
var compileWithConfig = compile.bind(null, config, docMap);
function default_1(files, watcher, config, docMap, _compile) {
if (_compile === void 0) { _compile = compile; }
var compileWithConfig = _compile.bind(null, config, docMap);
files.forEach(compileWithConfig);
// run chokidar on the glob
if (config.watch) {
utils_1.getWatcher(config.components, config.componentsRoot, files, config.getDocFileName)
if (watcher) {
watcher
// on filechange, recompile the corresponding file

@@ -65,0 +64,0 @@ .on('add', compileWithConfig)

@@ -0,1 +1,2 @@

import { FSWatcher } from 'chokidar';
import { DocgenCLIConfigWithComponents } from './docgen';

@@ -10,5 +11,9 @@ export interface DocgenCLIConfigWithOutFile extends DocgenCLIConfigWithComponents {

* @param files
* @param watcher
* @param config
* @param _compile
*/
export default function (files: string[], config: DocgenCLIConfigWithOutFile): void;
export default function (files: string[], watcher: FSWatcher | undefined, config: DocgenCLIConfigWithOutFile, docMap: {
[filepath: string]: string;
}, _compile?: typeof compile): void;
/**

@@ -15,0 +20,0 @@ * Compile all components in `files` into one single

@@ -44,6 +44,8 @@ "use strict";

* @param files
* @param watcher
* @param config
* @param _compile
*/
function default_1(files, config) {
var docMap = utils_1.getDocMap(files, config.getDocFileName);
function default_1(files, watcher, config, docMap, _compile) {
if (_compile === void 0) { _compile = compile; }
// This fileCache contains will, because it is

@@ -55,8 +57,6 @@ // bound, the same along usage of this function.

var fileCache = {};
var compileSingleDocWithConfig = compile.bind(null, config, files, fileCache, docMap);
var compileSingleDocWithConfig = _compile.bind(null, config, files, fileCache, docMap);
compileSingleDocWithConfig();
if (config.watch) {
utils_1.getWatcher(config.components, config.componentsRoot, files, config.getDocFileName)
.on('add', compileSingleDocWithConfig)
.on('change', compileSingleDocWithConfig);
if (watcher) {
watcher.on('add', compileSingleDocWithConfig).on('change', compileSingleDocWithConfig);
}

@@ -63,0 +63,0 @@ }

@@ -1,2 +0,2 @@

import chokidar from 'chokidar';
import { FSWatcher } from 'chokidar';
import { DocgenCLIConfig } from './compileTemplates';

@@ -19,10 +19,18 @@ /**

* the glob but their corresponding doc files
* @param components
* @param componentsRoot
* @param files
* @param getDocFileName
* @param components glob or globs to watch
* @param cwd cwd to pass to chokidar
* @param additionalFilesWatched the files found by globby to
*/
export declare function getWatcher(components: string | string[], componentsRoot: string, files: string[], getDocFileName: (file: string) => string): chokidar.FSWatcher;
export declare function getDocMap(files: string[], getDocFileName: (file: string) => string): {
export declare function getWatcher(components: string | string[], cwd: string, additionalFilesWatched: string[]): FSWatcher;
/**
* retrun an object matching document relative file path
* with their corresponding components, it's inteded to be use
* with watchers to update the right documentation on update of
* Readme.md files
* @param files file paths of the matched comeponents
* @param getDocFileName way to transform a comopnent path into it's Readme.md
* @param root componentRoot to de-absolutize the DocFileName path
*/
export declare function getDocMap(files: string[], getDocFileName: (file: string) => string, root: string): {
[filepath: string]: string;
};

@@ -117,21 +117,26 @@ "use strict";

* the glob but their corresponding doc files
* @param components
* @param componentsRoot
* @param files
* @param getDocFileName
* @param components glob or globs to watch
* @param cwd cwd to pass to chokidar
* @param additionalFilesWatched the files found by globby to
*/
function getWatcher(components, componentsRoot, files, getDocFileName) {
var watcher = chokidar_1.default.watch(components, { cwd: componentsRoot });
files.forEach(function (f) {
var docfile = getDocFileName(f);
watcher.add(docfile);
});
return watcher;
function getWatcher(components, cwd, additionalFilesWatched) {
var w = chokidar_1.default.watch(components, { cwd: cwd });
w.add(additionalFilesWatched);
return w;
}
exports.getWatcher = getWatcher;
function getDocMap(files, getDocFileName) {
/**
* retrun an object matching document relative file path
* with their corresponding components, it's inteded to be use
* with watchers to update the right documentation on update of
* Readme.md files
* @param files file paths of the matched comeponents
* @param getDocFileName way to transform a comopnent path into it's Readme.md
* @param root componentRoot to de-absolutize the DocFileName path
*/
function getDocMap(files, getDocFileName, root) {
var docMap = {};
files.forEach(function (f) {
var docFilePath = getDocFileName(f);
docMap[docFilePath] = f;
docMap[path.relative(root, docFilePath)] = f;
});

@@ -138,0 +143,0 @@ return docMap;

{
"name": "vue-docgen-cli",
"version": "3.20.3",
"version": "3.20.4",
"scripts": {

@@ -25,3 +25,3 @@ "compile": "tsc -p ./tsconfig.build.json",

},
"gitHead": "02dad977160fa429c80b27a90554356c3b01427b"
"gitHead": "6e7617cc4614960d8f4714fbb77ad938880ffcac"
}

@@ -74,3 +74,3 @@ # vue-docgen-cli

> type: `string`, default: `"src/components/**/[a-zA-Z]*.{vue,js,jsx,ts,tsx}"`
> type: `string | string[]` , default: `"src/components/**/[a-zA-Z]*.{vue,js,jsx,ts,tsx}"`

@@ -77,0 +77,0 @@ Glob string used to get all the components to parse and document.

@@ -1,2 +0,3 @@

import { compile } from '../multiMd'
import { FSWatcher } from 'chokidar'
import * as multiMd from '../multiMd'
import extractConfig from '../extractConfig'

@@ -7,2 +8,3 @@ import { writeDownMdFile } from '../utils'

const FAKE_MD_CONTENT = '## fake markdonw Content'
const FILES = ['src/comps/button/button.vue', 'src/comps/checkbox/checkbox.vue']

@@ -26,2 +28,6 @@ var mockCompileMarkdown: jest.Mock

let conf: DocgenCLIConfigWithComponents
const fakeOn = jest.fn()
let w = {
on: fakeOn.mockImplementation(() => ({ on: fakeOn }))
}

@@ -35,7 +41,25 @@ beforeEach(() => {

it('should get the current components doc', async done => {
await compile(conf, {}, FAKE_COMPONENT_PATH)
expect(writeDownMdFile).toHaveBeenCalledWith(FAKE_MD_CONTENT, MD_FILE_PATH)
done()
describe('compile', () => {
it('should get the current components doc', async done => {
await multiMd.compile(conf, {}, FAKE_COMPONENT_PATH)
expect(writeDownMdFile).toHaveBeenCalledWith(FAKE_MD_CONTENT, MD_FILE_PATH)
done()
})
})
describe('default', () => {
it('should build one md from each file passed', () => {
jest.spyOn(multiMd, 'compile').mockImplementation(() => Promise.resolve())
multiMd.default(FILES, undefined, conf, {}, multiMd.compile)
expect(multiMd.compile).toHaveBeenCalledTimes(FILES.length)
})
it('should watch file changes if a watcher is passed', () => {
fakeOn.mockClear()
multiMd.default(FILES, (w as unknown) as FSWatcher, conf, {})
expect(fakeOn).toHaveBeenCalledWith('add', expect.any(Function))
expect(fakeOn).toHaveBeenCalledWith('change', expect.any(Function))
expect(fakeOn).toHaveBeenCalledWith('unlink', expect.any(Function))
})
})
})

@@ -1,2 +0,3 @@

import { compile, DocgenCLIConfigWithOutFile } from '../singleMd'
import { FSWatcher } from 'chokidar'
import * as singleMd from '../singleMd'
import extractConfig from '../extractConfig'

@@ -6,2 +7,3 @@ import { writeDownMdFile } from '../utils'

const FAKE_MD_CONTENT = '## fake markdonw Content'
const FILES = ['src/comps/button/button.vue']

@@ -19,22 +21,41 @@ var mockCompileMarkdown: jest.Mock

describe('singleMd', () => {
describe('compile', () => {
const CWD = 'here'
const FAKE_COMPONENT_PATH = 'here'
const FAKE_COMPONENT_FULL_PATH = 'component/is/here'
const MD_FILE_PATH = 'files/docs.md'
let conf: DocgenCLIConfigWithOutFile
let conf: singleMd.DocgenCLIConfigWithOutFile
const fakeOn = jest.fn()
let w = {
on: fakeOn.mockImplementation(() => ({ on: fakeOn }))
}
beforeEach(() => {
conf = extractConfig([], CWD) as DocgenCLIConfigWithOutFile
conf = extractConfig([], CWD) as singleMd.DocgenCLIConfigWithOutFile
conf.components = '**/*.vue'
conf.outFile = 'files/docs.md'
conf.getDocFileName = jest.fn(() => FAKE_COMPONENT_FULL_PATH)
conf.getDestFile = jest.fn(() => MD_FILE_PATH)
})
it('should get the current components doc', async done => {
await compile(conf, [FAKE_COMPONENT_PATH], {}, {})
expect(writeDownMdFile).toHaveBeenCalledWith(FAKE_MD_CONTENT, MD_FILE_PATH)
done()
describe('compile', () => {
it('should get the current components doc', async done => {
await singleMd.compile(conf, [FAKE_COMPONENT_PATH], {}, {})
expect(writeDownMdFile).toHaveBeenCalledWith(FAKE_MD_CONTENT, MD_FILE_PATH)
done()
})
})
describe('default', () => {
it('should build one md from merging contents', () => {
jest.spyOn(singleMd, 'compile').mockImplementation(() => Promise.resolve())
singleMd.default(FILES, undefined, conf, {}, singleMd.compile)
expect(singleMd.compile).toHaveBeenCalledWith(conf, FILES, {}, {})
})
it('should watch file changes if a watcher is passed', () => {
fakeOn.mockClear()
singleMd.default(FILES, (w as unknown) as FSWatcher, conf, {})
expect(fakeOn).toHaveBeenCalledWith('add', expect.any(Function))
expect(fakeOn).toHaveBeenCalledWith('change', expect.any(Function))
})
})
})
import * as path from 'path'
import { writeDownMdFile, compileMarkdown } from '../utils'
import { writeDownMdFile, compileMarkdown, getDocMap, getWatcher } from '../utils'
import extractConfig, { DocgenCLIConfig } from '../extractConfig'

@@ -9,6 +9,2 @@

jest.mock('chokidar', () => ({
watch: jest.fn()
}))
var mockFs: {

@@ -114,1 +110,52 @@ readFile: jest.Mock

})
var mockWatch: jest.Mock, mockAddWatch: jest.Mock
jest.mock('chokidar', () => {
mockAddWatch = jest.fn()
mockWatch = jest.fn(() => ({
add: mockAddWatch
}))
return {
watch: mockWatch
}
})
const FILES = [
'src/components/Button/Button.vue',
'src/components/Input/Input.vue',
'src/components/CounterButton/CounterButton.vue',
'src/components/PushButton/PushButton.vue'
]
const COMPONENTS_GLOB = 'components/**/*.vue'
const getDocFileName = (componentPath: string) =>
path.resolve(path.dirname(componentPath), 'Readme.md')
describe('getWatcher', () => {
it('should watch the files passed', () => {
mockWatch.mockClear()
getWatcher(COMPONENTS_GLOB, 'src', FILES)
expect(mockWatch).toHaveBeenCalledWith(COMPONENTS_GLOB, expect.any(Object))
})
it('should add all the additional files', () => {
mockAddWatch.mockClear()
getWatcher(COMPONENTS_GLOB, 'src', FILES)
expect(mockAddWatch).toHaveBeenCalledWith(FILES)
})
})
describe('getDocMap', () => {
it('should return relative maps', () => {
const docMap = getDocMap(FILES, getDocFileName, 'src')
expect(docMap).toMatchInlineSnapshot(`
Object {
"components/Button/Readme.md": "src/components/Button/Button.vue",
"components/CounterButton/Readme.md": "src/components/CounterButton/CounterButton.vue",
"components/Input/Readme.md": "src/components/Input/Input.vue",
"components/PushButton/Readme.md": "src/components/PushButton/PushButton.vue",
}
`)
})
})

@@ -0,6 +1,8 @@

import * as path from 'path'
import globby from 'globby'
import * as path from 'path'
import { FSWatcher } from 'chokidar'
import { DocgenCLIConfig } from './extractConfig'
import singleMd, { DocgenCLIConfigWithOutFile } from './singleMd'
import multiMd from './multiMd'
import { getWatcher, getDocMap } from './utils'

@@ -31,9 +33,21 @@ export interface DocgenCLIConfigWithComponents extends DocgenCLIConfig {

// then create the watcher if necessary
var watcher: FSWatcher | undefined
if (config.watch) {
watcher = getWatcher(
config.components,
config.componentsRoot,
files.map(f => path.relative(config.componentsRoot, config.getDocFileName(f)))
)
}
const docMap = getDocMap(files, config.getDocFileName, config.componentsRoot)
if (config.outFile) {
// create one combined documentation file
singleMd(files, config as DocgenCLIConfigWithOutFile)
singleMd(files, watcher, config as DocgenCLIConfigWithOutFile, docMap)
} else {
// create one documentation file per component
multiMd(files, config)
multiMd(files, watcher, config, docMap)
}
}
import * as fs from 'fs'
import { FSWatcher } from 'chokidar'
import { promisify } from 'util'
import { compileMarkdown, writeDownMdFile, getWatcher, getDocMap } from './utils'
import { compileMarkdown, writeDownMdFile } from './utils'
import { DocgenCLIConfigWithComponents } from './docgen'

@@ -15,11 +16,15 @@

*/
export default function(files: string[], config: DocgenCLIConfigWithComponents) {
const docMap = getDocMap(files, config.getDocFileName)
const compileWithConfig = compile.bind(null, config, docMap)
export default function(
files: string[],
watcher: FSWatcher | undefined,
config: DocgenCLIConfigWithComponents,
docMap: { [filepath: string]: string },
_compile = compile
) {
const compileWithConfig = _compile.bind(null, config, docMap)
files.forEach(compileWithConfig)
// run chokidar on the glob
if (config.watch) {
getWatcher(config.components, config.componentsRoot, files, config.getDocFileName)
if (watcher) {
watcher
// on filechange, recompile the corresponding file

@@ -29,3 +34,3 @@ .on('add', compileWithConfig)

// on file delete, delete corresponding md file
.on('unlink', relPath => {
.on('unlink', (relPath: string) => {
unlink(config.getDestFile(relPath, config))

@@ -32,0 +37,0 @@ })

@@ -1,2 +0,3 @@

import { compileMarkdown, writeDownMdFile, getWatcher, getDocMap } from './utils'
import { FSWatcher } from 'chokidar'
import { compileMarkdown, writeDownMdFile } from './utils'
import { DocgenCLIConfigWithComponents } from './docgen'

@@ -13,7 +14,13 @@

* @param files
* @param watcher
* @param config
* @param _compile
*/
export default function(files: string[], config: DocgenCLIConfigWithOutFile) {
const docMap = getDocMap(files, config.getDocFileName)
export default function(
files: string[],
watcher: FSWatcher | undefined,
config: DocgenCLIConfigWithOutFile,
docMap: { [filepath: string]: string },
_compile = compile
) {
// This fileCache contains will, because it is

@@ -25,9 +32,7 @@ // bound, the same along usage of this function.

const fileCache = {}
const compileSingleDocWithConfig = compile.bind(null, config, files, fileCache, docMap)
const compileSingleDocWithConfig = _compile.bind(null, config, files, fileCache, docMap)
compileSingleDocWithConfig()
if (config.watch) {
getWatcher(config.components, config.componentsRoot, files, config.getDocFileName)
.on('add', compileSingleDocWithConfig)
.on('change', compileSingleDocWithConfig)
if (watcher) {
watcher.on('add', compileSingleDocWithConfig).on('change', compileSingleDocWithConfig)
}

@@ -34,0 +39,0 @@ }

import * as path from 'path'
import * as fs from 'fs'
import { promisify } from 'util'
import chokidar from 'chokidar'
import chokidar, { FSWatcher } from 'chokidar'
import mkdirpNative from 'mkdirp'

@@ -46,24 +46,29 @@ import prettier from 'prettier'

* the glob but their corresponding doc files
* @param components
* @param componentsRoot
* @param files
* @param getDocFileName
* @param components glob or globs to watch
* @param cwd cwd to pass to chokidar
* @param additionalFilesWatched the files found by globby to
*/
export function getWatcher(
components: string | string[],
componentsRoot: string,
files: string[],
getDocFileName: (file: string) => string
) {
const watcher = chokidar.watch(components, { cwd: componentsRoot })
files.forEach(f => {
const docfile = getDocFileName(f)
watcher.add(docfile)
})
return watcher
cwd: string,
additionalFilesWatched: string[]
): FSWatcher {
const w = chokidar.watch(components, { cwd })
w.add(additionalFilesWatched)
return w
}
/**
* retrun an object matching document relative file path
* with their corresponding components, it's inteded to be use
* with watchers to update the right documentation on update of
* Readme.md files
* @param files file paths of the matched comeponents
* @param getDocFileName way to transform a comopnent path into it's Readme.md
* @param root componentRoot to de-absolutize the DocFileName path
*/
export function getDocMap(
files: string[],
getDocFileName: (file: string) => string
getDocFileName: (file: string) => string,
root: string
): { [filepath: string]: string } {

@@ -73,5 +78,5 @@ const docMap: { [filepath: string]: string } = {}

const docFilePath = getDocFileName(f)
docMap[docFilePath] = f
docMap[path.relative(root, docFilePath)] = f
})
return docMap
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc