chore: swap hygen for plop

This commit is contained in:
Ben Allfree 2023-11-01 02:57:36 -07:00
parent 3e0b46c9af
commit 07615b8bf3
4 changed files with 586 additions and 288 deletions

View File

@ -1,17 +0,0 @@
const replace = require('replace-in-file')
module.exports = {
helpers: {
replace: (files, from, to) => {
try {
const results = replace.sync({
files,
from,
to,
})
console.log('Replacement results:', results)
} catch (error) {
console.error('Error occurred:', error)
}
},
},
}

View File

@ -24,8 +24,8 @@
"start:daemon": "cd packages/daemon && yarn start",
"pm2": "concurrently 'yarn:pm2:*'",
"pm2:daemon": "cd packages/daemon && yarn pm2",
"prepare": "husky install",
"release:create": "hygen blog new"
"plop": "plop",
"prepare": "husky install"
},
"workspaces": {
"packages": [
@ -47,6 +47,8 @@
"chokidar-cli": "^3.0.0",
"concurrently": "^8.2.1",
"husky": "^8.0.0",
"js-yaml": "^4.1.0",
"plop": "^4.0.0",
"postinstall-postinstall": "^2.1.0",
"prettier": "^3.0.3",
"prettier-plugin-organize-imports": "^3.2.3",
@ -60,7 +62,6 @@
},
"dependencies": {
"@s-libs/micro-dash": "^16.1.0",
"hygen": "^6.2.11",
"ora": "^7.0.1",
"pocketbase": "^0.18.0"
}

69
plopfile.js Normal file
View File

@ -0,0 +1,69 @@
import chalk from 'chalk'
import yaml from 'js-yaml'
import ora from 'ora'
import { join } from 'path'
import { cwd } from 'process'
import { factory } from 'rizzdown'
export default function (plop) {
plop.setHelper('isoTimestamp', function () {
return new Date().toISOString()
})
plop.setHelper('yamlEncode', function (text) {
return yaml.dump(text).trim()
})
plop.setGenerator('blog-article', {
description: 'Generate a new blog article',
prompts: [
{
type: 'input',
name: 'synopsis',
message: '30-50 word synopsis of the news you wish to announce',
},
],
actions: [
async function (data) {
const profilePath = join(cwd(), `.rizzdown/blog`)
const subjectMatter = data.synopsis
const { generate } = factory({ profilePath, subjectMatter })
const spin = async (title, prompt) => {
const spinner = ora().start(title)
const res = await generate(prompt, {})
spinner.stopAndPersist({ symbol: chalk.green(`✔︎`) })
return res
}
data.title = await spin(
`Generating title...`,
`A title for this blog post, no more than 10 words. No exaggerations or puffery. Factual. ASCII characters only. Do not enclose in quotations.`,
)
data.description = await spin(
`Generating description...`,
`An OpenGraph summary/description for this blog post, no more than 50 words. A call to action. Factual. ASCII characters only.`,
)
data.summary = await spin(
`Generating summary...`,
`A one-paragraph introductory summary. ASCII characters only.`,
)
data.detail = await spin(
`Generating detail...`,
`A detailed analysis of the importance and use of this news. ASCII characters only.`,
)
console.log({ data })
},
{
type: 'add',
path: 'frontends/www/content/blog/{{dashCase title}}.md',
templateFile: 'plop-templates/blog.hbs',
},
],
})
}

781
yarn.lock

File diff suppressed because it is too large Load Diff