Skip to content

Commit

Permalink
Adding prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser committed Feb 19, 2018
1 parent aa78edc commit 8ebf832
Show file tree
Hide file tree
Showing 144 changed files with 22,377 additions and 14,722 deletions.
40 changes: 19 additions & 21 deletions .eslintrc.js
@@ -1,28 +1,26 @@
var warning = process.env['CI'] ? 2 : 1;

module.exports = {
"parser": "babel-eslint",
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
parser: 'babel-eslint',
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'prettier',
],
"plugins": ["import"],
"rules": {
"comma-dangle": 0,
"no-unused-vars": [warning, {"vars": "all", "args": "none"}],
"no-console": warning,
"no-var": 2,
"no-debugger": warning,
"indent": [warning, 2, {"SwitchCase": 1, "ignoreComments": true}],
"max-len": [warning, 100, 2],
"prefer-const": warning,
"no-fallthrough": warning
plugins: ['import'],
rules: {
'no-unused-vars': [warning, { vars: 'all', args: 'none' }],
'no-console': warning,
'no-var': 2,
'no-debugger': warning,
'prefer-const': warning,
'no-fallthrough': warning,
},
"settings": {
"import/parser": "babel-eslint"
settings: {
'import/parser': 'babel-eslint',
},
env: {
node: true,
},
"env": {
"node": true
}
};
4 changes: 4 additions & 0 deletions .prettierrc
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "es5"
}
174 changes: 113 additions & 61 deletions bin/cli.js
Expand Up @@ -27,13 +27,15 @@ function success(text) {

function checkLocalModule(env) {
if (!env.modulePath) {
console.log(chalk.red('No local knex install found in:'), chalk.magenta(tildify(env.cwd)));
console.log(
chalk.red('No local knex install found in:'),
chalk.magenta(tildify(env.cwd))
);
exit('Try running: npm install knex.');
}
}

function initKnex(env) {

checkLocalModule(env);

if (!env.configPath) {
Expand All @@ -42,7 +44,10 @@ function initKnex(env) {

if (process.cwd() !== env.cwd) {
process.chdir(env.cwd);
console.log('Working directory changed to', chalk.magenta(tildify(env.cwd)));
console.log(
'Working directory changed to',
chalk.magenta(tildify(env.cwd))
);
}

var environment = commander.env || process.env.NODE_ENV;
Expand All @@ -63,32 +68,40 @@ function initKnex(env) {
process.exit(1);
}

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

function invoke(env) {

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

commander
.version(
chalk.blue('Knex CLI version: ', chalk.green(cliPkg.version)) + '\n' +
chalk.blue('Local Knex version: ', chalk.green(env.modulePackage.version)) + '\n'
chalk.blue('Knex CLI version: ', chalk.green(cliPkg.version)) +
'\n' +
chalk.blue(
'Local Knex version: ',
chalk.green(env.modulePackage.version)
) +
'\n'
)
.option('--debug', 'Run with debugging.')
.option('--knexfile [path]', 'Specify the knexfile path.')
.option('--cwd [path]', 'Specify the working directory.')
.option('--env [name]', 'environment, default: process.env.NODE_ENV || development');

.option(
'--env [name]',
'environment, default: process.env.NODE_ENV || development'
);

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();
if (filetypes.indexOf(type) === -1) {
Expand All @@ -99,88 +112,124 @@ function invoke(env) {
}
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);
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);
});

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();
pending = instance.migrate.make(name, {extension: ext}).then(function(name) {
success(chalk.green(`Created Migration: ${name}`));
}).catch(exit);
pending = instance.migrate
.make(name, { extension: ext })
.then(function(name) {
success(chalk.green(`Created Migration: ${name}`));
})
.catch(exit);
});

commander
.command('migrate:latest')
.description(' Run all migrations that have not yet been run.')
.action(function() {
pending = initKnex(env).migrate.latest().spread(function(batchNo, log) {
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'))
);
}).catch(exit);
pending = initKnex(env)
.migrate.latest()
.spread(function(batchNo, log) {
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'))
);
})
.catch(exit);
});

commander
.command('migrate:rollback')
.description(' Rollback the last set of migrations performed.')
.action(function() {
pending = initKnex(env).migrate.rollback().spread(function(batchNo, log) {
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'))
);
}).catch(exit);
pending = initKnex(env)
.migrate.rollback()
.spread(function(batchNo, log) {
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'))
);
})
.catch(exit);
});

commander
.command('migrate:currentVersion')
.description(' View the current version for the migration.')
.action(function () {
pending = initKnex(env).migrate.currentVersion().then(function(version) {
success(chalk.green('Current Version: ') + chalk.blue(version));
}).catch(exit);
.action(function() {
pending = initKnex(env)
.migrate.currentVersion()
.then(function(version) {
success(chalk.green('Current Version: ') + chalk.blue(version));
})
.catch(exit);
});

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();
pending = instance.seed.make(name, {extension: ext}).then(function(name) {
success(chalk.green(`Created seed file: ${name}`));
}).catch(exit);
pending = instance.seed
.make(name, { extension: ext })
.then(function(name) {
success(chalk.green(`Created seed file: ${name}`));
})
.catch(exit);
});

