Skip to content

Commit

Permalink
Merge pull request #39 from mike-north/linting-and-styling
Browse files Browse the repository at this point in the history
JSHint and JSCS
  • Loading branch information
kategengler committed Aug 9, 2015
2 parents d31b56e + e945b42 commit bd69ed2
Show file tree
Hide file tree
Showing 19 changed files with 211 additions and 145 deletions.
45 changes: 45 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"disallowKeywords": ["with"],
"disallowKeywordsOnNewLine": ["else"],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleVarDecl": "exceptUndefined",
"disallowNewlineBeforeBlockStatements": true,
"disallowQuotedKeysInObjects": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpacesInFunction": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInsideParentheses": true,
"disallowTrailingWhitespace": true,
"maximumLineLength": 120,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"requireCapitalizedComments": true,
"requireCapitalizedConstructors": true,
"requireCurlyBraces": true,
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"case",
"return",
"try",
"catch",
"typeof"
],
"requireSpaceAfterLineComment": true,
"requireSpaceAfterBinaryOperators": true,
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpaceBeforeObjectValues": true,
"requireSpacesInFunction": {
"beforeOpeningCurlyBrace": true
},
"disallowTrailingComma": true,
"validateIndentation": 2,
"validateLineBreaks": "LF",
"validateQuoteMarks": "'"
}
3 changes: 3 additions & 0 deletions lib/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"node": true
}
2 changes: 1 addition & 1 deletion lib/commands/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
'try': require('./try'),
try: require('./try'),
'try:testall': require('./testall'),
'try:reset': require('./reset')
};
2 changes: 1 addition & 1 deletion lib/commands/testall.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
works: 'insideProject',

availableOptions: [
{ name: 'skip-cleanup', type: Boolean, default: false },
{ name: 'skip-cleanup', type: Boolean, default: false }
],

