自动化部署

This commit is contained in:
wxf
2025-06-13 17:16:09 +08:00
parent 7218813f5f
commit 2c856571a2
4 changed files with 218 additions and 7 deletions
+48
View File
@@ -0,0 +1,48 @@
const { execSync } = require('child_process');
const { NodeSSH } = require('node-ssh');
const path = require('path');
const fs = require('fs');
const ssh = new NodeSSH();
const remoteConfig = {
host: '124.221.147.173',
username: 'root',
password: '15703453653wxf.+',
// port: 22, // 默认22端口,如有变动请取消注释
};
const localDist = path.resolve(__dirname, 'docs/.vitepress/dist');
const remoteDir = '/www/wwwroot/flys_blog';
async function main() {
try {
// 1. 打包
console.log('打包中...');
execSync('npx vitepress build docs', { stdio: 'inherit' });
// 2. 连接服务器
console.log('连接服务器...');
await ssh.connect(remoteConfig);
// 3. 清空远程目录
console.log('清空远程目录...');
await ssh.execCommand(`rm -rf ${remoteDir}/*`);
// 4. 上传 dist 文件夹内容
console.log('上传文件...');
await ssh.putDirectory(localDist, remoteDir, {
recursive: true,
concurrency: 10,
validate: (itemPath) => !itemPath.endsWith('.DS_Store'),
});
console.log('部署完成!');
ssh.dispose();
} catch (err) {
console.error('部署失败:', err);
process.exit(1);
}
}
main();
+6 -6
View File
@@ -1,25 +1,25 @@
{ {
"hash": "a9219e8e", "hash": "7f4cec3f",
"configHash": "d900ecba", "configHash": "d900ecba",
"lockfileHash": "87bc6ebb", "lockfileHash": "8a3c39ce",
"browserHash": "86982eb7", "browserHash": "0c2c841e",
"optimized": { "optimized": {
"vue": { "vue": {
"src": "../../../../node_modules/vue/dist/vue.runtime.esm-bundler.js", "src": "../../../../node_modules/vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js", "file": "vue.js",
"fileHash": "dd79b94a", "fileHash": "c2521b6a",
"needsInterop": false "needsInterop": false
}, },
"vitepress > @vue/devtools-api": { "vitepress > @vue/devtools-api": {
"src": "../../../../node_modules/@vue/devtools-api/dist/index.js", "src": "../../../../node_modules/@vue/devtools-api/dist/index.js",
"file": "vitepress___@vue_devtools-api.js", "file": "vitepress___@vue_devtools-api.js",
"fileHash": "e1b7354e", "fileHash": "cebddba8",
"needsInterop": false "needsInterop": false
}, },
"vitepress > @vueuse/core": { "vitepress > @vueuse/core": {
"src": "../../../../node_modules/@vueuse/core/index.mjs", "src": "../../../../node_modules/@vueuse/core/index.mjs",
"file": "vitepress___@vueuse_core.js", "file": "vitepress___@vueuse_core.js",
"fileHash": "271209e6", "fileHash": "378e5298",
"needsInterop": false "needsInterop": false
} }
}, },
+160
View File
@@ -5,6 +5,9 @@
"packages": { "packages": {
"": { "": {
"name": "vitepress-project", "name": "vitepress-project",
"dependencies": {
"node-ssh": "^13.2.1"
},
"devDependencies": { "devDependencies": {
"vitepress": "^1.6.3", "vitepress": "^1.6.3",
"vue": "^3.2.47" "vue": "^3.2.47"
@@ -1498,6 +1501,24 @@
"node": ">= 14.0.0" "node": ">= 14.0.0"
} }
}, },
"node_modules/asn1": {
"version": "0.2.6",
"resolved": "https://registry.npmmirror.com/asn1/-/asn1-0.2.6.tgz",
"integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==",
"license": "MIT",
"dependencies": {
"safer-buffer": "~2.1.0"
}
},
"node_modules/bcrypt-pbkdf": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
"integrity": "sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==",
"license": "BSD-3-Clause",
"dependencies": {
"tweetnacl": "^0.14.3"
}
},
"node_modules/birpc": { "node_modules/birpc": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmmirror.com/birpc/-/birpc-2.3.0.tgz", "resolved": "https://registry.npmmirror.com/birpc/-/birpc-2.3.0.tgz",
@@ -1508,6 +1529,15 @@
"url": "https://github.com/sponsors/antfu" "url": "https://github.com/sponsors/antfu"
} }
}, },
"node_modules/buildcheck": {
"version": "0.0.6",
"resolved": "https://registry.npmmirror.com/buildcheck/-/buildcheck-0.0.6.tgz",
"integrity": "sha512-8f9ZJCUXyT1M35Jx7MkBgmBMo3oHTTBIPLiY9xyL0pl3T5RwcPEY8cUHr5LBNfu/fk6c2T4DJZuVM/8ZZT2D2A==",
"optional": true,
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/ccount": { "node_modules/ccount": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmmirror.com/ccount/-/ccount-2.0.1.tgz", "resolved": "https://registry.npmmirror.com/ccount/-/ccount-2.0.1.tgz",
@@ -1568,6 +1598,20 @@
"url": "https://github.com/sponsors/mesqueeb" "url": "https://github.com/sponsors/mesqueeb"
} }
}, },
"node_modules/cpu-features": {
"version": "0.0.10",
"resolved": "https://registry.npmmirror.com/cpu-features/-/cpu-features-0.0.10.tgz",
"integrity": "sha512-9IkYqtX3YHPCzoVg1Py+o9057a3i0fp7S530UWokCSaFVTc7CwXPRiOjRjBQQ18ZCNafx78YfnG+HALxtVmOGA==",
"hasInstallScript": true,
"optional": true,
"dependencies": {
"buildcheck": "~0.0.6",
"nan": "^2.19.0"
},
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/csstype": { "node_modules/csstype": {
"version": "3.1.3", "version": "3.1.3",
"resolved": "https://registry.npmmirror.com/csstype/-/csstype-3.1.3.tgz", "resolved": "https://registry.npmmirror.com/csstype/-/csstype-3.1.3.tgz",
@@ -1746,6 +1790,18 @@
"url": "https://github.com/sponsors/wooorm" "url": "https://github.com/sponsors/wooorm"
} }
}, },
"node_modules/is-stream": {
"version": "2.0.1",
"resolved": "https://registry.npmmirror.com/is-stream/-/is-stream-2.0.1.tgz",
"integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==",
"license": "MIT",
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/is-what": { "node_modules/is-what": {
"version": "4.1.16", "version": "4.1.16",
"resolved": "https://registry.npmmirror.com/is-what/-/is-what-4.1.16.tgz", "resolved": "https://registry.npmmirror.com/is-what/-/is-what-4.1.16.tgz",
@@ -1769,6 +1825,21 @@
"@jridgewell/sourcemap-codec": "^1.5.0" "@jridgewell/sourcemap-codec": "^1.5.0"
} }
}, },
"node_modules/make-dir": {
"version": "3.1.0",
"resolved": "https://registry.npmmirror.com/make-dir/-/make-dir-3.1.0.tgz",
"integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==",
"license": "MIT",
"dependencies": {
"semver": "^6.0.0"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/mark.js": { "node_modules/mark.js": {
"version": "8.11.1", "version": "8.11.1",
"resolved": "https://registry.npmmirror.com/mark.js/-/mark.js-8.11.1.tgz", "resolved": "https://registry.npmmirror.com/mark.js/-/mark.js-8.11.1.tgz",
@@ -1906,6 +1977,13 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/nan": {
"version": "2.22.2",
"resolved": "https://registry.npmmirror.com/nan/-/nan-2.22.2.tgz",
"integrity": "sha512-DANghxFkS1plDdRsX0X9pm0Z6SJNN6gBdtXfanwoZ8hooC5gosGFSBGRYHUVPz1asKA/kMRqDRdHrluZ61SpBQ==",
"license": "MIT",
"optional": true
},
"node_modules/nanoid": { "node_modules/nanoid": {
"version": "3.3.11", "version": "3.3.11",
"resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.11.tgz", "resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.11.tgz",
@@ -1925,6 +2003,23 @@
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
} }
}, },
"node_modules/node-ssh": {
"version": "13.2.1",
"resolved": "https://registry.npmmirror.com/node-ssh/-/node-ssh-13.2.1.tgz",
"integrity": "sha512-rfl4GWMygQfzlExPkQ2LWyya5n2jOBm5vhEnup+4mdw7tQhNpJWbP5ldr09Jfj93k5SfY5lxcn8od5qrQ/6mBg==",
"license": "MIT",
"dependencies": {
"is-stream": "^2.0.0",
"make-dir": "^3.1.0",
"sb-promise-queue": "^2.1.0",
"sb-scandir": "^3.1.0",
"shell-escape": "^0.2.0",
"ssh2": "^1.14.0"
},
"engines": {
"node": ">= 10"
}
},
"node_modules/oniguruma-to-es": { "node_modules/oniguruma-to-es": {
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmmirror.com/oniguruma-to-es/-/oniguruma-to-es-3.1.1.tgz", "resolved": "https://registry.npmmirror.com/oniguruma-to-es/-/oniguruma-to-es-3.1.1.tgz",
@@ -2076,6 +2171,33 @@
"fsevents": "~2.3.2" "fsevents": "~2.3.2"
} }
}, },
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmmirror.com/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT"
},
"node_modules/sb-promise-queue": {
"version": "2.1.1",
"resolved": "https://registry.npmmirror.com/sb-promise-queue/-/sb-promise-queue-2.1.1.tgz",
"integrity": "sha512-qXfdcJQMxMljxmPprn4Q4hl3pJmoljSCzUvvEBa9Kscewnv56n0KqrO6yWSrGLOL9E021wcGdPa39CHGKA6G0w==",
"license": "MIT",
"engines": {
"node": ">= 8"
}
},
"node_modules/sb-scandir": {
"version": "3.1.1",
"resolved": "https://registry.npmmirror.com/sb-scandir/-/sb-scandir-3.1.1.tgz",
"integrity": "sha512-Q5xiQMtoragW9z8YsVYTAZcew+cRzdVBefPbb9theaIKw6cBo34WonP9qOCTKgyAmn/Ch5gmtAxT/krUgMILpA==",
"license": "MIT",
"dependencies": {
"sb-promise-queue": "^2.1.0"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/search-insights": { "node_modules/search-insights": {
"version": "2.17.3", "version": "2.17.3",
"resolved": "https://registry.npmmirror.com/search-insights/-/search-insights-2.17.3.tgz", "resolved": "https://registry.npmmirror.com/search-insights/-/search-insights-2.17.3.tgz",
@@ -2084,6 +2206,21 @@
"license": "MIT", "license": "MIT",
"peer": true "peer": true
}, },
"node_modules/semver": {
"version": "6.3.1",
"resolved": "https://registry.npmmirror.com/semver/-/semver-6.3.1.tgz",
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/shell-escape": {
"version": "0.2.0",
"resolved": "https://registry.npmmirror.com/shell-escape/-/shell-escape-0.2.0.tgz",
"integrity": "sha512-uRRBT2MfEOyxuECseCZd28jC1AJ8hmqqneWQ4VWUTgCAFvb3wKU1jLqj6egC4Exrr88ogg3dp+zroH4wJuaXzw==",
"license": "MIT"
},
"node_modules/shiki": { "node_modules/shiki": {
"version": "2.5.0", "version": "2.5.0",
"resolved": "https://registry.npmmirror.com/shiki/-/shiki-2.5.0.tgz", "resolved": "https://registry.npmmirror.com/shiki/-/shiki-2.5.0.tgz",
@@ -2132,6 +2269,23 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/ssh2": {
"version": "1.16.0",
"resolved": "https://registry.npmmirror.com/ssh2/-/ssh2-1.16.0.tgz",
"integrity": "sha512-r1X4KsBGedJqo7h8F5c4Ybpcr5RjyP+aWIG007uBPRjmdQWfEiVLzSK71Zji1B9sKxwaCvD8y8cwSkYrlLiRRg==",
"hasInstallScript": true,
"dependencies": {
"asn1": "^0.2.6",
"bcrypt-pbkdf": "^1.0.2"
},
"engines": {
"node": ">=10.16.0"
},
"optionalDependencies": {
"cpu-features": "~0.0.10",
"nan": "^2.20.0"
}
},
"node_modules/stringify-entities": { "node_modules/stringify-entities": {
"version": "4.0.4", "version": "4.0.4",
"resolved": "https://registry.npmmirror.com/stringify-entities/-/stringify-entities-4.0.4.tgz", "resolved": "https://registry.npmmirror.com/stringify-entities/-/stringify-entities-4.0.4.tgz",
@@ -2178,6 +2332,12 @@
"url": "https://github.com/sponsors/wooorm" "url": "https://github.com/sponsors/wooorm"
} }
}, },
"node_modules/tweetnacl": {
"version": "0.14.5",
"resolved": "https://registry.npmmirror.com/tweetnacl/-/tweetnacl-0.14.5.tgz",
"integrity": "sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==",
"license": "Unlicense"
},
"node_modules/unist-util-is": { "node_modules/unist-util-is": {
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmmirror.com/unist-util-is/-/unist-util-is-6.0.0.tgz", "resolved": "https://registry.npmmirror.com/unist-util-is/-/unist-util-is-6.0.0.tgz",
+4 -1
View File
@@ -4,7 +4,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vitepress dev docs", "dev": "vitepress dev docs",
"build": "vitepress build docs", "build": "node deploy.cjs",
"serve": "vitepress serve docs" "serve": "vitepress serve docs"
}, },
"devDependencies": { "devDependencies": {
@@ -17,5 +17,8 @@
"@algolia/client-search" "@algolia/client-search"
] ]
} }
},
"dependencies": {
"node-ssh": "^13.2.1"
} }
} }