From 747020946ed9fac72e0cb7335aa4fa13bd0bc60a Mon Sep 17 00:00:00 2001 From: youthfulhps Date: Mon, 21 Aug 2023 13:20:29 +0900 Subject: [PATCH] feature: Implement incomplete main script --- src/main.ts | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index e227ad5..283529f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,10 +1,36 @@ -import { scrapRawScript } from '~/helpers/scraper'; +import { format } from 'prettier'; +import { scrapRawScript } from '~/helpers/parser'; +import { parsers as babelParsers } from 'prettier/parser-babel'; +import { parsers as typescriptParsers } from 'prettier/parser-typescript'; + +import { printers } from './helpers/printer'; + +export const parsers: { [parserName: string]: any } = { + babel: { + ...babelParsers.babel, + astFormat: 'babel-ast', + }, + typescript: { + ...typescriptParsers.typescript, + astFormat: 'typescript-ast', + }, +}; + +const myCustomPlugin = { + parsers, + printers, + astFormat: 'estree', +}; export default (async () => { const args = process.argv.slice(2); if (args[0] === '--target') { const rawScript = await scrapRawScript(args[1]); - console.log(rawScript); + + const formattedScript = format(rawScript, { + plugins: [myCustomPlugin], + }); + console.log(formattedScript); } })();