12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- const { execSync} = require('child_process');
- const { getObjValue, arrIndex, isNullES } = require('js-fast-way')
- const fs = require('fs');
- // 配置
- const config = [
- {
- name: 'test', //测试服
- ip: '192.168.0.109', //服务器地址
- username: 'root', //登录账号
- password: 'admin123@', //登录密码
- fileName: 'saber', //本地文件名
- path: '/www/wwwroot/testmanger.hczcxx.cn', //服务器上的文件路径
- url: 'http://192.168.0.109:1888/', //demo地址
- },
- {
- name: 'user', //正式服
- ip: '39.108.216.210', //服务器地址
- username: 'root', //登录账号
- password: '%CX0&qPRk2BitWPH^tCa5jxZKPYuST', //登录密码
- fileName: 'saber', //本地文件名
- path: '/www/wwwroot/testmanger.hcxxy.com', //服务器上的文件路径
- url: 'http://testmanger.hczcxx.cn', //demo地址
- },
- ];
- const argv = process.argv[2]
- // 执行命令并打印输出
- function runCommand(command) {
- console.log(`执行命令: ${command}`);
- try {
- execSync(command, { stdio: 'inherit' });
- } catch (error) {
- console.error(`命令执行失败: ${error.message}`);
- process.exit(1);
- }
- }
- //处理数据
- function setConfigData() {
- if (argv === 'undefined' || isNullES(argv)) {
- process.exit(1);
- return
- }
- console.log(`----------------------------`)
- console.log(`准备开始上传到服务器...`);
- if (argv === 'all') {
- //全部上传
- for (let i = 0; i < config.length; i++) {
- const {name, ip, username, password, fileName, path, url} = getObjValue(config[i])
- const file_name = `${fileName}.zip`
- //判断本地文件是否存在
- if (!fs.existsSync(`./zip/${file_name}`)) {
- console.error(`文件 ./zip/${file_name} 不存在`);
- process.exit(1);
- }
- console.log(`----------------------------`)
- console.log(`准备上传到服务器:${name}`);
- runCommand(`node ./scripts/upload/upload.js ${ip} ${username} '${password}' ${file_name} ${path} ${url}`);
- }
- } else {
- const index = arrIndex(config, 'name', argv)
- if (index === -1) {
- console.log('此平台不存在')
- process.exit(1);
- return
- }
- const {name, ip, username, password, fileName, path, url} = getObjValue(config[index])
- const file_name = `${fileName}.zip`
- //判断本地文件是否存在
- if (!fs.existsSync(`./zip/${file_name}`)) {
- console.error(`文件 ./zip/${file_name} 不存在`);
- process.exit(1);
- }
- console.log(`----------------------------`)
- console.log(`准备上传到服务器:${name}`);
- runCommand(`node ./scripts/upload/upload.js ${ip} ${username} '${password}' ${file_name} ${path} ${url}`);
- }
- console.log(`----------------------------`)
- console.log(`全部上传并部署完成`);
- }
- setConfigData()
|