-
Notifications
You must be signed in to change notification settings - Fork 0
Support for local/private templates #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm not sure if I understand exactly what you need, but:
tmplr owner/repo/subdirectory
# .tmplr.tml
run: ./templates/some-recipe.yml Which can be combined with What you currently can't do, but should be easy to add the support for:
tmplr -r ./templates/some-other-template.yml
|
Yes, subdirectories are per degit support. My thoughts were manly on private repositories and on the missing feature of Vite template to scaffold the project when we have to use custom templates (not the one provided by Vite) For example Vite has out of the box templates https://vitejs.dev/guide/#scaffolding-your-first-vite-project that can be scaffoled like: but in case of custom Vite template and together with tmplr we have to make it into three commands:
Idea was to have a tmplr starter that can handle above in a single command like: Starter will create directory my-react-app, cd into it, copy/checkout the project and run the tmplr recipe. Like nextjs starter or any other https://petermekhaeil.com/how-to-build-an-npx-starter-template/ but with the ability to use any repo or local directory. |
Doing those 3 in one command line is already supported (though unfortunately, not documented yet). You can do what you specified in one command like this: npx tmplr owner/repo -d my-react-app |
Thanks a lot for the single command, so it would be possible to use both paremters |
it would be, though some modifications would be required. right now, template recipes can only operate in their given scope: when you receive them from some remote repository, the content of the repository is cloned to the working directory, and when you run them locally (without passing any arguments), then they are executed within the given working directory. to emulate similar behavior and without requiring weird new mechanism for access control, the all that said, until such steps:
- read: name
prompt: What is the package name?
- read: template
prompt: Which template you want to use?
choices:
- first
- second
- run: './templates/{{template}}/.tmplr.yml'
with:
name: '{{name}}'
target:
path: './packages/{{name}}' where you have steps:
# this makes the name variable accessible in copied files
- read: name
from: args.name
- copy: README.md
to:
path: '{{args.target}}/README.md' then you would be able to create new packages in I have setup an example sandbox for this particular use case. You can fork it, open a terminal and run |
Thanks a lot for the solution. |
further reflection on implementation: while allowing filesystems to also read from some out-of-scope addresses (predetermined on construction), and effectively separating read-scope from write-scope, this is a fundamental change with a lot of side effects, some perhaps involving security issues. the leaner method would be to merely copy the contents of given folder into working directory, basically treating local files as another source. this can be done before any recipe is executed, removing the need to increase the execution scope of recipes in any way. additionally, this allows local templates to perfectly mirror remote templates, which should make it easier to write and maintain them. this solution would perhaps look something like this: npx tmplr file:./templates/first-template -d ./packages/my-new-package |
using local templates is supported from tmplr local:/my/template |
Hi,
Is it possible to create a project from local templates (
templates/*
) that are not published in a seperate repository, but are part of a monorepo (pnpm workspace using NX package based approach).Idea is to have a command like Vite
pnpm create vite my-vue-app --template vue
where the template can be either remote repository or local file path, it will create a folder with the provided name (can be exposed as default npm package name) and will copy content from local template or checkout (using degit) from remote repisitory.Vite community templates are only supported using
degit
but without any project scaffolding as per documentation https://vitejs.dev/guide/#community-templates.Im happy for
tmplr
and realy found it via the degit issue Rich-Harris/degit#30, it is a good fit to scaffold a package based NX workspace and created seperate feature request nrwl/nx#17979.The text was updated successfully, but these errors were encountered: