增加部署用的插件

@param {object} webpackConfig
@param {object} wpkConfig
@param {object} env
504013
function addDeployPlugin(webpackConfig, wpkConfig, env) {
    env = proccessFtpPath(env);

    webpackConfig.plugins.push(new DeployPlugin({
        server: `${env.__ftp_user__}:${env.__ftp_password__}@${env.__ftp_host__}:${env.__ftp_port__}`,
        workspace: wpkConfig.output.path,
        deployTo: env.__ftp_path__
    }));
}
518604
function EnvPacket(env) {
  Packet.call(this);
  this.env = env || {};
  this.json = JSON.stringify(this.env);
}
386839
function build (config) {
  return new Promise((resolve, reject) => {
    const compiler = webpack(Object.assign(config, {
      output: { filename: 'file' },
      plugins: [
        new webpack.DefinePlugin({
          'process.env.NODE_ENV': '"production"',
          'process.browser': true
        })
      ]
    }), (err, stats) => {
      if (err || stats.hasErrors()) reject(err || new Error(stats.toString('errors-only')))
      const compilation = stats.compilation
      const compiler = compilation.compiler
      const memoryFs = compiler.outputFileSystem
      const outputFile = compilation.assets.file.existsAt
      resolve(memoryFs.readFileSync(outputFile, 'utf8'))
    })
    compiler.outputFileSystem = new MemoryFs()
  })
}
1043793
function beautifyJsForDebug(env, webpackConfig) {
    var webpack = require('webpack');
    var index = -1;
    for (var i = 0, length = webpackConfig.plugins.length; i < length; i++) {
        if (webpackConfig.plugins[i] instanceof webpack.optimize.UglifyJsPlugin) {
            index = i;
            break;
        }
    }
    if (index != -1) {
        webpackConfig.plugins.splice(index, 1);
    }
    process.env.NODE_ENV = 'development';
}
577445
function initTasks (gulp, config) {
	var pkg = readPackageJSON();
	var name = capitalize(camelCase(config.component.pkgName || pkg.name));

	config = defaults(config, { aliasify: pkg.aliasify });
	config.component = defaults(config.component, {
		pkgName: pkg.name,
		dependencies: pkg.deps,
		name: name,
		src: 'src',
		lib: 'lib',
		dist: 'dist',
		file: (config.component.name || name) + '.js'
	});

	if (config.example) {
		if (config.example === true) config.example = {};

		defaults(config.example, {
			src: 'example/src',
			dist: 'example/dist',
			files: ['index.html'],
			scripts: ['example.js'],
			less: ['example.less']
		});
	}

	require('./tasks/bump')(gulp, config);
	require('./tasks/dev')(gulp, config);
	require('./tasks/dist')(gulp, config);
	require('./tasks/release')(gulp, config);

	var buildTasks = ['build:dist'];
	var cleanTasks = ['clean:dist'];

	if (config.component.lib) {
		require('./tasks/lib')(gulp, config);
		buildTasks.push('build:lib');
		cleanTasks.push('clean:lib');
	}

	if (config.example) {
		require('./tasks/examples')(gulp, config);
		buildTasks.push('build:examples');
		cleanTasks.push('clean:examples');
	}

	gulp.task('build', buildTasks);
	gulp.task('clean', cleanTasks);
}
200856
function _loadWebpackConfig(configFileName) {
  const customWebpackConfigPath = path.join(process.cwd(), configFileName);

  let webpackConfig = null;

  try {
    webpackConfig = require(customWebpackConfigPath);
  } catch(err) {}

  if (!webpackConfig) {
    webpackConfig = require('../config/webpack/webpack.config.js');
  } else {
    console.log('R> loaded custom webpack config: ', customWebpackConfigPath)
  }

  return webpackConfig;
}
1026165
function getConfig(config) {

  const path = require('path');

  const DefinePlugin = require('webpack/lib/DefinePlugin');
  const testWebpackConfig = require('../webpack/test.webpack.config');
  const skyPagesConfigUtil = require('../sky-pages/sky-pages.config');
  const testKarmaConf = require('./test.karma.conf');

  const runtimePath = path.resolve(process.cwd(), 'runtime');
  const skyPagesConfig = skyPagesConfigUtil.getSkyPagesConfig('test');
  let webpackConfig = testWebpackConfig.getWebpackConfig(skyPagesConfig);

  // Import shared karma config
  testKarmaConf(config);

  // First DefinePlugin wins so we want to override the normal src/app/ value in ROOT_DIR
  webpackConfig.plugins.unshift(
    new DefinePlugin({
      'ROOT_DIR': JSON.stringify(runtimePath)
    })
  );

  // Adjust the loader src path.
  webpackConfig.module.rules[webpackConfig.module.rules.length - 1].include = runtimePath;

  // This is needed exclusively for internal runtime unit tests,
  // which is why it's here instead of alias-builder or the shared test.webpack.config.js
  addRuntimeAlias(webpackConfig, runtimePath, '');
  addRuntimeAlias(webpackConfig, runtimePath, '/i18n');

  // Remove sky-style-loader
  delete config.preprocessors['../../utils/spec-styles.js'];
  config.files.pop();

  config.set({
    webpack: webpackConfig,
    coverageReporter: {
      dir: path.join(process.cwd(), 'coverage', 'runtime')
    }
  });
}
131957
function webpackCache(e) {
		var keys = Object.keys(webpackConfig.cache);
		var key, matchedKey;
		for (var keyIndex = 0; keyIndex < keys.length; keyIndex++) {
			key = keys[keyIndex];
			if (key.indexOf(e.path) !== -1) {
				matchedKey = key;
				break;
			}
		}
		if (matchedKey) {
			delete webpackConfig.cache[matchedKey];
		}
	}
