Make use of resin-vcs instead of using gitwrap directly

This commit is contained in:
Juan Cruz Viotti 2015-03-12 11:24:36 -04:00
parent 13011cca23
commit 8410a709c9
5 changed files with 33 additions and 78 deletions

@ -1,5 +1,5 @@
(function() {
var _, async, commandOptions, gitwrap, path, resin, visuals;
var _, async, commandOptions, path, resin, vcs, visuals;
path = require('path');
@ -13,7 +13,7 @@
commandOptions = require('./command-options');
gitwrap = require('gitwrap');
vcs = require('resin-vcs');
exports.create = {
signature: 'app create <name>',
@ -108,30 +108,23 @@
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 git;
git = gitwrap.create(process.cwd());
var currentDirectory;
currentDirectory = process.cwd();
return async.waterfall([
function(callback) {
return git.isGitRepository(function(isGitDirectory) {
return callback(null, isGitDirectory);
});
}, function(isGitDirectory, callback) {
if (isGitDirectory) {
return callback();
}
return git.execute('init', _.unary(callback));
return vcs.initialize(currentDirectory, callback);
}, function(callback) {
return resin.models.application.get(params.id, callback);
}, function(application, callback) {
return git.execute("remote add resin " + application.git_repository, function(error) {
if (error != null) {
return callback(error);
}
console.info("git repository added: " + application.git_repository);
return callback(null, application.git_repository);
});
return vcs.addRemote(currentDirectory, application.git_repository, callback);
}
], done);
], function(error, remoteUrl) {
if (error != null) {
return done(error);
}
console.info("git repository added: " + remoteUrl);
return done(null, remoteUrl);
});
}
};

@ -1,5 +1,5 @@
(function() {
var _, async, examplesData, fs, gitwrap, path, resin, visuals;
var _, async, examplesData, fs, path, resin, vcs, visuals;
async = require('async');
@ -13,7 +13,7 @@
visuals = require('resin-cli-visuals');
gitwrap = require('gitwrap');
vcs = require('resin-vcs');
examplesData = require('../data/examples.json');
@ -64,31 +64,14 @@
help: 'Use this command to clone an example application to the current directory\n\nThis command outputs information about the cloning process.\nUse `--quiet` to remove that output.\n\nExample:\n\n $ resin example clone 3',
permission: 'user',
action: function(params, options, done) {
var example;
var currentDirectory, example;
example = examplesData[params.id - 1];
if (example == null) {
return done(new Error("Unknown example: " + id));
}
return async.waterfall([
function(callback) {
var exampleAbsolutePath;
exampleAbsolutePath = path.join(process.cwd(), example.name);
return fs.exists(exampleAbsolutePath, function(exists) {
var error;
if (!exists) {
return callback();
}
error = new Error("Directory exists: " + example.name);
return callback(error);
});
}, function(callback) {
var currentDirectory, git;
currentDirectory = process.cwd();
console.info("Cloning " + example.display_name + " to " + currentDirectory);
git = gitwrap.create(currentDirectory);
return git.execute("clone " + example.repository, callback);
}
], done);
currentDirectory = process.cwd();
console.info("Cloning " + example.display_name + " to " + currentDirectory);
return vcs.clone(example.repository, currentDirectory, done);
}
};

@ -4,7 +4,7 @@ async = require('async')
resin = require('resin-sdk')
visuals = require('resin-cli-visuals')
commandOptions = require('./command-options')
gitwrap = require('gitwrap')
vcs = require('resin-vcs')
exports.create =
signature: 'app create <name>'
@ -147,28 +147,23 @@ exports.associate =
'''
permission: 'user'
action: (params, options, done) ->
git = gitwrap.create(process.cwd())
currentDirectory = process.cwd()
async.waterfall([
async.waterfall [
(callback) ->
git.isGitRepository (isGitDirectory) ->
return callback(null, isGitDirectory)
(isGitDirectory, callback) ->
return callback() if isGitDirectory
git.execute('init', _.unary(callback))
vcs.initialize(currentDirectory, callback)
(callback) ->
resin.models.application.get(params.id, callback)
(application, callback) ->
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)
vcs.addRemote(currentDirectory, application.git_repository, callback)
], done)
], (error, remoteUrl) ->
return done(error) if error?
console.info("git repository added: #{remoteUrl}")
return done(null, remoteUrl)
exports.init =
signature: 'init'

@ -4,7 +4,7 @@ path = require('path')
_ = require('lodash')
resin = require('resin-sdk')
visuals = require('resin-cli-visuals')
gitwrap = require('gitwrap')
vcs = require('resin-vcs')
examplesData = require('../data/examples.json')
exports.list =
@ -85,22 +85,6 @@ exports.clone =
if not example?
return done(new Error("Unknown example: #{id}"))
async.waterfall [
(callback) ->
exampleAbsolutePath = path.join(process.cwd(), example.name)
fs.exists exampleAbsolutePath, (exists) ->
return callback() if not exists
error = new Error("Directory exists: #{example.name}")
return callback(error)
(callback) ->
currentDirectory = process.cwd()
console.info("Cloning #{example.display_name} to #{currentDirectory}")
git = gitwrap.create(currentDirectory)
git.execute("clone #{example.repository}", callback)
], done
currentDirectory = process.cwd()
console.info("Cloning #{example.display_name} to #{currentDirectory}")
vcs.clone(example.repository, currentDirectory, done)

@ -53,7 +53,6 @@
"conf.js": "^0.1.1",
"diskio": "^1.0.0",
"drivelist": "^1.2.1",
"gitwrap": "^1.1.0",
"lodash": "~2.4.1",
"lodash-contrib": "~241.4.14",
"mkdirp": "~0.5.0",
@ -63,6 +62,7 @@
"progress-stream": "^0.5.0",
"resin-cli-visuals": "^0.0.8",
"resin-sdk": "^0.0.2",
"resin-vcs": "git://github.com/resin-io/resin-vcs",
"underscore.string": "~2.4.0",
"update-notifier": "^0.3.1"
}