我刚刚开始使用令人惊叹的 yeoman.io 生成器。一切都很好,直到我试图搭建整个董事的脚手架。不知何故,this.directory、this.bulkDirectory 等无法正常工作。我没有收到任何错误,没有任何副本(而 this.bulkCopy 确实有效并给出了成功消息)。
在 copyMainFiles 函数中,我实际上想将包含文件的完整目录复制到指定位置。我不是很期待手动 this.copy 每个文件。
简而言之:this.directory、this.bulkDirectory 和 this.copy 不工作。 this.bulkCopy 正在运行。
这是de index.js(剥离),我希望有人知道哪里出了问题。 yeoman 版本:1.4.6
'use strict';
var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var NulvijftigGenerator = yeoman.generators.Base.extend({
promptUser: function() {
var done = this.async();
// have Yeoman greet the user
console.log('asasd');
var prompts = [{
name: 'appName',
message: 'Blablabla'
}];
this.prompt(prompts, function (props) {
this.appName = props.appName;
this.folderName = props.folderName;
this.templateType = props.templateType;
this.plugins = props.plugins;
/* this.addDemoSection = props.addDemoSection; */
done();
}.bind(this));
},
scaffoldFolders: function(){
// if the user selected basic webshop, create the required folders
if(this.templateType == "extrawebshop"){
// main folder (frontend value in configuration)
this.mkdir(this.folderName);
this.mkdir(this.folderName + "/account");
}
if(this.templateType == "basicwebsite"){
// main folder (frontend value in configuration)
this.mkdir(this.folderName);
}
},
copyMainFiles: function(){
// if the user selected basic webshop, copy the required files
if(this.templateType == "basicwebsite"){
this.directory("basicwebsite", this.folderName);
}
var context = {
site_name: this.appName
};
//this.template("_header.html", "app/header.html", context);
},
runNpm: function(){
var done = this.async();
this.npmInstall("", function(){
console.log("\nEverything Setup !!!\n");
done();
});
}
});
module.exports = NulvijftigGenerator;
最佳答案
我不太确定为什么你的配置不起作用,但是,简单来说,有几件事需要考虑:
this.directory
确实有效,- 前两个参数为源路径和目的路径,
- 这两个路径分别相对于
this.sourcePath()
和this.destinationPath()
。
因此,如果您的文件夹结构类似于
..
templates
src
sass
jsx
dist
css
js
html
那么简单
writing: {
app: function() {
this.directory('src', 'src');
this.directory('dist', 'dist');
}
}
应该可以。
但是!
如果目录的完整递归路径中至少有一个文件,则该目录仅被递归复制。另一方面,我不确定是否有必要(并且不会真正使事情过于复杂)复制空文件夹结构。
关于javascript - Yeoman - 复制目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29345966/