1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-06-30 05:31:44 +02:00
portfolio/scripts/new.js

34 lines
857 B
JavaScript
Raw Normal View History

2018-05-14 01:50:11 +02:00
const fs = require('fs')
const path = require('path')
const prepend = require('prepend')
const slugify = require('slugify')
const ora = require('ora')
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`')
return
}
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 })
2018-05-14 01:50:11 +02:00
const projects = path.join(__dirname, '..', 'data', '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-05-23 20:53:08 +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.`)
})