我yeoman发电机不会复制文件

问题描述:

我正在使用yeoman制作一个web应用程序,我被困在创建一个发电机。问题是它不会将文件复制到输出文件夹。我yeoman发电机不会复制文件

这里是我的代码:

'use strict'; 
var fs = require('fs'); 
var path = require('path'); 
var yeoman = require('yeoman-generator'); 
var yosay = require('yosay'); 
var chalk = require('chalk'); 
var wiredep = require('wiredep'); 

module.exports=yeoman.extend({ 

    scaffoldFolders: function(){ 
     this.mkdir("app"); 
     this.mkdir("app/css"); 
     this.mkdir("app/sections"); 
     this.mkdir("build"); 
    }, 

    initializing: function(){ 
    this.pkg=require('../../package.json'); 
    }, 

    prompting: function() { 
    var done = this.async(); 

    this.log(yosay(
     'Welcome to the marvelous ' + chalk.red('generator-palmyra') + ' generator!' 
    )); 

    var prompts = [{ 
     type: 'checkbox', 
     name: 'mainframeworks', 
     message:'Would you like AngularJS or JQuery ?', 
     choices: [{ 
     name: 'Angular', 
     value: 'includeAngular', 
     checked: true 
     }, { 
     name: 'JQuery', 
     value: 'includeJQuery', 
     checked: true 
     }] 
     }, 
    { 
     type: 'checkbox', 
     name: 'features', 
     message:'What more front-end frameworks would you like ?', 
     choices: [{ 
     name: 'Sass', 
     value: 'includeSass', 
     checked: true 
    }, { 
     name: 'Bootstrap', 
     value: 'includeBootstrap', 
     checked: true 
    }, { 
     name: 'Modernizr', 
     value: 'includeModernizr', 
     checked: true 
     }] 
    } 
    ]; 


    this.prompt(prompts, function (answers) { 
    var features = answers.features; 
    var mainframeworks = answers.mainframeworks; 
    var hasFeature = function (feat) { 
    return features.indexOf(feat) !== -1; 
    }; 
    var hasMainframeworks = function (mainframework) { 
    return mainframeworks.indexOf(mainframework) !== -1; 
    }; 
// manually deal with the response, get back and store the results. 
    this.includeSass = hasFeature('includeSass'); 
    this.includeBootstrap = hasFeature('includeBootstrap'); 
    this.includeModernizr = hasFeature('includeModernizr'); 
    this.includeAngular = hasMainframeworks('includeAngular'); 
    this.includeJQuery = hasMainframeworks('includeJQuery'); 
    done(); 
}.bind(this)); 
}, 



    writing() { 

    gulpfile= function(){ 
    this.fs.copy(
     this.templatePath('gulpfile.js'), 
     this.destinationPath('gulpfile.js') 
       ); 
         }, 
    packageJSON= function() { 
     this.fs.copy(
    this.templatePath('_package.json'), 
    this.destinationPath('package.json') 
); 
           }, 
    git= function() { 
     this.fs.copy(
     this.templatePath('gitignore'), 
     this.destinationPath('.gitignore') 
        ); 
     this.fs.copy(
     this.templatePath('gitattributes'), 
     this.destinationPath('.gitattributes') 
        ); 
        }, 
     bower= function() { 
          var bower = { 
          name: this._.slugify(this.appname), 
          private: true, 
          dependencies: {} 
          }; 
          if (this.includeBootstrap) { 
          var bs = 'bootstrap' + (this.includeSass ? '-sass' : ''); 
          bower.dependencies[bs] = '~3.3.1'; 
          } 
          if (this.includeModernizr) { 
          bower.dependencies.modernizr = '~2.8.1'; 
          } 
         if (this.includeAngular) { 
         bower.dependencies.angular = '~1.3.15'; 
         } 
         if (this.includeJQuery) { 
         bower.dependencies.jquery = '~2.1.1'; 
         } 
         this.fs.copy(
          this.templatePath('bowerrc'), 
          this.destinationPath('.bowerrc') 
         ); 
          this.write('bower.json', JSON.stringify(bower, null, 2)); 
         }, 
     jshint= function() { 
     this.fs.copy(
     this.templatePath('jshintrc'), 
     this.destinationPath('.jshintrc') 
       ); 
          }, 
    mainStylesheet= function() { 
          var css = 'main'; 
          if (this.includeSass) { 
           css += '.scss'; 
          } else { 
           css += '.css'; 
          } 
         this.copy(css, 'app/styles/' + css); 
           }, 
    writeIndex= function() { 
           this.indexFile = this.src.read('index.html'); 
           this.indexFile = this.engine(this.indexFile, this); 
           // wire Bootstrap plugins 
           if (this.includeBootstrap) { 
            var bs = '/bower_components/'; 
            if (this.includeSass) { 
            bs += 'bootstrap-sass/assets/javascripts/bootstrap/'; 
            } else { 
            bs += 'bootstrap/js/'; 
            } 
            this.indexFile = this.appendScripts(this.indexFile, 'scripts/plugins.js', [ 
            bs + 'affix.js', 
            bs + 'alert.js', 
            bs + 'dropdown.js', 
            bs + 'tooltip.js', 
            bs + 'modal.js', 
            bs + 'transition.js', 
            bs + 'button.js', 
            bs + 'popover.js', 
            bs + 'carousel.js', 
            bs + 'scrollspy.js', 
            bs + 'collapse.js', 
            bs + 'tab.js' 
            ]); 
           } 
           this.indexFile = this.appendFiles({ 
            html: this.indexFile, 
            fileType: 'js', 
            optimizedPath: 'scripts/main.js', 
            sourceFileList: ['scripts/main.js'] 
           }); 
           this.write('app/index.html', this.indexFile); 
           }, 
           app= function() { 
           this.copy('main.js', 'app/scripts/main.js'); 
           } 
          }, 
    install: function() { 
    var howToInstall = 
     '\nAfter running ' + 
     chalk.yellow.bold('npm install & bower install') + 
     ', inject your' + 
     '\nfront end dependencies by running ' + 
     chalk.yellow.bold('gulp wiredep') + 
     '.'; 
    if (this.options['skip-install']) { 
     this.log(howToInstall); 
     return; 
    } 
    this.installDependencies(); 
    this.on('end', function() { 
     var bowerJson = this.dest.readJSON('bower.json'); 
     // wire Bower packages to .html 
     wiredep({ 
     bowerJson: bowerJson, 
     directory: 'bower_components', 
     exclude: ['bootstrap-sass', 'bootstrap.js'], 
     ignorePath: /^(\.\.\/)*\.\./, 
     src: 'app/index.html' 
     }); 
     if (this.includeSass) { 
     // wire Bower packages to .scss 
     wiredep({ 
      bowerJson: bowerJson, 
      directory: 'bower_components', 
      ignorePath: /^(\.\.\/)+/, 
      src: 'app/styles/*.scss' 
     }); 
     } 
    }.bind(this)); 
    } 
}); 

