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.`) })