编译后自动提交git

This commit is contained in:
lcc
2025-07-27 16:18:58 +08:00
parent 0b9b494d0f
commit 7820a87e24
3 changed files with 66 additions and 1 deletions
+50
View File
@@ -0,0 +1,50 @@
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
// 配置目标Git仓库信息
const config = {
repoUrl: 'http://git2.haodian.cn/lcc/pinan_dist.git', // 目标仓库地址
branch: 'master', // 目标分支
distPath: path.resolve(__dirname, './dist'), // 构建产物目录
commitMessage: `Auto-deploy at ${new Date().toISOString()}` // 提交信息
};
try {
// 检查dist目录是否存在
if (!fs.existsSync(config.distPath)) {
throw new Error('dist目录不存在,请先执行构建命令');
}
// 进入dist目录
process.chdir(config.distPath);
// 初始化git仓库(如果需要)
if (!fs.existsSync(path.join(config.distPath, '.git'))) {
execSync('git init');
execSync(`git remote add origin ${config.repoUrl}`);
}
// 拉取最新代码
execSync(`git pull origin ${config.branch} --rebase`, { stdio: 'ignore' });
// 添加所有文件
execSync('git add .');
// 提交更改
try {
execSync(`git commit -m "${config.commitMessage}"`);
} catch (e) {
console.log('没有需要提交的更改');
process.exit(0);
}
// 推送到目标仓库
execSync(`git push origin ${config.branch}`);
console.log('部署成功!');
process.exit(0);
} catch (error) {
console.error('部署失败:', error.message);
process.exit(1);
}
+2 -1
View File
@@ -9,7 +9,8 @@
"build:preview": "vue-cli-service build --mode preview",
"build:report": "vue-cli-service build --report",
"lint": "vue-cli-service lint",
"clean:lib": "rimraf node_modules"
"clean:lib": "rimraf node_modules",
"build:deploy": "vue-cli-service build && node deploy.js"
},
"dependencies": {
"@amap/amap-jsapi-loader": "^1.0.1",
+14
View File
@@ -1,5 +1,6 @@
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const { transformElementScss } = require('ele-admin/lib/utils/dynamic-theme');
const path = require('path'); // 添加这一行引入 path 模块
module.exports = {
devServer: {
@@ -30,6 +31,19 @@ module.exports = {
threshold: 10240
})
);
} else if (process.env.NODE_ENV === 'production') {
config.plugin('done').use(require('webpack/lib/ProgressPlugin'), [
{
handler: (percentage) => {
// 当构建完成时执行部署脚本
if (percentage === 1) {
console.log('构建完成,开始部署到Git仓库...');
const deployScript = path.resolve(__dirname, './deploy.js');
require(deployScript);
}
}
}
]);
}
},
css: {