{"id":15285323,"url":"https://github.com/zhs007/zhandlebars","last_synced_at":"2026-01-05T15:04:42.938Z","repository":{"id":57405810,"uuid":"47675201","full_name":"zhs007/zhandlebars","owner":"zhs007","description":null,"archived":false,"fork":false,"pushed_at":"2016-01-30T17:49:42.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-04T19:47:40.933Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/zhs007.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}},"created_at":"2015-12-09T07:15:51.000Z","updated_at":"2016-01-30T17:31:45.000Z","dependencies_parsed_at":"2022-09-11T23:51:22.996Z","dependency_job_id":null,"html_url":"https://github.com/zhs007/zhandlebars","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhs007%2Fzhandlebars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhs007%2Fzhandlebars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhs007%2Fzhandlebars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhs007%2Fzhandlebars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhs007","download_url":"https://codeload.github.com/zhs007/zhandlebars/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245152769,"owners_count":20569399,"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":[],"created_at":"2024-09-30T15:04:12.710Z","updated_at":"2026-01-05T15:04:42.931Z","avatar_url":"https://github.com/zhs007.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zHandlebars\n**zHandlebars** 是一个基于 **Handlebars** 的项目生成器。\n\nHow\n---\n我们会需要根据一组模板生成一个初始项目，一般来说，目录复制，然后改一些小地方即可。\n\n但还有可能生成的文件名和项目名有关系，目录结构可能也和项目名有关，甚至会根据一组不定数量的最终生成的文件等等。\n\n而 **zHandlebars** 就是用来做这件事的。\n\n我们基于模板引擎 **Handlebars** ，也就是说所有的语法和 **Handlebars** 一致，我们就是在 **Handlebars** 对一个文件处理的基础上，增加了一个组合配置文件，而且这个配置文件支持通配符，支持 **Handlebars** 语法。\n\n这个配置文件我们用json的格式来保存：\n\n```\n[\n  {\"name\": \"{{projname_lc}}\", \"src\": \"\", \"type\": \"dir\"},\n  {\"name\": \"{{projname_lc}}/bin/{{projname_lc}}.js\", \"src\": \"/main/bin/main.js\", \"type\": \"file\"},\n  {\"name\": \"{{projname_lc}}/config.js\", \"src\": \"/main/config.js\", \"type\": \"file\"},\n  {\"name\": \"{{projname_lc}}/package.json\", \"src\": \"/main/package.json\", \"type\": \"file\"},\n  {\"name\": \"{{projname_lc}}/lib/*.js\", \"src\": \"/main/lib/*.js\", \"type\": \"file\"},\n  {\"name\": \"{{projname_lc}}/src/*.js\", \"src\": \"/main/src/*.js\", \"type\": \"file\"},\n  {\"name\": \"{{projname_lc}}/ctrl/*.js\", \"src\": \"/main/ctrl/*.js\", \"type\": \"file\"}\n]\n```\n\n上面可以看到，其实这个配置文件就是一个简单的json数组，每个元素是一条匹配条件，其中 name 表示目标文件或目录名，src 表示原始文件名，type 是类型，目前就 **dir**、**file**、**binfile** 3种，如果是 dir，就只是建目录而已，所以 src 可以给空字符串。\n\n特别提一下 **overwrite** 属性，这个属性主要用于 **type** 是 **file** 或者 **binfile** 的，有3个值，分别是 **w** 、 **r** 、 **rw** ，表示如果源文件存在时，是直接覆盖写，还是彻底放弃处理，或者是读取已经存在的目标文件里的标识内容，重新整合写入，默认是 **w** ，如果是 **binfile** ，**rw** 就是 **w** 。\n\n如果是 **file** 或者 **binfile** ，这里支持通配符，通配符的规则兼容 **[glob](https://github.com/isaacs/node-glob)** 。\n\n规则上，是会先把这个配置文件通过模板引擎 **Handlebars** 处理一轮，然后按顺序新建目录和文件，新建文件的时候，其实会自动把不存在的目录生成出来的，不需要特别处理目录。\n\n有了配置文件和模板文件外，使用起来就非常简单了。\n\n```\n\"use strict\";\n\nvar path = require('path');\nvar zhandlebars = require('../lib/index');\n\nlet params = {projname: 'test', projname_lc: 'test'};\nzhandlebars.procProj(params, path.join(__dirname, './zrestify.json'), path.join(__dirname, './'));\n```\n\n更新说明\n---\n* **ver 0.1.7**\n * json配置文件里支持 **overwrite** ，可以决定这个文件的覆盖规则，主要用于处理文件时，如果目标文件已经存在，使用何种方式来处理。\n\n* **ver 0.1.6**\n * json配置文件里支持 **jscode** ，可以在处理这个文件的时候执行一段js脚本，主要是用来处理批量的参数的。\n\n* **ver 0.1.3**\n * 支持 **binfile** 类型，对于不需要模板处理的文件都可以这样设置，会快一些。\n\n\n使用到的第三方库\n---\n\n* 使用 **[glob](https://github.com/isaacs/node-glob)** 做文件通配符处理。\n* 使用 **[handlebars](https://github.com/wycats/handlebars.js/)** 模板做基本代码模板。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhs007%2Fzhandlebars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhs007%2Fzhandlebars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhs007%2Fzhandlebars/lists"}