mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
8bb80df732
* compiler error (#4033) * compiler error * add gen decl module * fix global event and other bug (#4032) * components such as event-target to ts * divide CCEvent and CCTouch into game coordinates and ui coordinate mod * repair editor environment where mask does not take effect bug * fix render component blendState modification does not take effect bug * fix bug * fix ts tip
55 lines
1.7 KiB
JavaScript
55 lines
1.7 KiB
JavaScript
const { spawnSync } = require('child_process');
|
|
const { join, extname, basename, dirname } = require('path');
|
|
const { readFileSync, existsSync } = require('fs');
|
|
const ts = require('typescript');
|
|
|
|
const tscExecutableName = process.platform === 'win32' ? 'tsc.cmd' : 'tsc';
|
|
const tscExecutablePath = join(__dirname, '..', 'node_modules', '.bin', tscExecutableName);
|
|
const tssConfigDir = join(__dirname, '..');
|
|
const tscConfigPath = join(tssConfigDir, 'tsconfig-gendecls.json');
|
|
|
|
function generate () {
|
|
const tscConfig = ts.readConfigFile(tscConfigPath, (path) => readFileSync(path).toString());
|
|
if (tscConfig.error) {
|
|
console.error(`Bad tsconfig.json: ${tscConfig.error.messageText}`);
|
|
return undefined;
|
|
}
|
|
|
|
const outputJSPath = join(tssConfigDir, tscConfig.config.compilerOptions.outFile);
|
|
console.log(outputJSPath);
|
|
|
|
const extName = extname(outputJSPath);
|
|
if (extName !== '.js') {
|
|
console.error(`Unexpected output extension ${extName}, please check it.`);
|
|
return undefined;
|
|
}
|
|
|
|
const dirName = dirname(outputJSPath);
|
|
const baseName = basename(outputJSPath, extName);
|
|
const destExtensions = [
|
|
'.d.ts',
|
|
'.d.ts.map',
|
|
];
|
|
|
|
const destFiles = destExtensions.map((destExtension) => {
|
|
const destFile = join(dirName, baseName + destExtension);
|
|
if (existsSync(destFile)) {
|
|
console.log(`Delete old ${destFile}.`);
|
|
}
|
|
return destFile;
|
|
});
|
|
|
|
console.log(`Generating...`);
|
|
|
|
spawnSync(tscExecutablePath, [
|
|
'-p',
|
|
tscConfigPath,
|
|
], {
|
|
stdio: [ null, process.stdout, process.stderr ]
|
|
});
|
|
|
|
return destFiles;
|
|
}
|
|
|
|
module.exports = { generate };
|