Adds JSCS for gulpfile and scripts

install JSCS globally npm install jscs -g
use `npm run jscs`
This commit is contained in:
Austin Pray
2015-01-23 11:56:39 -06:00
parent 2b39b64909
commit ae62873779
5 changed files with 164 additions and 61 deletions

95
.jscsrc Normal file
View File

@@ -0,0 +1,95 @@
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireOperatorBeforeLineBreak": true,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"maximumLineLength": {
"value": 80,
"allowComments": true,
"allowRegex": true
},
"validateIndentation": 2,
"validateQuoteMarks": "'",
"disallowMultipleLineStrings": true,
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowMultipleVarDecl": true,
"disallowKeywordsOnNewLine": [
"else"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBinaryOperators": [
"=",
"+=",
"-=",
"*=",
"/=",
"%=",
"<<=",
">>=",
">>>=",
"&=",
"|=",
"^=",
"+=",
"+",
"-",
"*",
"/",
"%",
"<<",
">>",
">>>",
"&",
"|",
"^",
"&&",
"||",
"===",
"==",
">=",
"<=",
"<",
">",
"!=",
"!=="
],
"requireSpaceAfterBinaryOperators": true,
"requireSpacesInConditionalExpression": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpacesInForStatement": true,
"requireLineFeedAtFileEnd": true,
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInsideObjectBrackets": "all",
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpacesInsideParentheses": true,
"validateJSDoc": {
"checkParamNames": true,
"requireParamTypes": true
},
"disallowMultipleLineBreaks": true,
"disallowNewlineBeforeBlockStatements": true
}

View File

@@ -6,8 +6,9 @@ php:
- 5.5
- 5.4
before_install:
- npm install -g bower
- npm install -g bower gulp jscs
- npm install
script:
- npm run build
- npm run jshint
- npm run jscs

View File

@@ -16,61 +16,66 @@
(function($) {
// Use this variable to set up the common and page specific functions. If you
// rename this variable, you will also need to rename the namespace below.
var Sage = {
// All pages
common: {
init: function() {
// JavaScript to be fired on all pages
// Use this variable to set up the common and page specific functions. If you
// rename this variable, you will also need to rename the namespace below.
var Sage = {
// All pages
'common': {
init: function() {
// JavaScript to be fired on all pages
},
finalize: function() {
// JavaScript to be fired on all pages, after page specific JS is fired
}
},
finalize: function() {
// JavaScript to be fired on all pages, after page specific JS is fired
}
},
// Home page
home: {
init: function() {
// JavaScript to be fired on the home page
// Home page
'home': {
init: function() {
// JavaScript to be fired on the home page
},
finalize: function() {
// JavaScript to be fired on the home page, after the init JS
}
},
finalize: function() {
// JavaScript to be fired on the home page, after the init JS
// About us page, note the change from about-us to about_us.
'about_us': {
init: function() {
// JavaScript to be fired on the about us page
}
}
},
// About us page, note the change from about-us to about_us.
about_us: {
init: function() {
// JavaScript to be fired on the about us page
};
// The routing fires all common scripts, followed by the page specific scripts.
// Add additional events for more control over timing e.g. a finalize event
var UTIL = {
fire: function(func, funcname, args) {
var fire;
var namespace = Sage;
funcname = (funcname === undefined) ? 'init' : funcname;
fire = func !== '';
fire = fire && namespace[func];
fire = fire && typeof namespace[func][funcname] === 'function';
if (fire) {
namespace[func][funcname](args);
}
},
loadEvents: function() {
// Fire common init JS
UTIL.fire('common');
// Fire page-specific init JS, and then finalize JS
$.each(document.body.className.replace(/-/g, '_').split(/\s+/), function(i, classnm) {
UTIL.fire(classnm);
UTIL.fire(classnm, 'finalize');
});
// Fire common finalize JS
UTIL.fire('common', 'finalize');
}
}
};
};
// The routing fires all common scripts, followed by the page specific scripts.
// Add additional events for more control over timing e.g. a finalize event
var UTIL = {
fire: function(func, funcname, args) {
var namespace = Sage;
funcname = (funcname === undefined) ? 'init' : funcname;
if (func !== '' && namespace[func] && typeof namespace[func][funcname] === 'function') {
namespace[func][funcname](args);
}
},
loadEvents: function() {
// Fire common init JS
UTIL.fire('common');
// Fire page-specific init JS, and then finalize JS
$.each(document.body.className.replace(/-/g, '_').split(/\s+/),function(i,classnm) {
UTIL.fire(classnm);
UTIL.fire(classnm, 'finalize');
});
// Fire common finalize JS
UTIL.fire('common', 'finalize');
}
};
// Load Events
$(document).ready(UTIL.loadEvents);
// Load Events
$(document).ready(UTIL.loadEvents);
})(jQuery); // Fully reference jQuery after this point.

View File

@@ -15,7 +15,7 @@ var project = manifest.getProjectGlobs();
var cssTasks = function(filename) {
return lazypipe()
.pipe($.plumber)
.pipe(function () {
.pipe(function() {
return $.if(mapsEnabled, $.sourcemaps.init());
})
.pipe(function() {
@@ -35,11 +35,12 @@ var cssTasks = function(filename) {
.pipe($.pleeease, {
autoprefixer: {
browsers: [
'last 2 versions', 'ie 8', 'ie 9', 'android 2.3', 'android 4', 'opera 12'
'last 2 versions', 'ie 8', 'ie 9', 'android 2.3', 'android 4',
'opera 12'
]
}
})
.pipe(function () {
.pipe(function() {
return $.if(mapsEnabled, $.sourcemaps.write('.'));
})
.pipe(gulp.dest, path.dist + 'styles')
@@ -48,7 +49,7 @@ var cssTasks = function(filename) {
gulp.task('styles', function() {
var merged = merge();
manifest.forEachDependency('css', function (dep) {
manifest.forEachDependency('css', function(dep) {
merged.add(gulp.src(dep.globs)
.pipe(cssTasks(dep.name)));
});
@@ -67,14 +68,14 @@ gulp.task('jshint', function() {
var jsTasks = function(filename) {
var fn = filename;
return lazypipe()
.pipe(function () {
.pipe(function() {
return $.if(mapsEnabled, $.sourcemaps.init());
})
.pipe(function() {
return $.if(!!fn, $.concat(fn || 'all.js'));
})
.pipe($.uglify)
.pipe(function () {
.pipe(function() {
return $.if(mapsEnabled, $.sourcemaps.write('.'));
})
.pipe(gulp.dest, path.dist + 'scripts')
@@ -83,7 +84,7 @@ var jsTasks = function(filename) {
gulp.task('scripts', ['jshint'], function() {
var merged = merge();
manifest.forEachDependency('js', function (dep) {
manifest.forEachDependency('js', function(dep) {
merged.add(gulp.src(dep.globs)
.pipe(jsTasks(dep.name)));
});
@@ -106,7 +107,7 @@ gulp.task('images', function() {
});
gulp.task('version', function() {
return gulp.src([path.dist + '**/*.{js,css}'], { base: path.dist })
return gulp.src([path.dist + '**/*.{js,css}'], {base: path.dist})
.pipe(gulp.dest(path.dist))
.pipe($.rev())
.pipe(gulp.dest(path.dist))

View File

@@ -18,7 +18,8 @@
],
"scripts": {
"build": "bower install && gulp",
"jshint": "gulp jshint"
"jshint": "gulp jshint",
"jscs": "jscs gulpfile.js assets/scripts/*.js"
},
"engines": {
"node": ">= 0.10.0"