我认为这个问题是在写作方法。我也想问下一步该去哪里?或者我通过了一个基本步骤去学习web dev

+0

您是否收到任何错误?如果是这样,请分享它们。 –

+0

没有错误...当我与yeoman一起运行时...提示方法工作原理:询问我是否想使用角度或jquery ...填充选项后...它只是在那里结束 –

如果你格式化你的代码,你会看到writing函数没有做任何事情。它声明了一堆子函数,但不运行任何人。

我认为问题是你想要一个对象,而是写了一个函数:writing() {}而不是writing: {}

我做了一个代码的快速修复,但没有测试出来。所以有可能是进一步的语法问题,但它应该大致是这样的:

'use strict'; 
 
var fs = require('fs'); 
 
var path = require('path'); 
 
var yeoman = require('yeoman-generator'); 
 
var yosay = require('yosay'); 
 
var chalk = require('chalk'); 
 
var wiredep = require('wiredep'); 
 

 
module.exports = yeoman.extend({ 
 
    scaffoldFolders: function() { 
 
     this.mkdir('app'); 
 
     this.mkdir('app/css'); 
 
     this.mkdir('app/sections'); 
 
     this.mkdir('build'); 
 
    }, 
 

 
    initializing: function() { 
 
     this.pkg = require('../../package.json'); 
 
    }, 
 

 
    prompting: function() { 
 
     var done = this.async(); 
 

 
     this.log(
 
      yosay(
 
       'Welcome to the marvelous ' + 
 
        chalk.red('generator-palmyra') + 
 
        ' generator!' 
 
      ) 
 
     ); 
 

 
     var prompts = [ 
 
      { 
 
       type: 'checkbox', 
 
       name: 'mainframeworks', 
 
       message: 'Would you like AngularJS or JQuery ?', 
 
       choices: [ 
 
        { 
 
         name: 'Angular', 
 
         value: 'includeAngular', 
 
         checked: true, 
 
        }, 
 
        { 
 
         name: 'JQuery', 
 
         value: 'includeJQuery', 
 
         checked: true, 
 
        }, 
 
       ], 
 
      }, 
 
      { 
 
       type: 'checkbox', 
 
       name: 'features', 
 
       message: 'What more front-end frameworks would you like ?', 
 
       choices: [ 
 
        { 
 
         name: 'Sass', 
 
         value: 'includeSass', 
 
         checked: true, 
 
        }, 
 
        { 
 
         name: 'Bootstrap', 
 
         value: 'includeBootstrap', 
 
         checked: true, 
 
        }, 
 
        { 
 
         name: 'Modernizr', 
 
         value: 'includeModernizr', 
 
         checked: true, 
 
        }, 
 
       ], 
 
      }, 
 
     ]; 
 

 
     this.prompt(
 
      prompts, 
 
      function(answers) { 
 
       var features = answers.features; 
 
       var mainframeworks = answers.mainframeworks; 
 
       var hasFeature = function(feat) { 
 
        return features.indexOf(feat) !== -1; 
 
       }; 
 
       var hasMainframeworks = function(mainframework) { 
 
        return mainframeworks.indexOf(mainframework) !== -1; 
 
       }; 
 
       // manually deal with the response, get back and store the results. 
 
       this.includeSass = hasFeature('includeSass'); 
 
       this.includeBootstrap = hasFeature('includeBootstrap'); 
 
       this.includeModernizr = hasFeature('includeModernizr'); 
 
       this.includeAngular = hasMainframeworks('includeAngular'); 
 
       this.includeJQuery = hasMainframeworks('includeJQuery'); 
 
       done(); 
 
      }.bind(this) 
 
     ); 
 
    }, 
 

 
    writing: { 
 
     gulpfile: function() { 
 
      this.fs.copy(
 
       this.templatePath('gulpfile.js'), 
 
       this.destinationPath('gulpfile.js') 
 
      ); 
 
     }, 
 
     packageJSON: function() { 
 
      this.fs.copy(
 
       this.templatePath('_package.json'), 
 
       this.destinationPath('package.json') 
 
      ); 
 
     }, 
 
     git: function() { 
 
      this.fs.copy(
 
       this.templatePath('gitignore'), 
 
       this.destinationPath('.gitignore') 
 
      ); 
 
      this.fs.copy(
 
       this.templatePath('gitattributes'), 
 
       this.destinationPath('.gitattributes') 
 
      ); 
 
     }, 
 
     bower: function() { 
 
      var bower = { 
 
       name: this._.slugify(this.appname), 
 
       private: true, 
 
       dependencies: {}, 
 
      }; 
 
      if (this.includeBootstrap) { 
 
       var bs = 'bootstrap' + (this.includeSass ? '-sass' : ''); 
 
       bower.dependencies[bs] = '~3.3.1'; 
 
      } 
 
      if (this.includeModernizr) { 
 
       bower.dependencies.modernizr = '~2.8.1'; 
 
      } 
 
      if (this.includeAngular) { 
 
       bower.dependencies.angular = '~1.3.15'; 
 
      } 
 
      if (this.includeJQuery) { 
 
       bower.dependencies.jquery = '~2.1.1'; 
 
      } 
 
      this.fs.copy(this.templatePath('bowerrc'), this.destinationPath('.bowerrc')); 
 
      this.write('bower.json', JSON.stringify(bower, null, 2)); 
 
     }, 
 
     jshint: function() { 
 
      this.fs.copy(
 
       this.templatePath('jshintrc'), 
 
       this.destinationPath('.jshintrc') 
 
      ); 
 
     }, 
 
     mainStylesheet: function() { 
 
      var css = 'main'; 
 
      if (this.includeSass) { 
 
       css += '.scss'; 
 
      } else { 
 
       css += '.css'; 
 
      } 
 
      this.copy(css, 'app/styles/' + css); 
 
     }, 
 
     writeIndex: function() { 
 
      this.indexFile = this.src.read('index.html'); 
 
      this.indexFile = this.engine(this.indexFile, this); 
 
      // wire Bootstrap plugins 
 
      if (this.includeBootstrap) { 
 
       var bs = '/bower_components/'; 
 
       if (this.includeSass) { 
 
        bs += 'bootstrap-sass/assets/javascripts/bootstrap/'; 
 
       } else { 
 
        bs += 'bootstrap/js/'; 
 
       } 
 
       this.indexFile = this.appendScripts(
 
        this.indexFile, 
 
        'scripts/plugins.js', 
 
        [ 
 
         bs + 'affix.js', 
 
         bs + 'alert.js', 
 
         bs + 'dropdown.js', 
 
         bs + 'tooltip.js', 
 
         bs + 'modal.js', 
 
         bs + 'transition.js', 
 
         bs + 'button.js', 
 
         bs + 'popover.js', 
 
         bs + 'carousel.js', 
 
         bs + 'scrollspy.js', 
 
         bs + 'collapse.js', 
 
         bs + 'tab.js', 
 
        ] 
 
       ); 
 
      } 
 
      this.indexFile = this.appendFiles({ 
 
       html: this.indexFile, 
 
       fileType: 'js', 
 
       optimizedPath: 'scripts/main.js', 
 
       sourceFileList: ['scripts/main.js'], 
 
      }); 
 
      this.write('app/index.html', this.indexFile); 
 
     }, 
 
     app: function() { 
 
      this.copy('main.js', 'app/scripts/main.js'); 
 
     }, 
 
    }, 
 

 
    install: function() { 
 
     var howToInstall = 
 
      '\nAfter running ' + 
 
      chalk.yellow.bold('npm install & bower install') + 
 
      ', inject your' + 
 
      '\nfront end dependencies by running ' + 
 
      chalk.yellow.bold('gulp wiredep') + 
 
      '.'; 
 
     if (this.options['skip-install']) { 
 
      this.log(howToInstall); 
 
      return; 
 
     } 
 
     this.installDependencies(); 
 
     this.on(
 
      'end', 
 
      function() { 
 
       var bowerJson = this.dest.readJSON('bower.json'); 
 
       // wire Bower packages to .html 
 
       wiredep({ 
 
        bowerJson: bowerJson, 
 
        directory: 'bower_components', 
 
        exclude: ['bootstrap-sass', 'bootstrap.js'], 
 
        ignorePath: /^(\.\.\/)*\.\./, 
 
        src: 'app/index.html', 
 
       }); 
 
       if (this.includeSass) { 
 
        // wire Bower packages to .scss 
 
        wiredep({ 
 
         bowerJson: bowerJson, 
 
         directory: 'bower_components', 
 
         ignorePath: /^(\.\.\/)+/, 
 
         src: 'app/styles/*.scss', 
 
        }); 
 
       } 
 
      }.bind(this) 
 
     ); 
 
    }, 
 
});

+0

我做出了这些更改。 ..这是同一个问题......文件不会复制到新目录中 –

我删除了var做=异步()和替换“this.prompt”被“退货。提示“ 大部分文件被复制...但仍有更多无效代码::