Templates CLI

Have You ever wanted to create new NextJS route which let You use query parameters using useSearchParams hook?
Or insert a server side page exporting load and action functions for SvelteKit with new satisfies operator?
Or make a Java Spring Controller files with all the @Annotations and routes set for GET, POST, PUT ready?

And You always needed to check the documentation, because You forget how excatly the pages looks like? Which hooks to use, what types to import, how to properly name the functions?

If yes, then Templates CLI is for You :).

It's a simple tool that let's You very easly create, manage and use a set of templates pages for Your projects.

Full written in Rust (needed to point it out, cos this is why You learn Rust, right?).

Best way to learn is by example!

tp add svelte p ps e -p reports

This will create a +page.svelte, +page.server.ts, +error.ts in ./reports folder, each containing their own template You prepared beforehand (containing types, function, whatever You want).

Install

cargo install templates

Please make sure that ~/.cargo/bin is in your PATH.
In the future more distro related options will be added :)

Usage

Config

First thing You need to do is set up a templates folder. Default value is ~/tmp.

tp set [path_to_your_templates_folder]

Inside this folder create a subfolders for each group of templates (e.g. svelte, next). Then add files inside in a format [cli_shortcut]template_name.

Few examples:

Add

tp add <lib> [pages] -p <path>

Using example settings from config section:

tp add next p lj

This will create a page.ts and layout.js in ./ dir and copy content of next/[p]page.ts and next/[lj]layout.js respectively inside them.

Print

tp print

Print the current configuration.