updated prettier config
This commit is contained in:
@@ -9,7 +9,7 @@ import { CLIArgs } from './main'
|
||||
export default function (
|
||||
name: string,
|
||||
watchCallback: (meta: UserScriptMetaFull, error: string | null) => void,
|
||||
PrettierConfig: Options | null,
|
||||
PrettierConfig: Options,
|
||||
CLIArgs: CLIArgs
|
||||
): [UserScriptMetaFull, string | null] {
|
||||
//read meta file
|
||||
@@ -153,7 +153,7 @@ function runPostEsbuild(
|
||||
result: RunEsbuildResult,
|
||||
metaString: string,
|
||||
CLIArgs: CLIArgs,
|
||||
PrettierConfig: Options | null
|
||||
PrettierConfig: Options
|
||||
) {
|
||||
let error: string | null = null
|
||||
let path = ScriptPath(name)
|
||||
@@ -165,10 +165,7 @@ function runPostEsbuild(
|
||||
} else if (result.content) {
|
||||
let content = metaString + result.content
|
||||
if (CLIArgs.prettier) {
|
||||
content = format(
|
||||
content,
|
||||
PrettierConfig === null ? undefined : PrettierConfig
|
||||
)
|
||||
content = format(content, PrettierConfig)
|
||||
}
|
||||
writeFileSync(pathDist, content)
|
||||
} else {
|
||||
|
||||
15
src/main.ts
15
src/main.ts
@@ -13,9 +13,9 @@ export interface CLIArgs {
|
||||
}
|
||||
|
||||
const CLIArgs = commandLineArgs([
|
||||
{ name: 'watch', alias: 'w', type: Boolean },
|
||||
{ name: 'minify', alias: 'm', type: Boolean },
|
||||
{ name: 'prettier', alias: 'p', type: Boolean },
|
||||
{ name: 'watch', alias: 'w', type: Boolean, defaultValue: false },
|
||||
{ name: 'minify', alias: 'm', type: Boolean, defaultValue: false },
|
||||
{ name: 'prettier', alias: 'p', type: Boolean, defaultValue: false },
|
||||
]) as CLIArgs
|
||||
|
||||
//if package.json doesn't exist then there is no point in continuing
|
||||
@@ -27,7 +27,14 @@ if (!existsSync('package.json') || !lstatSync('package.json').isFile()) {
|
||||
//delete compiled scripts
|
||||
readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`))
|
||||
|
||||
const PrettierConfig = resolveConfig.sync(process.cwd())
|
||||
//read prettierrc file and make sure `babel` is the configured parser
|
||||
const PrettierConfig = (() => {
|
||||
let config = resolveConfig.sync(process.cwd()) || {}
|
||||
return {
|
||||
...config,
|
||||
parser: 'babel',
|
||||
}
|
||||
})()
|
||||
|
||||
//compile scripts
|
||||
let scripts = readdirSync(ScriptBase)
|
||||
|
||||
Reference in New Issue
Block a user