缺少的 Fulstack 工具箱
Blitz 发电机
Generator
这个软件包存放了所有与 Blitz 代码相关的文件 。 总的来说 src 查找目录 generator 类和目录 generators 那样会延长时间 子类并不非常有趣,大部分的乐趣发生在抽象的家长类. 每个生成器可能(取决于它是净新添加文件还是修改已存在的文件)有一个相应的模板,定义在 templates 目录.
创建新生成器需要新建 Generator 子类 src/generators,并有可能在 templates 如果生成器生成净新文件。 对于模板,我们使用自己的诱导语言。 模板中的每个变量,周围有 __ (例如:. __modelName__)将替换为返回对象中的相应值 Generator::getTemplateValues。这种替换也用文件名进行.
生成器框架也支持有条件的代码生成,类似于其他常见的调温语言如手提棒. 所有模型变量都通过 process.env 并可用于有条件的声明。 生成器不会在条件中评价任何表达式,所以该条件必须在生成器类中评价,并作为变量传递到模板. 两者 if else 和三重语句得到支持,以及 if 语句无 else 需要:
// VALID
if (process.env.someCondition) {
console.log("condition was true")
}
// VALID
if (process.env.someCondition) {
console.log("condition was true")
} else {
console.log("condition was false")
}
// VALID
const action = process.env.someCondition
? () => console.log("condition was true")
: () => console.log("condition was false")
// **NOT** VALID
// This will compile fine, but will not product the expected results.
// The template argument `someValue` will be evaluated for truthiness
// and the conditional will be evaluated based on that, regardless of
// the rest of the expression
if (process.env.someValue === "some test") {
console.log("dynamic condition")
}
