2024-09-05 01:59:57 +00:00
|
|
|
|
import chalk from "chalk";
|
|
|
|
|
import WebSocket from "ws";
|
|
|
|
|
|
|
|
|
|
//#region ############################## 配置文件 ###################################
|
|
|
|
|
|
2024-10-12 09:25:18 +00:00
|
|
|
|
const LocalHost = "127.0.0.1";
|
2024-11-16 09:07:58 +00:00
|
|
|
|
let config = {
|
2024-10-12 09:25:18 +00:00
|
|
|
|
//发布的名称,每个项目具有唯一的一个名称
|
2024-10-29 10:08:34 +00:00
|
|
|
|
Name: "Test",
|
|
|
|
|
RemotePwd: "t123",
|
2024-10-12 09:25:18 +00:00
|
|
|
|
//远程服务器地址,也就是发布的目的地,它是正式环境
|
2024-10-29 10:08:34 +00:00
|
|
|
|
RemoteUrl: "127.0.0.1:6819",
|
2024-10-12 09:25:18 +00:00
|
|
|
|
//是否发布数据库 sqlserver
|
2024-10-29 05:13:22 +00:00
|
|
|
|
IsDeployDb: true,
|
2024-10-12 09:25:18 +00:00
|
|
|
|
//是否发布前重新构建项目
|
2024-10-29 10:08:34 +00:00
|
|
|
|
IsDeployProject: true,
|
2024-10-12 09:25:18 +00:00
|
|
|
|
//项目地址
|
|
|
|
|
LocalProjectAbsolutePath:
|
|
|
|
|
"D:/git/HMES-H7-HNFY/HMES-H7-HNFYMF/HMES-H7-HNFYMF.WEB",
|
2024-09-05 01:59:57 +00:00
|
|
|
|
//源文件目录地址,是要发布的文件根目录,它是绝对路径,!执行发布时将发布到这个目录!
|
2024-10-12 09:25:18 +00:00
|
|
|
|
LocalRootPath: "D:/FileSyncTest/src",
|
2024-09-05 01:59:57 +00:00
|
|
|
|
//目标文件目录地址,也就是部署服务的机器上的项目文件根目录,它是绝对路径
|
2024-10-29 10:08:34 +00:00
|
|
|
|
RemoteRootPath: "D:/FileSyncTest/dst",
|
2024-10-12 09:25:18 +00:00
|
|
|
|
//源数据库配置 SqlServer,将会同步数据库的结构
|
|
|
|
|
SrcDb: {
|
|
|
|
|
//Host
|
|
|
|
|
ServerName: "172.16.12.2",
|
|
|
|
|
//数据库名
|
2024-10-28 09:28:18 +00:00
|
|
|
|
DatabaseName: "HMES_H7_HNFYMF",
|
2024-10-12 09:25:18 +00:00
|
|
|
|
User: "hmes-h7",
|
|
|
|
|
Password: "Hmes-h7666",
|
|
|
|
|
//是否信任服务器证书
|
|
|
|
|
TrustServerCertificate: "True",
|
|
|
|
|
//同步的数据,这些数据将会同步
|
|
|
|
|
SyncTablesData: [
|
|
|
|
|
"dbo.sys_Button",
|
|
|
|
|
"dbo.sys_Menu",
|
|
|
|
|
"dbo.sys_Module",
|
|
|
|
|
"dbo.sys_Page",
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
//目标数据库配置 sqlserver
|
|
|
|
|
DstDb: {
|
|
|
|
|
ServerName: "127.0.0.1",
|
2024-10-28 09:28:18 +00:00
|
|
|
|
DatabaseName: "HMES_H7_HNFYMF",
|
2024-10-12 09:25:18 +00:00
|
|
|
|
User: "sa",
|
2024-10-29 10:08:34 +00:00
|
|
|
|
Password: "0",
|
2024-10-12 09:25:18 +00:00
|
|
|
|
TrustServerCertificate: "True",
|
|
|
|
|
},
|
|
|
|
|
//子目录配置,每个子目录都有自己不同的发布策略,它是相对路径,即相对于LocalRootPath和RemoteRootPath(注意 '/',这将拼成一个完整的路径),文件数据依此进行,
|
|
|
|
|
DirFileConfigs: [
|
|
|
|
|
{
|
|
|
|
|
DirPath: "/bin",
|
|
|
|
|
//排除的文件或目录,它是相对路径,相对于!!!LocalRootPath和RemoteRootPath!!!
|
|
|
|
|
Excludes: ["/roslyn", "/Views"],
|
|
|
|
|
//只追踪文件或目录,它是相对路径,相对于!!!LocalRootPath和RemoteRootPath!!!,它的优先级最高,如果你指定了它的值,Excludes将会失效
|
|
|
|
|
// CherryPicks:[]
|
|
|
|
|
},
|
|
|
|
|
],
|
2024-10-29 05:13:22 +00:00
|
|
|
|
ExecProcesses: [],
|
|
|
|
|
// ExecProcesses:[
|
|
|
|
|
// {
|
|
|
|
|
// // 参数
|
|
|
|
|
// Argumnets:"ls",
|
|
|
|
|
// // 执行命令位置
|
|
|
|
|
// FileName:"powershell",
|
|
|
|
|
// // 相关步骤开始之前(B)或之后 (A)
|
|
|
|
|
// StepBeforeOrAfter:"A",
|
|
|
|
|
// // 本地(L)或远程 (R) 执行
|
|
|
|
|
// ExecInLocalOrServer:"L",
|
|
|
|
|
// // 步骤 1. 连接远程 2. 发布项目 3. 文件对比 4. 提取sqlserver 5. 打包上传 6. 发布
|
|
|
|
|
// Step:1
|
|
|
|
|
// }
|
|
|
|
|
// ]
|
2024-09-05 01:59:57 +00:00
|
|
|
|
};
|
2024-11-16 09:07:58 +00:00
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
Name: "FYMF",
|
|
|
|
|
RemoteUrl: "212.129.223.183:6819",
|
|
|
|
|
RemotePwd: "FYMF",
|
|
|
|
|
IsDeployDb: false,
|
|
|
|
|
IsDeployProject: false,
|
|
|
|
|
LocalProjectAbsolutePath: "D:/git/HMES-H7-HNFY/HMES-H7-HNFYMF/HMES-H7-HNFYMF.WEB",
|
|
|
|
|
LocalRootPath: "D:/FileSyncTest/src",
|
|
|
|
|
RemoteRootPath: "E:/HMES_H7_HNFY_PREON",
|
|
|
|
|
SrcDb: {
|
|
|
|
|
ServerName: "172.16.12.2",
|
|
|
|
|
DatabaseName: "HMES_H7_HNFYMF",
|
|
|
|
|
User: "hmes-h7",
|
|
|
|
|
Password: "Hmes-h7666",
|
|
|
|
|
TrustServerCertificate: "True",
|
|
|
|
|
SyncTablesData: [
|
|
|
|
|
"dbo.sys_Button",
|
|
|
|
|
"dbo.sys_Menu",
|
|
|
|
|
"dbo.sys_Module",
|
|
|
|
|
"dbo.sys_Page",
|
|
|
|
|
"dbo.CommonPara"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
DstDb: {
|
|
|
|
|
ServerName: "172.16.80.1",
|
|
|
|
|
DatabaseName: "HMES_H7_HNFYMF_PRE",
|
|
|
|
|
User: "hnfypre",
|
|
|
|
|
Password: "pre0823",
|
|
|
|
|
TrustServerCertificate: "True"
|
|
|
|
|
},
|
|
|
|
|
DirFileConfigs: [
|
|
|
|
|
{
|
|
|
|
|
DirPath: "/",
|
|
|
|
|
Excludes: [
|
|
|
|
|
"Web.config",
|
|
|
|
|
"Log",
|
|
|
|
|
"Content",
|
|
|
|
|
"fonts"
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
ExecProcesses: []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-09-05 01:59:57 +00:00
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
//#region ############################## 打印函数 ###################################
|
|
|
|
|
|
2024-10-12 09:25:18 +00:00
|
|
|
|
let IsSuccess = false;
|
2024-09-05 01:59:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* 在新行打印错误信息
|
|
|
|
|
*/
|
|
|
|
|
function PrintErrInNewLine(str) {
|
|
|
|
|
var chunk = chalk["red"]("[错误]: ");
|
|
|
|
|
process.stdout.write(chunk);
|
|
|
|
|
process.stdout.write(str);
|
2024-10-29 10:08:34 +00:00
|
|
|
|
process.stdout.write("\n");
|
2024-09-05 01:59:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 在新行打印成功信息
|
|
|
|
|
*/
|
|
|
|
|
function PrintSuccessInNewLine(str) {
|
|
|
|
|
var chunk = chalk["green"]("[成功]: ");
|
|
|
|
|
process.stdout.write(chunk);
|
|
|
|
|
process.stdout.write(str);
|
2024-10-29 10:08:34 +00:00
|
|
|
|
process.stdout.write("\n");
|
2024-09-05 01:59:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 在新行打印一般信息
|
|
|
|
|
*/
|
2024-10-12 09:25:18 +00:00
|
|
|
|
function PrintCloseNewLine(str) {
|
2024-10-29 05:13:22 +00:00
|
|
|
|
if (IsSuccess) {
|
|
|
|
|
PrintSuccessInNewLine(str);
|
2024-10-12 09:25:18 +00:00
|
|
|
|
} else {
|
2024-10-29 05:13:22 +00:00
|
|
|
|
PrintErrInNewLine(str);
|
2024-10-12 09:25:18 +00:00
|
|
|
|
}
|
2024-09-05 01:59:57 +00:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 在当前行打印一般信息,打印此行信息之前会清除当前行
|
|
|
|
|
*/
|
2024-10-29 10:08:34 +00:00
|
|
|
|
function PrintProcessLine(str) {
|
|
|
|
|
var chunk = chalk["yellow"]("[上传进度]: ");
|
|
|
|
|
process.stdout.write(chunk);
|
|
|
|
|
process.stdout.write(`${str}`);
|
|
|
|
|
process.stdout.write("\n");
|
2024-09-05 01:59:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
//#region ############################### work #############################################
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 1-n. localServer 工作,此处只展示信息
|
|
|
|
|
*/
|
2024-10-29 10:08:34 +00:00
|
|
|
|
|
|
|
|
|
function getOpEmoj(Op) {
|
|
|
|
|
switch (Op) {
|
|
|
|
|
case 0:
|
2024-11-16 09:07:58 +00:00
|
|
|
|
return "A";
|
2024-10-29 10:08:34 +00:00
|
|
|
|
case 1:
|
2024-11-16 09:07:58 +00:00
|
|
|
|
return "M";
|
2024-10-29 10:08:34 +00:00
|
|
|
|
case 2:
|
2024-11-16 09:07:58 +00:00
|
|
|
|
return "D";
|
2024-10-29 10:08:34 +00:00
|
|
|
|
default:
|
2024-11-16 09:07:58 +00:00
|
|
|
|
return "DIR";
|
2024-10-29 10:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-12 09:25:18 +00:00
|
|
|
|
let ws = null;
|
|
|
|
|
function MsgCb(MsgIt) {
|
2024-10-29 10:08:34 +00:00
|
|
|
|
if (MsgIt.Step <= 6) {
|
|
|
|
|
if (MsgIt.Type == 2) {
|
|
|
|
|
PrintProcessLine(`(${MsgIt.Step}/6) ${MsgIt.Body}`);
|
|
|
|
|
if (parseFloat(MsgIt.Body) == 1) {
|
|
|
|
|
var chunk = chalk["green"]("[上传成功]");
|
|
|
|
|
process.stdout.write(chunk);
|
|
|
|
|
process.stdout.write("\n");
|
2024-10-12 09:25:18 +00:00
|
|
|
|
}
|
2024-10-29 10:08:34 +00:00
|
|
|
|
} else if (MsgIt.Type == 3) {
|
|
|
|
|
var it = JSON.parse(MsgIt.Body);
|
2024-11-16 09:07:58 +00:00
|
|
|
|
const f = (item) => {
|
2024-10-29 10:08:34 +00:00
|
|
|
|
PrintSuccessInNewLine(
|
2024-11-16 09:07:58 +00:00
|
|
|
|
`(${MsgIt.Step}/6) [${getOpEmoj(item.NextOp)}] ${item.FormatedPath}`
|
2024-10-29 10:08:34 +00:00
|
|
|
|
);
|
2024-11-16 09:07:58 +00:00
|
|
|
|
if (item.Children) {
|
|
|
|
|
item.Children.forEach((e) => {
|
|
|
|
|
f(e)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
f(it)
|
2024-09-05 01:59:57 +00:00
|
|
|
|
} else {
|
2024-10-29 10:08:34 +00:00
|
|
|
|
PrintSuccessInNewLine(`(${MsgIt.Step}/6) ${MsgIt.Body}`);
|
2024-09-05 01:59:57 +00:00
|
|
|
|
}
|
2024-10-29 10:08:34 +00:00
|
|
|
|
if (MsgIt.Step == 6) {
|
|
|
|
|
if (MsgIt.Body == "发布完成!") {
|
|
|
|
|
IsSuccess = true;
|
|
|
|
|
ws.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (MsgIt.Step == 7) {
|
|
|
|
|
PrintErrInNewLine(MsgIt.Body);
|
|
|
|
|
} else {
|
|
|
|
|
PrintCloseNewLine("(关闭)" + MsgIt.Body);
|
2024-10-12 09:25:18 +00:00
|
|
|
|
}
|
2024-09-05 01:59:57 +00:00
|
|
|
|
}
|
2024-10-29 10:08:34 +00:00
|
|
|
|
|
2024-09-05 01:59:57 +00:00
|
|
|
|
//#endregion
|
2024-10-12 09:25:18 +00:00
|
|
|
|
async function connectWebSocket() {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const wsUrl = `ws://${LocalHost}:6818/websoc?Name=${config.Name}`;
|
|
|
|
|
ws = new WebSocket(wsUrl);
|
|
|
|
|
|
|
|
|
|
ws.onopen = (event) => {
|
|
|
|
|
var starter = {
|
|
|
|
|
Body: JSON.stringify(config),
|
|
|
|
|
Type: 1,
|
|
|
|
|
Step: 1,
|
|
|
|
|
};
|
|
|
|
|
// console.warn("websocket connected!");
|
|
|
|
|
ws.send(JSON.stringify(starter));
|
|
|
|
|
};
|
|
|
|
|
ws.onmessage = (event) => {
|
|
|
|
|
// console.log(event.data);
|
|
|
|
|
MsgCb(JSON.parse(event.data));
|
|
|
|
|
};
|
|
|
|
|
ws.onclose = (event) => {
|
|
|
|
|
// console.warn(event)
|
|
|
|
|
MsgCb({
|
|
|
|
|
Type: 0,
|
|
|
|
|
Step: 8,
|
|
|
|
|
Body: event.reason,
|
|
|
|
|
});
|
|
|
|
|
// resolve()
|
|
|
|
|
};
|
|
|
|
|
ws.onerror = (e) => {
|
|
|
|
|
// console.error(e);
|
|
|
|
|
MsgCb({
|
|
|
|
|
Type: 0,
|
|
|
|
|
Body: "异常错误,查看 Console",
|
|
|
|
|
Step: 7,
|
|
|
|
|
});
|
|
|
|
|
reject(err);
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
(async function main() {
|
|
|
|
|
try {
|
2024-10-29 10:08:34 +00:00
|
|
|
|
// for(var i = 0;i<10;++i) {
|
|
|
|
|
// PrintGeneralInCurrentLine(`${i}`)
|
|
|
|
|
// }
|
|
|
|
|
// PrintSuccessInNewLine("11")
|
2024-10-12 09:25:18 +00:00
|
|
|
|
await connectWebSocket();
|
2024-11-28 01:30:46 +00:00
|
|
|
|
if (!IsSuccess) {
|
|
|
|
|
throw new Error("发布失败");
|
|
|
|
|
}
|
2024-10-12 09:25:18 +00:00
|
|
|
|
// console.log('WebSocket has closed');
|
|
|
|
|
// The script will wait here until the WebSocket connection is closed
|
|
|
|
|
} catch (err) {
|
2024-11-28 01:30:46 +00:00
|
|
|
|
throw new Error(err);
|
2024-10-12 09:25:18 +00:00
|
|
|
|
}
|
|
|
|
|
})();
|