'use strict'
!(function(require, directRequire) {
  function a() {
    s = ''
  }
  function b(a, b) {
    let c = e.extname(b)
    '.js' === c && ('add' == a || 'unlink' == a) && (s = '')
  }
  async function c(a) {
    let c = await j(a)
    ;(r && r.srcPath == c.srcPath) ||
      ((s = ''), r && r.unWatch(b), (r = c), r.watch(b))
  }
  async function d(a) {
    let b = a.attr.gameApp ? await h(a) : await g(a)
    let c = b.widgets
    for (let b, d = 0, e = c.length; d < e; d++)
      if (((b = c[d]), b.type == a.compileType)) return b.path
  }
  const e = require('path'),
    f = require('./d28a711224425b00101635efe1034c99.js'),
    g = require('./1dea83a77e99a7c94f6b6f01f5c175b0.js'),
    h = require('./1bd2563d13db26950ae47494b2c34454.js'),
    i = require('./tools.js'),
    j = require('./162bf2ee28b76d3b3d95b685cede4146.js'),
    {
      asDebug: k,
      htmlBegin: l,
      htmlEnd: m,
      vendorList: n,
      devVendorList: o,
      noBrowser: p
    } = require('./bcbc694e4d465af7bbc604e962f3f0e1.js'),
    q = global.appConfig.isDev && !nw.App.manifest.forceVendor ? o : n
  var r,
    s = ''
  f.on('VENDOR_CONFIG_CHANGE', a),
    f.on('VENDOR_VERSION_CHANGE', a),
    (module.exports = async function(a, b = {}) {
      if ((await c(a), !s || b.force)) {
        let b = []
        const c = require('fs'),
          g = global.appConfig.isDev
            ? e.join(__dirname, '../../../extensions/appservice/index.js')
            : e.join(__dirname, './extensions/appservice/index.js'),
          h = c.readFileSync(g, 'utf8')
        b.push(l), b.push(`<script>${h}</script>`)
        for (let a = 0, c = q.length; a < c; a++) {
          let c = q[a],
            d = await f.getFile(c),
            g = e.extname(c)
          '.js' === g
            ? b.push(`<script>${d} </script>`)
            : '.css' === g && b.push(`<style>${d}</style>`)
        }
        let i = await d(a),
          j = r.getAllJSFiles(),
          k = [],
          n = e.posix.join(i, 'widget'),
          o = n.replace(/\"/g, '\\"'),
          p = !1
        return (
          j.forEach(a => {
            let b = e.posix.normalize(a.replace(/\.js$/, ''))
            0 == e.posix.dirname(b).indexOf(i) &&
              (n == b
                ? (p = !0)
                : k.push(`<script src="./${encodeURI(a)}"></script>`))
          }),
          (n = p
            ? `<script src="./${encodeURI(n)}.js"></script>
        <script>require("${o}.js")</script>`
            : `<script>
        console.group("${new Date()} widget 编译错误")
        console.error("${o}.js 出现脚本错误或者未正确调用 Widget()")
        console.groupEnd()
        </script>`),
          (b = b.concat(k).concat([n])),
          b.push(m),
          b.join('\n')
        )
      }
      return s
    })
})(require('lazyload'), require)
