概述
我正在创建一个尤曼生成器,将产生一个定制的角度应用程序。它将产生自定义角度控制器和服务。
虽然我可以简单地接受由角度发生器生成的当前角模板,添加我的代码,然后将其保存为生成器中的模板,但我更愿意让生成器在运行时将“正式”的角度生成器(以前由用户安装)作为子生成器,因此不必在每次角度生成器模板更改时同步模板。
问题
我有此功能,但唯一的问题是,当我从生成器中将代码添加到子生成器(例如控制器)生成的文件中时,我会得到以下消息:
conflict app/scripts/controllers/mycontroller.js
? Overwrite app/scripts/controllers/mycontroller.js? overwrite
force app/scripts/controllers/mycontroller.js是否有一种方法可以在子生成器生成的文件写入磁盘之前获得它,这样我就可以编辑它,而无需生成覆盖提示?
我认为提示您覆盖第一次创建的文件是令人困惑的。
数据
在读取约曼医生时,它使其听起来像是生成器和子生成器共享相同的“软”内存文件系统:
由于异步API很难使用,所以Yeoman提供了一个同步的文件系统API,其中每个文件都被写入内存中的文件系统,并且只在Yeoman运行时被写到磁盘上一次。这个内存文件系统在所有组成的生成器之间共享。
但是,子生成器似乎将文件写入磁盘,而不是内存中的文件系统。不幸的是,我没有控制子生成器,因为它是标准的角尤曼生成器。
这是我的生成器(向下滚动到标有“相关部分”的部分):
'use strict';
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
module.exports = yeoman.generators.Base.extend({
prompting: function () {
var done = this.async();
// Have Yeoman greet the user.
this.log(yosay(
'Welcome to the epic ' + chalk.red('AngularVr') + ' generator!'
));
var prompts = [{
type: 'confirm',
name: 'someOption',
message: 'Would you like to enable this option?',
default: true
}];
this.prompt(prompts, function (props) {
this.props = props;
done();
}.bind(this));
},
writing: {
app: function () {
this.fs.copy(
this.templatePath('_vt_marker.json'),
this.destinationPath('vt_marker.json')
);
},
====================== Relevant Portion ===============
subgenerators: function () {
this.log("now executing subgenerators");
this.composeWith('angular:controller', {args: ['mycontroller']} );
this.log("now done with subgeneration");
},
subgenerators_read: function () {
// add a new line to generated file..this generates overwrite prompt
var fp = this.destinationPath('app/scripts/controllers/mycontroller.js');
var fc = this.fs.read(fp);
fc += '\nhello there\n';
this.fs.write(fp, fc);
},
});这是我第一次尝试编写一个约曼生成器。
非常感谢。
发布于 2015-10-02 20:23:01
问题可能只是您的生成器或生成器角运行在旧版本的yeoman-generator上。
现在的最新版本是0.20.3 https://www.npmjs.com/package/yeoman-generator
https://stackoverflow.com/questions/32881236
复制相似问题