运行多个本地ide

功能及平台机制说明

提供开启多个本地IDE协同开发,在端口不冲突的情况运行多个应用对应的本地协同服务,通过设置端口定义文件service/service.json里定义不同端口即可运行。

具体操作

  1. 进入本地安装目录,在端口定义文件service/service.json里定义不同端口,所有端口设置为不同就可以,有冲突会提示,另外端口有效取值范围0~~65536
    1. 如有端口冲突,端口取值超出范围都会提示,如下图所示
  2. 针对调试springboot应用服务,需要修改springboot启动端口,在切换本地IDE前,可以在应用架构主服务中修改端口,如下图所示
    1. 如springboot服务端口未调整,在调试调用服务会异常,日志中会报冲突占用情况,如下图
  3. 端口设置完成,打开本地IDE协同界面中,服务端口默认9502,如其他应用端口定义后,需要配置上在端口定义文件中定义的端口
  4. 如上设置完成后,可在本地开启多个本地IDE进行调试运行

注意事项说明

  1. 如果当前平台版本是45版本,开启多个本地IDE应用预览会有端口冲突问题,需要修改本地IDE安装目录\tools\uix-web\scripts\DevServer.js文件,文件内容如下
const path = require('path');
const fs = require('fs');
const http = require('http');
const ejs = require('ejs');
const {src, dest} = require('gulp');
const WebpackDevServer = require('webpack-dev-server');
const logger = require('./logger');
const webpack = require('webpack');
const DevServerMiddleware = require('./DevServerMiddleware');
const generateServiceManifest = require("./ServiceManifest");
const lnk = require('lnk');
const mkdirp = require("mkdirp");
const chokidar = require('chokidar');
const DevContextRouter = require("./DevContextRouter");
const DevServerDllWatcher = require("./dll/DevServerDllWatcher");
const disableDll = process.argv.includes('--disableDll');
const compression = require('compression')
const isWatch = process.argv.includes('--watch');
const uixWebPort = process.env.UIXWEB_PORT || '5555';


const {doEslintCheck} = require('../eslint/scripts/lint');

const i18n = require('./i18n/i18n');

const JUSTEP_HOME = process.env.JUSTEP_HOME;
const debugTargetDeviceName = process.env.UIX_DEBUG_TARGET_DEVICE_NAME;
const isDebug = global.DEBUG === false ? false : !process.argv.includes('--release');

console.log("disableDll:" + disableDll);
console.log("isDebug:" + isDebug);
let ui2Path = null;


class DevServer {
  constructor() {
    const exceptionHandler = require('express-exception-handler');
    exceptionHandler.handle();
    this.app = require('express')()

    process.on('uncaughtException', (e)=>{
      console.error('devserver 异常:');
      console.error(e);
    });


    //this.app.use(compression());
    this.expressWs = require('express-ws')(this.app);
    this.ui2Path = path.resolve(JUSTEP_HOME, "model", "UI2");
    ui2Path = ui2Path || this.ui2Path;
    this.disableDll = disableDll;
    this.isDebug = isDebug;
    this.contextRouters = {};

    this.startWatcher();


  }

  rootMiddleware(req,res,next){
    if(req.path == '/eslint'){
      return doEslintCheck(req,res,next);
    }else if(req.path == "/"){
      res.send({health:true});
    }else{
      next();
    }
  }

  async start() {
    process.on('uncaughtException', (e)=>{
      console.error('DevServer异常:', e);
      console.error(e);
    });

    this.app.use(function (req, res, next) {
      next();
    });

    await this.startRouter();

    this.app.use("/i18n/:endType/:action",i18n.processRequest);

    this.app.use([this.rootMiddleware]);


    this.app.listen(uixWebPort,()=>{

      logger.info(this.app._router.stack          // registered routes
        .filter(r => r.route)    // take out all the middleware
        .map(r => r.route.path));
    });
  }

  async startRouter() {
    fs.readdirSync(this.ui2Path).forEach((name) => {

      let routerPath = path.join(this.ui2Path, name);

      let wxIdentifyPath = path.join(this.ui2Path, name, "config", ".wx");
      let mxIdentifyPath = path.join(this.ui2Path, name, "config", ".mx");
      let pcxIdentifyPath = path.join(this.ui2Path, name, "config", ".pcx");
      let routerIdentifyPath = path.join(this.ui2Path, name, "config", "application.xml");

      if (fs.existsSync(routerIdentifyPath) && fs.existsSync(mxIdentifyPath)) {
        let contextRouter = new DevContextRouter({
          routerName: name,
          contextName: `${name}app`,
          devServer: this,
          deviceType:"mx"
        });

        this.contextRouters[name] = contextRouter;
      }else if (fs.existsSync(routerIdentifyPath) && fs.existsSync(wxIdentifyPath)) {
        let contextRouter = new DevContextRouter({
          routerName: name,
          contextName: `${name}app`,
          devServer: this,
          deviceType:"wx"
        });
        this.contextRouters[name] = contextRouter;
      } else if (fs.existsSync(routerIdentifyPath) && fs.existsSync(pcxIdentifyPath)) {
        let contextRouter = new DevContextRouter({
          routerName: name,
          contextName: `${name}app`,
          devServer: this,
          deviceType:"pcx"
        });
        this.contextRouters[name] = contextRouter;
      }
    });

    for (let key in this.contextRouters) {
      logger.info(`端 ${key} 开发服务开始启动`);
      if(debugTargetDeviceName){
        let debugTargetDeviceNames = debugTargetDeviceName.split(',');
        if(debugTargetDeviceNames.indexOf(key) != -1){
          await this.contextRouters[key].start();
        }
      }else{
        await this.contextRouters[key].start();
      }
      logger.info(`端 ${key} 开发服务启动成功`);
    }
  }

  startWatcher(){
    this.devServerDllWatcher = new DevServerDllWatcher();
  }
}

module.exports = DevServer;

results matching ""

    No results matching ""