【发布时间】:2015-11-10 19:31:58
【问题描述】:
第一次开始制作 Yeoman 生成器...我想要做的是从存储库中获取 VM,并且可以选择从另一个存储库中获取现有代码库到同一目录。
当我克隆 repo 时,我想删除 .git 信息(libgit2 不支持深度或其他选项,所以我使用 rimraf 去除 git 历史记录),复制并重命名两个配置文件,并替换字符串在 Yeoman 的“提示”阶段由用户提供输入的那些文件。
在操作完成之前,我无法阻止进度。这是我到目前为止所拥有的。它似乎主要工作......除了 replace() 不像我预期的那样工作:
configuring: function() {
var done = this.async();
var vm_repository = "https://github.com/geerlingguy/drupal-vm.git";
var vm_directory = this.destinationRoot() + '/drupalvm';
this.log(chalk.yellow('Cloning DrupalVM from ' + vm_repository));
clone(vm_repository, vm_directory, done)
.then(function() {
rimraf(vm_directory + '/.*', function(error) {
if (error) return console.log(error);
});
rimraf(vm_directory + '/docs', function(error) {
if (error) return console.log(error);
});
rimraf(vm_directory + '/examples', function(error) {
if (error) return console.log(error);
});
rimraf(vm_directory + '/mkdocs.yml', function(error) {
if (error) return console.log(error);
});
console.log('Repository cloned successfully.');
done();
})
.catch(function(error) { console.log(error) });
},
writing: function() {
var done = this.async();
var vm_directory = this.destinationRoot() + '/drupalvm';
fs.copy(this.destinationRoot() + '/drupalvm/example.config.yml', this.destinationRoot() + '/drupalvm/config.yml', function (error) {
if (error) return console.log(error);
});
fs.copy(this.destinationRoot() + '/drupalvm/example.drupal.make.yml', this.destinationRoot() + '/drupalvm/drupal.make.yml', function (error) {
if (error) return console.log(error);
});
done();
},
end: function() {
this.log('what 4');
// rewrite values with user input
replace({
regex: "/vagrant_machine_name\: drupalvm/",
replacement: "vagrant_machine_name: " + this.vagrant_machine_name,
paths: [this.destinationRoot() + '/drupalvm/config.yml'],
recursive: false,
silent: false,
});
replace({
regex: "vagrant_ip: 192.168.88.88",
replacement: "vagrant_ip: " + this.vagrant_ip,
paths: [this.destinationRoot() + '/drupalvm/config.yml'],
recursive: false,
silent: false,
});
},
这是否异常有效.. 可能不是。 yeoman/nodejs 脚本非常新。
我哪里出错了?另外,如何通过函数将上下文和变量作为参数传递?它们不断出现未定义。
【问题讨论】:
标签: javascript node.js yeoman