Skip to content

Commit

Permalink
feat(bin): created separate bin file, fixes #23
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Mar 30, 2016
1 parent c64cb7e commit 3c2d69f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
registry=http://registry.npmjs.org/
progress=false

41 changes: 41 additions & 0 deletions bin/deps-ok.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env node

'use strict'

var argv = require('optimist').argv;
var check = require('..');
var path = require('path');

function isPackageJson(filename) {
return /package\.json$/.test(filename);
}

function isBowerJson(filename) {
return /bower\.json$/.test(filename);
}

if (argv.version) {
var pkg = require('./package.json');
console.log(pkg.name, pkg.version);
process.exit(0);
return;
}

var dir = process.cwd();
if (argv.filename) {
if (argv.verbose) {
console.log('checking', argv.filename);
}
if (isPackageJson(argv.filename) || isBowerJson(argv.filename)) {
dir = path.dirname(argv.filename);
} else {
dir = argv.filename;
}
dir = path.resolve(dir);
}

if (argv.verbose) {
console.log('checking deps', dir);
}
var ok = check(dir, Boolean(argv.verbose));
process.exit(ok ? 0 : 1);
46 changes: 1 addition & 45 deletions index.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,45 +1 @@
#!/usr/bin/env node

var argv = require('optimist').argv;
var check = require('./src/check-folder');
var path = require('path');

function isPackageJson(filename) {
return /package\.json$/.test(filename);
}

function isBowerJson(filename) {
return /bower\.json$/.test(filename);
}

if (!module.parent) {

if (argv.version) {
var pkg = require('./package.json');
console.log(pkg.name, pkg.version);
process.exit(0);
return;
}

var dir = process.cwd();
if (argv.filename) {
if (argv.verbose) {
console.log('checking', argv.filename);
}
if (isPackageJson(argv.filename) || isBowerJson(argv.filename)) {
dir = path.dirname(argv.filename);
} else {
dir = argv.filename;
}
dir = path.resolve(dir);
}

if (argv.verbose) {
console.log('checking deps', dir);
}
var ok = check(dir, Boolean(argv.verbose));
process.exit(ok ? 0 : 1);
return;
}

module.exports = check;
module.exports = require('./src/check-folder');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "deps-ok",
"description": "Fast checking of top level dependencies based on version numbers",
"author": "Gleb Bahmutov <[email protected]>",
"bin": "index.js",
"bin": "bin/deps-ok.js",
"version": "0.0.0-semantic-release",
"bugs": {
"url": "https://github.com/bahmutov/deps-ok/issues"
Expand Down
17 changes: 10 additions & 7 deletions test/e2e.coffee
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
join = require('path').join
relative = join.bind(null, __dirname)
check = require '..'

gt.module 'e2e NPM tests in root folder',
setup: ->
process.chdir join(__dirname, '..')
process.chdir relative('..')
teardown: ->
process.chdir __dirname

gt.async 'test itself', ->
gt.exec 'node', ['index.js', '--verbose'], 0,
gt.exec 'node', ['bin/deps-ok.js', '--verbose'], 0,
'this module has all dependencies'

gt.module 'e2e NPM tests in this folder'

args = ['../bin/deps-ok.js', '--verbose', '--filename']

gt.async 'test itself with folder', ->
gt.exec 'node', ['../index.js', '--verbose', '--filename', join(__dirname, '..')], 0,
gt.exec 'node', args.concat(relative('..')), 0,
'this module has all dependencies'

gt.async 'test itself with package.json path', ->
gt.exec 'node', ['../index.js', '--verbose', '--filename', join(__dirname, '../package.json')], 0,
gt.exec 'node', args.concat(relative('../package.json')), 0,
'this module has all dependencies'

gt.async 'test version with latest keyword', ->
gt.exec 'node', ['../index.js', '--verbose', '--filename', join(__dirname, './package-with-latest.json')], 1,
gt.exec 'node', args.concat(relative('./package-with-latest.json')), 1,
'this has some missing dependencies'

gt.async 'test version with github version', ->
gt.exec 'node', ['../index.js', '--verbose', '--filename', join(__dirname, './package-with-github.json')], 0,
gt.exec 'node', args.concat(relative('./package-with-github.json')), 0,
'this handles github: version string'

gt.async 'test non-existing file', ->
gt.exec 'node', ['../index.js', '--verbose', '--filename', join(__dirname, './does-not-exist.json')], 1,
gt.exec 'node', args.concat(relative('./does-not-exist.json')), 1,
'package file does not exist'

0 comments on commit 3c2d69f

Please sign in to comment.