commander
.command('seed:run')
.description(' Run seed files.')
.action(function() {
pending = initKnex(env).seed.run().spread(function(log) {
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'))}`));
}).catch(exit);
pending = initKnex(env)
.seed.run()
.spread(function(log) {
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'))}`
)
);
})
.catch(exit);
});

commander.parse(process.argv);
Expand All @@ -194,7 +243,7 @@ function invoke(env) {
var cli = new Liftoff({
name: 'knex',
extensions: interpret.jsVariants,
v8flags: require('v8flags')
v8flags: require('v8flags'),
});

cli.on('require', function(name) {
Expand All @@ -205,9 +254,12 @@ cli.on('requireFail', function(name) {
console.log(chalk.red('Failed to load external module'), chalk.magenta(name));
});

cli.launch({
cwd: argv.cwd,
configPath: argv.knexfile,
require: argv.require,
completion: argv.completion
}, invoke);
cli.launch(
{
cwd: argv.cwd,
configPath: argv.knexfile,
require: argv.require,
completion: argv.completion,
},
invoke
);
26 changes: 20 additions & 6 deletions package.json
@@ -1,7 +1,8 @@
{
"name": "knex",
"version": "0.14.4",
"description": "A batteries-included SQL query & schema builder for Postgres, MySQL and SQLite3 and the Browser",
"description":
"A batteries-included SQL query & schema builder for Postgres, MySQL and SQLite3 and the Browser",
"main": "knex.js",
"dependencies": {
"babel-runtime": "^6.26.0",
Expand Down Expand Up @@ -35,10 +36,12 @@
"chai": "^4.1.2",
"coveralls": "~3.0.0",
"eslint": "4.16.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-import": "^2.8.0",
"estraverse": "^4.2.0",
"istanbul": "^0.4.5",
"json-loader": "^0.5.7",
"lint-staged": "^6.1.1",
"mariasql": "^0.2.6",
"mocha": "^3.5.3",
"mock-fs": "^4.4.2",
Expand All @@ -47,6 +50,7 @@
"mysql2": "^1.5.2",
"pg": "^7.4.1",
"pg-query-stream": "^1.1.1",
"prettier": "^1.10.2",
"rimraf": "^2.6.2",
"sinon": "^4.2.2",
"sinon-chai": "^2.14.0",
Expand All @@ -66,22 +70,32 @@
"babel-preset-es2015-loose",
"rimraf"
],
"lint-staged": {
"*.{js,json}": ["prettier --write", "git add"]
},
"scripts": {
"build": "npm run babel",
"precommit": "lint-staged",
"format": "prettier --write \"{src,bin,scripts,test}/**/*.js\"",
"debug_test": "node-debug _mocha -t 0 test/index.js",
"babel": "rimraf ./lib && babel src --out-dir lib --copy-files",
"coveralls": "cat ./test/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"coveralls":
"cat ./test/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"dev": "rimraf ./lib && babel -w src --out-dir lib --copy-files",
"lint": "eslint src/**",
"plaintest": "mocha --check-leaks -b -R spec test/index.js && npm run tape",
"prepublish": "npm run babel",
"pre_test": "npm run lint",
"tape": "node test/tape/index.js | tap-spec",
"debug_tape": "node-debug test/tape/index.js",
"test": "npm run pre_test && istanbul --config=test/.istanbul.yml cover node_modules/mocha/bin/_mocha -- --check-leaks -t 10000 -b -R spec test/index.js && npm run tape",
"stress:init": "docker-compose -f scripts/stress-test/docker-compose.yml up --no-start && docker-compose -f scripts/stress-test/docker-compose.yml start",
"stress:test": "node scripts/stress-test/knex-stress-test.js | grep -A 3 -- '- STATS '",
"stress:destroy": "docker-compose -f scripts/stress-test/docker-compose.yml stop"
"test":
"npm run pre_test && istanbul --config=test/.istanbul.yml cover node_modules/mocha/bin/_mocha -- --check-leaks -t 10000 -b -R spec test/index.js && npm run tape",
"stress:init":
"docker-compose -f scripts/stress-test/docker-compose.yml up --no-start && docker-compose -f scripts/stress-test/docker-compose.yml start",
"stress:test":
"node scripts/stress-test/knex-stress-test.js | grep -A 3 -- '- STATS '",
"stress:destroy":
"docker-compose -f scripts/stress-test/docker-compose.yml stop"
},
"bin": {
"knex": "./bin/cli.js"
Expand Down

0 comments on commit 8ebf832

Please sign in to comment.