{"id":21269585,"url":"https://github.com/fardjad/node-templgen","last_synced_at":"2026-02-01T05:33:12.838Z","repository":{"id":187457637,"uuid":"676937559","full_name":"fardjad/node-templgen","owner":"fardjad","description":"Extensible template based file generator","archived":false,"fork":false,"pushed_at":"2024-12-10T01:27:54.000Z","size":1703,"stargazers_count":0,"open_issues_count":12,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-26T14:38:50.227Z","etag":null,"topics":["boilerplate","cli-library","code-generation","code-generator","ejs","file-generator","generate","generator","node-module","scaffold","scaffolding","template","typescript-library"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/templgen","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/fardjad.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":"2023-08-10T11:03:59.000Z","updated_at":"2024-04-22T12:11:00.000Z","dependencies_parsed_at":"2023-08-10T15:31:46.233Z","dependency_job_id":"2a603219-b539-4875-ad69-2b0ab35edf05","html_url":"https://github.com/fardjad/node-templgen","commit_stats":{"total_commits":168,"total_committers":2,"mean_commits":84.0,"dds":"0.13095238095238093","last_synced_commit":"814afe85a680d20a35d775104cb5d39e7a533e96"},"previous_names":["fardjad/node-templgen"],"tags_count":147,"template":false,"template_full_name":null,"purl":"pkg:github/fardjad/node-templgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fardjad%2Fnode-templgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fardjad%2Fnode-templgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fardjad%2Fnode-templgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fardjad%2Fnode-templgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fardjad","download_url":"https://codeload.github.com/fardjad/node-templgen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fardjad%2Fnode-templgen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28970034,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T04:44:20.970Z","status":"ssl_error","status_checked_at":"2026-02-01T04:44:19.994Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["boilerplate","cli-library","code-generation","code-generator","ejs","file-generator","generate","generator","node-module","scaffold","scaffolding","template","typescript-library"],"created_at":"2024-11-21T08:09:04.532Z","updated_at":"2026-02-01T05:33:12.822Z","avatar_url":"https://github.com/fardjad.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# TemplGen\n\n\u003cimg alt=\"TemplGen Logo\" width=\"300px\" height=\"300px\" src=\"./media/logo.png\"\u003e\n\nExtensible template based file generator\n\n\u003cdiv class=\"paragraph\"\u003e\n\n\u003cspan class=\"image\"\u003e\u003ca href=\"https://www.npmjs.com/package/templgen\" class=\"image\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/templgen\" alt=\"templgen\" /\u003e\u003c/a\u003e\u003c/span\u003e \u003cspan class=\"image\"\u003e\u003ca href=\"https://www.npmjs.com/package/templgen\" class=\"image\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/templgen\" alt=\"templgen\" /\u003e\u003c/a\u003e\u003c/span\u003e \u003cspan class=\"image\"\u003e\u003ca href=\"https://github.com/fardjad/node-templgen/actions\" class=\"image\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/fardjad/node-templgen/test-and-release.yml?branch=main\" alt=\"test and release\" /\u003e\u003c/a\u003e\u003c/span\u003e\n\n\u003c/div\u003e\n\n\u003c/div\u003e\n\n\u003chr /\u003e\n\nTemplGen is a small and extensible template based file generator module that\nprovides a simple API for creating code scaffolding tools.\n\nIt borrows some ideas from [Nx][1] but it is meant to be used as a\nbuilding block for creating CLI tools rather than being a full fledged tool\nitself.\n\n## Features\n\n- ESM and CommonJS support\n- Support for copying binary files as well as rendering template files\n- Variable substitution in file names\n- Use EJS (by default) or [any other template engine][2]\n- Overridable file system methods. You can [override][3] the default functions used\n  to create directories, read files, write files, and copy files. That is\n  useful for [testing][4], logging, implementing interactive prompts, etc.\n\n## Installation\n\n```bash\nnpm install --save templgen\n```\n\n## Usage\n\n```javascript\nimport { FileGenerator } from \"templgen\";\n\nconst sourceDirectory = \"/source/directory\";\nconst targetDirectory = \"/target/directory\";\nconst files = [\n  // Will be copied to /target/directory/copy_as_is\n  \"/source/directory/copy_as_is\",\n  // Will be rendered with EJS and written to /target/directory/render_with_ejs\n  \"/source/directory/render_with_ejs.template\",\n  // Will be copied to /target/directory/subdir/replaced.txt\n  \"/source/directory/subdir/__variable__.txt\",\n];\nconst variables = {\n  variable: \"replaced\",\n};\n\nconst fileGenerator = new FileGenerator();\nawait fileGenerator.generate(\n  sourceDirectory,\n  targetDirectory,\n  files,\n  variables,\n);\n```\n\nSee [example](./example) for a working example.\n\n### Advanced Usage\n\n#### Custom File System Functions\n\n```javascript\nimport fs from \"node:fs\";\nimport { FileGenerator } from \"templgen\";\n\nconst sourceDirectory = \"/source/directory\";\nconst targetDirectory = \"/target/directory\";\nconst files = [\"/source/directory/render_with_ejs.template\"];\nconst variables = {\n  variable: \"replaced\",\n};\n\nconst myWriteFile = async (filePath, ...arguments_) =\u003e {\n  console.log(`Writing file: ${path.relative(targetDirectory, filePath)}`);\n  // you can show a prompt here\n  return fs.promises.writeFile(filePath, ...arguments_);\n};\nconst myCopyFile = async (sourcePath, destinationPath, ...arguments_) =\u003e {\n  console.log(\n    `Writing file: ${path.relative(targetDirectory, destinationPath)}`,\n  );\n  // you can show a prompt here\n  return fs.promises.copyFile(sourcePath, destinationPath, ...arguments_);\n};\n\nconst fileGenerator = new FileGenerator({\n  writeFile: myWriteFile,\n  copyFile: myCopyFile,\n  // you can override mkdir and readFile too\n});\n\nawait fileGenerator.generate(\n  sourceDirectory,\n  targetDirectory,\n  files,\n  variables,\n);\n```\n\n#### Custom Template Engine\n\n```javascript\nimport Handlebars from \"handlebars\";\nimport { FileGenerator } from \"templgen\";\n\nconst sourceDirectory = \"/source/directory\";\nconst targetDirectory = \"/target/directory\";\nconst files = [\n  // Will be rendered with custom template engine and written to /target/directory/render_with_custom\n  \"/source/directory/render_with_custom.template\",\n];\nconst variables = {\n  variable: \"replaced\",\n};\n\nconst fileGenerator = new FileGenerator({\n  render: async (template, variables, paths) =\u003e {\n    // The paths in the paths object can be used for caching, logging, etc.\n    console.log(paths);\n\n    return Handlebars.compile(template)(variables);\n  },\n});\n\nawait fileGenerator.generate(\n  sourceDirectory,\n  targetDirectory,\n  files,\n  variables,\n);\n```\n\n[1]: https://nx.dev/core-features/plugin-features/use-code-generators\n[2]: #custom-template-engine\n[3]: #custom-file-system-functions\n[4]: ./src/index.test.ts\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffardjad%2Fnode-templgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffardjad%2Fnode-templgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffardjad%2Fnode-templgen/lists"}