UNPKG

generator-pr

Version:
86 lines (72 loc) 2.15 kB
'use strict' var yeoman = require('yeoman-generator') var chalk = require('chalk') var yosay = require('yosay') var moment = require('moment') var getPlanningDir = require('../../common/util').getPlanningDir function checkPlanStyle(style) { if (style !== 'today' && style !== 'next') { this.log('Please provide planning style value as "today" or "next".') process.exit(-1) } } module.exports = yeoman.Base.extend({ constructor: function () { yeoman.Base.apply(this, arguments) this.option('day', { type: Number, required: false }) this.option('style', { type: String, required: false }) }, prompting: function () { var prompts = [] if (this.options.style) { this.style = this.options.style checkPlanStyle(this.style) prompts.push({ type: 'input', name: 'saveStyle', message: 'Do you want to save the planning style for future?', default: false }) } else { var planStyle = this.config.get('planStyle') if (!planStyle && !this.options.day) { prompts.push({ type: 'input', name: 'planStyle', message: 'What is your normal planning style, today or next day?', default: 'next' }) } } return this.prompt(prompts).then(function (props) { if (props.planStyle) { checkPlanStyle(props.planStyle) this.config.set('planStyle', props.planStyle) } if (props.saveStyle === 'true') { this.config.set('planStyle', this.style) } }.bind(this)) }, writing: function () { // Default set planning time to tomorrow this.time = moment().add(1, 'days') if (this.options.day) { this.time.set('date', this.options.day) } else { var planStyle = this.config.get('planStyle') if (planStyle === 'today') { this.time = this.time.subtract(1, 'days') } } var date = this.time.get('date') var dest = getPlanningDir(this.time) + date + '.js' this.fs.copyTpl( this.templatePath('day.js'), this.destinationPath(dest), { date: date } ) } })