From b574947318215b4730c58209e005db5591daa47a Mon Sep 17 00:00:00 2001 From: Pedro Nauck Date: Sat, 11 Aug 2018 00:43:18 -0300 Subject: [PATCH] feat(docz-core): resolve markdown files by default --- packages/docz-core/src/Entries.tsx | 33 +++++++++++++++---- .../docz-core/src/bundlers/webpack/loaders.ts | 2 +- packages/docz-core/src/commands/args.ts | 7 +++- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/packages/docz-core/src/Entries.tsx b/packages/docz-core/src/Entries.tsx index 3b8f38d76..db017ab4f 100644 --- a/packages/docz-core/src/Entries.tsx +++ b/packages/docz-core/src/Entries.tsx @@ -1,6 +1,6 @@ import * as path from 'path' import * as fs from 'fs-extra' -import * as glob from 'fast-glob' +import glob from 'fast-glob' import * as paths from './config/paths' import { touch, compiled } from './utils/fs' @@ -13,6 +13,20 @@ import { repoInfo } from './utils/repo-info' export const fromTemplates = (file: string) => path.join(paths.templates, file) +const DEFAULT_IGNORE = [ + '!**/node_modules/**', + 'readme.md', + 'changelog.md', + 'code_of_conduct.md', + 'contributing.md', + 'license.md', +] + +const matchFilesWithSrc = (config: Config) => (files: string[]) => { + const src = path.relative(paths.root, config.src) + return files.map(file => (file.startsWith(src) ? file : path.join(src, file))) +} + const writeAppFiles = async (config: Config, dev: boolean): Promise => { const { plugins, theme } = config const props = Plugin.propsOfPlugins(plugins) @@ -61,12 +75,17 @@ export class Entries { } private async getMap(config: Config): Promise { - const { src, files: pattern } = config - - const ignoreGlob = '!node_modules' - const files: string[] = glob.sync( - Array.isArray(pattern) ? [...pattern, ignoreGlob] : [pattern, ignoreGlob] - ) + const { src, files: pattern, ignore } = config + const arr = Array.isArray(pattern) ? pattern : [pattern] + const toMatch = matchFilesWithSrc(config) + + const files = await glob(toMatch(arr), { + ignore: DEFAULT_IGNORE.concat(ignore), + onlyFiles: true, + unique: true, + nocase: true, + matchBase: true, + }) const createEntry = async (file: string) => { const ast = await parseMdx(file) diff --git a/packages/docz-core/src/bundlers/webpack/loaders.ts b/packages/docz-core/src/bundlers/webpack/loaders.ts index 5e635d1ec..531eb7be9 100644 --- a/packages/docz-core/src/bundlers/webpack/loaders.ts +++ b/packages/docz-core/src/bundlers/webpack/loaders.ts @@ -79,7 +79,7 @@ export const mdx = (config: Config, args: Args) => { config.module .rule('mdx') - .test(/\.md?x$/) + .test(/\.(md|markdown|mdx)$/) .include.add(srcPath) .end() .exclude.add(/node_modules/) diff --git a/packages/docz-core/src/commands/args.ts b/packages/docz-core/src/commands/args.ts index e810c17c6..98ea77388 100644 --- a/packages/docz-core/src/commands/args.ts +++ b/packages/docz-core/src/commands/args.ts @@ -44,6 +44,7 @@ export interface Argv { base: string src: string files: string + ignore: string[] dest: string /* bundler args */ debug: boolean @@ -92,7 +93,11 @@ export const args = (env: Env) => (yargs: any) => { }) yargs.positional('files', { type: 'string', - default: getEnv('docz.files', '**/*.mdx'), + default: getEnv('docz.files', '**/*.{md,mdx,markdown}'), + }) + yargs.positional('ignore', { + type: 'array', + default: getEnv('docz.ignore', []), }) yargs.positional('dest', { alias: 'd',