1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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: 'measure', //本地文件名
- path: '/www/wwwroot/measure.hcxxy.com', //服务器上的文件路径
- url: 'http://192.168.0.109:5180/', //demo地址
- },
- {
- name: 'user', //正式服
- ip: '39.108.216.210', //服务器地址
- username: 'root', //登录账号
- password: '%CX0&qPRk2BitWPH^tCa5jxZKPYuST', //登录密码
- fileName: 'measure', //本地文件名
- path: '/www/wwwroot/measure.hczcxx.cn', //服务器上的文件路径
- url: 'http://measure.hczcxx.cn/', //demo地址
- },
- {
- name: '183', //甬台温
- ip: '183.247.216.148:237', //服务器地址
- username: 'root', //登录账号
- password: 'DAJL@20240520@root', //登录密码
- fileName: 'measure-local', //本地文件名
- path: '/www/wwwroot/measure.hcxxy.com', //服务器上的文件路径
- url: 'http://183.247.216.148:6070/tz_web/', //demo地址
- },
- ];
- const argv = process.argv[2]
- const args = process.argv[3]
- // 执行命令并打印输出
- 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}-${args}.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 ${args} ${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}-${args}.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 ${args} ${ip} ${username} '${password}' ${file_name} ${path} ${url}`);
- }
- console.log(`----------------------------`)
- console.log(`全部上传并部署完成`);
- }
- setConfigData()
|