toloframework
Version:
Javascript/HTML/CSS compiler for Firefox OS or nodewebkit apps using modules in the nodejs style.
42 lines (39 loc) • 1.25 kB
JavaScript
var Fatal = require("./fatal");
var UglifyJS = require("uglify-js");
/**
* @param args {object} -
* * __name__ {string}: Name of the Javascript.
* * __content__ {string}: Javascript source content.
*
* @return
* * __src__ {string}: Verbatim Javascript source content.
* * __zip__ {string}: Minified version of the Javascript content.
* * __map__ {object}: SourceMap object.
*/
module.exports = function(args) {
try {
var minification = UglifyJS.minify(args.content, {
compress: true,
fromString: true,
outSourceMap: args.name + ".map"
});
var sourceMap = JSON.parse(minification.map);
sourceMap = {
version: sourceMap.version,
file: sourceMap.file,
sources: [args.name],
sourcesContent: [args.content],
names: sourceMap.names,
mappings: sourceMap.mappings
};
return {src: args.content, zip: minification.code, map: sourceMap};
}
catch (ex) {
Fatal.fire(
ex.message + "\n\n"
+ Fatal.extractCodeAtPos( args.content, ex.pos ),
args.name,
args.name
);
}
};