|
| 1 | +'use strict'; |
| 2 | +var yeoman = require('yeoman-generator'); |
| 3 | +var chalk = require('chalk'); |
| 4 | +var yosay = require('yosay'); |
| 5 | + |
| 6 | +module.exports = yeoman.generators.Base.extend({ |
| 7 | + initializing: function () { |
| 8 | + this.pkg = require('../package.json'); |
| 9 | + |
| 10 | + }, |
| 11 | + constructor: function () { |
| 12 | + yeoman.generators.Base.apply(this, arguments); |
| 13 | + }, |
| 14 | + |
| 15 | + prompting: function () { |
| 16 | + var done = this.async(); |
| 17 | + |
| 18 | + // Have Yeoman greet the user. |
| 19 | + this.log(yosay( |
| 20 | + 'Welcome to the brilliant ' + chalk.red('AngularRequireFullstack') + ' generator! by ' + chalk.blue('MONITS') |
| 21 | + )); |
| 22 | + |
| 23 | + this.log( |
| 24 | + 'I will generate a fullstack structure based on AngularJS + RequireJS, alongside some must-have modules' |
| 25 | + ); |
| 26 | + |
| 27 | + var prompts = [{ |
| 28 | + type: 'input', |
| 29 | + name: 'projectName', |
| 30 | + message: 'Your project name:', |
| 31 | + default: this.appname |
| 32 | + },{ |
| 33 | + type: 'confirm', |
| 34 | + name: 'continueOption', |
| 35 | + message: 'This process may take some time, do you want to continue?', |
| 36 | + default: true |
| 37 | + }]; |
| 38 | + |
| 39 | + this.prompt(prompts, function (props) { |
| 40 | + this.props = props; |
| 41 | + if (!this.props.continueOption) { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + this.appname = this.props.projectName; |
| 46 | + // To access props later use this.props.someOption; |
| 47 | + |
| 48 | + done(); |
| 49 | + }.bind(this)); |
| 50 | + }, |
| 51 | + |
| 52 | + writing: { |
| 53 | + app: function () { |
| 54 | + this.fs.copy( |
| 55 | + this.templatePath('_package.json'), |
| 56 | + this.destinationPath('package.json') |
| 57 | + ); |
| 58 | + this.fs.copy( |
| 59 | + this.templatePath('_bower.json'), |
| 60 | + this.destinationPath('bower.json') |
| 61 | + ); |
| 62 | + |
| 63 | + //Main files |
| 64 | + this.fs.copyTpl( |
| 65 | + this.templatePath('/scripts/_app.js'), |
| 66 | + this.destinationPath('/app/scripts/' + this.appname + '.js'), |
| 67 | + this |
| 68 | + ); |
| 69 | + this.fs.copyTpl( |
| 70 | + this.templatePath('/scripts/_build.js'), |
| 71 | + this.destinationPath('/app/scripts/build.js'), |
| 72 | + this |
| 73 | + ); |
| 74 | + this.fs.copyTpl( |
| 75 | + this.templatePath('/scripts/_paths.js'), |
| 76 | + this.destinationPath('/app/scripts/paths.js'), |
| 77 | + this |
| 78 | + ); |
| 79 | + this.fs.copyTpl( |
| 80 | + this.templatePath('/scripts/_routes.js'), |
| 81 | + this.destinationPath('/app/scripts/routes.js'), |
| 82 | + this |
| 83 | + ); |
| 84 | + this.fs.copy( |
| 85 | + this.templatePath('Gruntfile.js'), |
| 86 | + this.destinationPath('Gruntfile.js') |
| 87 | + ); |
| 88 | + this.fs.copy( |
| 89 | + this.templatePath('robots.txt'), |
| 90 | + this.destinationPath('/app/robots.txt') |
| 91 | + ); |
| 92 | + |
| 93 | + //i18n |
| 94 | + this.fs.copy( |
| 95 | + this.templatePath('/scripts/i18n/*.*'), |
| 96 | + this.destinationPath('/app/scripts/i18n/') |
| 97 | + ); |
| 98 | + |
| 99 | + //Controllers |
| 100 | + this.fs.copyTpl( |
| 101 | + this.templatePath('/scripts/controllers/_IndexCtrl.js'), |
| 102 | + this.destinationPath('/app/scripts/controllers/IndexCtrl.js'), |
| 103 | + this |
| 104 | + ); |
| 105 | + this.fs.copyTpl( |
| 106 | + this.templatePath('/scripts/controllers/_HomeCtrl.js'), |
| 107 | + this.destinationPath('/app/scripts/controllers/HomeCtrl.js'), |
| 108 | + this |
| 109 | + ); |
| 110 | + |
| 111 | + //Directives |
| 112 | + this.fs.copyTpl( |
| 113 | + this.templatePath('/scripts/directives/_sample.js'), |
| 114 | + this.destinationPath('/app/scripts/directives/sample.js'), |
| 115 | + this |
| 116 | + ); |
| 117 | + |
| 118 | + //Services |
| 119 | + this.fs.copyTpl( |
| 120 | + this.templatePath('/scripts/services/_sampleService.js'), |
| 121 | + this.destinationPath('/app/scripts/services/sampleService.js'), |
| 122 | + this |
| 123 | + ); |
| 124 | + |
| 125 | + this.fs.copy( |
| 126 | + this.templatePath('/scripts/services/dependencyResolverFor.js'), |
| 127 | + this.destinationPath('/app/scripts/services/dependencyResolverFor.js') |
| 128 | + ); |
| 129 | + |
| 130 | + //Images |
| 131 | + this.fs.copy( |
| 132 | + this.templatePath('/images/yeoman.png'), |
| 133 | + this.destinationPath('/app/images/yeoman.png') |
| 134 | + ); |
| 135 | + |
| 136 | + //Styles |
| 137 | + this.fs.copy( |
| 138 | + this.templatePath('/styles/**/*'), |
| 139 | + this.destinationPath('/app/styles/') |
| 140 | + ); |
| 141 | + |
| 142 | + //Views |
| 143 | + this.fs.copyTpl( |
| 144 | + this.templatePath('_index.html'), |
| 145 | + this.destinationPath('/app/index.html'), |
| 146 | + this |
| 147 | + ); |
| 148 | + |
| 149 | + this.fs.copy( |
| 150 | + this.templatePath('404.html'), |
| 151 | + this.destinationPath('/app/404.html') |
| 152 | + ); |
| 153 | + |
| 154 | + this.fs.copyTpl( |
| 155 | + this.templatePath('/views/_home.html'), |
| 156 | + this.destinationPath('/app/views/home.html'), |
| 157 | + this |
| 158 | + ); |
| 159 | + |
| 160 | + //this.gruntfile.insertConfig("compass", "{ watch: { watch: true } }"); |
| 161 | + }, |
| 162 | + |
| 163 | + projectfiles: function () { |
| 164 | + this.fs.copy( |
| 165 | + this.templatePath('editorconfig'), |
| 166 | + this.destinationPath('.editorconfig') |
| 167 | + ); |
| 168 | + this.fs.copy( |
| 169 | + this.templatePath('jshintrc'), |
| 170 | + this.destinationPath('.jshintrc') |
| 171 | + ); |
| 172 | + } |
| 173 | + }, |
| 174 | + |
| 175 | + install: function () { |
| 176 | + this.installDependencies(); |
| 177 | + }, |
| 178 | + |
| 179 | + end: function () { |
| 180 | + this.log('Run ' + chalk.red('grunt serve') + ' to see the app in action or ' + chalk.blue('grunt build') + ' when you are ready to deploy it'); |
| 181 | + this.log('Visit our blog at ' + chalk.blue('https://medium.com/monits-blog')); |
| 182 | + } |
| 183 | +}); |
0 commit comments