package.js 1.1 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
const PLATFORMS = [
  'h5',
  'app-plus',
  'mp-weixin',
  'mp-qq',
  'mp-baidu',
  'mp-alipay',
  'mp-toutiao'
]

module.exports = {
  initCustomScript (name, pkgPath) {
    const pkg = require(pkgPath)
    const uniAppOptions = pkg['uni-app']

    let scriptOptions = false

fxy060608's avatar
fxy060608 已提交
18 19
    if (uniAppOptions && uniAppOptions.scripts) {
      scriptOptions = uniAppOptions.scripts[name]
fxy060608's avatar
fxy060608 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32
    }

    if (!scriptOptions) {
      console.error(`package.json->uni-app->scripts->${name} 不存在`)
      process.exit(0)
    }

    if (!scriptOptions.env || !scriptOptions.env.UNI_PLATFORM) {
      console.error(`package.json->uni-app->scripts->${name}->env 不存在,必须配置 env->UNI_PLATFORM 基础平台`)
      process.exit(0)
    }

    if (PLATFORMS.indexOf(scriptOptions.env.UNI_PLATFORM) === -1) {
Q
qiang 已提交
33
      console.error(`UNI_PLATFORM 支持以下平台 ${JSON.stringify(PLATFORMS)}`)
fxy060608's avatar
fxy060608 已提交
34 35 36 37 38 39 40 41 42 43
      process.exit(0)
    }

    process.env.UNI_PLATFORM = scriptOptions.env.UNI_PLATFORM

    process.UNI_SCRIPT_ENV = scriptOptions.env || {}
    process.UNI_SCRIPT_DEFINE = scriptOptions.define || {}

    return scriptOptions
  }
Q
qiang 已提交
44
}