Jakefile.js
function minifyScripts(scriptNames) {
  console.log("Minifying and concatting scripts.");

  var UglifyJS = require("uglify-js");

  var regexMinifed = /min.js$/;
  var regexCopyright = /^\/\*![\s\S]*?\*\//m;
  var buffer = [];
  scriptNames.forEach(function(script) {
    var scriptFile = fs.readFileSync(srcDir + script, "utf8");
    var copyright = regexCopyright.exec(scriptFile);
    if (copyright) {
      buffer.push(copyright);
    }

    // check if file is already minified
    if (!regexMinifed.test(script)) {
      var result = UglifyJS.minify(scriptFile);
      if (result.error) {
        throw new Error(error);
      }
      scriptFile = result.code;
    } else {
      console.log("> Skipping: " + script + " is already minified.");
    }

    buffer.push(scriptFile + ";");
  });

  var combined = buffer.join("\n");
  fs.writeFileSync(publishDir + scriptDir + scriptFilename, combined);
  console.log("Combined all scripts into " + scriptFilename);
}
function minifyScripts(scriptNames) {
  console.log("Minifying and concatting scripts.");

  var UglifyJS = require("uglify-js");

  var regexMinifed = /min.js$/;
  var regexCopyright = /^\/\*![\s\S]*?\*\//m;
  var buffer = [];
  scriptNames.forEach(function(script) {
    var scriptFile = fs.readFileSync(srcDir + script, "utf8");
    var copyright = regexCopyright.exec(scriptFile);
    if (copyright) {
      buffer.push(copyright);
    }

    // check if file is already minified
    if (!regexMinifed.test(script)) {
      var result = UglifyJS.minify(scriptFile);
      if (result.error) {
        throw new Error(error);
      }
      scriptFile = result.code;
    } else {
      console.log("> Skipping: " + script + " is already minified.");
    }

    buffer.push(scriptFile + ";");
  });

  var combined = buffer.join("\n");
  fs.writeFileSync(publishDir + scriptDir + scriptFilename, combined);
  console.log("Combined all scripts into " + scriptFilename);
}
function minifyScripts ( scriptNames ) { console . log ( "Minifying and concatting scripts." ) ; var UglifyJS = require ( "uglify-js" ) ; var regexMinifed = / min.js$ / ; var regexCopyright = / ^\/\*![\s\S]*?\*\/ / m ; var buffer = [ ] ; scriptNames . forEach ( function ( script ) { var scriptFile = fs . readFileSync ( srcDir + script , "utf8" ) ; var copyright = regexCopyright . exec ( scriptFile ) ; if ( copyright ) { buffer . push ( copyright ) ; } // check if file is already minified if ( ! regexMinifed . test ( script ) ) { var result = UglifyJS . minify ( scriptFile ) ; if ( result . error ) { throw new Error ( error ) ; } scriptFile = result . code ; } else { console . log ( "> Skipping: " + script + " is already minified." ) ; } buffer . push ( scriptFile + ";" ) ; } ) ; var combined = buffer . join ( "\n" ) ; fs . writeFileSync ( publishDir + scriptDir + scriptFilename , combined ) ; console . log ( "Combined all scripts into " + scriptFilename ) ; }
run all scripts through uglifyJS and write to new dest
run all scripts through uglifyJS and write to new dest