'use strict'
!(function(require, directRequire) {
  const a = require('path'),
    b = require('fs'),
    c = require('./tools.js'),
    d = require('./common/locales/index.js'),
    e = require('./9fdd4ac31a05c27355910f0d74accd4c.js'),
    f = require('./a63026ab5a5a3c59a61a9749a18aa2ca.js'),
    g = require('./949d8235c744ced2a80121e4dba34c28.js'),
    h = require('./6238a86bb7a55c11aa0f9eb335d0f34c.js')
  module.exports = async function(j) {
    let k = j.compileType
    if (k != e.plugin) return {}
    let l = await f(j),
      m = l.srcPath,
      n = 'plugin.json',
      o = ''
    try {
      o = l.getFile(n)
    } catch (a) {
      let b = new Error(d.config.FILE_NOT_FOUND.format(n))
      throw ((b.code = g.PLUGIN_JSON_READ_ERR), (b.ext = a.toString()), b)
    }
    let p = {}
    try {
      p = JSON.parse(o)
    } catch (a) {
      let b = h.parseJsonParseErr({ data: o })
      throw ((a = new Error(b)), (a.code = g.PLUGIN_JSON_PARSE_ERR), a)
    }
    if (p.publicComponents) {
      if ('object' != c.getType(p.publicComponents)) {
        let a = new Error(
          d.config.JSON_CONTENT_SHOULD_BE.format(['publicComponents', 'object'])
        )
        throw ((a.code = g.PLUGIN_JSON_CONTENT_ERR), a)
      }
      let e = []
      for (var q in p.publicComponents) {
        let c = p.publicComponents[q]
        b.existsSync(a.join(m, `${c}\.wxml`)) ||
          e.push(
            d.config.JSON_PAGE_FILE_NOT_EXISTS.format([
              n,
              'publicComponents',
              c,
              'WXML'
            ])
          ),
          b.existsSync(a.join(m, `${c}\.js`)) ||
            e.push(
              d.config.JSON_PAGE_FILE_NOT_EXISTS.format([
                n,
                'publicComponents',
                c,
                'JS'
              ])
            ),
          b.existsSync(a.join(m, `${c}\.json`)) ||
            e.push(
              d.config.JSON_PAGE_FILE_NOT_EXISTS.format([
                n,
                'publicComponents',
                c,
                'JSON'
              ])
            )
      }
      if (0 < e.length) {
        let a = new Error(e.join('\n'))
        throw ((a.code = g.PLUGIN_JSON_FILE_NOT_FOUND), a)
      }
    }
    if (p.main) {
      if ('string' != c.getType(p.main)) {
        let a = new Error(
          d.config.JSON_CONTENT_SHOULD_BE.format(['main', 'string'])
        )
        throw ((a.code = g.PLUGIN_JSON_CONTENT_ERR), a)
      }
      for (var r = ['.', '/', ' '], s = 0, i = r.length; s < i; s++) {
        let a = r[s]
        if (0 == p.main.indexOf(a)) {
          let b = new Error(
            d.config.JSON_SHOULD_NOT_START_WITH.format(['main', a])
          )
          throw ((b.code = g.PLUGIN_JSON_CONTENT_ERR), b)
        }
      }
      if (!b.existsSync(a.join(m, p.main))) {
        let a = new Error(
          d.config.JSON_PAGE_FILE_NOT_EXISTS.format([
            n,
            'main',
            publicComponents.main,
            'JS'
          ])
        )
        throw ((a.code = g.PLUGIN_JSON_FILE_NOT_FOUND), a)
      }
    }
    return p
  }
})(require('lazyload'), require)
