UNPKG

generator-webpack-server-dev

Version:
103 lines (90 loc) 2.75 kB
'use strict'; var yeoman = require('yeoman-generator'); var chalk = require('chalk'); var yosay = require('yosay'); var mkdirp = require('mkdirp'); var path = require('path'); var extend = require('deep-extend'); module.exports = yeoman.Base.extend({ prompting: function() { // Have Yeoman greet the user. this.log(yosay( 'Welcome to the super-excellent ' + chalk.red('generator-webpack-server-dev') + ' generator!' )); var prompts = [{ type: 'input', name: 'projectName', message: 'Please input project name (webpack-server-dev):', default: 'webpack-server-dev' }, { type: 'input', name: 'projectDesc', message: 'Please input project description:' }, { type: 'input', name: 'projectMain', message: 'Main file (main.js):', default: 'main.js' }, { type: 'input', name: 'projectAuthor', message: 'Author ():', default: '' }, { type: 'list', name: 'projectLicense', message: 'Please choose license:', choices: ['MIT', 'ISC', 'Apache-2.0', 'AGPL-3.0'] }]; return this.prompt(prompts).then(function(props) { // To access props later use this.props.someAnswer; this.props = props; }.bind(this)); }, defaults: function() { if (path.basename(this.destinationPath()) !== this.props.projectName) { this.log( 'Your generator must be inside a folder named ' + this.props.projectName + '\n' + 'I\'ll automatically create this folder.' ); mkdirp(this.props.projectName); this.destinationRoot(this.destinationPath(this.props.projectName)); } }, writing: function() { var pkg = this.fs.readJSON(this.templatePath('package_tmpl.json'), {}); pkg.keywords = pkg.keywords || []; pkg.keywords.push('generator-webpack-server-dev'); pkg.name = this.props.projectName; pkg.description = this.props.projectDesc; pkg.main = this.props.projectMain; pkg.author = this.props.projectAuthor; pkg.license = this.props.projectLicense; extend(pkg, { scripts: { 'dev': 'webpack-dev-server --inline --hot --no-info' }, devDependencies: { 'webpack': '^1.13.1', 'webpack-dev-server': '^1.14.1' } }); this.fs.writeJSON(this.destinationPath('package.json'), pkg); this.fs.copy( this.templatePath('index.html'), this.destinationPath('index.html') ); this.fs.copy( this.templatePath('webpack.config.js'), this.destinationPath('webpack.config.js') ); mkdirp('src'); this.fs.copy( this.templatePath('main.js'), 'src/main.js' ); }, install: function() { this.installDependencies(); } });