{"id":26830627,"url":"https://github.com/guichaguri/jatg","last_synced_at":"2025-03-30T14:16:49.784Z","repository":{"id":247200110,"uuid":"825232507","full_name":"Guichaguri/jatg","owner":"Guichaguri","description":"Just Another Template Generator","archived":false,"fork":false,"pushed_at":"2024-07-26T11:46:19.000Z","size":204,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T18:36:02.399Z","etag":null,"topics":["template","template-generator"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/jatg","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Guichaguri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-07T07:38:47.000Z","updated_at":"2024-07-26T11:46:23.000Z","dependencies_parsed_at":"2024-07-26T11:06:08.496Z","dependency_job_id":null,"html_url":"https://github.com/Guichaguri/jatg","commit_stats":null,"previous_names":["guichaguri/jatg"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guichaguri%2Fjatg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guichaguri%2Fjatg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guichaguri%2Fjatg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guichaguri%2Fjatg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Guichaguri","download_url":"https://codeload.github.com/Guichaguri/jatg/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246326783,"owners_count":20759439,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["template","template-generator"],"created_at":"2025-03-30T14:16:49.292Z","updated_at":"2025-03-30T14:16:49.776Z","avatar_url":"https://github.com/Guichaguri.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jatg - just another template generator\n\njatg is a low configuration tool to generate files based on templates.\n\nMost template generation tools require elaborate configurations, lack intuitive usage, are tied to a specific framework or do not support variable transformations.\nThe objective of this tool is to be as intuitive as possible while providing a flexible feature set.\n\nSimply create your template files, add them to the configuration file and then run `jatg` to generate the resulting files.\n\n## Setting Up\n\n### Create the `templates.json`\n\nYou can create the file by running `npx jatg --init`, or just start by copying the example below:\n\n**templates.json**\n```json\n{\n  \"$schema\": \"https://unpkg.com/jatg/templates.schema.json\",\n  \"templates\": [\n    {\n      \"name\": \"my-awesome-template\",\n      \"sourcePaths\": [\"./templates\"],\n      \"outputPath\": \"./src/modules\",\n      \"variables\": [\n        {\n          \"variable\": \"name\",\n          \"name\": \"Module Name\"\n        }\n      ]\n    }\n  ]\n}\n```\n\nRead the [configuration reference](#configuration) for a list of all possible properties.\n\n### Create your template files\n\nYou can have as many files as needed for a single template.\n\n**templates/%name%.ts**\n```\nexport class %name.pascalCase% {\n  // ...\n}\n```\n\nThe template can have variables, and they can be transformed through functions. Read more about them in the [variables reference](#variables).\n\n### Run it\n\nJust run the CLI to generate files based on the templates created.\n\nYou'll be prompted which template you want to generate, and what are the variable values.\n\n```sh\nnpx jatg\n```\n\nPretty straightforward, isn't it?\n\n---\n\n## Reference\n\n### Variables\n\nA template can have multiple variables. Those can be defined in the configuration and can be used to make template contents and file names dynamic.\n\nThe syntax is the variable name surrounded by percentages (`%variable_name%`) and the value can be formatted through special functions, separated by dots (`%variable_name.upper%`).\n\nFor the variable named `entity` and the value `user-post`, here are a few examples:\n\n| Template                        | Result       | What is hapenning?                                                          |\n|---------------------------------|--------------|-----------------------------------------------------------------------------|\n| `%entity%`                      | `user-post`  | prints the variable value as-is                                             |\n| `%entity.upper%`                | `USER-POST`  | prints the variable formatted value in uppercase                            |\n| `%entity.plural.upper%`         | `USER-POSTS` | prints the variable value formatted in plural and in uppercase              |\n| `%entity.plural.dotCase.upper%` | `USER.POSTS` | prints the variable value formatted in plural, in dot case and in uppercase |\n\nVariables can be used in template file contents, the template file name and the configuration `outputPath`.\n\nVariables that are not defined in the configuration file will be ignored and kept as-is. However, valid variables with invalid formatting functions will throw an error.\n\n#### Formatting Functions\n\n##### Basic\n\nThese are based on the basic string functions included in JavaScript.\n\n| Function   | Before       | After      |\n|------------|--------------|------------|\n| `upper`    | \"TwoWords\"   | \"TWOWORDS\" |\n| `lower`    | \"TwoWords\"   | \"twowords\" |\n| `trim`     | \" TwoWords \" | \"TwoWords\" |\n| `unaccent` | \"maçã\"       | \"maca\"     |\n\n##### Change Case\n\nThese functions use [change-case](https://www.npmjs.com/package/change-case) under the hood.\n\n| Function          | Result      |\n|-------------------|-------------|\n| `camelCase`       | `twoWords`  |\n| `capitalCase`     | `Two Words` |\n| `constantCase`    | `TWO_WORDS` |\n| `dotCase`         | `two.words` |\n| `kebabCase`       | `two-words` |\n| `noCase`          | `two words` |\n| `pascalCase`      | `TwoWords`  |\n| `pascalSnakeCase` | `Two_Words` |\n| `pathCase`        | `two/words` |\n| `sentenceCase`    | `Two words` |\n| `snakeCase`       | `two_words` |\n| `trainCase`       | `Two-Words` |\n| `initials`        | `TW`        |\n\n##### Pluralize\n\nThese functions use [pluralize](https://www.npmjs.com/package/pluralize) under the hood.\n\n| Function   | Result     |\n|------------|------------|\n| `plural`   | `twoWords` |\n| `singular` | `twoWord`  |\n\n\n### Template files\n\n#### File names and directories\n\nThe `sourcePaths` is a list of paths to template files and directories that contain template files.\n\nFor directories, all files inside it will be considered templates.\nThe directory structure will be kept for the generated results.\n\nThe file names don't need to follow any specific extension.\nIf you need to, you can end them with `.template`.\nThe `.template` extension will be removed for the resulting file.\n\nThe file names, directories and the `outputPath` can contain [variables](#variables).\n\nHere's an example of the folder structure:\n```\ntemplates/\n├── entities/\n│   └── %name%.entity.ts.template\n└── models/\n    └── %name%.model.ts.template\n```\n\nThe [templates.json](#configuration) file:\n```json5\n// templates.json\n{\n  // ...\n  \"sourcePaths\": [\"./templates\"],\n  \"outputPath\": \"./src/modules/%name%\",\n  // ...\n}\n```\n\nThe resulting files for the variable `name` being \"product\":\n```\nsrc/\n└── modules/\n    └── product/\n        ├── entities/\n        │   └── product.entity.ts\n        └── models/\n            └── product.model.ts\n```\n\n#### Template file contents\n\nTemplate files must be in plain text encoded in UTF-8.\nThe files can contain as many [variables](#variables) as needed.\n\n\n### Configuration\n\nThe format of the `template.json` file is also documented through the [TemplateConfiguration TypeScript interface](https://github.com/Guichaguri/jatg/blob/main/src/models/template.model.ts) and the [JSON Schema](https://github.com/Guichaguri/jatg/blob/main/templates.schema.json).\n\n#### Root\n\n| Property     | Type                                                  | Required | Description                                                        |\n|--------------|-------------------------------------------------------|----------|--------------------------------------------------------------------|\n| `templates`  | array\\\u003c[Template Definition](#template-definition)\u003e   | Required | The list of templates that can be generated                        |\n| `composites` | array\\\u003c[Composite Definition](#composite-definition)\u003e |          | The list of templates that are a combination of multiple templates |\n\n#### Template Definition\n\n| Property      | Type                                                | Required | Description                                                                                      |\n|---------------|-----------------------------------------------------|----------|--------------------------------------------------------------------------------------------------|\n| `name`        | string                                              | Required | The template name                                                                                |\n| `sourcePaths` | array\\\u003cstring\u003e                                      | Required | The path list of template files or directories containing templates                              |\n| `outputPath`  | string                                              | Required | The output directory where the source paths will be copied into. The path can contain variables. |\n| `variables`   | array\\\u003c[Variable Definition](#variable-definition)\u003e | Required | The variables that the user can type. These variables will be replaced in the final template     |\n\n#### Variable Definition\n\n| Property        | Type                   | Required | Description                                                                                                      |\n|-----------------|------------------------|----------|------------------------------------------------------------------------------------------------------------------|\n| `variable`      | string                 | Required | The variable identification                                                                                      |\n| `name`          | string                 |          | A human-redable name                                                                                             |\n| `description`   | string                 |          | A human-redable description                                                                                      |\n| `type`          | `\"text\"` \\| `\"number\"` |          | The variable type. This is used for input validation. Defaults to `\"text\"`.                                      |\n| `choices`       | array\\\u003cstring\u003e         |          | A list of choices that the user can pick. If this property defined, the user can only pick one of these options. |\n| `initial`       | string \\| number       |          | The initial value                                                                                                |\n| `allowEmpty`    | boolean                |          | Whether this variable allows empty values. Defaults to `false`.                                                  |\n| `preprocessing` | array\\\u003cstring\u003e         |          | The list of [formatting functions](#formatting-functions) to apply globally for this variable.                   |\n\n#### Composite Definition\n\n| Property    | Type           | Required | Description                                      |\n|-------------|----------------|----------|--------------------------------------------------|\n| `name`      | string         | Required | The name of the composite                        |\n| `templates` | array\\\u003cstring\u003e | Required | The list of template names that will be combined |\n\n\n### CLI\n\n#### Install\n\n##### npx\n\nYou can run the generation through npx by simply running the command: `npx jatg`.\n\n##### Global\n\nYou can also install globally through `npm install --global jatg` and run it directly through `jatg`.\n\n##### Project\n\nYou can also install it as a dev dependency to your project through `npm install -D jatg` and add a script in your `package.json`:\n\n```json5\n{\n  // ...\n  \"scripts\": {\n    \"generate\": \"jatg\"\n  }\n  // ...\n}\n```\n\nThen you can run it through `npm run generate`.\n\n#### Options\n\nYou can also specify options, such as picking a specific template:\n```sh\nnpx jatg --template my-awesome-template\n```\n\nAlternatively, you can use environment variables to set the option values.\n\n| Description                                                  | Option                     | Environment Variable        | Default Value      |\n|--------------------------------------------------------------|----------------------------|-----------------------------|--------------------|\n| Sets the base for other paths                                | `--base-path`, `-b`        | `JATG_BASE_PATH`            | `./`               |\n| The path for the configuration file                          | `--templates-config`, `-c` | `JATG_TEMPLATE_CONFIG_PATH` | `./templates.json` |\n| Sets which template will be used, which will not be prompted | `--template`, `-t`         | `JATG_TEMPLATE_NAME`        |                    |\n| Sets a template variable value, which will not be prompted   |                            | `JATG_VARIABLE_*`[^1]       |                    |\n| Whether the generated files should overwrite existing ones   | `--overwrite`, `-o`        |                             | false              |\n| Initializes a new template                                   | `--init`                   |                             |                    |\n| Prints the command manual                                    | `--help`                   |                             |                    |\n| Prints the jatg version                                      | `--version`                |                             |                    |\n\n[^1]: Environment variables prefixed with `JATG_VARIABLE_` will fill the respective template variable.\nFor example, if you want to set the value of a template variable named `foobar`, you can add the environment variable `JATG_VARIABLE_FOOBAR` and it will not be prompted on generation. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguichaguri%2Fjatg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguichaguri%2Fjatg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguichaguri%2Fjatg/lists"}