31 lines
840 B
JavaScript
31 lines
840 B
JavaScript
const { execSync } = require('child_process');
|
|
|
|
function tryRequire(modulePath) {
|
|
try {
|
|
require.resolve(modulePath);
|
|
return require(modulePath);
|
|
} catch (e) {
|
|
if (e.code === 'MODULE_NOT_FOUND') {
|
|
return null;
|
|
}
|
|
throw e; // 如果是其他错误,继续抛出
|
|
}
|
|
}
|
|
|
|
const tscBuilder = tryRequire('../lib/compiler/tscBuilder.js');
|
|
|
|
if (tscBuilder && tscBuilder.build) {
|
|
console.log('Using tscBuilder for compilation');
|
|
tscBuilder.build(process.cwd(), process.argv);
|
|
} else {
|
|
console.log('tscBuilder not found, falling back to tsc');
|
|
try {
|
|
execSync('npx tsc', {
|
|
stdio: 'inherit',
|
|
cwd: process.cwd()
|
|
});
|
|
} catch (tscError) {
|
|
console.error('Failed to run tsc:', tscError.message);
|
|
process.exit(1);
|
|
}
|
|
} |