Skip to content

Commit

Permalink
Make codebase conform to ESLint rules
Browse files Browse the repository at this point in the history
Just a couple of changes.
  • Loading branch information
rhys-vdw committed May 16, 2016
1 parent cfe80e3 commit 3846b71
Show file tree
Hide file tree
Showing 77 changed files with 2,156 additions and 2,079 deletions.
2 changes: 1 addition & 1 deletion knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// For details and documentation:
// http://knexjs.org

module.exports = require('./lib/index')
module.exports = require('./lib/index');
88 changes: 48 additions & 40 deletions src/bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env node


var Liftoff = require('liftoff');
var Promise = require('bluebird');
var interpret = require('interpret');
var path = require('path');
var chalk = require('chalk');
var tildify = require('tildify');
var commander = require('commander');
var cliPkg = require('../../package');
var argv = require('minimist')(process.argv.slice(2));
var fs = Promise.promisifyAll(require('fs'));
/* eslint no-console:0 */

import Liftoff from 'liftoff';
import Promise from 'bluebird';
import interpret from 'interpret';
import path from 'path';
import chalk from 'chalk';
import tildify from 'tildify';
import commander from 'commander';
const argv = require('minimist')(process.argv.slice(2));
const fs = Promise.promisifyAll(require('fs'));
const cliPkg = require('../../package');

function exit(text) {
if (text instanceof Error) {
Expand Down Expand Up @@ -46,9 +46,9 @@ function initKnex(env) {
console.log('Working directory changed to', chalk.magenta(tildify(env.cwd)));
}

var environment = commander.env || process.env.NODE_ENV;
var defaultEnv = 'development';
var config = require(env.configPath);
let environment = commander.env || process.env.NODE_ENV;
const defaultEnv = 'development';
let config = require(env.configPath);

if (!environment && typeof config[defaultEnv] === 'object') {
environment = defaultEnv;
Expand All @@ -66,13 +66,14 @@ function initKnex(env) {

if (argv.debug !== undefined)
config.debug = argv.debug;
var knex = require(env.modulePath);
const knex = require(env.modulePath);
return knex(config);
}

function invoke(env) {

var pending, filetypes = ['js', 'coffee', 'eg', 'ls'];
const filetypes = ['js', 'coffee', 'eg', 'ls'];
let pending = null;

commander
.version(
Expand All @@ -88,34 +89,35 @@ function invoke(env) {
commander
.command('init')
.description(' Create a fresh knexfile.')
.option('-x [' + filetypes.join('|') + ']', 'Specify the knexfile extension (default js)')
.option(`-x [${filetypes.join('|')}]`, 'Specify the knexfile extension (default js)')
.action(function() {
var type = (argv.x || 'js').toLowerCase();
const type = (argv.x || 'js').toLowerCase();
if (filetypes.indexOf(type) === -1) {
exit('Invalid filetype specified: ' + type);
exit(`Invalid filetype specified: ${type}`);
}
if (env.configPath) {
exit('Error: ' + env.configPath + ' already exists');
exit(`Error: ${env.configPath} already exists`);
}
checkLocalModule(env);
var stubPath = './knexfile.' + type;
pending = fs.readFileAsync(path.dirname(env.modulePath) + '/lib/migrate/stub/knexfile-' + type + '.stub')
.then(function(code) {
return fs.writeFileAsync(stubPath, code);
}).then(function() {
success(chalk.green('Created ' + stubPath));
}).catch(exit);
const stubPath = `./knexfile.${type}`;
pending = fs.readFileAsync(
path.dirname(env.modulePath) +
'/lib/migrate/stub/knexfile-' +
type + '.stub'
).then(code => fs.writeFileAsync(stubPath, code)).then(() => {
success(chalk.green(`Created ${stubPath}`));
}).catch(exit);
});

commander
.command('migrate:make <name>')
.description(' Create a named migration file.')
.option('-x [' + filetypes.join('|') + ']', 'Specify the stub extension (default js)')
.option(`-x [${filetypes.join('|')}]`, 'Specify the stub extension (default js)')
.action(function(name) {
var instance = initKnex(env);
var ext = (argv.x || env.configPath.split('.').pop()).toLowerCase();
const instance = initKnex(env);
const ext = (argv.x || env.configPath.split('.').pop()).toLowerCase();
pending = instance.migrate.make(name, {extension: ext}).then(function(name) {
success(chalk.green('Created Migration: ' + name));
success(chalk.green(`Created Migration: ${name}`));
}).catch(exit);
});

Expand All @@ -127,7 +129,10 @@ function invoke(env) {
if (log.length === 0) {
success(chalk.cyan('Already up to date'));
}
success(chalk.green('Batch ' + batchNo + ' run: ' + log.length + ' migrations \n' + chalk.cyan(log.join('\n'))));
success(
chalk.green(`Batch ${batchNo} run: ${log.length} migrations \n`) +
chalk.cyan(log.join('\n'))
);
}).catch(exit);
});

Expand All @@ -139,7 +144,10 @@ function invoke(env) {
if (log.length === 0) {
success(chalk.cyan('Already at the base migration'));
}
success(chalk.green('Batch ' + batchNo + ' rolled back: ' + log.length + ' migrations \n') + chalk.cyan(log.join('\n')));
success(
chalk.green(`Batch ${batchNo} rolled back: ${log.length} migrations \n`) +
chalk.cyan(log.join('\n'))
);
}).catch(exit);
});

Expand All @@ -155,12 +163,12 @@ function invoke(env) {
commander
.command('seed:make <name>')
.description(' Create a named seed file.')
.option('-x [' + filetypes.join('|') + ']', 'Specify the stub extension (default js)')
.option(`-x [${filetypes.join('|')}]`, 'Specify the stub extension (default js)')
.action(function(name) {
var instance = initKnex(env);
var ext = (argv.x || env.configPath.split('.').pop()).toLowerCase();
const instance = initKnex(env);
const ext = (argv.x || env.configPath.split('.').pop()).toLowerCase();
pending = instance.seed.make(name, {extension: ext}).then(function(name) {
success(chalk.green('Created seed file: ' + name));
success(chalk.green(`Created seed file: ${name}`));
}).catch(exit);
});

Expand All @@ -172,7 +180,7 @@ function invoke(env) {
if (log.length === 0) {
success(chalk.cyan('No seed files exist'));
}
success(chalk.green('Ran ' + log.length + ' seed files \n' + chalk.cyan(log.join('\n'))));
success(chalk.green(`Ran ${log.length} seed files \n${chalk.cyan(log.join('\n'))}`));
}).catch(exit);
});

Expand All @@ -183,7 +191,7 @@ function invoke(env) {
});
}

var cli = new Liftoff({
const cli = new Liftoff({
name: 'knex',
extensions: interpret.jsVariants,
v8flags: require('v8flags')
Expand Down
Loading

0 comments on commit 3846b71

Please sign in to comment.