Add "dry run" options for push-to-ghost command
These options make Seance go through the motions of processing a post without actually uploading images and/or pushing them to Ghost. This makes it easier to test out stuff for new features (or, more accurately, it reduces the need to clean up afterwards!)
This commit is contained in:
parent
1d80daba64
commit
a41b45c58f
2 changed files with 76 additions and 39 deletions
11
cli.js
11
cli.js
|
@ -140,8 +140,15 @@ program.command('fetch-medium <post_url>')
|
||||||
program.command('push-ghost <file>')
|
program.command('push-ghost <file>')
|
||||||
.alias('push')
|
.alias('push')
|
||||||
.description('push a downloaded Medium post to Ghost')
|
.description('push a downloaded Medium post to Ghost')
|
||||||
.action((file) => {
|
.option('-d, --dry-run', "full dry run: doesn't upload anything (same as --no-upload --no-push)")
|
||||||
seance.pushToGhost(file)
|
.option('--no-upload', "partial dry run: don't upload images")
|
||||||
|
.option('--no-push', "partial dry run: don't push to ghost")
|
||||||
|
.action((file, o) => {
|
||||||
|
seance.pushToGhost(file, {
|
||||||
|
dryRun: o.dryRun,
|
||||||
|
noUpload: !o.upload,
|
||||||
|
noPush: !o.push,
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
program.command('medium-to-ghost <mediumUrl>')
|
program.command('medium-to-ghost <mediumUrl>')
|
||||||
|
|
38
seance.js
38
seance.js
|
@ -110,15 +110,28 @@ class Seance {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function [pushToGhost]
|
* function [pushToGhost]
|
||||||
|
* @description
|
||||||
|
* Pre-processes and uploads the given article to Ghost
|
||||||
|
*
|
||||||
|
* @param {Boolean} options.noUpload Skip uploading of images
|
||||||
|
* @param {Boolean} options.noPush Skip pushing to Ghost; just generate the file
|
||||||
|
* @param {Boolean} options.dryRun Combination of noUpload and noPush
|
||||||
* @returns [string] status
|
* @returns [string] status
|
||||||
*/
|
*/
|
||||||
async pushToGhost (postSlug) {
|
async pushToGhost (postSlug, options={}) {
|
||||||
this.emit('update', {
|
this.emit('update', {
|
||||||
status: 'starting',
|
status: 'starting',
|
||||||
message: 'Starting upload: ' + postSlug,
|
message: 'Starting upload: ' + postSlug,
|
||||||
loglevel: 'info'
|
loglevel: 'info'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!!options.dryRun) {
|
||||||
|
options.noUpload = true
|
||||||
|
options.noPush = true
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('noUpload', options.noUpload)
|
||||||
|
|
||||||
// Decide working path
|
// Decide working path
|
||||||
var postFolder = path.resolve('content/' + postSlug)
|
var postFolder = path.resolve('content/' + postSlug)
|
||||||
|
|
||||||
|
@ -256,7 +269,9 @@ class Seance {
|
||||||
uploadedImages.push(imageName)
|
uploadedImages.push(imageName)
|
||||||
|
|
||||||
// Let's wait for the upload, just to avoid conflicts
|
// Let's wait for the upload, just to avoid conflicts
|
||||||
|
if (!options.noUpload) {
|
||||||
await this.uploadDav(davPath, imagePath)
|
await this.uploadDav(davPath, imagePath)
|
||||||
|
}
|
||||||
|
|
||||||
newLine = '![' + imageAlt + '](' + uploadedPath + '/' + imageName + ')'
|
newLine = '![' + imageAlt + '](' + uploadedPath + '/' + imageName + ')'
|
||||||
}
|
}
|
||||||
|
@ -304,7 +319,10 @@ class Seance {
|
||||||
loglevel: 'info'
|
loglevel: 'info'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!options.noUpload) {
|
||||||
this.uploadDav(davPath, imagePath)
|
this.uploadDav(davPath, imagePath)
|
||||||
|
}
|
||||||
|
|
||||||
featuredImagePath = uploadedPath + '/' + imageName
|
featuredImagePath = uploadedPath + '/' + imageName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,6 +343,7 @@ class Seance {
|
||||||
loglevel: 'info'
|
loglevel: 'info'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!options.noPush) {
|
||||||
let res = await this.ghostAdmin.posts.add({
|
let res = await this.ghostAdmin.posts.add({
|
||||||
title: postMeta.title,
|
title: postMeta.title,
|
||||||
custom_excerpt: postMeta.subtitle || null,
|
custom_excerpt: postMeta.subtitle || null,
|
||||||
|
@ -348,8 +367,6 @@ class Seance {
|
||||||
loglevel: 'info'
|
loglevel: 'info'
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(res)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
slug: res.slug,
|
slug: res.slug,
|
||||||
id: res.id,
|
id: res.id,
|
||||||
|
@ -360,7 +377,20 @@ class Seance {
|
||||||
subtitle: res.custom_excerpt,
|
subtitle: res.custom_excerpt,
|
||||||
status: res.status,
|
status: res.status,
|
||||||
}
|
}
|
||||||
};
|
} else {
|
||||||
|
// just return without pushing to Ghost
|
||||||
|
return {
|
||||||
|
slug: postSlug,
|
||||||
|
id: 0,
|
||||||
|
uuid: 0,
|
||||||
|
preview_url: null,
|
||||||
|
primary_author: {},
|
||||||
|
title: postMeta.title,
|
||||||
|
subtitle: postMeta.subtitle,
|
||||||
|
status: 'none',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue