From b86da120d1c5efd206c6584e1428348fd61d2538 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 23 May 2018 20:53:08 +0200 Subject: [PATCH] new project script tweaks --- scripts/new-project.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/new-project.js b/scripts/new-project.js index 6bf0270..5859505 100644 --- a/scripts/new-project.js +++ b/scripts/new-project.js @@ -7,14 +7,27 @@ const ora = require('ora') const templatePath = path.join(__dirname, 'new-project.yml') const template = fs.readFileSync(templatePath).toString() -const title = process.argv[2] -const titleSlug = slugify(title) -const spinner = ora(`Adding '${title}'.`).start() +const spinner = ora('Adding new project').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 newContents = template + .split('TITLE') + .join(title) + .split('SLUG') + .join(titleSlug) prepend(projects, newContents, error => { - if (error) throw error + if (error) { + spinner.fail(error) + } spinner.succeed(`Added '${title}' to top of projects.yml file.`) })