mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.48k stars 635 forks source link

Maintaining version history #1384

Closed regicsolutions closed 1 year ago

regicsolutions commented 2 years ago

Anyone know if an extension similar to cruft exists for nunjucks? https://github.com/cruft/cruft where there's a cli that can be leveraged to simply update a template to the latest version?

Use case: I have a template that hundreds of developers are using, when I make an enhancement to that template, I'm looking for an automated way for those hundreds of developers to update there template to the latest version.

webketje commented 1 year ago

Motion to close: this is out of scope for Nunjucks itself. Distribute the template as part of an NPM package or re-upload it to a CDN-like server.

regicsolutions commented 1 year ago

Ok thanks, appreciate the reply! Making it an NPM package isn’t a bad idea, only downside is it adds an additional layer for non-NPM projects. Never seen something like this done with a CDN-like server, you wouldn’t happen to have any examples would you? Assuming a custom cli would be needed?

webketje commented 1 year ago

@regicsolutions sorry I thought this was pretty self-explanatory. I would prefer the NPM approach, but here's an example of using the CDN approach. If you have a super-simple FTP server reachable at https://my.server.com with a directory cdn/templates, upload your templates there under version folders. Use symlinks to create "permanent" URLs (eg latest uploaded version to "latest"). All of this can be automated through CI pipelines.

https://my.server.com/cdn/templates/footer/v0.5.1/template.njk
https://my.server.com/cdn/templates/footer/v1.0.0/template.njk
https://my.server.com/cdn/templates/footer/v1.2.0/template.njk
https://my.server.com/cdn/templates/footer/v0/template.njk --> points to latest v0
https://my.server.com/cdn/templates/footer/latest/template.njk --> points to v1.2.0

Developers then simply use curl,wget (can be automated in a CI script) or manually navigate to the URL to update the template.