All files roosevelt-uglify.js

100% Statements 19/19
100% Branches 8/8
100% Functions 1/1
100% Lines 19/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 416x 6x 6x   6x   7x 7x             7x     7x 1x     7x 7x 7x     7x   7x 1x 1x     7x 1x     6x      
const UglifyJS = require('uglify-js').minify
const fs = require('fs')
const path = require('path')
 
module.exports = {
  parse: function (app, fileName) {
    let code = fs.readFileSync(path.join(app.get('jsPath'), fileName), 'utf-8')
    let options = app.get('params').js.compiler.params || {}
    let result
    let newJs
    let errors
    let warnings
 
    // make a copy of the params so the originals aren't modified
    options = JSON.parse(JSON.stringify(options))
 
    // port showWarnings param over to uglify params
    if (app.get('params').js.compiler.showWarnings) {
      options.warnings = true
    }
 
    result = UglifyJS(code, options)
    newJs = result.code
    errors = result.error
 
    // only populated when warnings option passed
    warnings = result.warnings
 
    if (warnings) {
      console.warn('⚠️  UglifyJS Warnings:'.bold.yellow)
      console.warn(warnings)
    }
 
    if (errors) {
      throw errors
    }
 
    return newJs
  }
}