{"id":19974416,"url":"https://github.com/alanchenchen/alan-cli","last_synced_at":"2025-05-04T02:32:40.283Z","repository":{"id":57175427,"uuid":"112713493","full_name":"alanchenchen/alan-cli","owner":"alanchenchen","description":"A simple CLI for generating your projects","archived":false,"fork":false,"pushed_at":"2019-09-22T16:35:00.000Z","size":54,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-21T14:47:56.382Z","etag":null,"topics":["alan-cli","cli","template-hooks"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alanchenchen.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":"2017-12-01T08:16:38.000Z","updated_at":"2021-04-22T06:02:19.000Z","dependencies_parsed_at":"2022-09-03T09:03:17.471Z","dependency_job_id":null,"html_url":"https://github.com/alanchenchen/alan-cli","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanchenchen%2Falan-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanchenchen%2Falan-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanchenchen%2Falan-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanchenchen%2Falan-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alanchenchen","download_url":"https://codeload.github.com/alanchenchen/alan-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252279073,"owners_count":21722833,"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":["alan-cli","cli","template-hooks"],"created_at":"2024-11-13T03:14:57.558Z","updated_at":"2025-05-04T02:32:39.993Z","avatar_url":"https://github.com/alanchenchen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# alan-cli\n\n![](https://img.shields.io/npm/v/alan-cli.svg)\n![](https://img.shields.io/npm/dt/alan-cli.svg)\n[![LICENSE](https://img.shields.io/badge/license-Anti%20996-blue.svg)](https://github.com/996icu/996.ICU/blob/master/LICENSE)\n\nA simple CLI for creating your projects\n\u003e Author：Alan Chen\n\n\u003e version: 2.1.0\n\n\u003e date: 2019/09/22\n\n## Feature\n一款轻量的前端CLI工具，支持自定义添加模板，删除模板，和初始化项目。不仅仅局限于webpack模板，初始化项目其实就是将模板对应的github仓库拷贝到本地。目前CLI内置了5款模板，用于解决多种开发场景配置繁琐的问题。\n\n## Usage\n全局安装alan-cli。`npm install -g alan-cli`\n\n打开terminal或 cmd ，输入`alan` or `alan -h` ，你将看到如下信息:\n```\n  Usage: alan \u003ccommand\u003e\n\n\n  Commands:\n\n    add|a      Add a new template\n    list|l     List all the templates\n    init|i     Generate a new project\n    delete|d   Delete a template\n\n  Options:\n\n    -h, --help     output usage information\n    -V, --version  output the version number\n```\n\n\u003e 如果你是在使用 `MacOS`, `sudo`可能要加载 `add`和 `delete`命令前.\n\n## Commands\n### list | l\n这个命令会展示当前脚手架的模板列表.\n```\n$ alan list\n┌───────────────────┬────────────────────────────────────────────────────┬─────────────────────────────────────────┬────────┐\n│ Template Name     │ Description                                        │ Owner/Name                              │ Branch │\n├───────────────────┼────────────────────────────────────────────────────┼─────────────────────────────────────────┼────────┤\n│ express-decorator │ building server application with express-decorator │ alanchenchen/express-decorator-template │ master │\n├───────────────────┼────────────────────────────────────────────────────┼─────────────────────────────────────────┼────────┤\n│ simple            │ building multiple entries                          │ alanchenchen/simple-template            │ master │\n├───────────────────┼────────────────────────────────────────────────────┼─────────────────────────────────────────┼────────┤\n│ vue               │ building vue project easily                        │ alanchenchen/vue-template               │ master │\n├───────────────────┼────────────────────────────────────────────────────┼─────────────────────────────────────────┼────────┤\n│ react             │ building react SPA                                 │ alanchenchen/react-template             │ master │\n├───────────────────┼────────────────────────────────────────────────────┼─────────────────────────────────────────┼────────┤\n│ library           │ building npm library                               │ alanchenchen/library-template           │ master │\n└───────────────────┴────────────────────────────────────────────────────┴─────────────────────────────────────────┴────────┘\n```\n目前内置了5个模板,详情请看模板仓库 :\n  * [express-decorator](https://github.com/alanchenchen/express-decorator-template)\n  * [simple](https://github.com/alanchenchen/simple-template)\n  * [vue](https://github.com/alanchenchen/vue-template)\n  * [react](https://github.com/alanchenchen/react-template)\n  * [library](https://github.com/alanchenchen/library-template)\n\n### init | i\n初始化新项目，初始化过程会有几次问答，Template name是模板名称，选择`simple`，`react`或者`library`，Project name是项目名称，Project description是项目描述，Project version是项目版本，最后一个问题是在哪个地方初始化项目，默认是当前目录，建议直接按enter.\n```\n$ alan init\n\n? Template name: simple    building multiple entries\n? Project name: demo\n? Project description: a project based on alan-cli\n? Project version: 0.0.1\n? Where to init the project: (./)\nNew project has been initialized successfully!\n      cd demo\n      npm install or yarn\n```\n\n### add|a\n如果你有自定义的模板，你可以直接将github某一仓库模板添加到本地模板列表。模板添加后会自动展示出当前模板列表\n```\n$ alan add\n\n? Set the custom name of the template: library\n? Set the short description of the template: building npm library\n? Owner/name of the template: alanchenchen/library-template\n? Branch of the template: master\n┌───────────────┬─────────────────────────────┬───────────────────────────────┬────────┐\n│ Template Name │ Description                 │ Owner/Name                    │ Branch │\n├───────────────┼─────────────────────────────┼───────────────────────────────┼────────┤\n│ simple        │ building multiple entries   │ alanchenchen/simple-template  │ master │\n├───────────────┼─────────────────────────────┼───────────────────────────────┼────────┤\n│ vue           │ building vue project easily │ alanchenchen/vue-template     │ master │\n├───────────────┼─────────────────────────────┼───────────────────────────────┼────────┤\n│ react         │ building react SPA          │ alanchenchen/react-template   │ master │\n├───────────────┼─────────────────────────────┼───────────────────────────────┼────────┤\n│ library       │ building npm library        │ alanchenchen/library-template │ master │\n└───────────────┴─────────────────────────────┴───────────────────────────────┴────────┘\n```\n\n## Template\n项目模板必须要有固定的目录结构，仓库根目录必须要有一个`template`目录，cli会将整个`template`目录下的所有文件下载下来。仓库根目录可选一个`template.hooks.js`文件，`template.hooks.js`是该模板的cli预处理模块。代码示例如下：\n```js\n  // 模板hooks文件里，只能导入node原生模块，否则会报错找不到依赖包\n  const { resolve } = require('path')\n\n  /*\n   * 必须导出一个对象，对象包含两个函数的键值对\n   */\n  module.exports = {\n      // 模板初始前钩子，会在模板下载下来，但是生成目录之前触发\n      async beforeInit() {},\n      // 模板初始后钩子，会在模板下载下来，生成目录之后触发\n      /*\n       * 每个钩子函数均有一个形参，形参是一个对象，如下：\n       *        {\n       *          fs,                // fs-extral包，并不是原生fs模块，使用方法可以参考其文档\n       *          print,             // 一个对象，控制台打印模块，print.info()、print.success()、print.warn()、print.error()\n       *          prompt,            // 用于命令行交互提问的模块，同inquirer的prompt方法\n       *          configs: {         \n       *             cliMessage,     // 一个对象，cli中前面几个提示用户输入的答案，name是项目名、description是项目描述、version是版本号\n       *             resourcePath    // 模板资源目录的绝对路径，这个路径在不同钩子函数不同，beforeInit阶段指向缓存目录(可以访问到template.hooks.js)，afterInit阶段指向cli进程目录(模板的根目录)\n       *         }\n       *\n       */\n      async afterInit({\n          configs,\n          fs,\n          print\n      }) {\n          // 以下是cli的默认钩子，会在每个模板初始化之后在package.json文件里写入用户输入的项目信息\n          try {\n              const {resourcePath, cliMessage} = configs\n              const targetPath = resolve(resourcePath, './package.json')\n              let clone = require(targetPath)\n              clone.name = cliMessage.name\n              clone.description = cliMessage.description\n              clone.version = cliMessage.version\n      \n              await fs.outputFile(targetPath, JSON.stringify(clone, null, 2), 'utf-8')\n          } catch (err) {\n              print.error(err)\n          }\n      }\n  }\n\n```\n\n## license\n* Anti 996(996.ICU)\n\n## Thanks to\n* [scion](https://github.com/jrainlau/scion)\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falanchenchen%2Falan-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falanchenchen%2Falan-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falanchenchen%2Falan-cli/lists"}