[英]Conflict Safe Append to Existing File in Yeoman Generator
I'm writing a yeoman generator for a Django/Angular project I'm working on. 我正在为我正在工作的Django / Angular项目编写一个yeoman生成器。 A large part of the boilerplate in the project involves managing dependencies.
项目中的大部分样板都涉及管理依赖项。 To make this dependency management easier, I'm treating certain files essentially as header files that define what a certain package exports or imports.
为了使这种依赖关系管理更容易,我将某些文件本质上视为头文件,这些头文件定义了某个程序包导出或导入的内容。 For example, when I create a new file
my_model.py
in my my_app/models/
package, I'd like to append the line from .my_model import MyModel
to my_app/models/__init__.py
例如,当我在
my_app/models/
包中创建一个新文件my_model.py
时,我想将from .my_model import MyModel
的行附加到my_app/models/__init__.py
Since this is just a simple append which doesn't particularly depend on what's in the rest of the __init__.py
file, I consider it a pretty safe file update. 由于这只是一个简单的追加,并不特别取决于
__init__.py
文件其余部分的内容,因此我认为这是一个非常安全的文件更新。 My question is whether there's a way to flag particular file updates in yeoman as safe from a development perspective, thereby allowing a user to not have to sign off on them during the conflict resolution phase of running the generator. 我的问题是,从开发的角度来看,是否有一种方法可以将yeoman中的特定文件更新标记为安全,从而使用户在运行生成器的冲突解决阶段不必注销它们。
Currently the way I'm executing the append is this: 目前,我执行附加的方式是这样的:
var self = this;
this.fs.copy(
this.destinationPath(this.props.appName + '/models/__init__.py'),
this.destinationPath(this.props.appName + '/models/__init__.py'),
{
process: function (contents) {
return contents += 'from .' + _.snakeCase(self.props.modelName) + ' import ' + self.props.modelName + '\n';
}
}
);
There's no way to sign off on a conflict. 没有办法在冲突上签字。 It's not your responsibility to decide for your end user what is "safe" and what is not.
为最终用户决定什么是“安全”,什么不是,不是您的责任。
What if you introduce a bug and that's breaking the user file? 如果您引入错误并破坏了用户文件怎么办? That's why generators cannot skip conflicts.
这就是生成器无法跳过冲突的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.