Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added cssmin, uglify and no-jslint tasks

  • Loading branch information...
commit d7391e7fd47c82b39f6bfbfb6c2d8f98272d8117 1 parent 38c59d0
@davglass authored
Showing with 103 additions and 50 deletions.
  1. +103 −50 lib/module.js
View
153 lib/module.js
@@ -16,6 +16,39 @@ var Stack = require('./stack').Stack,
Queue = require('gear').Queue,
Registry = require('gear').Registry,
registry,
+ cName = {
+ compressor: 'YUICompressor',
+ jsminify: 'UglifyJS'
+ },
+ compressorFn = 'jsminify',
+ compressorConfig = {
+ callback: function (e) {
+ log.err('compression failed');
+ console.log(' ' + String(e.message).trim() + (' // line ' + e.line + ', pos ' + e.col).grey);
+ log.error('dropped the clutch, build failed');
+ },
+ config: {
+ mangle: true,
+ squeeze: true,
+ semicolon: false,
+ lift_vars: true,
+ mangle_toplevel: true,
+ no_mangle_functions: true,
+ max_line_length: 6000
+ }
+ },
+ configCompressor = function (options) {
+ if (options.compressor) {
+ compressorFn = 'compressor';
+ compressorConfig = {
+ 'disable-optimizations': true,
+ 'preserve-semi': true,
+ 'line-break': 6000
+ };
+ } else {
+ compressorConfig.semi = options.semi;
+ }
+ },
strictMode = false,
defaultLint = lint.defaults,
_exec = require('child_process').exec,
@@ -91,7 +124,12 @@ var Stack = require('./stack').Stack,
return i;
},
stringify = function (config) {
- var str = JSON.stringify(config) || '';
+ config = config || {};
+ //This may need tweaked..
+ if (config.after) {
+ delete config.after;
+ }
+ var str = JSON.stringify(config);
str = str.replace(/:/g, ': ').replace(/,/g, ', ');
if (str === '{}' || str === '[]') {
str = '';
@@ -158,10 +196,7 @@ var buildCSS = function (mod, name, callback) {
})
.csslint(cssLint)
.write(path.join(buildDir, name, name + '.css'))
- .compressor({
- 'line-break': 6000,
- type: 'css'
- })
+ .cssmin()
.write(path.join(buildDir, name, name + '-min.css'))
.run(function (err, result) {
if (err) {
@@ -211,16 +246,18 @@ var buildJS = function (mod, name, callback) {
});
queue.replace(replacers);
}
+ if (defaultLint) {
+ queue.jslint(jslintConfig);
+ }
- queue.jslint(jslintConfig)
- .md5check({
- callback: function (md5) {
- var key = path.join(fileName, fileName + '-debug.js');
- metaData[key] = md5;
- },
- error: cacheBuild,
- current: metaData[path.join(fileName, fileName + '-debug.js')]
- })
+ queue.md5check({
+ callback: function (md5) {
+ var key = path.join(fileName, fileName + '-debug.js');
+ metaData[key] = md5;
+ },
+ error: cacheBuild,
+ current: metaData[path.join(fileName, fileName + '-debug.js')]
+ })
.write(path.join(buildDir, fileName, fileName + '-debug.js'));
if (regex) {
@@ -231,12 +268,9 @@ var buildJS = function (mod, name, callback) {
queue.log('writing RAW file')
.write(path.join(buildDir, fileName, fileName + '.js'))
- .log('compressing')
- .compressor({
- 'disable-optimizations': true,
- 'preserve-semi': true,
- 'line-break': 6000
- })
+ .log('compressing ' + path.join(fileName, fileName + '.js with ' + cName[compressorFn]));
+
+ queue[compressorFn](compressorConfig)
.log('writing -min file')
.write(path.join(buildDir, fileName, fileName + '-min.js'))
.run(function (err, result) {
@@ -321,12 +355,9 @@ var buildLang = function (mod, name, callback) {
regex: /@LANG_DETAILS@/,
replace: ''
}
- ])
- .compressor({
- 'disable-optimizations': true,
- 'preserve-semi': true,
- 'line-break': 6000
- })
+ ]);
+
+ queue[compressorFn](compressorConfig)
.write(path.join(buildDir, name, 'lang', fileName))
.run(stack.add(function (err, result) {
if (err) {
@@ -345,12 +376,11 @@ var buildLang = function (mod, name, callback) {
exports.lang = buildLang;
var copyAssets = function (mod, name, callback) {
- log.info('shifting assets for ' + name);
-
var from = path.join(process.cwd(), 'assets'),
to = path.join(buildDir, name, 'assets');
if (exists(from)) {
+ log.info('shifting assets for ' + name);
ncp(from, to, callback);
} else {
callback();
@@ -361,13 +391,24 @@ var buildSkin = function (mod, name, callback) {
log.info('shifting skin for ' + name);
var stack = new Stack(),
+ subMod = '',
from = path.join(process.cwd(), 'assets'),
to = path.join(buildDir, name, 'assets');
+ if (exists(path.join(process.cwd(), 'assets', name))) {
+ log.info('found a subskin, shifting for ' + name);
+ from = path.join(process.cwd(), 'assets', name);
+ subMod = name;
+ }
+
if (exists(from)) {
ncp(from, to, stack.add(function () {
//Get list of Skins
- fs.readdir(path.join(process.cwd(), 'assets/skins'), stack.add(function (err, skins) {
+ fs.readdir(path.join(process.cwd(), 'assets', subMod, 'skins'), stack.add(function (err, skins) {
+ if (err) {
+ console.log(err);
+ log.error('skin files are not right!');
+ }
//Walk the skins and write them out
skins.forEach(function (skinName) {
@@ -376,7 +417,7 @@ var buildSkin = function (mod, name, callback) {
logger: log,
registry: registry
}),
- base = path.join(process.cwd(), 'assets/skins/', skinName);
+ base = path.join(process.cwd(), 'assets', subMod, 'skins', skinName);
queue.read([
path.resolve(base, '../../', name + '-core.css'),
@@ -388,10 +429,7 @@ var buildSkin = function (mod, name, callback) {
.cssstamp({
stamp: '/* YUI CSS Detection Stamp */\n#yui3-css-stamp.skin-' + skinName + '-' + name + ' { display: none; }'
})
- .compressor({
- 'line-break': 6000,
- type: 'css'
- })
+ .cssmin()
.log('writing skin file with core wrapper')
.write(path.join(buildDir, name, 'assets', 'skins', skinName, name + '.css'))
.run(stack.add(function () {
@@ -478,9 +516,14 @@ exports.copy = buildCopy;
var build = function (mod, name, options, callback) {
var stack = new Stack();
- defaultLint = lint[options.lint];
- log.info('using ' + options.lint + ' jslint setting');
- setJSLint();
+ if (options.lint === false) {
+ defaultLint = options.lint;
+ log.warn('skipping jslint, how you\'re linting your stuff!');
+ } else {
+ defaultLint = lint[options.lint];
+ log.info('using ' + options.lint + ' jslint setting');
+ setJSLint();
+ }
if (options['cache-file']) {
metaFile = options['cache-file'];
@@ -488,6 +531,8 @@ var build = function (mod, name, options, callback) {
loadMeta();
+ configCompressor(options);
+
cacheBuild = options.cache;
if (options.strict) {
@@ -503,9 +548,11 @@ var build = function (mod, name, options, callback) {
if (err) {
log.warn('skipping coverage file build due to previous build error');
} else {
- exports.coverage(mod, name, stack.add(noop));
+ if (options.coverage) {
+ exports.coverage(mod, name, stack.add(noop));
+ }
}
- if (mod.config.skinnable || mod.skinnable) {
+ if ((mod.config && mod.config.skinnable) || mod.skinnable) {
exports.skin(mod, name, stack.add(noop));
} else if (mod.assets) {
copyAssets(mod, name, stack.add(noop));
@@ -586,6 +633,7 @@ var _rollup = function (mod, name, options, callback) {
logger: log
}),
modName = mod.name || name,
+ fileName = mod.basefilename || name,
regex = (typeof mod.regex !== 'undefined') ? mod.regex : loggerRegex,
files = [];
@@ -598,7 +646,8 @@ var _rollup = function (mod, name, options, callback) {
.jsstamp({
postfix: "YUI.add('" + modName + "', function (Y, NAME) {}, '@VERSION@'" + stringify(mod.config) + ");\n"
})
- .write(path.join(buildDir, name, name + '-debug.js'));
+ .log('writing rollup file ' + path.join(fileName, fileName + '-debug.js'))
+ .write(path.join(buildDir, fileName, fileName + '-debug.js'));
if (regex) {
queue.replace({
@@ -606,18 +655,20 @@ var _rollup = function (mod, name, options, callback) {
}); // Strip Y.log's
}
- queue.jslint(jslintConfig)
- .log('linting done, writing ' + name + '.js')
- .write(path.join(buildDir, name, name + '.js'))
- .compressor({
- 'disable-optimizations': true,
- 'preserve-semi': true,
- 'line-break': 6000
- })
- .write(path.join(buildDir, name, name + '-min.js'))
+ if (defaultLint) {
+ queue.jslint(jslintConfig);
+ }
+
+ queue.log('linting done, writing ' + path.join(fileName, fileName + '.js'))
+ .write(path.join(buildDir, fileName, fileName + '.js'))
+ .log('compressing ' + path.join(fileName, fileName + '.js with ' + cName[compressorFn]));
+
+ queue[compressorFn](compressorConfig)
+ .log('compressing done, writing ' + path.join(fileName, fileName + '-min.js'))
+ .write(path.join(buildDir, fileName, fileName + '-min.js'))
.run(function (err, result) {
if (err) {
- log.err(name + ' rollup: ' + err);
+ log.error(name + ' rollup: ' + err);
}
callback();
});
@@ -641,6 +692,8 @@ exports.rollup = function (mods, callback) {
options = item.options;
mod = item.mod;
+ configCompressor(options);
+
if (mod.build) {
log.info('found a sub build, down shifting');
mod.build.name = mod.build.name || name;
Please sign in to comment.
Something went wrong with that request. Please try again.