Skip to content

Commit

Permalink
Add .editorconfig, .jshintrc, a jshint pre-commit hook, and refactor …
Browse files Browse the repository at this point in the history
…to pass jshint
  • Loading branch information
Alex Van Camp committed Jan 31, 2016
1 parent a39f917 commit 1bbcb37
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 277 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
root = true

# Enforce Unix line-endings
# 4 spaces instead of tabs
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

indent_style = space
indent_size = 4

charset = utf-8

# NPM forces an indent size of 2 on package.json.
# If you can't beat em, join em.
[*.json]
indent_size = 2

# Don't remove trailing whitespace from Markdown
[*.md]
trim_trailing_whitespace = false
70 changes: 70 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"maxerr": 50,
"bitwise": true,
"camelcase": true,
"curly": false,
"eqeqeq": true,
"forin": true,
"freeze": true,
"immed": true,
"indent": 4,
"latedef": false,
"newcap": true,
"noarg": true,
"noempty": true,
"nonbsp": true,
"nonew": false,
"plusplus": false,
"quotmark": "single",
"undef": true,
"unused": true,
"strict": true,
"maxparams": 6,
"maxdepth": 6,
"maxstatements": false,
"maxcomplexity": false,
"maxlen": 120,
"asi": false,
"boss": false,
"debug": false,
"eqnull": false,
"esnext": false,
"moz": false,
"evil": false,
"expr": false,
"funcscope": false,
"globalstrict": true,
"iterator": false,
"lastsemic": false,
"laxbreak": true,
"laxcomma": true,
"loopfunc": false,
"multistr": false,
"noyield": false,
"notypeof": false,
"proto": false,
"scripturl": false,
"shadow": false,
"sub": false,
"supernew": false,
"validthis": false,
"browser": true,
"browserify": false,
"couch": false,
"devel": true,
"dojo": false,
"jasmine": false,
"jquery": true,
"mocha": true,
"mootools": false,
"node": true,
"nonstandard": false,
"prototypejs": false,
"qunit": false,
"rhino": false,
"shelljs": false,
"worker": false,
"wsh": false,
"yui": false,
"globals": {}
}
2 changes: 2 additions & 0 deletions bin/nodecg
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

'use strict';

var chalk = require('chalk');
var execSync = require('child_process').execSync;
var REQUIRED_VERSION = 'v0.11.22';
Expand Down
56 changes: 29 additions & 27 deletions commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,33 @@ module.exports = function configCommand(program) {
.command('config')
.description('Configure the NodeCG instance in the current directory')
.alias('cfg')
.action(function() {
if (fs.existsSync(path.join(process.cwd(), 'cfg/nodecg.json'))) {
console.warn('cfg/nodecg.json already exists, exiting');
process.exit(0);
}

inquirer.prompt(questions, function(answers) {
var cfg = {
host: answers.host,
port: answers.port,
logging: {
console: {
enabled: answers['console.enabled'],
level: answers['console.level']
},
file: {
enabled: answers['file.enabled'],
path: 'logs/server.log',
level: answers['file.level']
}
}
};
var dir = path.resolve(process.cwd(), 'cfg');
fs.mkdirpSync(dir);
fs.writeFileSync(path.join(dir, 'nodecg.json'), JSON.stringify(cfg, null, 4));
});
})
.action(action);
};

function action() {
if (fs.existsSync(path.join(process.cwd(), 'cfg/nodecg.json'))) {
console.warn('cfg/nodecg.json already exists, exiting');
process.exit(0);
}

inquirer.prompt(questions, function(answers) {
var cfg = {
host: answers.host,
port: answers.port,
logging: {
console: {
enabled: answers['console.enabled'],
level: answers['console.level']
},
file: {
enabled: answers['file.enabled'],
path: 'logs/server.log',
level: answers['file.level']
}
}
};
var dir = path.resolve(process.cwd(), 'cfg');
fs.mkdirpSync(dir);
fs.writeFileSync(path.join(dir, 'nodecg.json'), JSON.stringify(cfg, null, 4));
});
}
4 changes: 2 additions & 2 deletions commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* https://github.com/tsantef/commander-starter
*/

'use strict';

var fs = require('fs');
var path = require('path');

