core/plugin.js
function loadPlugin(pluginRoot, noUI) {
  // noUI flag is used for loading dev plugins whose ui is from webpack dev server
  try {
    // const pkgJson = require(paths.join(pluginRoot, 'package.json'));
    const pluginInstance = {};
    // Core part
    const coreIndex = paths.join(pluginRoot, 'core/index.js');
    if (fs.existsSync(coreIndex)) {
      Object.assign(pluginInstance, require(coreIndex));
    }

    // UI part
    if (!noUI && fs.existsSync(path.join(pluginRoot, 'build/main.js'))) {
      pluginInstance.ui = {
        root: path.join(pluginRoot, 'build'),
      };
    }

    // Plugin meta defined in package.json
    const pkgJsonPath = path.join(pluginRoot, 'package.json');
    let pkgJson = null;
    if (fs.existsSync(pkgJsonPath)) {
      pkgJson = fs.readJsonSync(pkgJsonPath);
      ['appType', 'name', 'featureFiles'].forEach(key => {
        if (!pluginInstance.hasOwnProperty(key) && pkgJson.hasOwnProperty(key)) {
          if (key === 'name') {
            let name = pkgJson.name;
            if (name.startsWith('rekit-plugin')) name = name.replace('rekit-plugin-', '');
            pluginInstance.name = name;
          } else {
            pluginInstance[key] = pkgJson[key] || null;
          }
        }
      });
      if (pkgJson.rekitPlugin) {
        Object.keys(pkgJson.rekitPlugin).forEach(key => {
          if (!pluginInstance.hasOwnProperty(key)) {
            pluginInstance[key] = pkgJson.rekitPlugin[key];
          }
        });
      }
    }
    return pluginInstance;
  } catch (e) {
    logger.warn(`Failed to load plugin: ${pluginRoot}`, e);
  }

  return null;
}
function loadPlugin(pluginRoot, noUI) {
  // noUI flag is used for loading dev plugins whose ui is from webpack dev server
  try {
    // const pkgJson = require(paths.join(pluginRoot, 'package.json'));
    const pluginInstance = {};
    // Core part
    const coreIndex = paths.join(pluginRoot, 'core/index.js');
    if (fs.existsSync(coreIndex)) {
      Object.assign(pluginInstance, require(coreIndex));
    }

    // UI part
    if (!noUI && fs.existsSync(path.join(pluginRoot, 'build/main.js'))) {
      pluginInstance.ui = {
        root: path.join(pluginRoot, 'build'),
      };
    }

    // Plugin meta defined in package.json
    const pkgJsonPath = path.join(pluginRoot, 'package.json');
    let pkgJson = null;
    if (fs.existsSync(pkgJsonPath)) {
      pkgJson = fs.readJsonSync(pkgJsonPath);
      ['appType', 'name', 'featureFiles'].forEach(key => {
        if (!pluginInstance.hasOwnProperty(key) && pkgJson.hasOwnProperty(key)) {
          if (key === 'name') {
            let name = pkgJson.name;
            if (name.startsWith('rekit-plugin')) name = name.replace('rekit-plugin-', '');
            pluginInstance.name = name;
          } else {
            pluginInstance[key] = pkgJson[key] || null;
          }
        }
      });
      if (pkgJson.rekitPlugin) {
        Object.keys(pkgJson.rekitPlugin).forEach(key => {
          if (!pluginInstance.hasOwnProperty(key)) {
            pluginInstance[key] = pkgJson.rekitPlugin[key];
          }
        });
      }
    }
    return pluginInstance;
  } catch (e) {
    logger.warn(`Failed to load plugin: ${pluginRoot}`, e);
  }

  return null;
}
function loadPlugin ( pluginRoot , noUI ) { // noUI flag is used for loading dev plugins whose ui is from webpack dev server try { // const pkgJson = require(paths.join(pluginRoot, 'package.json')); const pluginInstance = { } ; // Core part const coreIndex = paths . join ( pluginRoot , 'core/index.js' ) ; if ( fs . existsSync ( coreIndex ) ) { Object . assign ( pluginInstance , require ( coreIndex ) ) ; } // UI part if ( ! noUI && fs . existsSync ( path . join ( pluginRoot , 'build/main.js' ) ) ) { pluginInstance . ui = { root : path . join ( pluginRoot , 'build' ) , } ; } // Plugin meta defined in package.json const pkgJsonPath = path . join ( pluginRoot , 'package.json' ) ; let pkgJson = null ; if ( fs . existsSync ( pkgJsonPath ) ) { pkgJson = fs . readJsonSync ( pkgJsonPath ) ; [ 'appType' , 'name' , 'featureFiles' ] . forEach ( key => { if ( ! pluginInstance . hasOwnProperty ( key ) && pkgJson . hasOwnProperty ( key ) ) { if ( key === 'name' ) { let name = pkgJson . name ; if ( name . startsWith ( 'rekit-plugin' ) ) name = name . replace ( 'rekit-plugin-' , '' ) ; pluginInstance . name = name ; } else { pluginInstance [ key ] = pkgJson [ key ] || null ; } } } ) ; if ( pkgJson . rekitPlugin ) { Object . keys ( pkgJson . rekitPlugin ) . forEach ( key => { if ( ! pluginInstance . hasOwnProperty ( key ) ) { pluginInstance [ key ] = pkgJson . rekitPlugin [ key ] ; } } ) ; } } return pluginInstance ; } catch ( e ) { logger . warn ( ` ${ pluginRoot } ` , e ) ; } return null ; }
Load plugin instance, plugin depends on project config
Load plugin instance plugin depends on project config