diff --git a/lib/index.js b/lib/index.js index 3baf3f0..6c7ef94 100644 --- a/lib/index.js +++ b/lib/index.js @@ -12,6 +12,24 @@ function run() { const [runCmd, tscArgs, runArgs, isCleanDirectory] = parseArgs(process.argv); const cwd = process.cwd(); + let outDir; + const projectIndex = tscArgs.findIndex(arg => arg === '--project'); + if (projectIndex !== -1) { + const projectPath = tscArgs[projectIndex + 1]; + const tsconfig = readJSONFile(path.resolve(cwd, projectPath)); + outDir = tsconfig.compilerOptions.outDir; + } else { + const outDirIndex = tscArgs.findIndex(arg => arg === '--outDir'); + if (outDirIndex !== -1) { + outDir = tscArgs[outDirIndex + 1]; + } else { + const tsconfig = readJSONFile(path.resolve(cwd, 'tsconfig.json')); + outDir = tsconfig.compilerOptions.outDir; + } + } + + runArgs.push('--baseDir', path.resolve(cwd, outDir)); + if (isCleanDirectory) { /** * 删除编译目录,有几种情况 @@ -19,22 +37,6 @@ function run() { * 2、tscArgs 中没有 --outDir 参数,从 tsconfig.json 中读取 outDir 参数 * 3、如果 tscArgs 中包含 --project 参数,那么就以 --project 参数指定的 tsconfig.json 为准 */ - let outDir; - const projectIndex = tscArgs.findIndex(arg => arg === '--project'); - if (projectIndex !== -1) { - const projectPath = tscArgs[projectIndex + 1]; - const tsconfig = readJSONFile(path.resolve(cwd, projectPath)); - outDir = tsconfig.compilerOptions.outDir; - } else { - const outDirIndex = tscArgs.findIndex(arg => arg === '--outDir'); - if (outDirIndex !== -1) { - outDir = tscArgs[outDirIndex + 1]; - } else { - const tsconfig = readJSONFile(path.resolve(cwd, 'tsconfig.json')); - outDir = tsconfig.compilerOptions.outDir; - } - } - deleteFolderRecursive(path.resolve(cwd, outDir)); }