seance/index.js

79 lines
2 KiB
JavaScript
Raw Normal View History

2019-10-06 09:57:08 -04:00
#! /usr/bin/env node
2019-12-19 07:20:24 -05:00
// load configuraton from .env file (if exists)
const dotenv = require('dotenv')
dotenv.config()
2019-10-06 09:57:08 -04:00
const program = require('commander');
const path = require('path')
2019-10-06 09:57:08 -04:00
const {
fetchFromMedium,
pushToGhost,
mediumToGhost,
generateUserData,
checkScissors,
uploadDav,
2019-10-06 09:57:08 -04:00
} = require ('./functions');
program
.version('1.0.0-dev')
.description('pull posts from Medium and add them to a Ghost blog');
program.command('fetch-medium <post_url>')
.alias('fetch')
.description('fetch a Medium post')
.action((post_url) => {
fetchFromMedium(post_url)
.then((post) => {
console.info(`"${post.title}" fetched successfully.`)
})
2019-10-06 09:57:08 -04:00
});
program.command('push-ghost <file>')
.alias('push')
.description('push a downloaded Medium post to Ghost')
.action((file) => {
pushToGhost(file);
});
program.command('medium-to-ghost <mediumUrl>')
.alias('import')
.description('copy a Medium file over to Ghost')
.action((mediumUrl) => {
pushToGhost(mediumUrl);
});
program.command('create-user <username> <email>')
.description('create ghost-import.json to import Medium user to Ghost')
.action(async (username, email) => {
const jsonOut = await generateUserData(username, email)
.catch((err) => {
console.log(`Error: ${err.error}`)
return
})
console.log(await jsonOut);
2019-10-06 09:57:08 -04:00
});
2019-12-19 07:20:24 -05:00
program.command('webdav-test <file>')
.description('[test command] upload stuff to WebDAV')
.action(async (file) => {
// decide path
current_date = new Date();
var dir_path = path.join(
process.env.WEBDAV_PATH_PREFIX,
current_date.getUTCFullYear().toString(),
current_date.getUTCMonth().toString(),
'test' // TODO: replace with article slug
)
uploadDav(dir_path, file);
2019-12-19 07:20:24 -05:00
});
program.command('check-scissors <file>')
.description('[test command] check if an image matches the set separator')
.action(async (file) => {
console.log(await checkScissors(file))
})
2019-10-06 09:57:08 -04:00
program.parse(process.argv)