Permalink
Browse files

fix MultiTask issue with global variable

  • Loading branch information...
carlosmarte committed Jun 18, 2013
1 parent c6fdbe0 commit 48950967674a4b043edc44322cdaa0ed6aa8ddd1
Showing with 41 additions and 18 deletions.
  1. +4 −1 .gitignore
  2. +4 −4 README.md
  3. +4 −2 ToDo.md
  4. +29 −11 tasks/git_ftp.js
View
@@ -17,4 +17,7 @@ npm-debug.log
.gitattributes
.npmignore
.DS_Store
.gitignore
.gitignore
node_modules/grunt-*
test/grunt-project
View
@@ -6,7 +6,7 @@ Node Packaged Modules for [Grunt](http://gruntjs.com).
# Prerequisites
- Grunt `~0.4.1`
- Grunt `~0.4.1` (http://gruntjs.com/getting-started)
- Node v0.10.5 (http://nodejs.org)
- Git (http://git-scm.com)
- FTP Server
@@ -51,7 +51,7 @@ git_ftp: {
}
}
```
> .gitftppass configuration file
> .gitftppass FTP Host configuration file
```js
{
@@ -69,6 +69,6 @@ git_ftp: {
Task submitted by [Roberto Carlos Marte](http://Carlosmarte.me/)
> npm package grunt-git-ftp(https://npmjs.org/package/grunt-git-ftp)
> Node Packaged Modules(https://npmjs.org/package/grunt-git-ftp)
*This file was generated on Sun Jun 15 2013 11:00:31.*
*This file was generated on Mon Jun 17 2013 08:40:00.*
View
@@ -1,2 +1,4 @@
## with .gitftppass file
check if values exist
#Things to do
> 1. write test script
> 2. check if .gitftppass values exist
> 3. move function into package file
View
@@ -40,7 +40,7 @@ module.exports = function(grunt){
this.host_config = null;
return this;
},App = null;
};
/*
* Get host file and parse json
@@ -60,7 +60,7 @@ module.exports = function(grunt){
log.error('Error, please check {' + host_name.red + '} or json file format');
}
}else{
log.error('Error, ftp setting file not found in : ' + filename.red);
log.error('Error, ftp configuration file not found in : ' + grunt_root_path + '/' + filename.red);
}
return this.host_config;
};
@@ -69,28 +69,44 @@ module.exports = function(grunt){
* Get/Set FTP Key Values
*/
Grunt_git_ftp_class.prototype.ftp = function(key,val){
//if key isn't
if(this.host_config._key === undefined || typeof(this.host_config[this.host_config._key]) !== 'object'){
log.error('Error, please check that { \n' +
' "'+ this.host_config._key.red +'": { \n' +
' "host": "ftp.host-address.com", \n' +
' "port": 21, \n' +
' "user": "ftp-username", \n' +
' "password": "ftp-account-password", \n' +
' "remote_path": "ftp-basepath" \n' +
' } \n' +
'} exist your ftp configuration file');
throw 'key not found in .gitftppass';
}
//get host config key
if(arguments.length === 2){
this.host_config[this.host_config._key][key] = val;
}
return (this.host_config[this.host_config._key][key] ? this.host_config[this.host_config._key][key] : null);
};
/*
* Command function
* Command function return string
*/
Grunt_git_ftp_class.prototype.cmd = function(command,cb,err){
this.commands(false,command,cb,err);
};
/*
* Command function
* Command function return array
*/
Grunt_git_ftp_class.prototype.cmd_split = function(split,command,cb,err){
this.commands(split,command,cb,err);
};
/*
* Command function
* Command wrapper function
*/
Grunt_git_ftp_class.prototype.commands = function(should_split,command,cb,err){
cmd(command,function(error, stdout, stderr){
@@ -126,7 +142,7 @@ module.exports = function(grunt){
* Create Remote Directory
*/
Grunt_git_ftp_class.prototype.create_remote_directory = function(list,cb){
var remote_root_path = App.ftp('remote_path');
var remote_root_path = this.ftp('remote_path');
if(Object.keys(list).length){
async.forEach(Object.keys(list),function(dir, next_array){
ftp.mkdir(dir,true,function(err){
@@ -145,8 +161,8 @@ module.exports = function(grunt){
* Upload local file to server
*/
Grunt_git_ftp_class.prototype.upload_files = function(list,cb){
var remote_root_path = App.ftp('remote_path'),
host = App.ftp('host');
var remote_root_path = this.ftp('remote_path'),
host = this.ftp('host');
if(list.length){
async.forEach(list,function(filepath, next_array){
ftp.put(grunt_root_path + '/' + filepath,path.normalize(remote_root_path + '/' + filepath),function(err){
@@ -166,12 +182,14 @@ module.exports = function(grunt){
}
};
App = new Grunt_git_ftp_class();
/*
* Grunt Multi Task
*/
grunt.registerMultiTask('git_ftp','queries last git commit and FTPs modified files to server',function(){
var App = new Grunt_git_ftp_class(),
//options with these defaults
var options = this.options({
options = this.options({
'host_file':'.gitftppass',
'host':'default'
});

0 comments on commit 4895096

Please sign in to comment.