1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-12-22 17:23:22 +01:00

new project script tweaks

This commit is contained in:
Matthias Kretschmann 2018-05-23 20:53:08 +02:00
parent 996058032e
commit b86da120d1
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -7,14 +7,27 @@ const ora = require('ora')
const templatePath = path.join(__dirname, 'new-project.yml') const templatePath = path.join(__dirname, 'new-project.yml')
const template = fs.readFileSync(templatePath).toString() const template = fs.readFileSync(templatePath).toString()
const title = process.argv[2] const spinner = ora('Adding new project').start()
const titleSlug = slugify(title)
const spinner = ora(`Adding '${title}'.`).start()
const newContents = template.replace('TITLE', title).replace('SLUG', titleSlug) if (!process.argv[2]) {
spinner.fail('Use the format `npm run new -- Title of project`')
return
}
const title = process.argv[2]
spinner.text = `Adding '${title}'.`
const titleSlug = slugify(title, { lower: true })
const projects = path.join(__dirname, '..', 'data', 'projects.yml') const projects = path.join(__dirname, '..', 'data', 'projects.yml')
const newContents = template
.split('TITLE')
.join(title)
.split('SLUG')
.join(titleSlug)
prepend(projects, newContents, error => { prepend(projects, newContents, error => {
if (error) throw error if (error) {
spinner.fail(error)
}
spinner.succeed(`Added '${title}' to top of projects.yml file.`) spinner.succeed(`Added '${title}' to top of projects.yml file.`)
}) })