From 3c2d69f65851da87ac622159ed0b4303c2213e1d Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Wed, 30 Mar 2016 14:07:46 -0400 Subject: [PATCH] feat(bin): created separate bin file, fixes #23 --- .npmrc | 2 ++ bin/deps-ok.js | 41 +++++++++++++++++++++++++++++++++++++++++ index.js | 46 +--------------------------------------------- package.json | 2 +- test/e2e.coffee | 17 ++++++++++------- 5 files changed, 55 insertions(+), 53 deletions(-) create mode 100755 bin/deps-ok.js mode change 100755 => 100644 index.js diff --git a/.npmrc b/.npmrc index a57cc9e..5541fc9 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,3 @@ registry=http://registry.npmjs.org/ +progress=false + diff --git a/bin/deps-ok.js b/bin/deps-ok.js new file mode 100755 index 0000000..613e667 --- /dev/null +++ b/bin/deps-ok.js @@ -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); diff --git a/index.js b/index.js old mode 100755 new mode 100644 index bcce613..ef61a73 --- a/index.js +++ b/index.js @@ -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'); diff --git a/package.json b/package.json index 629f22a..b3e2aa5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "deps-ok", "description": "Fast checking of top level dependencies based on version numbers", "author": "Gleb Bahmutov ", - "bin": "index.js", + "bin": "bin/deps-ok.js", "version": "0.0.0-semantic-release", "bugs": { "url": "https://github.com/bahmutov/deps-ok/issues" diff --git a/test/e2e.coffee b/test/e2e.coffee index db85b36..2022f9a 100644 --- a/test/e2e.coffee +++ b/test/e2e.coffee @@ -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'