xref: /third_party/weex-loader/deps/weex-scripter/lib/require-bundle.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/weex-loader/deps/weex-scripter/lib/
188c88e8eSopenharmony_civar path = require('path')
288c88e8eSopenharmony_civar execSync = require('child_process').execSync
388c88e8eSopenharmony_civar resolveBin = require('resolve-bin')
488c88e8eSopenharmony_ci
588c88e8eSopenharmony_cifunction replaceRequire(code) {
688c88e8eSopenharmony_ci  var count = 0
788c88e8eSopenharmony_ci  var hasRequire = false
888c88e8eSopenharmony_ci  code = code.replace(/require/g, function ($0) {
988c88e8eSopenharmony_ci    hasRequire = true
1088c88e8eSopenharmony_ci    return count++ < 5 ? 'browserifyRequire' : $0
1188c88e8eSopenharmony_ci  })
1288c88e8eSopenharmony_ci  if (hasRequire) {
1388c88e8eSopenharmony_ci    code = 'var ' + code
1488c88e8eSopenharmony_ci  }
1588c88e8eSopenharmony_ci  return code
1688c88e8eSopenharmony_ci}
1788c88e8eSopenharmony_ci
1888c88e8eSopenharmony_cifunction getBundle(requires) {
1988c88e8eSopenharmony_ci  var cmd = '"' + resolveBin.sync('browserify') + '"'
2088c88e8eSopenharmony_ci  Object.keys(requires).forEach(function (key) {
2188c88e8eSopenharmony_ci    cmd += ' -r ' + '"' + requires[key] + ':' + key + '"'
2288c88e8eSopenharmony_ci  })
2388c88e8eSopenharmony_ci  var bundleCode = execSync(cmd)
2488c88e8eSopenharmony_ci  bundleCode = replaceRequire(bundleCode.toString())
2588c88e8eSopenharmony_ci  return bundleCode
2688c88e8eSopenharmony_ci}
2788c88e8eSopenharmony_ci
2888c88e8eSopenharmony_ciexports.getBundle = getBundle
29

Indexes created Thu Nov 07 10:32:03 CST 2024