1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-11-15 01:25:25 +01:00
portfolio/scripts/new.js

31 lines
816 B
JavaScript
Raw Normal View History

2018-09-24 00:13:41 +02:00
import fs from 'fs'
import path from 'path'
import prepend from 'prepend'
import slugify from 'slugify'
import ora from 'ora'
2018-05-14 01:50:11 +02:00
2018-06-20 23:38:08 +02:00
const templatePath = path.join(__dirname, 'new.yml')
2018-05-14 01:50:11 +02:00
const template = fs.readFileSync(templatePath).toString()
2018-05-23 20:53:08 +02:00
const spinner = ora('Adding new project').start()
if (!process.argv[2]) {
spinner.fail('Use the format `npm run new -- Title of project`')
}
2018-05-14 01:50:11 +02:00
const title = process.argv[2]
2018-05-23 20:53:08 +02:00
spinner.text = `Adding '${title}'.`
2018-05-14 01:50:11 +02:00
2018-05-23 20:53:08 +02:00
const titleSlug = slugify(title, { lower: true })
2019-03-30 00:24:57 +01:00
const projects = path.join(__dirname, '..', 'content', 'projects.yml')
2018-05-23 20:53:08 +02:00
const newContents = template
.split('TITLE')
.join(title)
.split('SLUG')
.join(titleSlug)
2018-05-14 01:50:11 +02:00
prepend(projects, newContents, error => {
2018-09-24 00:13:41 +02:00
if (error) spinner.fail(error)
2018-05-14 01:50:11 +02:00
spinner.succeed(`Added '${title}' to top of projects.yml file.`)
})