run: function(commandOptions, rawArgs) {
Expand Down
14 changes: 7 additions & 7 deletions lib/commands/try.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ module.exports = {
],

availableOptions: [
{ name: 'skip-cleanup', type: Boolean, default: false },
{ name: 'skip-cleanup', type: Boolean, default: false }
],

getCommand: function() {
var args = process.argv.slice();
var tryIndex = args.indexOf(this.name);
var subcommandArgs = args.slice(tryIndex + 2);

//remove ember-try options from the args that are passed on to ember
// Remove ember-try options from the args that are passed on to ember
var skipIndex = subcommandArgs.indexOf('--skip-cleanup');
if(skipIndex !== -1){
if (skipIndex !== -1) {
subcommandArgs.splice(skipIndex, 1);
}

Expand All @@ -44,7 +44,7 @@ module.exports = {
var config = require('../utils/config')({ project: this.project });
var scenario = findByName(config.scenarios, scenarioName);

if(!scenario) {
if (!scenario) {
throw new Error('The `ember try` command requires a scenario ' +
'specified in the ember-try.js config.');
}
Expand All @@ -60,9 +60,9 @@ module.exports = {
}
};

function findByName(arr, name){
var matches = arr.filter(function(item){
if(item.name == name){
function findByName(arr, name) {
var matches = arr.filter(function(item) {
if (item.name === name) {
return item;
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var CoreObject = require('core-object');
var BowerHelpers = require('../utils/bower-helpers');

module.exports = CoreObject.extend({
run: function(){
run: function() {
return BowerHelpers.cleanup(this.project.root);
}
});
42 changes: 20 additions & 22 deletions lib/tasks/testall.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,68 @@ var run = require('../utils/run');
var findEmberPath = require('./../utils/find-ember-path');

module.exports = CoreObject.extend({
run: function(options){
run: function(options) {
var task = this;
var scenarios = this.config.scenarios;
this.ScenarioManager = new ScenarioManager({ui: this.ui, project: this.project});

return BowerHelpers.backupBowerFile(task.project.root).then(function() {
return mapSeries(scenarios, task._testVersion, task).then(function (results) {
return mapSeries(scenarios, task._testVersion, task).then(function(results) {
var promise;
if(options.skipCleanup){
//create a fake promise for consistency
if (options.skipCleanup) {
// Create a fake promise for consistency
promise = RSVP.Promise.resolve();
} else {
promise = BowerHelpers.cleanup(task.project.root);
}
return promise.then(function(){
return promise.then(function() {
task._printResults(scenarios, results);
if(results.indexOf(false) > -1){
if (results.indexOf(false) > -1) {
process.exit(1);
}
else {
} else {
process.exit(0);
}
});
}).catch(function(err){
}).catch(function(err) {
task.ui.writeLine(err);
task.ui.writeLine(err.stack);
process.exit(1);
});
});
},

_testVersion: function(scenario){
_testVersion: function(scenario) {
var task = this;
return this.ScenarioManager.changeTo(scenario)
.then(function(){
.then(function() {
return task._runTests();
});
},

_runTests: function(){
_runTests: function() {
var task = this;

return findEmberPath(task.project.root)
.then(function(emberPath){
return run('node', [emberPath, 'test'], {cwd: task.project.root})
.then(function(emberPath) {
return run('node', [emberPath, 'test'], {cwd: task.project.root});
})
.then(function(){
.then(function() {
return RSVP.resolve(true);
})
.catch(function(err){
.catch(function(err) {
return RSVP.resolve(false);
});
},

_printResults: function(scenarios, results){
_printResults: function(scenarios, results) {
var task = this;
task.ui.writeLine('');
task.ui.writeLine("------ RESULTS ------");
task.ui.writeLine('------ RESULTS ------');
task.ui.writeLine('');
scenarios.forEach(function(scenario, index){
if(results[index]){
scenarios.forEach(function(scenario, index) {
if (results[index]) {
task.ui.writeLine(chalk.green(scenario.name + ': PASS'));
}
else {
} else {
task.ui.writeLine(chalk.red(scenario.name + ': FAIL'));
}
});
Expand Down
31 changes: 15 additions & 16 deletions lib/tasks/try.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,52 @@ var BowerHelpers = require('../utils/bower-helpers');
var findEmberPath = require('./../utils/find-ember-path');

module.exports = CoreObject.extend({
run: function(scenario, commandArgs, commandOptions){
run: function(scenario, commandArgs, commandOptions) {
var task = this;
var commandName = commandOptions[1] || 'test';
process.on('SIGINT', function() {
task.ui.writeLine( "\nGracefully shutting down from SIGINT (Ctrl-C)" );
BowerHelpers.cleanup(task.project.root).then(function(){
process.exit( );
task.ui.writeLine('\nGracefully shutting down from SIGINT (Ctrl-C)');
BowerHelpers.cleanup(task.project.root).then(function() {
process.exit();
});
});

this.ScenarioManager = new ScenarioManager({ui: this.ui, project: this.project});
return BowerHelpers.backupBowerFile(task.project.root).then(function(){
return BowerHelpers.backupBowerFile(task.project.root).then(function() {
return task.ScenarioManager.changeTo(scenario)
.then(function() {
return findEmberPath(task.project.root);
})
.then(function(emberPath){
.then(function(emberPath) {
var args = [].concat(emberPath, commandArgs);

return run('node', args, {cwd: task.project.root})
.then(function(){
.then(function() {
return RSVP.resolve(true);
})
.catch(function(){
.catch(function() {
return RSVP.resolve(false);
});
})
.then(function(result){
.then(function(result) {
var promise;
if(commandOptions.skipCleanup){
//create a fake promise for consistency
if (commandOptions.skipCleanup) {
// Create a fake promise for consistency
promise = RSVP.Promise.resolve();
} else {
promise = BowerHelpers.cleanup(task.project.root);
}
return promise.then(function(){
if(!result){
return promise.then(function() {
if (!result) {
task.ui.writeLine('');
task.ui.writeLine('ember ' + commandName + ' with scenario ' + scenario.name + ' exited nonzero');
process.exit(1);
}
else {
} else {
process.exit(0);
}
});
})
.catch(function(err){
.catch(function(err) {
task.ui.writeLine(err);
task.ui.writeLine(err.stack);
process.exit(1);
Expand Down
24 changes: 13 additions & 11 deletions lib/utils/bower-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,49 @@ module.exports = {
findBowerPath: function(root) {
return findEmberPath(root)
.then(function(emberPath) {
// find bower's entry point module relative to
// ember-cli's entry point script
/* Find bower's entry point module relative to
ember-cli's entry point script */
return resolve('bower', { basedir: path.dirname(emberPath) });
})
.then(function(bowerPath) {
return path.join(bowerPath, '..', '..', 'bin', 'bower');
});
},

install: function(root){
install: function(root) {
var helpers = this;

return rimraf(path.join(root, 'bower_components'))
.then(function() {
return helpers.findBowerPath(root)
return helpers.findBowerPath(root);
})
.then(function(bowerPath) {
return run('node', [bowerPath, 'install', '--config.interactive=false'], {cwd: root});
});
},
resetBowerFile: function(root){
resetBowerFile: function(root) {
var copy = RSVP.denodeify(fs.copy);
return copy(path.join(root, 'bower.json.ember-try'),
path.join(root, 'bower.json'));
},
backupBowerFile: function(root){
backupBowerFile: function(root) {
var copy = RSVP.denodeify(fs.copy);
return copy(path.join(root, 'bower.json'),
path.join(root, 'bower.json.ember-try'));
},
cleanup: function(root){
cleanup: function(root) {
var helpers = this;
return helpers.resetBowerFile(root).then(function(){
return helpers.resetBowerFile(root).then(function() {
return rimraf(path.join(root, 'bower.json.ember-try'));
})
.catch(function(){})
.then(function(){
.catch(function(e) {
console.log('Error cleaning up bower scenario:', e);
})
.then(function() {
return helpers.install(root);
});
},
findVersion: function(packageName, root){
findVersion: function(packageName, root) {
var filename = path.join(root, 'bower_components', packageName, 'bower.json');
if (fs.existsSync(filename)) {
return JSON.parse(fs.readFileSync(filename)).version;
Expand Down
31 changes: 15 additions & 16 deletions lib/utils/config.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
var path = require('path');
var fs = require('fs');

function config(options){
function config(options) {
var configFile = path.join(options.project.root, 'config', 'ember-try.js');
if(fs.existsSync(configFile)){
if (fs.existsSync(configFile)) {
return require(configFile);
}
else {
} else {
return defaultConfig();
}
}

module.exports = config;

function defaultConfig(){
function defaultConfig() {
return {
scenarios: [
{
name: "default",
dependencies: { } // no dependencies needed as the
// default is already specified in
// the consuming app's bower.json
name: 'default',
dependencies: { } /* No dependencies needed as the
default is already specified in
the consuming app's bower.json */
},
{
name: "ember-release",
name: 'ember-release',
dependencies: {
"ember": "release"
ember: 'release'
}
},
{
name: "ember-beta",
name: 'ember-beta',
dependencies: {
"ember": "beta"
ember: 'beta'
}
},
{
name: "ember-canary",
name: 'ember-canary',
dependencies: {
"ember": "canary"
ember: 'canary'
}
}
]
}
};
}
Loading

0 comments on commit bd69ed2

Please sign in to comment.