|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var generators = require('yeoman-generator'); |
| 4 | +var mkdirp = require('mkdirp'); |
| 5 | +var yosay = require('yosay'); |
| 6 | +var chalk = require('chalk'); |
| 7 | +var S = require('string'); |
| 8 | + |
| 9 | +module.exports = generators.Base.extend({ |
| 10 | + _createProjectFileSystem: function() { |
| 11 | + var sourceRoot = this.sourceRoot(); |
| 12 | + var componentRoot = this.componentRoot; |
| 13 | + var componentName = S(this.componentName).capitalize().s; |
| 14 | + var templateContext = { |
| 15 | + componentName: componentName |
| 16 | + }; |
| 17 | + var componentDir = componentRoot + '/' + componentName; |
| 18 | + mkdirp(componentRoot + '/' + componentName); |
| 19 | + |
| 20 | + |
| 21 | + this.fs.copyTpl(sourceRoot + '/_package.json', componentDir + '/package.json', templateContext); |
| 22 | + this.fs.copyTpl(sourceRoot + '/ComponentPage.js', componentDir + '/' + componentName + '.js', templateContext); |
| 23 | + this.fs.copyTpl(sourceRoot + '/ComponentPage.scss', componentDir + '/' + componentName + '.scss', templateContext); |
| 24 | + }, |
| 25 | + |
| 26 | + constructor: function() { |
| 27 | + generators.Base.apply(this, arguments); |
| 28 | + |
| 29 | + this.argument('componentName', { |
| 30 | + required: true, |
| 31 | + type: String, |
| 32 | + desc: 'Name of the component', |
| 33 | + }); |
| 34 | + |
| 35 | + this.argument('componentRoot', { |
| 36 | + required: true, |
| 37 | + type: String, |
| 38 | + desc: 'Root of the component', |
| 39 | + }); |
| 40 | + |
| 41 | + this.log('Creating module ' + this.componentName + '.'); |
| 42 | + }, |
| 43 | + |
| 44 | + initializing: function() { |
| 45 | + var message = chalk.bgBlack.bold('\nWelcome to React-Vertical Project\n') + chalk.underline('JS React/Flux Compiler\n'); |
| 46 | + this.log(yosay(message)); |
| 47 | + }, |
| 48 | + |
| 49 | + configuring: function() { |
| 50 | + this.config.save(); |
| 51 | + }, |
| 52 | + |
| 53 | + writing: function() { |
| 54 | + this._createProjectFileSystem(); |
| 55 | + }, |
| 56 | +}); |
0 commit comments