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')
|
|
|
|
|
|
|
|
const templatePath = path.join(__dirname, 'new-project.yml')
|
|
|
|
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.`)
|
|
|
|
})
|