'use strict'
!(function(require, directRequire) {
  function a() {
    l = {}
  }
  function b(a, b = {}) {
    return new Promise(async (c, d) => {
      let e = k.srcPath,
        g = k.getAllWXMLFiles()
      const { type: l } = b,
        m = k.getAllWXSFiles()
      m && 0 < m.length && (g = g.concat(m))
      let n
      try {
        n = await h.getCompileConfig(a)
      } catch (a) {
        return d(a)
      }
      g = g.map(a => {
        return `./${a}`
      })
      let o = `$plugin_${b.pluginId}_${b.version}`
      if (!g || 0 == g.length) return c({ code: '', name: o })
      let p = ['-d', l, n.join(' ')].concat(g).concat(['-p', '-gn', o]),
        q = a.setting && a.setting.newFeature
      const r = f.getWXMLParsePath(q)
      let s = j(r, p, { cwd: e }),
        t = [],
        u = []
      s.on('close', a => {
        if (0 === a) {
          let a = Buffer.concat(t).toString()
          return c({ code: a, name: o })
        }
        let b = Buffer.concat(u).toString(),
          e = new Error(
            `编译 .wxml 文件错误， 错误信息如上，可在控制台查看更详细信息`
          )
        return (e.code = i), (e.msgForConsole = b), d(e)
      }),
        s.stdout.on('data', a => {
          t.push(a)
        }),
        s.stderr.on('data', a => {
          u.push(a)
        })
    })
  }
  function c(b, c) {
    let d = e.extname(c)
    ;('.wxml' === d || '.wxs' === d || '.json' == d) && a()
  }
  async function d(b) {
    let d = await g(b)
    ;(k && k.srcPath == d.srcPath) ||
      (a(), k && k.unWatch(c), (k = d), k.watch(c))
  }
  const e = require('path'),
    f = require('./d28a711224425b00101635efe1034c99.js'),
    g = require('./a63026ab5a5a3c59a61a9749a18aa2ca.js'),
    h = require('./e53dfc2b83456f986002c49964f30fbf.js'),
    {
      PLUGIN_TRANS_WXML_JS_ERR: i
    } = require('./949d8235c744ced2a80121e4dba34c28.js'),
    { spawn: j } = require('child_process')
  var k,
    l = {}
  module.exports = async function(a, c = {}) {
    await d(a)
    const e = c.cut ? '-xc' : '-cc'
    return (
      l[e] ||
        (l[e] = await b(a, {
          pluginId: c.pluginId,
          version: c.version,
          type: e
        })),
      l[e]
    )
  }
})(require('lazyload'), require)