304729
function getEntries(config, env) {
  let entries = {
    main: []
  };

  //default entry point
  entries.main.push(path.resolve(config.sourceDir, 'index'));

  //svg-sprite
  if (utils.isFileExists(config.svgSpriteDir)) {
    entries.main.unshift(path.resolve(__dirname, './entries/svg-sprite.js'));
  }

  //extend default entries
  if (config.extendEntries && typeof config.extendEntries == 'object') {
    entries = merge(entries, config.extendEntries);
  }

  if (env === 'development') {
    let entryKeys = Object.keys(entries);
    entryKeys.forEach(function (e) {
      if (typeof entries[e] === 'string') {
        entries[e] = [entries[e]]
      }
      entries[e].unshift('webpack-hot-middleware/client?reload=true');
    });
  }

  return entries;
}
1104024
function createHtmlWebpackPluginHooks () {
  return {
    beforeAssetTagGeneration: new AsyncSeriesWaterfallHook(['pluginArgs']),
    alterAssetTags: new AsyncSeriesWaterfallHook(['pluginArgs']),
    alterAssetTagGroups: new AsyncSeriesWaterfallHook(['pluginArgs']),
    afterTemplateExecution: new AsyncSeriesWaterfallHook(['pluginArgs']),
    beforeEmit: new AsyncSeriesWaterfallHook(['pluginArgs']),
    afterEmit: new AsyncSeriesWaterfallHook(['pluginArgs'])
  };
}
128892
function getWebpackStats(config) {

    let statsPaths = config.testPathDirs.map(testPathDir => {
        return path.join(testPathDir, 'stats.json');
    });

    statsPaths.some(statsPath => {
        try {
            webpackStats = require(statsPath);
        } catch (oh) {
            // not found
        }
        return !!webpackStats;
    });

    if (!webpackStats) {
        throw new Error('Cannot find Webpack stats in: \n' + statsPaths.join('\n'));
    }

    return webpackStats;
}
283593
function load(filename, envs) {
    const config = {};
    if (!path.isAbsolute(filename)) {
        filename = path.resolve(process.cwd(), filename);
    }
    if (fs.existsSync(filename)) {
        const stat = fs.lstatSync(filename);
        if (stat.isFile()) {
            if (/.json$/.test(filename)) {
                const content = fs.readFileSync(filename, 'utf8');
                Object.assign(config, fn.resolve(JSON.parse(content), envs));
            }
        } else if (stat.isDirectory()) {
            const files = fs
                .readdirSync(filename)
                .filter(
                    f =>
                        fs.lstatSync(path.resolve(filename, f)).isFile() &&
                        /.json$/.test(f)
                );
            files.forEach(file => {
                const content = fs.readFileSync(
                    path.resolve(filename, file),
                    'utf8'
                );
                const basename = path.basename(file, path.extname(file));
                Object.assign(config, {
                    [basename]: fn.resolve(JSON.parse(content), envs)
                });
            });
        }
    }

    return config;
}
825767
function setEnvironments (config) {
  environments.environments = config.environments || {}
  environments.envId = getEnvId(config)
  environments.ENVID = environments.envId ? environments.envId.toUpperCase() : undefined
  environments.environmentTypes = environments.environments.static || keys(config)
  environments.environmentType = _.includes(environments.environmentTypes, environments.envId) ? environments.envId : environments.environments.default
}
223701
function applyEnv(env, secrets = {}, required = {}) {
  if (Array.isArray(env)) {
    env.forEach(key => {
      // if the key already exists don't overwrite it
      if (!process.env[key]) {
        const value = getValue(key, {}, secrets, required)
        process.env[key] = value
      }
    })
  } else {
    Object.entries(env).forEach(([key, value]) => {
      // if the key already exists don't overwrite it
      if (!process.env[key]) {
        const value = getValue(key, env, secrets, required)
        process.env[key] = value
      }
    })
  }
}
286609
function getDefinePlugin(env) {
    var definitions = {};
    for (var key in env) {
        definitions[key] = JSON.stringify(env[key]);
    }

    if (env.__mode__ != 'dev') {
        // 一般约定俗成的打包优化, 设置环境变量为 production 模式
        // 例如 vue-loader 会判断 NODE_ENV 在非 production 模式下, 处理过的文件会带有供调试的信息,
        // options.__file="sr/lib/hello-component/hello-component.vue"
        // 再例如 react 的 https://facebook.github.io/react/docs/optimizing-performance.html#webpack
        process.env.NODE_ENV = 'production';
        definitions['process.env.NODE_ENV'] = JSON.stringify(process.env.NODE_ENV);
    }

    return new webpack.DefinePlugin(definitions);
}
366174
function extendWithDotEnv(inputEnv, dotEnvPath = '.env') {
    let dotEnvBuffer = null
    try {
        dotEnvBuffer = fs.readFileSync(dotEnvPath)
    } catch (err) {
        if (err.code === 'ENOENT') return inputEnv
        throw err
    }
    const parsed = dotenv.parse(dotEnvBuffer)
    return extend(parsed, inputEnv)
}
468896
function loadConfig(done) {
  fs.stat('package.json', function(err) {
    if (err) return done(undefined, {});
    fs.readFile('package.json', function(err, contents) {
      if (err) return done(err);
      try {
        done(undefined, JSON.parse(contents).config || {});
      } catch(err) {
        done(err);
      }
    });
  });
}