index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. 'use strict';
  2. var util = require('util');
  3. var path = require('path');
  4. var yeoman = require('yeoman-generator');
  5. var ThreejsGenerator = module.exports = function ThreejsGenerator(args, options, config) {
  6. yeoman.generators.Base.apply(this, arguments);
  7. // this.on('end', function () {
  8. // this.installDependencies({ skipInstall: options['skip-install'] });
  9. // });
  10. this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));
  11. };
  12. util.inherits(ThreejsGenerator, yeoman.generators.Base);
  13. ThreejsGenerator.prototype.askFor = function askFor() {
  14. var cb = this.async();
  15. // have Yeoman greet the user.
  16. console.log(this.yeoman);
  17. this.prompt([{
  18. type: 'confirm',
  19. name: 'defaultOptions',
  20. message: 'Would you the default one?',
  21. default: true
  22. }], function (props) {
  23. this.defaultOptions = props.defaultOptions
  24. this.withRequirejs = true
  25. this.withDetectorjs = true
  26. this.withWindowResize = true
  27. if( this.defaultOptions === true ){
  28. cb();
  29. return;
  30. }
  31. this.prompt([{
  32. type : 'confirm',
  33. name : 'withRequirejs',
  34. message : 'Would you like to add require.js?',
  35. default : true
  36. }, {
  37. type : 'confirm',
  38. name : 'withDetectorjs',
  39. message : 'Would you like to support webgl detection?',
  40. default : true
  41. }, {
  42. type : 'confirm',
  43. name : 'withWindowResize',
  44. message : 'Would you like to support window resize?',
  45. default : true
  46. }, ], function (props) {
  47. this.withRequirejs = props.withRequirejs;
  48. this.withWindowResize = props.withWindowResize;
  49. this.withDetectorjs = props.withDetectorjs;
  50. cb();
  51. }.bind(this));
  52. }.bind(this));
  53. };
  54. ThreejsGenerator.prototype.app = function app() {
  55. this.copy('Makefile', 'Makefile');
  56. this.copy('index.html', 'index.html');
  57. this.copy('vendor/three.js/build/three.js', 'vendor/three.js/build/three.js');
  58. this.copy('setup.js', 'src/setup.js');
  59. this.copy('app.js', 'src/app.js');
  60. if( this.withWindowResize ){
  61. this.copy( 'vendor/threex.windowresize.js', 'vendor/threex.windowresize.js');
  62. }
  63. if( this.withDetectorjs ){
  64. this.copy('vendor/three.js/examples/js/Detector.js', 'vendor/three.js/examples/js/Detector.js');
  65. }
  66. if( this.withRequirejs ){
  67. this.copy('vendor/require.js/require.js', 'vendor/require.js/require.js');
  68. }
  69. };
  70. ThreejsGenerator.prototype.projectfiles = function projectfiles() {
  71. // this.copy('editorconfig', '.editorconfig');
  72. // this.copy('jshintrc', '.jshintrc');
  73. };