Skip to content
This repository was archived by the owner on Sep 18, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,29 +144,29 @@ async function main() {
}).filter((doc): doc is kolint.Document => Boolean(doc))

program.registerOutput = (filename, data, map) => {
const mapJSON = map?.toJSON()
const sources = mapJSON.sources ?? [filename]

for (const source of sources) {
const parsedSource = path.parse(source)
const defaultOutExt = '.html.ts'
const outExt = config.outExt ?? defaultOutExt
const mapOutExit = outExt + '.map'

if (config.out !== undefined) {
let filepath: string | undefined
const mapJSON = map?.toJSON()
const parsedFileName = path.parse(filename)

if (isOptionTrue(config.out)) {
filepath = path.join(parsedSource.dir, parsedSource.name) + (config.outExt ?? '.html.ts')
} else if (typeof config.out === 'string') {
filepath = path.join(config.out, parsedSource.name) + (config.outExt ?? '.html.ts')
}
if (config.out !== undefined) {
let filepath: string | undefined

if (filepath)
fs.writeFileSync(filepath, data)
if (isOptionTrue(config.out)) {
filepath = path.join(parsedFileName.dir, parsedFileName.name) + outExt
} else if (typeof config.out === 'string') {
filepath = path.join(config.out, parsedFileName.name) + outExt
}

if (isOptionTrue(config.sourceMap)) {
const filepath = path.join(typeof config.out === 'string' ? config.out : parsedSource.dir, parsedSource.name) + ((config.outExt ?? '.html.ts') + '.map')
fs.writeFileSync(filepath, JSON.stringify(mapJSON))
}
if (filepath)
fs.writeFileSync(filepath, data)
}

if (isOptionTrue(config.sourceMap)) {
const filepath = path.join(typeof config.out === 'string' ? config.out : parsedFileName.dir, parsedFileName.name) + mapOutExit
fs.writeFileSync(filepath, JSON.stringify(mapJSON))
}
}

Expand Down
30 changes: 30 additions & 0 deletions src/compiler/compiler-host.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as ts from 'typescript'
import * as path from 'path'

export interface CompilerHost {
getCompilerOptions(): ts.CompilerOptions
getSourceFile?(fileName: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): ts.SourceFile | undefined
createTypescriptCompilerHost(compilerOptions: ts.CompilerOptions): ts.CompilerHost
}

export function createCompilerHost(): CompilerHost {
return {
getCompilerOptions(): ts.CompilerOptions {
const configPath = process.cwd()
const configFileName = ts.findConfigFile(configPath, (p: string) => ts.sys.fileExists(path.resolve(configPath, p)))
let compilerOptions: ts.CompilerOptions
if (configFileName) {
const configFile = ts.readConfigFile(configFileName, (path: string, encoding?: string | undefined) => ts.sys.readFile(path, encoding))
const args = ts.parseJsonConfigFileContent(configFile.config, ts.sys, './')
compilerOptions = args.options
} else {
compilerOptions = {}
}
return compilerOptions
},

createTypescriptCompilerHost(compilerOptions: ts.CompilerOptions) {
return ts.createCompilerHost(compilerOptions)
}
}
}
Loading