bundle-utils.js 720 B

123456789101112131415161718192021222324252627
  1. 'use strict'
  2. const PathUtils = require('./path-utils')
  3. const fs = require('fs')
  4. const Promise = require('bluebird')
  5. const BundleUtils = {
  6. bundleResource (inPath, outPath) {
  7. return new Promise((resolve, reject) => {
  8. require('browserify')(inPath)
  9. .bundle()
  10. .pipe(fs.createWriteStream(outPath))
  11. .once('finish', () => resolve())
  12. .once('error', (e) => reject(e))
  13. })
  14. },
  15. bundleResourceIfNotExist (inPath, outPath) {
  16. inPath = PathUtils.calculateAbsolutePath(inPath)
  17. outPath = PathUtils.calculateAbsolutePath(outPath)
  18. return fs.existsSync(outPath)
  19. ? Promise.resolve()
  20. : BundleUtils.bundleResource(inPath, outPath)
  21. }
  22. }
  23. module.exports = BundleUtils