Skip to content

Commit

Permalink
solve bug #1
Browse files Browse the repository at this point in the history
  • Loading branch information
joejztang committed Nov 11, 2018
1 parent a2776be commit 14f0da3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
22 changes: 11 additions & 11 deletions lib/endraft.js
Expand Up @@ -55,8 +55,8 @@ module.exports = function(args) {
}.bind(this))
.then(function selectPost(posts) {
var filename = '';
var source = '';
var dest = '';
var source = path.join(source_dir, '_posts');
var dest = originDir;
var passOn = [];

return new Promise(function(resolve, reject) {
Expand All @@ -66,7 +66,7 @@ module.exports = function(args) {
if (posts.data[0].source !== undefined) {
source = path.join(source_dir, posts.data[0].source);
}
if (posts.data[0].dest !== undefined) {
if (posts.data[0].origin !== undefined&&posts.data[0].origin !== null) {
dest = path.join(source_dir, posts.data[0].origin);
}
filename = posts.data[0].source.split('/').pop();
Expand All @@ -75,10 +75,10 @@ module.exports = function(args) {
} else {
if (input.all) {
var pair = posts.map(function(post) {
source = post.source!==undefined? path.join(source_dir, post.source): '';
dest = post.origin!==undefined? path.join(source_dir, post.origin): '';
filename = post.source.split('/').pop();
passOn.push([source, dest, filename]);
var source_p = post.source!==undefined? path.join(source_dir, post.source): source;
var dest_p = post.origin!==undefined&&post.origin!==null? path.join(source_dir, post.origin): dest;
var filename_p = post.source.split('/').pop();
passOn.push([source_p, dest_p, filename_p]);
});
return resolve(passOn);
} else {
Expand All @@ -98,7 +98,7 @@ module.exports = function(args) {
if (posts.data[pos].source !== undefined) {
source = path.join(source_dir, posts.data[pos].source);
}
if (posts.data[pos].origin !== undefined) {
if (posts.data[pos].origin !== undefined&&posts.data[pos].origin !== null) {
dest = path.join(source_dir, posts.data[pos].origin);
}
filename = posts.data[pos].source.split('/').pop();
Expand All @@ -111,9 +111,9 @@ module.exports = function(args) {
})
.then(function checkFolderOrCreate(passOn) {
passOn.map(function(post) {
if (post[1] === '') {
post[1] = originDir;
}
// if (post[1] === '') {
// post[1] = originDir;
// }
try {
mkdirp.sync(post[1]);
} catch(e) {
Expand Down
23 changes: 12 additions & 11 deletions lib/undraft.js
Expand Up @@ -57,8 +57,8 @@ module.exports = function(args) {
}.bind(this))
.then(function selectPost(posts) {
var filename = '';
var source = '';
var dest = '';
var source = path.join(source_dir, '_drafts');
var dest = destDir;
var passOn = [];

return new Promise(function(resolve, reject) {
Expand All @@ -68,7 +68,7 @@ module.exports = function(args) {
if (posts.data[0].source !== undefined) {
source = path.join(source_dir, posts.data[0].source);
}
if (posts.data[0].dest !== undefined) {
if (posts.data[0].dest !== undefined&&posts.data[0].dest !== null) {
dest = path.join(source_dir, posts.data[0].dest);
}
filename = posts.data[0].source.split('/').pop();
Expand All @@ -77,11 +77,12 @@ module.exports = function(args) {
} else {
if (input.all) {
var pair = posts.map(function(post) {
source = post.source!==undefined? path.join(source_dir, post.source): '';
dest = post.dest!==undefined? path.join(source_dir, post.dest): '';
filename = post.source.split('/').pop();
passOn.push([source, dest, filename]);
var source_p = post.source!==undefined? path.join(source_dir, post.source): source;
var dest_p = post.dest!==undefined&&post.dest!==null? path.join(source_dir, post.dest): dest;
var filename_p = post.source.split('/').pop();
passOn.push([source_p, dest_p, filename_p]);
});
// console.log(passOn);
return resolve(passOn);
} else {
var choices = posts.map(function(post) {
Expand All @@ -100,7 +101,7 @@ module.exports = function(args) {
if (posts.data[pos].source !== undefined) {
source = path.join(source_dir, posts.data[pos].source);
}
if (posts.data[pos].dest !== undefined) {
if (posts.data[pos].dest !== undefined&&posts.data[pos].dest !== null) {
dest = path.join(source_dir, posts.data[pos].dest);
}
filename = posts.data[pos].source.split('/').pop();
Expand All @@ -113,9 +114,9 @@ module.exports = function(args) {
})
.then(function checkFolderOrCreate(passOn) {
passOn.map(function(post) {
if (post[1] === '') {
post[1] = destDir;
}
// if (post[1] === '') {
// post[1] = destDir;
// }
try {
mkdirp.sync(post[1]);
} catch(e) {
Expand Down

0 comments on commit 14f0da3

Please sign in to comment.