From 8fbde4c452c3c8f2d637c7b38370d718fed169b9 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 10 Mar 2015 10:03:49 -0400 Subject: [PATCH] Make use of gitwrap --- build/actions/app.js | 16 +++++----- build/git-example.js | 11 ------- build/git.js | 18 ----------- build/package.json | 68 ------------------------------------------ lib/actions/app.coffee | 11 +++---- lib/git.coffee | 8 ----- package.json | 1 + 7 files changed, 16 insertions(+), 117 deletions(-) delete mode 100644 build/git-example.js delete mode 100644 build/git.js delete mode 100644 build/package.json delete mode 100644 lib/git.coffee diff --git a/build/actions/app.js b/build/actions/app.js index eab96693..0bd56877 100644 --- a/build/actions/app.js +++ b/build/actions/app.js @@ -1,5 +1,5 @@ (function() { - var _, async, commandOptions, git, path, resin, visuals; + var _, async, commandOptions, gitwrap, path, resin, visuals; path = require('path'); @@ -13,7 +13,7 @@ commandOptions = require('./command-options'); - git = require('../git'); + gitwrap = require('gitwrap'); exports.create = { signature: 'app create ', @@ -108,20 +108,22 @@ help: 'Use this command to associate a project directory with a resin application.\n\nThis command adds a \'resin\' git remote to the directory and runs git init if necessary.\n\nExamples:\n\n $ resin app associate 91\n $ resin app associate 91 --project my/app/directory', permission: 'user', action: function(params, options, done) { - var currentDirectory; - currentDirectory = process.cwd(); + var git; + git = gitwrap.create(process.cwd()); return async.waterfall([ function(callback) { - return git.isGitDirectory(currentDirectory, callback); + return git.isGitRepository(function(isGitDirectory) { + return callback(null, isGitDirectory); + }); }, function(isGitDirectory, callback) { if (isGitDirectory) { return callback(); } - return git.execute('init', currentDirectory, _.unary(callback)); + return git.execute('init', _.unary(callback)); }, function(callback) { return resin.models.application.get(params.id, callback); }, function(application, callback) { - return git.execute("remote add resin " + application.git_repository, currentDirectory, function(error) { + return git.execute("remote add resin " + application.git_repository, function(error) { if (error != null) { return callback(error); } diff --git a/build/git-example.js b/build/git-example.js deleted file mode 100644 index 04afc31b..00000000 --- a/build/git-example.js +++ /dev/null @@ -1,11 +0,0 @@ -(function() { - var git; - - git = require('./git'); - - git.execute('status', process.cwd(), function(error, stdout, stderr) { - console.log(arguments); - return console.log(stdout); - }); - -}).call(this); diff --git a/build/git.js b/build/git.js deleted file mode 100644 index ace7e877..00000000 --- a/build/git.js +++ /dev/null @@ -1,18 +0,0 @@ -(function() { - var child_process; - - child_process = require('child_process'); - - exports.isGitDirectory = function(directory, callback) { - return exports.execute('status', directory, function(error, stdout, stderr) { - return callback(null, error == null); - }); - }; - - exports.execute = function(command, cwd, callback) { - return child_process.exec("git " + command, { - cwd: cwd - }, callback); - }; - -}).call(this); diff --git a/build/package.json b/build/package.json deleted file mode 100644 index c4005e4c..00000000 --- a/build/package.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "name": "resin-cli", - "version": "0.0.1", - "description": "Git Push to your devices", - "main": "./lib/actions/index.coffee", - "repository": { - "type": "git", - "url": "git@bitbucket.org:rulemotion/resin-cli.git" - }, - "preferGlobal": true, - "bundled_engine": "v0.12.0", - "man": [ - "./man/resin.1", - "./man/resin-completion.1", - "./man/resin-plugins.1" - ], - "bin": { - "resin": "./bin/resin" - }, - "scripts": { - "prepublish": "gulp build", - "test": "gult test", - "install": "node build/install-node.js bin/node" - }, - "keywords": [ - "resin", - "git" - ], - "author": "Juan Cruz Viotti ", - "license": "MIT", - "optionalDependencies": { - "windosu": "^0.1.3" - }, - "devDependencies": { - "chai": "~1.9.2", - "gulp": "~3.8.9", - "gulp-coffee": "^2.2.0", - "gulp-coffeelint": "~0.4.0", - "gulp-marked-man": "~0.3.1", - "gulp-mocha": "~1.1.1", - "gulp-shell": "^0.2.11", - "gulp-util": "~3.0.1", - "mocha": "~2.0.1", - "mocha-notifier-reporter": "~0.1.0", - "run-sequence": "~1.0.2", - "sinon": "~1.12.1", - "sinon-chai": "~2.6.0" - }, - "dependencies": { - "async": "~0.9.0", - "capitano": "~1.5.0", - "coffee-script": "~1.8.0", - "conf.js": "^0.1.1", - "diskio": "^1.0.0", - "drivelist": "^1.2.0", - "git-cli": "~0.8.2", - "lodash": "~2.4.1", - "lodash-contrib": "~241.4.14", - "mkdirp": "~0.5.0", - "node-binary": "^1.0.1", - "nplugm": "^2.0.0", - "open": "0.0.5", - "progress-stream": "^0.5.0", - "resin-cli-visuals": "resin-io/resin-cli-visuals", - "resin-sdk": "resin-io/resin-sdk", - "underscore.string": "~2.4.0" - } -} diff --git a/lib/actions/app.coffee b/lib/actions/app.coffee index e27f1068..fb17c067 100644 --- a/lib/actions/app.coffee +++ b/lib/actions/app.coffee @@ -4,7 +4,7 @@ async = require('async') resin = require('resin-sdk') visuals = require('resin-cli-visuals') commandOptions = require('./command-options') -git = require('../git') +gitwrap = require('gitwrap') exports.create = signature: 'app create ' @@ -147,22 +147,23 @@ exports.associate = ''' permission: 'user' action: (params, options, done) -> - currentDirectory = process.cwd() + git = gitwrap.create(process.cwd()) async.waterfall([ (callback) -> - git.isGitDirectory(currentDirectory, callback) + git.isGitRepository (isGitDirectory) -> + return callback(null, isGitDirectory) (isGitDirectory, callback) -> return callback() if isGitDirectory - git.execute('init', currentDirectory, _.unary(callback)) + git.execute('init', _.unary(callback)) (callback) -> resin.models.application.get(params.id, callback) (application, callback) -> - git.execute "remote add resin #{application.git_repository}", currentDirectory, (error) -> + git.execute "remote add resin #{application.git_repository}", (error) -> return callback(error) if error? console.info("git repository added: #{application.git_repository}") return callback(null, application.git_repository) diff --git a/lib/git.coffee b/lib/git.coffee deleted file mode 100644 index fb73fdad..00000000 --- a/lib/git.coffee +++ /dev/null @@ -1,8 +0,0 @@ -child_process = require('child_process') - -exports.isGitDirectory = (directory, callback) -> - exports.execute 'status', directory, (error, stdout, stderr) -> - return callback(null, not error?) - -exports.execute = (command, cwd, callback) -> - child_process.exec("git #{command}", { cwd }, callback) diff --git a/package.json b/package.json index dd011e4b..f41cdd84 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "diskio": "^1.0.0", "drivelist": "^1.2.1", "git-cli": "~0.8.2", + "gitwrap": "^1.0.0", "lodash": "~2.4.1", "lodash-contrib": "~241.4.14", "mkdirp": "~0.5.0",