module.exports = function commandLoader(program) {
'use strict';

var commands = {};
var loadPath = path.dirname(__filename);

Expand Down
95 changes: 48 additions & 47 deletions commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,58 @@ module.exports = function installCommand(program) {
.description('Install a bundle by cloning a git repo. Can be a GitHub owner/repo pair or a git url.' +
'\n\t\t If run in a bundle directory with no arguments, installs that bundle\'s dependencies.')
.option('-d, --dev', 'install development dependencies')
.action(function(repo, options) {
var nodecgPath = process.cwd();
if (!util.pathContainsNodeCG(nodecgPath)) {
console.error('NodeCG installation not found, are you in the right directory?');
return;
}
.action(action);
};

var dev = options.dev || false;
if (!repo) {
// If no args are supplied, assume the user is intending to operate on the bundle in the current dir
installDeps(process.cwd(), dev)
} else {
var parsed = npa(repo);
var repoUrl = null;
function action(repo, options) {
var nodecgPath = process.cwd();
if (!util.pathContainsNodeCG(nodecgPath)) {
console.error('NodeCG installation not found, are you in the right directory?');
return;
}

if (parsed.type === 'git') {
// TODO: This line was meant to accomodate nodegit, which is no longer used. Is is still needed?
repoUrl = parsed.spec.replace('+https', ''); //nodegit doesn't support git+https:// addresses
} else if (parsed.type === 'hosted') {
repoUrl = parsed.hosted.httpsUrl;
} else {
console.error('Please enter a valid git url (https) or GitHub username/repo pair.');
process.exit(1);
}
var dev = options.dev || false;
if (!repo) {
// If no args are supplied, assume the user is intending to operate on the bundle in the current dir
installDeps(process.cwd(), dev);
} else {
var parsed = npa(repo);
var repoUrl = null;

// Check that `bundles` exists
var bundlesPath = path.join(nodecgPath, 'bundles');
if (!fs.existsSync(bundlesPath)) {
fs.mkdirSync(bundlesPath);
}
if (parsed.type === 'git') {
// TODO: This line was meant to accommodate nodegit, which is no longer used. Is is still needed?
repoUrl = parsed.spec.replace('+https', ''); //nodegit doesn't support git+https:// addresses
} else if (parsed.type === 'hosted') {
repoUrl = parsed.hosted.httpsUrl;
} else {
console.error('Please enter a valid git url (https) or GitHub username/repo pair.');
process.exit(1);
}

// Extract repo name from git url
var temp = repoUrl.split('/').pop();
var bundleName = temp.substr(0, temp.length - 4);
var bundlePath = path.join(nodecgPath, 'bundles/', bundleName);
// Check that `bundles` exists
var bundlesPath = path.join(nodecgPath, 'bundles');
if (!fs.existsSync(bundlesPath)) {
fs.mkdirSync(bundlesPath);
}

// Fetch the latest tags from GitHub
process.stdout.write('Installing ' + bundleName + '... ');
try {
var cmdline = format('git clone %s "%s"', repoUrl, bundlePath);
execSync(cmdline, {stdio: ['pipe', 'pipe', 'pipe']});
process.stdout.write(chalk.green('done!') + os.EOL);
} catch (e) {
process.stdout.write(chalk.red('failed!') + os.EOL);
console.error(e.stack);
return;
}
// Extract repo name from git url
var temp = repoUrl.split('/').pop();
var bundleName = temp.substr(0, temp.length - 4);
var bundlePath = path.join(nodecgPath, 'bundles/', bundleName);

// After installing the bundle, install its npm dependencies
installDeps(bundlePath, dev)
}
});
// Fetch the latest tags from GitHub
process.stdout.write('Installing ' + bundleName + '... ');
try {
var cmdline = format('git clone %s "%s"', repoUrl, bundlePath);
execSync(cmdline, {stdio: ['pipe', 'pipe', 'pipe']});
process.stdout.write(chalk.green('done!') + os.EOL);
} catch (e) {
process.stdout.write(chalk.red('failed!') + os.EOL);
console.error(e.stack);
return;
}

};
// After installing the bundle, install its npm dependencies
installDeps(bundlePath, dev);
}
}

0 comments on commit 1bbcb37

Please sign in to comment.