/*
 * @Author: ZZT
 * @Date: 2022-01-10 16:57:55
 * @LastEditors: OBKoro1
 * @LastEditTime: 2022-01-10 17:50:47
 */
const fs = require('fs')
const path = require('path')
const dotenv = require('dotenv')
const { CONFIG_ENV } = process.env

const env = dotenv.config({
  path: path.join(__dirname, '../', `.env.${CONFIG_ENV}`)
})

const manifestJson = {
  name: '',
  appid: '',
  description: '',
  versionName: '1.0.0',
  versionCode: '100',
  transformPx: false,
  'app-plus': {
    usingComponents: true /* 5+App特有相关 */,
    splashscreen: {
      alwaysShowBeforeRender: true,
      waiting: true,
      autoclose: true,
      delay: 0
    },
    modules: {
      /* 模块配置 */
    },
    distribute: {
      /* 应用发布信息 */
      android: {
        /* android打包配置 */
        permissions: [
          '<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>',
          '<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>',
          '<uses-permission android:name="android.permission.READ_CONTACTS"/>',
          '<uses-permission android:name="android.permission.VIBRATE"/>',
          '<uses-permission android:name="android.permission.READ_LOGS"/>',
          '<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>',
          '<uses-feature android:name="android.hardware.camera.autofocus"/>',
          '<uses-permission android:name="android.permission.WRITE_CONTACTS"/>',
          '<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>',
          '<uses-permission android:name="android.permission.CAMERA"/>',
          '<uses-permission android:name="android.permission.RECORD_AUDIO"/>',
          '<uses-permission android:name="android.permission.GET_ACCOUNTS"/>',
          '<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>',
          '<uses-permission android:name="android.permission.READ_PHONE_STATE"/>',
          '<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>',
          '<uses-permission android:name="android.permission.WAKE_LOCK"/>',
          '<uses-permission android:name="android.permission.CALL_PHONE"/>',
          '<uses-permission android:name="android.permission.FLASHLIGHT"/>',
          '<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>',
          '<uses-feature android:name="android.hardware.camera"/>',
          '<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>',
          '<uses-permission android:name="android.permission.WRITE_SETTINGS"/>'
        ]
      },
      ios: {
        /* ios打包配置 */
      },
      sdkConfigs: {
        /* SDK配置 */
      }
    }
  },
  quickapp: {
    /* 快应用特有相关 */
  },
  'mp-weixin': {
    /* 微信小程序特有相关 */
    appid: env.parsed.APPID,
    setting: {
      urlCheck: false
    },
    usingComponents: true
  },
  'mp-alipay': {
    usingComponents: true
  },
  'mp-baidu': {
    usingComponents: true
  },
  'mp-toutiao': {
    usingComponents: true
  },
  'mp-qq': {
    usingComponents: true
  }
}

console.log(manifestJson)

try {
  fs.writeFileSync(
    path.join(__dirname, '../', './src', '/manifest.json'),
    JSON.stringify(manifestJson)
  )
} catch (error) {
  console.log(error)
}
