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:
Hippo 2021-03-30 17:41:13 +05:30
parent 1d80daba64
commit a41b45c58f
2 changed files with 76 additions and 39 deletions

11
cli.js
View file

@ -140,8 +140,15 @@ program.command('fetch-medium <post_url>')
program.command('push-ghost <file>')
.alias('push')
.description('push a downloaded Medium post to Ghost')
.action((file) => {
seance.pushToGhost(file)
.option('-d, --dry-run', "full dry run: doesn't upload anything (same as --no-upload --no-push)")
.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>')

View file

@ -110,15 +110,28 @@ class Seance {
/**
* 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
*/
async pushToGhost (postSlug) {
async pushToGhost (postSlug, options={}) {
this.emit('update', {
status: 'starting',
message: 'Starting upload: ' + postSlug,
loglevel: 'info'
})
if (!!options.dryRun) {
options.noUpload = true
options.noPush = true
}
console.log('noUpload', options.noUpload)
// Decide working path
var postFolder = path.resolve('content/' + postSlug)
@ -256,7 +269,9 @@ class Seance {
uploadedImages.push(imageName)
// Let's wait for the upload, just to avoid conflicts
if (!options.noUpload) {
await this.uploadDav(davPath, imagePath)
}
newLine = '![' + imageAlt + '](' + uploadedPath + '/' + imageName + ')'
}
@ -304,7 +319,10 @@ class Seance {
loglevel: 'info'
})
if (!options.noUpload) {
this.uploadDav(davPath, imagePath)
}
featuredImagePath = uploadedPath + '/' + imageName
}
}
@ -325,6 +343,7 @@ class Seance {
loglevel: 'info'
})
if (!options.noPush) {
let res = await this.ghostAdmin.posts.add({
title: postMeta.title,
custom_excerpt: postMeta.subtitle || null,
@ -348,8 +367,6 @@ class Seance {
loglevel: 'info'
})
console.log(res)
return {
slug: res.slug,
id: res.id,
@ -360,7 +377,20 @@ class Seance {
subtitle: res.custom_excerpt,
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',
}
}
}
/**