Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to create intermediary folders if missing, instead of returning an error #115

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion tasks/ftp-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ module.exports = function (grunt) {
ftp.raw.mkd(inPath, function (err) {
if(err) {
log.error('Error creating new remote folder ' + inPath + ' --> ' + err);
cb(err);
log.ok('Trying to create all intermediary folders');
inPath = inPath.replace(/[/]$/g, ""); // remove trailing "/" if present
var pathComponents = inPath.split("/");
pathComponents[0] = pathComponents[0].replace(/^$/, "/"); // if path is absolute, first component should be "/"
ftpCwdPathComponents(pathComponents, cb);
} else {
log.ok('New remote folder created ' + inPath.yellow);
ftpCwd(inPath, cb);
Expand All @@ -91,6 +95,32 @@ module.exports = function (grunt) {
});
}

function ftpCwdPathComponents (pathComponents, cb) {
if (!pathComponents || pathComponents.length === 0) {
cb(null);

} else {
var folder = pathComponents.shift();

ftp.raw.cwd(folder, function (err) {
if (err) {
ftp.raw.mkd(folder, function (err) {
if (err) {
log.error('Error creating new remote folder ' + folder + ' --> ' + err);
cb(err);
} else {
log.ok('New remote folder created ' + folder.yellow);
pathComponents.unshift(folder);
ftpCwdPathComponents(pathComponents, cb);
}
})
} else {
ftpCwdPathComponents(pathComponents, cb);
}
})
}
}

// A method for uploading a single file
function ftpPut (inFilename, done) {
var fpath = path.normalize(localRoot + path.sep + currPath + path.sep + inFilename);
Expand Down