Skip to content

Commit

Permalink
Merge pull request #268 from duhdugg/parseroptions-config
Browse files Browse the repository at this point in the history
allow setting parserOptions in cli config
  • Loading branch information
IWANABETHATGUY committed Mar 25, 2023
2 parents ab9f9a4 + 68149e3 commit fbf51ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions packages/cli/lib/genMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path'
import fg from 'fast-glob'
import fs from 'fs-extra'
import Log from 'log-horizon'
import { CliOptions } from '.'
import { CliOptions, getConfig } from '.'
import { parser } from '@vuese/parser'
import Render from '@vuese/markdown-render'

Expand Down Expand Up @@ -45,11 +45,12 @@ export default async (config: CliOptions): MarkdownResult => {
const abs = path.resolve(p)
const source = await fs.readFile(abs, 'utf-8')
try {
const parserRes = parser(source, {
const { parserOptions } = await getConfig({});
const parserRes = parser(source, Object.assign({
babelParserPlugins,
basedir: path.dirname(abs),
jsFile: abs.endsWith('.js')
})
}, parserOptions))
const r = new Render(parserRes)
const markdownRes = r.renderMarkdown()

Expand Down
10 changes: 6 additions & 4 deletions packages/cli/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cac from 'cac'
import JoyCon from 'joycon'
import fs from 'fs-extra'
import { BabelParserPlugins } from '@vuese/parser'
import { BabelParserPlugins, ParserOptions } from '@vuese/parser'
import Log from 'log-horizon'
import preview from './preview'
import genDocute from './genDocute'
Expand Down Expand Up @@ -38,11 +38,12 @@ export type CliOptions = {
open: boolean
port: number
host: string
keepFolderStructure: boolean
keepFolderStructure: boolean,
parserOptions: ParserOptions
}
type PartialCliOptions = Partial<CliOptions>

async function getConfig(
export async function getConfig(
flags: PartialCliOptions
): Promise<Partial<CliOptions>> {
const { path, data } = await joycon.load([
Expand All @@ -59,7 +60,8 @@ async function getConfig(
markdownDir: 'components',
markdownFile: '',
host: '127.0.0.1',
keepFolderStructure: false
keepFolderStructure: false,
parserOptions: {}
}
if (path) Object.assign(config, data, flags)
Object.assign(config, flags || {})
Expand Down

0 comments on commit fbf51ce

Please sign in to comment.