Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First version of CLI api

  • Loading branch information...
commit b81080df5a90ae2f86d35ad8983c9878b48a39fd 1 parent 21e37b2
@vtsvang authored
View
2  bin/pkgtool
@@ -1,4 +1,4 @@
#!/usr/bin/env node
require( "coffee-script" )
-require( "../index.coffee" )
+require( "../lib/cli.coffee" )
View
39 lib/cli.coffee
@@ -0,0 +1,39 @@
+program = require "commander"
+pkgtool = require "../index.coffee"
+pkg = require "../package.json"
+
+knownCommands = [ "expand", "hold", "update" ]
+
+program
+ .version( pkg.version )
+ .usage( "[options] <path> <command>" )
+ .option( "-f, --force", "Force fetch latest versions" )
+ .parse( process.argv )
+
+# show help unless arguments passed
+unless program.args.length
+ program.help()
+
+if program.args[ 0 ] in knownCommands
+ # default path
+ packagePath = process.cwd()
+else
+ # determine path
+ packagePath = program.args.shift()
+
+# determine command
+command = program.args.shift()
+
+# unknown command
+unless command in knownCommands
+ program.help()
+
+
+pkgInstance = pkgtool packagePath
+
+done = ( err ) ->
+ @save() unless err
+
+pkgInstance.load ( err ) ->
+ # routing
+ @[ command ] [ program.args..., done ]...
View
2  test/helpers.js
@@ -10,7 +10,7 @@ global.shld = require( "should" )
global.__testsRootDir = __dirname
global.__tmpDir = path.join(fs.realpathSync( path.join( __dirname, ".." ) ), ".tmp")
-global.__binaryPath = path.join( __dirname, "bin", "pkgtool" )
+global.__binaryPath = path.join( __dirname, "..", "bin", "pkgtool" )
global.__fixturesPaths = {
successful: path.join( __testsRootDir, "fixtures", "packages", "successful.json" ),
View
3  test/run.coffee
@@ -23,6 +23,9 @@ describe "Pkg Tool", ->
describe "CLI Interface", ->
+ @timeout 15e3
+ @slow 5e3
+
require "./specs/cli/expand"
require "./specs/cli/hold"
require "./specs/cli/update"
View
4 test/specs/cli/expand.coffee
@@ -1,8 +1,8 @@
describe "expand", ->
beforeEach ( done ) ->
- exec "#{ __binaryPath } .tmp/successful expand", ( err, stdout, stderr ) =>
- @pkg = require path.join __tmpDir, "successful", "package.json"
+ exec "#{ __binaryPath } .tmp/successful3 expand", ( err, stdout, stderr ) =>
+ @pkg = require path.join __tmpDir, "successful3", "package.json"
done()
it "should expand missing dependencies from node_modules", ->
View
19 test/specs/cli/hold.coffee
@@ -1,27 +1,22 @@
describe "hold", ->
beforeEach ( done ) ->
- exec "#{ __binaryPath } .tmp/successful hold", ( err, stdout, stderr ) =>
- @pkg = require path.join __tmpDir, "successful", "package.json"
+ exec "#{ __binaryPath } .tmp/successful2 hold", ( err, stdout, stderr ) =>
+ @pkg = require path.join __tmpDir, "successful2", "package.json"
done()
it "should hold dependencies from node_modules", ->
- console.log @pkg.devDependencies
+ @pkg.dependencies
.should.have.property "foo", "0.0.1"
it "should hold only specified package if it's name passed", ( done ) ->
- exec "#{ __binaryPath } .tmp/successful2 hold mocha", ( err, stdout, stderr ) =>
- pkg = require path.join __tmpDir, "successful2", "package.json"
+ exec "#{ __binaryPath } .tmp/successful hold mocha", ( err, stdout, stderr ) =>
+ pkg = require path.join __tmpDir, "successful", "package.json"
pkg.devDependencies
- .should.have.property "mocha", @latestMochaVersion
+ .should.have.property "mocha", "1.8.0"
pkg.dependencies
.should.have.property "async", "*"
- done()
-
-
- it "should fetch version from npmjs.org unless it's present in node_modules", ->
- @pkg.devDependencies
- .should.have.property "mocha", @latestMochaVersion
+ done()
View
4 test/specs/cli/update.coffee
@@ -2,7 +2,7 @@ describe "update", ->
it "should update all the versions of dependencies", ( done ) ->
exec "#{ __binaryPath } .tmp/successful update", ( err, stdout, stderr ) =>
- pkg = require path.join __tmpDir, "successful", "package.json"
+ pkg = JSON.parse fs.readFileSync ( fs.realpathSync path.join __tmpDir, "successful", "package.json" ), "utf8"
pkg.devDependencies
.should.have.property "mocha", @latestMochaVersion
@@ -11,7 +11,7 @@ describe "update", ->
it "should update only specified package if it's name passed", ( done ) ->
exec "#{ __binaryPath } .tmp/successful update mocha", ( err, stdout, stderr ) =>
- pkg = require path.join __tmpDir, "successful", "package.json"
+ pkg = JSON.parse fs.readFileSync ( fs.realpathSync path.join __tmpDir, "successful", "package.json" ), "utf8"
pkg.devDependencies
.should.have.property "mocha", @latestMochaVersion
Please sign in to comment.
Something went wrong with that request. Please try again.