{"id":26255067,"url":"https://github.com/mjgang/hbs-commander","last_synced_at":"2026-02-13T07:08:02.132Z","repository":{"id":273299022,"uuid":"919249761","full_name":"MJGang/hbs-commander","owner":"MJGang","description":"A library for intelligently inserting and replacing Handlebars templates with context-aware placement","archived":false,"fork":false,"pushed_at":"2025-03-20T02:07:56.000Z","size":99,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-04T16:58:01.532Z","etag":null,"topics":["automated","code-generator","handlebars","intelligence","low-code","templates"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/MJGang.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,"zenodo":null}},"created_at":"2025-01-20T03:30:23.000Z","updated_at":"2025-03-24T09:52:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"222bcdd9-37b2-4da5-90cb-b2d9ffc0a208","html_url":"https://github.com/MJGang/hbs-commander","commit_stats":null,"previous_names":["mjgang/hbs-commander"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MJGang/hbs-commander","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MJGang%2Fhbs-commander","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MJGang%2Fhbs-commander/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MJGang%2Fhbs-commander/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MJGang%2Fhbs-commander/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MJGang","download_url":"https://codeload.github.com/MJGang/hbs-commander/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MJGang%2Fhbs-commander/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265311871,"owners_count":23745161,"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":["automated","code-generator","handlebars","intelligence","low-code","templates"],"created_at":"2025-03-13T19:17:09.315Z","updated_at":"2026-02-13T07:08:02.105Z","avatar_url":"https://github.com/MJGang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://img.shields.io/npm/v/hbs-commander.svg?style=flat-square)](https://www.npmjs.com/package/hbs-commander)\n[![npm downloads](https://img.shields.io/npm/dm/hbs-commander.svg?style=flat-square)](https://npm-stat.com/charts.html?package=hbs-commander)\n[![License](https://img.shields.io/npm/l/hbs-commander.svg?style=flat-square)](https://github.com/MJGang/hbs-commander/blob/main/LICENSE)\n\n[中文文档](README_ZH.md)\n\n# 🛠️ hbs-commander\n\nA tool to simplify Handlebars template operations with precise control over content placement.\n\n## ✨ Features\n\n- **📝 Comment Mode**: Inject syntax rules by parsing Handlebars comments\n- **⚙️ Config Mode**: Implement functionality through configuration options\n- **🔧 Multiple Operations**: Supports append, prepend, replace, new, cover and more\n- **🎯 Parameter Support**: Flexible parameter passing similar to Vue template syntax\n- **🧙 Magic-string Integration**: Precise content manipulation with magic-string library\n- **📁 Directory Processing**: Recursive directory handling\n- **🔄 Auto Extension Handling**: Automatically remove .hbs extension\n- **🚫 File Filtering**: Only process .hbs template files\n- **📂 Auto Directory Creation**: Create missing target directories\n- **⏱️ Deferred Write**: Prevent race conditions by deferring file writes\n\n## 📦 Installation\n\n```bash\n# Using npm\nnpm install hbs-commander\n\n# Using yarn \nyarn add hbs-commander\n\n# Using pnpm\npnpm add hbs-commander\n```\n\n## 🚀 Usage\n\n### Comment Mode (Default)\n\n```hbs\n{{!-- append --}}\n\u003cdiv class='new-content'\u003e\n  \u003cp\u003eappend content\u003c/p\u003e\n\u003c/div\u003e\n{{!-- /append --}}\n```\n\n```javascript\nimport hbscmd from 'hbs-commander';\n\nhbscmd({\n  template: './template.hbs',\n  target: './target/file.vue'\n});\n```\n\n### Config Mode\n\n```javascript\nimport hbscmd from 'hbs-commander';\n\nhbscmd({\n  template: './template.hbs',\n  target: './target/file.vue',\n  mode: 'config',\n  type: 'append'\n});\n```\n\n### Directory Processing Example\n\n```javascript\n// Process entire directory\nhbscmd({\n  template: './templates',  // Template directory\n  target: './src',          // Target directory\n  mode: 'comment'           // or 'config'\n})\n```\n\n### Deferred Write Mode\n\nUse deferred write to prevent race conditions when multiple operations modify the same file:\n\n```javascript\n// Multiple operations on the same file\nawait Promise.all([\n  hbscmd({\n    template: './template1.hbs',\n    target: './target/file.vue',\n    deferWrite: true  // Enable deferred write\n  }),\n  hbscmd({\n    template: './template2.hbs',\n    target: './target/file.vue',\n    deferWrite: true  // Enable deferred write\n  })\n]);\n\n// Flush all changes to disk after all operations are complete\nawait hbscmd.applyDeferredWrites();\n```\n\n### Extension Handling Rules\n\nTemplate naming convention:\n\n- `filename.ext.hbs` → `filename.ext`\n- `filename.hbs` → `filename`\n\nExamples:\n\n- `button.html.hbs` → `button.html`\n- `main.js.hbs` → `main.js`\n- `config.hbs` → `config`\n\n## 📋 Supported Operations\n\n| Operation | Description | Attrs |\n|-----------|-------------|--------|\n| ➕ append    | Append content to target | `newLine` |\n| ⬅️ appendLeft | Append content to the left | `newLine`,`index`, `row`, `col` |\n| ➡️ appendRight | Append content to the right | `newLine`,`index`, `row`, `col` |\n| ⬆️ prepend   | Prepend content to target | `newLine` |\n| ⏴ prependLeft | Prepend content to the left | `newLine`,`index` |\n| ⏵ prependRight | Prepend content to the right | `newLine`,`index` |\n| 🔄 replace   | Replace content in target | `regexpOrString` |\n| 🆕 new       | Create new file with content |  |\n| 🖊️ cover     | Overwrite target file with content |  |\n\n## 🤝 Contributing\n\nContributions are welcome! Please follow these steps:\n\n1. Fork the repository\n2. Create a new branch (git checkout -b feature/your-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push to the branch (git push origin feature/your-feature)\n5. Create a new Pull Request\n\n## 📜 License\n\nMIT © [MJGang](https://github.com/MJGang)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjgang%2Fhbs-commander","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmjgang%2Fhbs-commander","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjgang%2Fhbs-commander/lists"}