当前位置: 首页 > news >正文

egret 白鹭的编译太慢了 自己写了一个

用的swc
他会检测git的改变

const simpleGit = require('simple-git');
const fs = require('fs');
const path = require('path');
// 初始化 simple-git
const swc = require('@swc/core');
const baseDir = 'D:\\project';
const gameDir = 'game\\module\\abcdefg';
const gitDir = 'D:\\project';
const git = simpleGit(gitDir);
const crypto = require('crypto');async function buildChangedTsFiles() {try {// 获取工作目录和暂存区的更改文件const statusSummary = await git.status();// 合并所有更改的文件名(已修改、已新增、已删除等)const changedFiles = [...statusSummary.modified,...statusSummary.created,...statusSummary.not_added];const changedTsFiles = changedFiles.filter(file => file.endsWith('.ts'));if (changedTsFiles.length > 0) {console.log('更改的 TypeScript 文件:');changedTsFiles.forEach(file => {buildOne(path.join(gitDir, file));});}} catch (error) {console.error(`Error: ${error.message}`);}
}function buildPath() {const inputDir = baseDir + "src\\" + gameDir;const outputDir = baseDir + "bin-debug\\" + gameDir;fs.mkdirSync(outputDir, { recursive: true });const files = fs.readdirSync(inputDir).filter(file => file.endsWith('.ts'));files.forEach(file => {buildOne(path.join(inputDir, file));});
}var builded = {};function buildOne(filePath) {if (builded[filePath] != null) {return;}let fileName = path.basename(filePath);const code = fs.readFileSync(filePath, 'utf-8');const hash = crypto.createHash('md5');hash.update(fileName);hash.update(code);let hashValue = hash.digest("hex");// console.log("检测改变:" + filePath);if (hashObj[filePath] == hashValue) {// console.log("没改变");return;}console.log(filePath, hashValue);hashObj[filePath] = hashValue;builded[filePath] = 1;console.log("编译:" + filePath);let out = filePath.replace(/\.ts$/, '.js').replace("src", "bin-debug");let output = swc.transformSync(code, {filename: fileName});fs.writeFileSync(out, output.code, 'utf-8');
}const hashFilePath = path.join(__dirname, 'hashes.json');
var hashObj;function readHash() {if (fs.existsSync(hashFilePath)) {hashObj = JSON.parse(fs.readFileSync(hashFilePath, 'utf-8'));} else {hashObj = {};}
}function saveHashes() {// console.log("save success");// console.log(hashObj);fs.writeFileSync(hashFilePath, JSON.stringify(hashObj, null, 2), 'utf-8');
}function buildHash() {for (const key in hashObj) {buildOne(key);}
}async function run() {readHash();buildHash();// buildPath();await buildChangedTsFiles();saveHashes();console.log("编译完成");
}run();
http://www.lryc.cn/news/403048.html

相关文章:

  • <数据集>pcb板缺陷检测数据集<目标检测>
  • 实验四:图像的锐化处理
  • 【Linux】权限的管理和Linux上的一些工具
  • ES6 字符串的新增方法(二十)
  • 如何将MP3或WAV文件解码成PCM文件
  • OpenAI 推出 GPT-4o mini,一种更小、更便宜的人工智能模型
  • Nacos 服务发现(订阅)源码分析(服务端)
  • DICOM CT\MR片子免费在线查看工具;python pydicom包加载查看;mayavi 3d查看
  • VSCode远程连接Ubuntu/Linux
  • 【Nginx80端口被占用】80端口被System占用如何解决【已解决】
  • 云计算的发展历程与边缘计算
  • 199.二叉树的右视图(DFS)
  • 机器学习基础入门(1)
  • mybatis的xml中,where标签不自动删除多余的and之类的问题
  • RK3588 编译opencvopencv_contrib记录
  • Eureka: 微服务架构中的服务发现与注册实践
  • 8、添加第三方包
  • 【算法】算法模板
  • 特征工程方法总结
  • Unity | AssetBundle
  • 【虚幻引擎】C++网络通信TCP和HTTP实战开发全流程,以接入科大讯飞星火大模型和文心一言千帆大模型为案例讲解
  • .NET单元测试使用AutoFixture按需填充的方法总结
  • 求职学习day5
  • 微服务常用的中间件有哪些?都有什么用途?
  • 华为云认证
  • 【Linux学习】常用基本指令
  • windows上安装Apache
  • wps office 2019 Pro Plus 集成序列号Vba安装版教程
  • 院内影像一体化平台PACS源码,C#语言的PACS/RIS系统,二级医院应用案例
  • 基于java的设计模式学习