prettier support
This commit is contained in:
28
src/build.ts
28
src/build.ts
@@ -3,12 +3,14 @@ import { existsSync, writeFileSync, unlinkSync } from 'fs'
|
||||
import { DistPath, ScriptBase, ScriptPath } from './paths'
|
||||
import { UserScriptMetaFull } from './types'
|
||||
import readMeta from './readmeta'
|
||||
import { format, Options } from 'prettier'
|
||||
|
||||
export default function (
|
||||
name: string,
|
||||
watchCallback:
|
||||
| ((meta: UserScriptMetaFull, error: string | null) => void)
|
||||
| false = false
|
||||
| false = false,
|
||||
PrettierConfig: Options | null
|
||||
): [UserScriptMetaFull, string | null] {
|
||||
//read meta file
|
||||
let [metaJson, metaString] = readMeta(name)
|
||||
@@ -44,7 +46,11 @@ export default function (
|
||||
console.error(name, result.errorRaw || result.error)
|
||||
error = result.error
|
||||
} else if (result.content) {
|
||||
writeFileSync(pathDist, metaString + result.content)
|
||||
let content = format(
|
||||
metaString + result.content,
|
||||
PrettierConfig === null ? undefined : PrettierConfig
|
||||
)
|
||||
writeFileSync(pathDist, content)
|
||||
} else {
|
||||
console.error(name, 'No output')
|
||||
}
|
||||
@@ -64,7 +70,11 @@ export default function (
|
||||
console.error(name, result.errorRaw || result.error)
|
||||
error = result.error
|
||||
} else if (result.content) {
|
||||
writeFileSync(pathDist, metaString + result.content)
|
||||
let content = format(
|
||||
metaString + result.content,
|
||||
PrettierConfig === null ? undefined : PrettierConfig
|
||||
)
|
||||
writeFileSync(pathDist, content)
|
||||
} else {
|
||||
console.error(name, 'No output')
|
||||
}
|
||||
@@ -160,18 +170,6 @@ function runEsbuild(
|
||||
}
|
||||
}
|
||||
|
||||
// //only remove the filename comments if there's only 1 file
|
||||
// function clearFilenameComments(content: string): string {
|
||||
// let regexp = new RegExp(`//\\s*${ScriptBase}/.*(?:\\n|$)`, 'g')
|
||||
// let matches = content.match(regexp)
|
||||
// if (matches) {
|
||||
// if (matches.length === 1) {
|
||||
// content = content.replace(regexp, '')
|
||||
// }
|
||||
// }
|
||||
// return content
|
||||
// }
|
||||
|
||||
//remove all filename comments
|
||||
function clearFilenameComments(content: string): string {
|
||||
let regexp = new RegExp(`//\\s*${ScriptBase}/.*(?:\\n|$)`, 'g')
|
||||
|
||||
Reference in New Issue
Block a user