2022-11-16 00:14:59 +01:00
|
|
|
#!/usr/bin/env ts-node
|
|
|
|
|
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
|
|
|
|
2022-11-16 00:14:59 +01:00
|
|
|
const templatePath = path.join(process.cwd(), 'scripts', '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 })
|
2022-11-16 00:14:59 +01:00
|
|
|
const projects = path.join(process.cwd(), '_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
|
|
|
|
2022-11-16 00:14:59 +01: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.`)
|
|
|
|
})
|