"use strict";

var rm = require('rimraf');

var path = require('path');

var webpack = require('webpack');

var chalk = require('chalk');

var ora = require('ora');

var pkg = require('../../package.json');

var exec = require('../scripts/helpers/exec');

var webpackConfig = require('./webpack.prod.babel');

var argv = require('../../server/argv');

var spinner = ora('building for production...');
spinner.start();

function logStep(name) {
  console.log("".concat(chalk.gray('>> Release:'), " ").concat(chalk.magenta.bold(name)));
}

function packageExists(_ref) {
  var name = _ref.name,
      version = _ref.version;

  var _execa$sync = execa.sync('npm', ['info', "".concat(name, "@").concat(version)]),
      stdout = _execa$sync.stdout;

  return stdout.length > 0;
}

webpack(webpackConfig, function (err, stats) {
  spinner.stop();
  if (err) throw err;
  process.stdout.write(stats.toString({
    colors: true,
    color: true,
    progress: true,
    modules: false,
    children: false,
    chunks: true,
    chunkModules: true
  }) + '\n\n');

  if (stats.hasErrors()) {
    console.log(chalk.red('  Build failed with errors.\n'));
    process.exit(1);
  }

  console.log(chalk.cyan('  Build complete.\n'));
  console.log(chalk.yellow('  Tip: built files are meant to be served over an HTTP server.\n' + '  Opening index.html over file:// won\'t work.\n'));
  var bumps = ['patch', 'minor', 'major', 'prerelease-alpha', 'prerelease-beta', 'premajor']; //提交

  function release() {
    return regeneratorRuntime.async(function release$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.prev = 0;
            _context.next = 3;
            return regeneratorRuntime.awrap(exec('git', ['add', '.']));

          case 3:
            _context.next = 5;
            return regeneratorRuntime.awrap(exec('git', ['commit', '-m', 'chore: packages', '-n']));

          case 5:
            _context.next = 7;
            return regeneratorRuntime.awrap(exec('git', ['push', '-n']));

          case 7:
            _context.next = 11;
            break;

          case 9:
            _context.prev = 9;
            _context.t0 = _context["catch"](0);

          case 11:
            _context.next = 13;
            return regeneratorRuntime.awrap(exec('np', ['patch', '--no-publish', '--no-cleanup', '--yolo', '-n']));

          case 13:
          case "end":
            return _context.stop();
        }
      }
    }, null, null, [[0, 9]]);
  } //发布
  //比较上一个版本资源与当前资源文件指纹比对


  release()["catch"](function (err) {
    console.error(err);
    process.exit(1);
  });
});