const config = require('../project.config.json');
const pkg = require('../package.json');
const path = require('path');
const semver = require('semver');

let projectPath = path.resolve(__dirname, '..');

const CIPluginFn = async () => {
  let version;
  let robot = 30;
  let desc = '';
  if (process.env.NODE_ENV === 'production') {
    version = pkg.version;
    robot = 1;
    desc = '正式环境小程序';
    if (process.env.APP_ENV === 'staging') {
      version = semver.inc(version, 'patch');
      robot = 2;
      desc = '测试环境小程序';
    }
  }

  /**
   * @typedef { import("@tarojs/plugin-mini-ci").CIOptions } CIOptions
   * @type {CIOptions}
   */
  return {
    weapp: {
      appid: config.appid,
      privateKeyPath: `${projectPath}/ci/private.wx88251c84f5cd886b.key`,
      robot: robot,
      setting: {
        minify: true,
      },
    },
    version,
    desc: desc,
  };
};

module.exports = { CIPluginFn };