Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
feat(docz-core): resolve markdown files by default (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck authored Aug 11, 2018
1 parent 3f05536 commit e0a95b3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
33 changes: 26 additions & 7 deletions packages/docz-core/src/Entries.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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<void> => {
const { plugins, theme } = config
const props = Plugin.propsOfPlugins(plugins)
Expand Down Expand Up @@ -61,12 +75,17 @@ export class Entries {
}

private async getMap(config: Config): Promise<EntryMap> {
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<string>(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)
Expand Down
2 changes: 1 addition & 1 deletion packages/docz-core/src/bundlers/webpack/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
7 changes: 6 additions & 1 deletion packages/docz-core/src/commands/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface Argv {
base: string
src: string
files: string
ignore: string[]
dest: string
/* bundler args */
debug: boolean
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit e0a95b3

Please sign in to comment.