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

Moving all files into target location as part of the "move" step. #51

Merged
merged 2 commits into from
Feb 26, 2017
Merged
Show file tree
Hide file tree
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
37 changes: 11 additions & 26 deletions lib/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,20 @@
'use strict';

var exec = require('child_process').exec;
var mkdirp = require('mkdirp').sync;
var mv = require('mv');

module.exports = function (state, callback) {
var complete = state.data.complete,
target = state.data.name;
var complete = state.data.complete;

if (state.target !== undefined) {
target = state.target;
mkdirp(target);
}

// Move the tmp dir and run a command if set
mv(state.template.tmp, target, function (err) {
if (err) {
callback(err);
return;
}
if (complete !== undefined) {
exec(complete, function (err) {
if (err) {
callback(err);
return;
}
callback(null, state);
});
} else {
if (complete !== undefined) {
exec(complete, function (err) {
if (err) {
callback(err);
return;
}
callback(null, state);
}
});
});
} else {
callback(null, state);
}
};

83 changes: 60 additions & 23 deletions lib/move.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*jslint node: true, stupid: true */
/*jslint stupid:true */
/* __ __ _ _ _______ ____ _ _ _ _ _ ____ _____ ____ _
| \/ | / \ | |/ / ____| / ___| | | | / \ | \ | |/ ___| ____/ ___|| |
| |\/| | / _ \ | ' /| _| | | | |_| | / _ \ | \| | | _| _| \___ \| |
Expand All @@ -14,36 +14,73 @@ var mv = require('mv');
var async = require('async');
var fs = require('fs');
var mkdirp = require('mkdirp');
var mv = require('mv');

module.exports = function (state, callback) {
var move = state.data.move;
var move = state.data.move,
target = state.data.name;

if (move === undefined || move.length === 0) {
callback(null, state);
return;
}

async.parallel(move.map(function (item) {
var orig = state.template.tmp + '/' + Object.keys(item)[0],
dest = state.template.tmp + '/' + item[Object.keys(item)[0]],
destPathOnly;

if (fs.existsSync(orig)) {
destPathOnly = dest.substring(0, dest.lastIndexOf('/'));
} else {
destPathOnly = dest;
}
async.series([
// Move around all the items specified in the schema
function (next) {
if (move === undefined || move.length === 0) {
next(null);
return;
}

async.parallel(move.map(function (item) {
var orig = state.template.tmp + '/' + Object.keys(item)[0],
dest = state.template.tmp + '/' + item[Object.keys(item)[0]],
destPathOnly;

if (fs.existsSync(orig)) {
destPathOnly = dest.substring(0, dest.lastIndexOf('/'));
} else {
destPathOnly = dest;
}

return function (done) {
mkdirp(destPathOnly, function (err) {
return function (done) {
mkdirp(destPathOnly, function (err) {
if (err) {
done(err);
return;
}
mv(orig, dest, done);
});
};
}), function (err) {
if (err) {
done(err);
next(err);
return;
}
mv(orig, dest, done);
next(null);
});
};
}), function (err) {
},
// Check if there is a specified target path to for everything to go, and make it
function (next) {
if (state.target !== undefined) {
target = state.target;
mkdirp(target, function (err) {
if (err) {
next(err);
return;
}
next(null);
});
}
next(null);
},
// Move all the files to the target path
function (next) {
mv(state.template.tmp, target, function (err) {
if (err) {
next(err);
return;
}
next(null);
});
}
], function (err) {
if (err) {
callback(err);
return;
Expand Down