@transloadit/post
Advanced tools
Comparing version 0.0.21 to 0.0.22
@@ -22,6 +22,8 @@ { | ||
"@transloadit/slugify": "^0.0.7", | ||
"inquirer": "7.0.5" | ||
"inquirer": "7.0.5", | ||
"open-in-editor": "^2.2.0", | ||
"title": "^3.4.2" | ||
}, | ||
"version": "0.0.21", | ||
"gitHead": "5b3759a7d21c823859bb53b1dbf7702bceeccc4d" | ||
"version": "0.0.22", | ||
"gitHead": "2911aea47c7efb04aaa15572a7c1fa0dcf6984f2" | ||
} |
64
post.js
#!/usr/bin/env node | ||
const fs = require('fs').promises | ||
const inquirer = require('inquirer') | ||
const openInEditor = require('open-in-editor') | ||
const fileExists = require('@transloadit/file-exists') | ||
const slugify = require('@transloadit/slugify') | ||
const title = require('title') | ||
async function post () { | ||
console.log(`Welcome to @transloadit/post@${require(`${__dirname}/package.json`).version}. `) | ||
console.log(`Please answer some questions about the blog post, `) | ||
console.log(`and I'll generate a starting point and open your editor. `) | ||
const postDir = `${process.cwd()}/${process.argv[2] || '_posts'}` | ||
if (!(await fileExists(`${postDir}`))) { | ||
if (!(await fileExists(postDir))) { | ||
throw new Error(`Dir does not exist: '${postDir.replace(process.cwd(), '.')}'`) | ||
@@ -14,14 +20,58 @@ } | ||
const mysqlNow = (new Date()).toISOString().replace('T', ' ').split('.')[0].split(' ')[0] | ||
// eslint-disable-next-line no-unused-vars | ||
const [dateY, datem, dated] = mysqlNow.split('-') | ||
const answers = await inquirer | ||
.prompt([ | ||
{ type: 'input', name: 'title', message: 'title' }, | ||
{ type: 'input', name: 'author', message: 'author', default: process.env.USER }, | ||
{ type: 'input', name: 'title', message: 'title:' }, | ||
{ type: 'input', name: 'author', message: 'author:', default: process.env.USER }, | ||
]) | ||
const outFile = `${postDir}/${mysqlNow}-${slugify(answers.title)}.md` | ||
const buff = `---\ntitle: ${answers.title}\nauthor: ${answers.author}\n---\n\n` | ||
if ((await fileExists(outFile))) { | ||
throw new Error(`File already exist: '${outFile.replace(process.cwd(), '.')}'`) | ||
} | ||
const strTitle = title(answers.title, { | ||
special: [ | ||
'tus', | ||
'io', | ||
], | ||
}) | ||
let buff = '' | ||
buff += `---\n` | ||
buff += `title: ${strTitle}\n` | ||
buff += `author: ${answers.author}\n` | ||
buff += `ogimage: /assets/images/blog/${dateY}-${datem}-x.jpg\n` | ||
buff += `tags: \n` | ||
buff += ` - \n` | ||
buff += `meta_description: >-\n` | ||
buff += ` \n` | ||
buff += `---\n` | ||
buff += `\n` | ||
await fs.writeFile(outFile, buff, 'utf-8') | ||
console.log(`\n`) | ||
console.log(`code '${outFile}'`) | ||
console.log(`\n`) | ||
console.log(`Opening'${outFile}' in your editor .. `) | ||
// Avoid crashing on /bin/sh: 1: code -w: not found | ||
// strip any arguments | ||
if (process.env.VISUAL) { | ||
process.env.VISUAL = process.env.VISUAL.split(/\s+/)[0] | ||
} | ||
let opts = {} | ||
if (process.env.VISUAL === 'code') { | ||
opts = { | ||
cmd : 'code', | ||
pattern: '-r -g {filename}:{line}:{column}', | ||
} | ||
} | ||
const editor = openInEditor.configure(opts) | ||
await editor.open(`${outFile}`, { | ||
line: 10, | ||
}) | ||
console.log(`Done. `) | ||
} | ||
@@ -28,0 +78,0 @@ post().catch(err => { |
> Even though this module is publicly accessible, we do not recommend using it in projects outside of Transloadit. We won't make any guarantees about its workings and can change things at any time, we won't adhere strictly to SemVer. | ||
> This module is maintained from a private mono repo called monolib. | ||
> This module is maintained from a private mono repo called monolib. | ||
## Install | ||
```bash | ||
sudo yarn global add @transloadit/post | ||
``` | ||
## Usage | ||
```bash | ||
$ post | ||
Welcome to @transloadit/post@0.0.21. | ||
Please answer some questions about the blog post, | ||
and I'll generate a starting point and open your editor. | ||
? title: a fresh look at tus.io | ||
? author: kvz | ||
Opening'/home/kvz/code/content/_posts/2020-04-28-a-fresh-look-at-tus-io.md' in your editor .. | ||
Done. | ||
``` | ||
![image](https://user-images.githubusercontent.com/26752/80525678-e4cb1880-8991-11ea-9266-d28b884e5c35.png) | ||
Following values can be used to detect code editor (in descending priority): | ||
- `process.env.OPEN_FILE` | ||
- `process.env.VISUAL` | ||
- `process.env.EDITOR` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38426
68
32
5
7
+ Addedopen-in-editor@^2.2.0
+ Addedtitle@^3.4.2
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.13.2.1(transitive)
+ Addedarch@2.2.0(transitive)
+ Addedarg@1.0.0(transitive)
+ Addedchalk@1.1.32.3.0(transitive)
+ Addedclap@1.2.3(transitive)
+ Addedclipboardy@1.2.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcross-spawn@5.1.0(transitive)
+ Addedexeca@0.8.0(transitive)
+ Addedget-stream@3.0.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-flag@2.0.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedlru-cache@4.1.5(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addedopen-in-editor@2.2.0(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedpseudomap@1.0.2(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedsupports-color@2.0.04.5.0(transitive)
+ Addedtitle@3.5.3(transitive)
+ Addedtitleize@1.0.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedyallist@2.1.2(transitive)