新增生成时间变量
fbigun opened this issue · comments
希望生成的模板可以插入生成时间,createTime,和模板中的 {{ downloadUrl }}方法一样
模板中应该可以直接用 {{ new Date() }}
报错内容
root@localhost:/mnt/c/Users/nanyang/Desktop/rules-local# npx surgio generate
2023-09-22 11:17:50 [surgio] info: 开始生成规则
✖ 规则 surfboard.conf 生成失败
⚠️ 发生错误
⚠️ Template render error: (/mnt/c/Users/nanyang/Desktop/rules-local/template/surfboard.tpl) [Line 3, Column 18]
expected variable end
⚠️ 版本号: 2.25.0
⚠️ 常见问题: https://url.royli.dev/7EMxu
⚠️ 加入交流群汇报问题 https://t.me/surgiotg
Template render error: (/mnt/c/Users/nanyang/Desktop/rules-local/template/surfboard.tpl) [Line 3, Column 18]
expected variable end
at Object._prettifyError (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/lib.js:36:11)
at Template.render (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:538:21)
at /mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:366:27
at createTemplate (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:315:9)
at handle (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:327:11)
at /mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:339:9
at next (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/lib.js:328:7)
at Object.asyncIter (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/lib.js:334:3)
at Environment.getTemplate (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:321:9)
at Environment.render (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:360:10)
at Artifact.render (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio/lib/generator/artifact.ts:304:30)
at run (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio/lib/generate.ts:46:39)
at default_1 (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio/lib/generate.ts:91:3)
at GenerateCommand.run (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio/lib/command/generate.ts:57:5)
surgio: 2.25.0 (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio)
node: 18.18.0 (/root/.nvm/versions/node/v18.18.0/bin/node)
npm: 9.8.1
npx: 9.8.1
报错内容
root@localhost:/mnt/c/Users/nanyang/Desktop/rules-local# npx surgio generate 2023-09-22 11:17:50 [surgio] info: 开始生成规则 ✖ 规则 surfboard.conf 生成失败 ⚠️ 发生错误 ⚠️ Template render error: (/mnt/c/Users/nanyang/Desktop/rules-local/template/surfboard.tpl) [Line 3, Column 18] expected variable end ⚠️ 版本号: 2.25.0 ⚠️ 常见问题: https://url.royli.dev/7EMxu ⚠️ 加入交流群汇报问题 https://t.me/surgiotg Template render error: (/mnt/c/Users/nanyang/Desktop/rules-local/template/surfboard.tpl) [Line 3, Column 18] expected variable end at Object._prettifyError (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/lib.js:36:11) at Template.render (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:538:21) at /mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:366:27 at createTemplate (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:315:9) at handle (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:327:11) at /mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:339:9 at next (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/lib.js:328:7) at Object.asyncIter (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/lib.js:334:3) at Environment.getTemplate (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:321:9) at Environment.render (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:360:10) at Artifact.render (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio/lib/generator/artifact.ts:304:30) at run (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio/lib/generate.ts:46:39) at default_1 (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio/lib/generate.ts:91:3) at GenerateCommand.run (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio/lib/command/generate.ts:57:5) surgio: 2.25.0 (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio) node: 18.18.0 (/root/.nvm/versions/node/v18.18.0/bin/node) npm: 9.8.1 npx: 9.8.1
更新依赖并升级之后,重新运行报错
root@sukean:/mnt/c/Users/nanyang/Desktop/rules-local# npx surgio generate
ℹ 开始生成规则
✖ 规则 surfboard.conf 生成失败
发生错误
(/mnt/c/Users/nanyang/Desktop/rules-local/template/surfboard.tpl) [Line 3, Column 18]
expected variable end
错误堆栈
Template render error: (/mnt/c/Users/nanyang/Desktop/rules-local/template/surfboard.tpl) [Line 3, Column 18]
expected variable end
at Object._prettifyError (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/lib.js:32:11)
at Template.render (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:442:21)
at /mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:301:27
at createTemplate (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:254:9)
at handle (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:265:11)
at /mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:276:9
at next (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/lib.js:258:7)
at Object.asyncIter (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/lib.js:263:3)
at Environment.getTemplate (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:259:9)
at Environment.render (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/nunjucks/src/environment.js:295:10)
at Artifact.render (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio/src/generator/artifact.ts:231:30)
at GenerateCommand.generate (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio/src/commands/generate.ts:68:41)
at GenerateCommand.run (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio/src/commands/generate.ts:31:5)
at GenerateCommand._run (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/@oclif/core/lib/command.js:117:22)
at Config.runCommand (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/@oclif/core/lib/config/config.js:314:25)
at Object.run (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/@oclif/core/lib/main.js:89:16)
诊断信息
版本号: 3.0.2
常见问题: https://url.royli.dev/7EMxu
加入交流群汇报问题 https://t.me/surgiotg
@surgio/gateway: 2.0.1
surgio: 3.0.2 (/mnt/c/Users/nanyang/Desktop/rules-local/node_modules/surgio)
node: 18.18.0 (/root/.nvm/versions/node/v18.18.0/bin/node)
npm: 9.8.1
npx: 9.8.1
应该是不能够直接用 {{ new Date() }}
另一个办法就是你自己定义一个 customParams.createTime = new Date()
可以使用