From 20275f888fc86ca81a5bee7f2d0b9043ae51059b Mon Sep 17 00:00:00 2001 From: syy11cn Date: Sat, 4 Jun 2022 13:55:41 +0800 Subject: [PATCH] feat(core): read config file --- packages/core/src/cli.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/core/src/cli.ts b/packages/core/src/cli.ts index 6f74bab..797f5c8 100644 --- a/packages/core/src/cli.ts +++ b/packages/core/src/cli.ts @@ -5,20 +5,23 @@ import yargs from 'yargs' import { defaultConfig } from './config' const argv = yargs(process.argv.slice(2)).options({ - md: { type: 'string' }, - theme: { type: 'string' }, + f: { type: 'string' }, + c: { type: 'string' }, }).parseSync() async function cli(props: { filename?: string - theme?: string + config?: string }): Promise { console.log('\x1B[36m%s\x1B[0m', '[Markdown Report]: Started...') - const { filename = 'index.md' } = props + const { filename = 'index.md', config = 'config.json' } = props try { const file = readFileSync(`${cwd()}/${filename}`) - const buffer = await getBuffer({ markdown: file.toString(), config: defaultConfig }) - writeFileSync(`${cwd()}/My document.docx`, buffer) + const cfg = { ...defaultConfig, ...JSON.parse(readFileSync(`${cwd()}/${config}`).toString()) } + const output = cfg.meta.pageHeaderText || 'My Document' + console.log(cfg) + const buffer = await getBuffer({ markdown: file.toString(), config: cfg }) + writeFileSync(`${cwd()}/${output.replace(/\.docx?$/, '')}.docx`, buffer) } catch (e) { console.log(`[Markdown Report]: ${e}`) @@ -28,4 +31,4 @@ async function cli(props: { console.log('\x1B[36m%s\x1B[0m', '[Markdown Report]: Finished.') } -cli({ filename: argv.md, theme: argv.theme }) +cli({ filename: argv.f, config: argv.c })