{"id":18532253,"url":"https://github.com/wyyxdgm/gm3","last_synced_at":"2026-04-29T17:01:28.106Z","repository":{"id":52159335,"uuid":"146839431","full_name":"wyyxdgm/gm3","owner":"wyyxdgm","description":"constructing your world by snippets","archived":false,"fork":false,"pushed_at":"2021-05-06T19:22:59.000Z","size":55,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T23:33:14.152Z","etag":null,"topics":["ejs","json2html","template"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wyyxdgm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-31T03:55:09.000Z","updated_at":"2023-05-14T04:25:29.000Z","dependencies_parsed_at":"2022-08-28T13:31:16.924Z","dependency_job_id":null,"html_url":"https://github.com/wyyxdgm/gm3","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wyyxdgm%2Fgm3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wyyxdgm%2Fgm3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wyyxdgm%2Fgm3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wyyxdgm%2Fgm3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wyyxdgm","download_url":"https://codeload.github.com/wyyxdgm/gm3/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254240248,"owners_count":22037847,"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":["ejs","json2html","template"],"created_at":"2024-11-06T19:05:10.157Z","updated_at":"2026-04-29T17:01:28.043Z","avatar_url":"https://github.com/wyyxdgm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GM3\n\n一个公共的html代码模板工具。可以借助模板引擎，将一些变动的元素以json数据的形式加以抽象，然后渲染到模板中，生成目标文件。让模板成为真正的模板。(模板引擎采用[EJS](https://github.com/mde/ejs))\n\n## Getting Started\n\n\n可以使用gm3全局安装npm包，直接执行 gm3 生成对应内容\n\n### 环境基础\n\n1.需要node环境，参考[Installing Node.js via package manager](https://nodejs.org/en/download/package-manager/)  \n\n2.安装gm3\n\n* 通过代码调用: `require('gm3')`\n```\nnpm install gm3 \n```\n\n* 全局使用 `gm3`\n```\nnpm install -g gm3       # or [url of this repository]\n```\n\n### 开发指南\n\n资源结构（举例）\n\n```\n├── demo3.html              #主要html源文件，文件名，通过gm.json配置。\n├── demo3.json              #主要json源文件，文件名，通过gm.json配置。\n├── gm.html                 #由gm生成的html，默认目标生成文件\n├── gm.json                 #gm.json是读取配置的入口文件，每个包下都必须有\n└── gm_components           #gm安装的依赖模板包\n    ├── demo1@V1.0.0\n    │   ├── demo1.html\n    │   ├── demo1.json\n    │   └── gm.json\n    └── demo2@V1.0.0\n        ├── demo2.html\n        ├── demo2.json\n        └── gm.json\n\n```\n\n## 架构解释\n\n* 资源至少包含gm.json，以及配置的html/json两个文件\n\n```\ndemo3@V1.0.0\n├── demo3.html\n├── demo3.json\n└── gm.json\n```\n\n* gm.json\n\n主体框架下，gm.json会配置源文件的文件名称（不带后缀），以及依赖关系。\n\n```\n{\n  \"name\": \"demo3\",              #project name \u0026\u0026 gm publish name\n  \"main\": \"demo3\",              #main source file\n  \"input\": {                    #if defineded,take this instead of 'main'\n    \"template\": \"./demo3.html\",\n    \"data\": \"demo3.json\"\n  },\n  \"output\": \"gm.html\",          #target file for building, 'gm.html' as defult\n  \"dependencies\": {             #the templates that used in this project\n    \"demo1\": \"@1.0.0\",\n    \"demo2\": \"@1.0.0\"\n  }\n}\n```\n\n**输入数据的指定**  `main` 和 `input` 都是用来指定输入源的。优先级: input \u003e main。  \n\n    `main` 无需后缀。默认 ${main}.html 和 ${main}.js（或 ${main}.json）  \n    `input` 包含template和data，值为文件相对路径。\n\n**输出数据的指定** `output` 配置输出路径。（默认gm.html）  \n\n* demo3.html\n\npartOne，partTwo，partThree都是html文本。采用\u003c%-%\u003e，语法参考 [EJS](https://github.com/tj/ejs)\n\n```\n\u003cdiv id=\"demo3\"\u003e\n  \u003cdiv class=\"part1\"\u003e\n    \u003c%-partOne%\u003e\n  \u003c/div\u003e\n  \u003cdiv class=\"part2\"\u003e\n    \u003c%-partTwo%\u003e\n  \u003c/div\u003e\n  \u003cdiv class=\"part3\"\u003e\n    \u003c%-partThree%\u003e\n  \u003c/div\u003e\n\u003c/div\u003e\n```\n\n* demo3.json\n\n```\n{\n    \"partOne\": {\n        \"$template\": \"demo2@V1.0.0\"\n    },\n    \"partTwo\": {\n        \"$template\": \"demo2@V1.0.0\",\n        \"$data\": {\n            \"content1\": {\n                \"$template\": \"demo1@V1.0.0\",\n                \"$data\": {\n                    \"placeholder\": \"hello by demo3\"\n                }\n            },\n            \"listContent\": [\"text1\", {\n                \"$template\": \"demo1@V1.0.0\",\n                \"$data\": {\n                    \"placeholder\": \"hello by demo3\"\n                }\n            }, \"text3\"]\n        }\n    },\n    \"partThree\": \"第三部分\"\n}\n```\n\n## template语法\n\n* 如果是一般数据，会直接渲染到html。\n* 如果是依赖于template生成,则数据结构可以是：\n\n```\n{\n    \"$template\": \"demo1@V1.0.0\",\n    \"$data\": {\n        \"placeholder\": \"hello by demo3\"\n    }\n}\n```\n\n模板 demo1\\@V1.0.0 如下：\n\n```\n//demo1.html\n\u003cinput type=\"text\" placeholder=\"\u003c%-placeholder%\u003e\" /\u003e\n\n//demo1.json\n{\n    \"placeholder\": \"请输入文本\"\n}\n```\n\n其中，`template` 和 `data` 是固定的属性。  \n ***template*** 由包名和版本号组成。固定格式引用。   \n ***data*** 填充该template的json数据，会覆盖模板的默认数据。可以为空，为空则用默认数据。\n\n## 指令 -- gm3\n\n```\nUsage: gm3 [options]\ndefault: gm3 = gm3 -b\n\nGm help.\n\n\n Options:\n  -d, --directory[=DIR]       The directory to be builded, default is current\n                                directory\n  -o, --output[=PATH]         Write the builded content to the target file\n  -m, --main[=PATH]           defind the entry file\n  -a, --append-array          Appends intead of replaces an array\n  -b, --build                 Compile \u0026\u0026 build file\n  -i, --install[=MODULES]     Install templates\n  -v, --version               Output version information and exit\n\nReport bugs to \u003cwyyxdgm@163.com\u003e.\n\n```\n\u003c!--\n  -A, --auth[=USER:PASS]      User auth by name and password\n  -s, --search[=key1:key2:...]  \n                              Search by keys\n  -p, --publish               Publish package\n  -I, --info                  Show local infos\n  -V, --verbose               Makes output more verbose\n  -h, --help                  Display this help message and exit\n--\u003e\n\n**举例**\n\n* `gm3 -h` 打印help信息。\n* `gm3 --install ../demo1` 会生成gm_components文件夹，并安装demo1。\n* `gm3 [--build]` 通过数据依赖继承关系，生成gm.html。\n* `gm3 -o test.html` 生成到test.html，此时忽略gm.json中的output值。\n* `gm3 -m main_file_name -o dist_file_name` 设定`file_name`为入口文件，并build。\n\n## 类库使用\n### 安装\n```bash\nnpm install gm3\n```\n### 使用\n\n- 规则\n\n\n$template 指定模板路径\ntemplate 指定模板内容\n$data 指定数据路径\ndata 指定数据内容\n\n\n### demo\n\n- 使用数据文件路径\n\n```\nconst gm3 = require('gm3');\nlet gm3Str = gm3.build({\n  dir: 'path_to_template_dir',\n  \"input\": {\n    \"$template\": \"template.js\",\n    \"$data\": 'template.json'\n  }\n});\nconsole.log(gm3Str);\n```\n\n- 使用数据对象\n\n```\nconst gm3 = require('gm3');\nlet gm3Str = gm3.build({\n  dir: 'path_to_template_dir',\n  \"input\": {\n    \"$template\": \"template.js\",\n    \"data\": {}\n  }\n});\nconsole.log(gm3Str);\n```\n\n- 使用模板数据+模板路径(注意，如果要使用include指令必须设置模板路径，可以通过main或input.$template设置)\n\n```\nconst gm3 = require('gm3');\nlet gm3Str = gm3.build({\n  dir: 'path_to_template_dir',\n  \"input\": {\n    \"template\": \"\u003c%-data1%\u003e\",\n    \"data\": {data1:'example'}\n  },\n  \"main\": \"path_to_template_file\"\n});\nconsole.log(gm3Str);\n```\n\n## 相关项目\n\n * EJS: https://github.com/mde/ejs\n\n## TODO\n\ncli support completely\n\n```\n  -d, --directory[=DIR]       The directory to be builded, default is current\n                                directory\n  -o, --output[=PATH]         Write the builded content to the target file\n  -m, --main[=PATH]           defind the entry file\n  -a, --append-array          Appends intead of replaces an array\n  -b, --build                 Compile \u0026\u0026 build file\n  -i, --install[=MODULES]     Install templates\n  -A, --auth[=USER:PASS]      User auth by name and password\n  -s, --search[=key1:key2:...]  \n                              Search by keys\n  -p, --publish               Publish package\n  -I, --info                  Show local infos\n  -V, --verbose               Makes output more verbose\n  -h, --help                  Display this help message and exit\n  -v, --version               Output version information and exit\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwyyxdgm%2Fgm3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwyyxdgm%2Fgm3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwyyxdgm%2Fgm3/lists"}