Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@transloadit/post

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@transloadit/post - npm Package Compare versions

Comparing version 0.0.21 to 0.0.22

8

package.json

@@ -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"
}
#!/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`
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc