Permalink
Browse files

Fixing all my late night hacking jslint issues

  • Loading branch information...
1 parent 5690ed0 commit b5672084b457d7923908ee15911a19665c3e7324 @davglass davglass committed Aug 23, 2012
Showing with 437 additions and 414 deletions.
  1. +4 −1 Makefile
  2. +17 −15 lib/ant.js
  3. +2 −2 lib/args.js
  4. +39 −40 lib/builder.js
  5. +14 −12 lib/index.js
  6. +4 −4 lib/log.js
  7. +227 −230 lib/module.js
  8. +31 −22 lib/pack.js
  9. +7 −5 lib/tasks.js
  10. +2 −2 lib/tasks/compressor.js
  11. +2 −2 lib/tasks/coverage.js
  12. +1 −1 lib/tasks/cssstamp.js
  13. +7 −5 lib/tasks/jsstamp.js
  14. +2 −2 lib/tasks/lint.js
  15. +3 −3 lib/tasks/replace.js
  16. +10 −10 lib/tasks/wrap.js
  17. +11 −10 lib/timer.js
  18. +28 −29 lib/walk.js
  19. +22 −19 lib/watch.js
  20. +4 −0 package.json
View
@@ -10,10 +10,13 @@ doc: version
clean:
rm -rRf ./output/*
+lint:
+ npm run-script pretest
+
docs: clean doc
deploydocs: docs
rm -rRf ../shifter-pages/*
cp -R ./output/* ../shifter-pages/
-.PHONY: docs clean deploydocs
+.PHONY: docs clean deploydocs lint
View
@@ -19,24 +19,26 @@ var json = {
builds: {}
};
-var parse = function(files, callback) {
+var parse = function (files, callback) {
if (!files.length) {
return callback(json);
}
var file = files.pop();
log.info('parsing ' + file);
- fs.readFile(path.join(process.cwd(), file), 'utf8',function(err, content) {
+ fs.readFile(path.join(process.cwd(), file), 'utf8', function (err, content) {
+ var data = {}, name;
if (err) {
log.err(err);
}
-
content = content.replace(/\\\n/g, '');
content = content.split('\n').sort().reverse();
- var data = {};
- content.forEach(function(line) {
+ content.forEach(function (line) {
+ /*jslint white: true */
+ //I totally don't agree with jslint on this one..
if (line.indexOf('#') !== 0 && line.length) {
- var values = line.split('=');
- var key = values.shift().replace('component.', '');
+ var values = line.split('='),
+ key = values.shift().replace('component.', ''),
+ parts;
switch (key) {
case 'component':
data.name = values[0];
@@ -45,12 +47,12 @@ var parse = function(files, callback) {
case 'prependfiles':
case 'jsfiles':
case 'cssfiles':
- data[key] = values[0].replace(/ /g, '').trim().split(',')
+ data[key] = values[0].replace(/ /g, '').trim().split(',');
break;
case 'rollup.modules.buildfiles':
hasRollups = true;
json[pack.bad] = true;
- data.rollup = values[0].replace(/ /g, '').trim().split(',')
+ data.rollup = values[0].replace(/ /g, '').trim().split(',');
break;
case 'basefilename':
data[key] = values[0];
@@ -78,7 +80,7 @@ var parse = function(files, callback) {
default:
data.meta = data.meta || {};
if (key.indexOf('.') > -1) {
- var parts = key.split('.');
+ parts = key.split('.');
data.meta[parts[0]] = data.meta[parts[0]] || {};
data.meta[parts[0]][parts[1]] = (values.length > 1) ? values : values[0];
} else {
@@ -89,7 +91,7 @@ var parse = function(files, callback) {
}
});
if (Object.keys(data).length && data.name) {
- var name = data.name;
+ name = data.name;
delete data.name;
json.builds[name] = data;
}
@@ -99,21 +101,21 @@ var parse = function(files, callback) {
-exports.process = function(options, callback) {
- fs.readdir(process.cwd(), function(err, files) {
+exports.process = function (options, callback) {
+ fs.readdir(process.cwd(), function (err, files) {
if (err) {
log.err(err);
}
var props = [];
- files.forEach(function(file) {
+ files.forEach(function (file) {
if (path.extname(file) === '.properties') {
props.push(file);
}
});
if (props.length) {
log.info('found ' + props.length + ' .properties files, upshifting to convert');
- parse(props, function(data) {
+ parse(props, function (data) {
var fileName = (options.config ? path.basename(options.config) : 'build.json');
log.info('saving newly parsed ' + fileName + ' file for ' + data.name);
fs.writeFile(path.join(process.cwd(), fileName), JSON.stringify(data, null, 4) + '\n', 'utf8');
View
@@ -21,10 +21,10 @@ var nopt = require('nopt'),
"m" : ["--modules"]
};
-var parse = function() {
+var parse = function () {
var parsed = nopt(known, shorts);
delete parsed.argv;
- parsed.lint = parsed.lint || 'preferred'
+ parsed.lint = parsed.lint || 'preferred';
return parsed;
};
View
@@ -6,60 +6,82 @@ http://yuilibrary.com/license/
var path = require('path'),
fs = require('fs'),
log = require('./log'),
- noop = function() {},
+ noop = function () {},
timer = require('./timer'),
spawn = require('child_process').spawn,
Stack = require('./stack').Stack,
module = require('./module');
-var has = function(opt, name) {
- return opt.some(function(v) {
+var has = function (opt, name) {
+ return opt.some(function (v) {
return (v === name);
});
};
-var prebuild = function(jobs, options, callback) {
+var prebuild = function (jobs, options, callback) {
var stack = new Stack();
- jobs.forEach(function(job) {
+ jobs.forEach(function (job) {
log.info('shifting build for: ' + job);
- var args = [];
+ var args = [],
+ child;
if (options.lint) {
args.push('--lint');
args.push(options.lint);
}
- var child = spawn('shifter', args, {
+ child = spawn('shifter', args, {
cwd: path.join(process.cwd(), '../', job)
});
- child.stdout.on('data', function(data) {
+ child.stdout.on('data', function (data) {
process.stdout.write(data.toString());
});
- child.on('exit', stack.add(function() {
+ child.on('exit', stack.add(function () {
log.info('build for ' + job + ' complete, downshifting');
}));
});
stack.done(callback);
};
-exports.start = function(json, options, skip) {
+exports.start = function (json, options, skip) {
log.info('putting the hammer down');
var stack = new Stack(),
- start = new Date();
+ start = new Date(),
+ end = function () {
+ var end = new Date();
+ log.info('done racing, the gears are toast');
+ log.info('finished in ' + timer.calc(start, end) + ', pretty fast huh?');
+ },
+ post = function (json, callback) {
+ if (json.postbuilds) {
+ log.info('found a postbuild, shifting it');
+ prebuild(json.postbuilds, options, function () {
+ delete json.postbuilds;
+ post(json, callback);
+ });
+ } else if (json.postexec) {
+ module.exec(json.postexec, function () {
+ delete json.postexec;
+ post(json, callback);
+ });
+ } else {
+ callback();
+ }
+ };
if (json.prebuilds && !skip) {
log.info('found a prebuild, shifting it');
- prebuild(json.prebuilds, options, function() {
+ prebuild(json.prebuilds, options, function () {
exports.start(json, options, true);
});
return;
}
if (json.exec && !skip) {
log.info('found a global exec, shifting it');
- module.exec(json.exec, function() {
+ module.exec(json.exec, function () {
exports.start(json, options, true);
});
return;
@@ -69,42 +91,19 @@ exports.start = function(json, options, skip) {
log.info('limiting to: ' + options.modules);
}
- Object.keys(json.builds).forEach(function(name) {
+ Object.keys(json.builds).forEach(function (name) {
var mod = json.builds[name];
if (!options.modules || has(options.modules, name)) {
log.info('shifting into gear for ' + name);
module.build(mod, name, options, stack.add(noop));
}
});
-
- var end = function() {
- var end = new Date();
- log.info('done racing, the gears are toast');
- log.info('finished in ' + timer.calc(start, end) + ', pretty fast huh?');
- };
- var post = function(json, callback) {
- if (json.postbuilds) {
- log.info('found a postbuild, shifting it');
- prebuild(json.postbuilds, options, function() {
- delete json.postbuilds;
- post(json, callback);
- });
- } else if (json.postexec) {
- module.exec(json.postexec, function() {
- delete json.postexec;
- post(json, callback);
- });
- } else {
- callback();
- }
- };
-
- stack.done(function() {
+ stack.done(function () {
var rollups = [];
if (json.rollups) {
log.info('build has rollup builds, shifting them now');
- Object.keys(json.rollups).forEach(function(name) {
+ Object.keys(json.rollups).forEach(function (name) {
var mod = json.rollups[name];
if (!options.modules || has(options.modules, name)) {
log.info('shifting into gear for ' + name);
@@ -115,7 +114,7 @@ exports.start = function(json, options, skip) {
});
}
});
- module.rollup(rollups, function() {
+ module.rollup(rollups, function () {
post(json, end);
});
} else {
View
@@ -12,54 +12,56 @@ var log = require('./log'),
exists = fs.exists || path.exists;
-exports.init = function() {
- var options = args.parse();
+exports.init = function () {
+ var options = args.parse(),
+ watch,
+ buildFile = options.config || path.join(process.cwd(), 'build.json'),
+ buildFileName = path.basename(buildFile);
if (options.version || options.help) {
require('./help');
}
if (options.watch) {
- var watch = require('./watch');
+ watch = require('./watch');
watch.start(options);
return;
}
log.info('revving up');
- var buildFile = options.config || path.join(process.cwd(), 'build.json'),
- buildFileName = path.basename(buildFile);
if (!options.walk) {
log.info('looking for ' + buildFileName + ' file');
}
- exists(buildFile, function(yes) {
+ exists(buildFile, function (yes) {
+ var json, walk, ant;
if (yes) {
if (options.ant) {
log.error('already has a ' + buildFileName + ' file, hitting the brakes');
}
- log.info('found '+ buildFileName + ' file, shifting');
+ log.info('found ' + buildFileName + ' file, shifting');
try {
- var json = require(buildFile);
+ json = require(buildFile);
} catch (e) {
console.log(e.stack);
log.error('hitting the brakes! failed to parse ' + buildFileName + ', syntax error?');
}
if (pack.valid(json)) {
log.info('putting the hammer down, let\'s build this thing!');
- pack.munge(json, function() {
+ pack.munge(json, function () {
builder.start(json, options);
});
} else {
log.error('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
}
} else {
if (options.walk) {
- var walk = require('./walk');
+ walk = require('./walk');
walk.run(options);
} else {
log.warn('no ' + buildFileName + ' file, downshifting to convert ant files');
- var ant = require('./ant');
- ant.process(options, function() {
+ ant = require('./ant');
+ ant.process(options, function () {
if (!options.ant) {
exports.init();
}
View
@@ -8,19 +8,19 @@ require('colors');
var prefix = 'shifter'.magenta;
-exports.info = function(str) {
+exports.info = function (str) {
console.log(prefix, '[info]'.white, str);
};
-exports.warn = function(str) {
+exports.warn = function (str) {
console.log(prefix, '[warn]'.yellow, str);
};
-exports.error = function(str) {
+exports.error = function (str) {
console.log(prefix, '[error]'.red, str);
process.exit(1);
};
-exports.err = function(str) {
+exports.err = function (str) {
console.log(prefix, '[err]'.red, str);
};
Oops, something went wrong.

0 comments on commit b567208

Please sign in to comment.