{"id":18368259,"url":"https://github.com/thinkjs/think-cli","last_synced_at":"2025-04-06T17:31:40.955Z","repository":{"id":17745128,"uuid":"82624298","full_name":"thinkjs/think-cli","owner":"thinkjs","description":"ThinkJS 3.x command line tool","archived":false,"fork":false,"pushed_at":"2022-12-29T04:27:38.000Z","size":1441,"stargazers_count":37,"open_issues_count":7,"forks_count":11,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-14T05:11:05.332Z","etag":null,"topics":["cli","thinkjs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"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/thinkjs.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-02-21T02:00:47.000Z","updated_at":"2022-04-09T01:45:27.000Z","dependencies_parsed_at":"2023-01-11T20:27:15.984Z","dependency_job_id":null,"html_url":"https://github.com/thinkjs/think-cli","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkjs","download_url":"https://codeload.github.com/thinkjs/think-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247522345,"owners_count":20952528,"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":["cli","thinkjs"],"created_at":"2024-11-05T23:25:19.816Z","updated_at":"2025-04-06T17:31:40.599Z","avatar_url":"https://github.com/thinkjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# think-cli\n[![Build Status](https://travis-ci.org/thinkjs/think-cli.svg?branch=master)](https://travis-ci.org/thinkjs/think-cli)\n[![AppVeyor](https://img.shields.io/appveyor/ci/lizheming/think-cli.svg?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgd2lkdGg9IjEyOCIgaGVpZ2h0PSIxMjgiIHZpZXdCb3g9IjAgMCAxMjggMTI4Ij48ZyBmaWxsPSIjMUJBMUUyIiB0cmFuc2Zvcm09InNjYWxlKDgpIj48cGF0aCBkPSJNMCAyLjI2NWw2LjUzOS0uODg4LjAwMyA2LjI4OC02LjUzNi4wMzd6Ii8%2BPHBhdGggZD0iTTYuNTM2IDguMzlsLjAwNSA2LjI5My02LjUzNi0uODk2di01LjQ0eiIvPjxwYXRoIGQ9Ik03LjMyOCAxLjI2MWw4LjY3LTEuMjYxdjcuNTg1bC04LjY3LjA2OXoiLz48cGF0aCBkPSJNMTYgOC40NDlsLS4wMDIgNy41NTEtOC42Ny0xLjIyLS4wMTItNi4zNDV6Ii8%2BPC9nPjwvc3ZnPg==)](https://ci.appveyor.com/project/lizheming/think-cli)\n[![Coverage Status](https://coveralls.io/repos/github/thinkjs/think-cli/badge.svg)](https://coveralls.io/github/thinkjs/think-cli)\n\n`think-cli` is a command-line interface for ThinkJS.\n\n## Installation\n\n```\n$ npm install -g think-cli\n```\n\n## Commands:\n* [new](#new) - generate a new project from a template\n* [list](#official-templates) - list available official templates\n* [module](#module) - add module from a template\n* [controller](#controller) - add controller from a template\n* [service](#service) - add service from a template\n* [model](#model) - add model from a template\n* [middleware](#middleware) - add middleware from a template\n* [adapter](#adapter) - add adapter from a template\n* [migrate](#migrate) - migrate the project to think-cli 2.0\n* [sync](#sync) - Synchronize the latest version of the project template to the local cache directory\n* [clean](#clean) - Clear the project template cache\n\n### new\n\n**Usage:**\n\n```\n$ thinkjs new \u003cproject-name\u003e \u003ctemplate-name\u003e\n```\n\n**Example:**\n```\n$ thinkjs new my-project standard\n```\n\nThe above command pulls the template from [think-template/standard](https://github.com/think-template/standard), prompts for some information, and generates the project at ./my-project/.\n\n* \u003cproject-name\u003e is optional, defaults to the current working directory\n* \u003ctemplate-name\u003e is optional, default is the standard template, support offline use\n\n**Example:**\n```\n$ thinkjs new\n```\n\nThe above command, prompts for some information, and generates the project at ./ (current working directory), support offline use\n\nIf you want to create a multi-module project, you need to add the `-m` parameter:\n\n```\n$ thinkjs new -m\n```\n\n#### official templates\n\nthinkjs provide some recommended templates.\n\nAll official project templates are repos in the [think-template organization](https://github.com/think-template). When a new template is added to the organization, you will be able to run `thinkjs new \u003cproject-name\u003e \u003ctemplate-name\u003e` to use that template. You can also run `thinkjs list` to see all available official templates.\n\nCurrent available templates include:\n\n* [standard](https://github.com/think-template/standard) - A full-featured standard template\n* [api](https://github.com/think-template/api) - API application template\n* [vue](https://github.com/think-template/vue) - ThinkJS Vue Template\n* [react](https://github.com/think-template/react) - ThinkJS React Template\n* [typescript](https://github.com/think-template/typescript) - ThinkJS typescript cli template\n\n#### Custom Templates\n\nIt's unlikely to make everyone happy with the official templates. You can simply fork an official template and then use it via `think-cli` with:\n\n```\n$ thinkjs new my-project username/repo\n```\nWhere `username/repo` is the GitHub repo shorthand for your fork.\n\nThe shorthand repo notation is passed to [download-git-repo](https://github.com/flipxfx/download-git-repo) so you can also use things like `bitbucket:username/repo` for a Bitbucket repo and `username/repo#branch` for tags or branches.\n\nIf you would like to download from a private repository use the `—clone` flag and the cli will use `git clone` so your SSH keys are used.\n\n#### Local Templates\n\nInstead of a GitHub repo, you can also use a template on your local file system:\n\n```\n$ thinkjs new my-project ~/fs/path/to-custom-template\n```\n\n### controller\n\n**Usage:**\n\n```\n$ thinkjs controller \u003ccontroller-name\u003e [module-name]\n```\n\n**Example:**\n```\n$ thinkjs controller user home\n```\n\nThe above command generates the controller at `src/home/controller/user.js`\n\n* module-name is optional, defaults to the `thinkjs.defaultModule` in in the package.json file of project root directory, you can modify it, **module-name only be used in multi-module projects**\n\nYou can also add the `-r` parameter to create a rest type controller\n\n**Example:**\n```\n$ thinkjs controller user -r\n```\n\n### service\n\n**Usage:**\n\n```\n$ thinkjs service \u003cservice-name\u003e [module-name]\n```\n\n**Example:**\n```\n$ thinkjs service user home\n```\n\nThe above command generates the service at `src/home/service/user.js`\n\nAs with controller, `module-name` is optional and can only be used in multi-module projects\n\n### model\n\n**Usage:**\n\n```\n$ thinkjs model \u003cmodel-name\u003e [module-name]\n```\n\n**Example:**\n```\n$ thinkjs model user home\n```\n\nThe above command generates the model at `src/home/model/user.js`\n\nAs with controller, `module-name` is optional and can only be used in multi-module projects\n\n### middleware\n\n**Usage:**\n\n```\n$ thinkjs middleware \u003cmiddleware-name\u003e [module-name]\n```\n\n**Example:**\n```\n$ thinkjs middleware user home\n```\n\nThe above command generates the middleware at `src/home/middleware/user.js`\n\nAs with controller, `module-name` is optional and can only be used in multi-module projects\n\n### adapter\n\n**Usage:**\n\n```\n$ thinkjs adapter \u003cadapter\u003e [module-name]\n```\n\n**Example:**\ncreate a adapter with the name base type user\n```\n$ thinkjs adapter user/base home\n```\n\nThe above command generates the adapter at `src/home/adapter/user/base.js`\n\nadapter name is optional, defaults to the `base`, Example:\n\n```\n$ thinkjs adapter user\n```\n\nThe above command generates the adapter at `src/adapter/user/base.js`\n\nAs with controller, `module-name` is optional and can only be used in multi-module projects\n\n### module\n\u003e The command can only be used in multi-module projects\n\n**Usage:**\n\n```\n$ thinkjs module [module-name]\n```\n\n**Example:**\n```\n$ thinkjs module user\n```\n\nThe above command generates a module with the name `user`\n\nAs with controller, `module-name` is optional,defaults to the `thinkjs.defaultModule` in in the package.json file of project root directory.\n\n\n### migrate\n\n**Usage:**\n\n```\n$ thinkjs module [module-name]\n```\n\nIf your project was created with think-cli 1.0 and you want to use the capabilities of think-cli 2.0, you need to use `migrate` command to migrate your project to think-cli 2.0.\n\n### sync\n\n**Usage:**\n\n```\n$ thinkjs sync\n```\n\nThe command will synchronize the latest version of the project template to the local cache directory.\n\n### clean\n\n**Usage:**\n\n```\n$ thinkjs clean\n```\n\nThe command will delete the project template cache.\n\nAfter the template cache is deleted, your next create file command will pull the latest template\n\n## Writing Custom Templates from Scratch\n\n* A template repo **must** have a `template` directory that holds the template files.\n* A template repo **must** have a metadata file for the template which can be either a `metadata.js` or `metadata.json` file. It can contain the following fields:\n  * `prompts` - used to collect user options data;\n  * `skipCompile` - used to skip template compile, usually used for pictures and other resource files;\n  * `completeMessage` - the message to be displayed to the user when the template has been generated. You can include custom instruction here.\n  * `new` - new command mapping configuration\n  * `controller` - controller command mapping configuration\n  * `model` - model command mapping configuration\n  * `service` - service command mapping configuration\n  * `middleware` - middleware command mapping configuration\n  * `adapter` - adapter command mapping configuration\n  * `module` - module command mapping configuration\n* Template can use any parameter carried in the command line\n\n### prompts\n\nThe prompts field in the metadata file should be an object hash containing prompts for the user. For each entry, the key is the variable name and the value is an [Inquirer.js question object](https://github.com/SBoudrias/Inquirer.js/#question). Example:\n\n```javascript\n{\n  \"prompts\": {\n    \"name\": {\n      \"type\": \"string\",\n      \"required\": true,\n      \"message\": \"Project name\"\n    }\n  }\n}\n```\n\nAfter all prompts are finished, all files inside template will be rendered using [Ejs](http://ejs.co/), with the prompt results as the data.\n\n### skipCompile\n\nThe project template is not always some code file, there are also some resource files, such as pictures, fonts, etc.\n\nOnly the code file needs to be compiled, because the code file may need to use syntax such as variables or conditional judgment, and pictures and other resource files are not needed, so we are use skipCompile field Skip these files.\n\nThe `skipCompile` field in the metadata file should be a [minimatch glob pattern](https://github.com/isaacs/minimatch). The files matched should skip rendering. Example:\n\n```javascript\n{\n  \"skipCompile\": \"src/**/*.png\"\n}\n```\n\nor\n\n```javascript\n{\n  \"skipCompile\": [\n    \"src/**/*.css\",\n    \"src/**/*.png\"\n  ]\n}\n```\n\n### completeMessage\n\nThe `skipCompile` field in the metadata file, it can access the variables in the template, as well as all the syntax provided by EJS. Example:\n\n```javascript\n{\n  \"completeMessage\": \"To get started:\\n\\n\u003c% if (!inPlace) { %\u003e# enter path\\n$ cd \u003c%= destDirName %\u003e\\n\\n\u003c% } %\u003e# install dependencies:\\n$ npm install\\n\\n# run the app\\n$ npm start\"\n}\n```\n\n### new\n\nThe `skipCompile` field in the metadata file should be an object hash containing map configuration required to generate a project from a template. It contain the following fields：\n\n  * `default` - Generate single module project mapping configuration\n  * `multiModule` - Generate multi-module project mapping configuration\n\nmapping configuration can access these variables: `action`,`moduleName`, `type`.\n\nExample:\n\n```javascript\n{\n  \"new\": {\n    \"default\": [\n      [\"src/bootstrap\", \"src/bootstrap\"],\n      [\"src/config\", \"src/config\"],\n      [\"src/controller/base.js\", \"src/controller/base.js\"],\n      [\"src/controller/index.js\", \"src/controller/index.js\"],\n      [\"src/logic\", \"src/logic\"],\n      [\"src/model\", \"src/model\"],\n      [\"test/index.js\", \"test/index.js\"],\n      [\"view/index_index.html\", \"view/index_index.html\"],\n      [\"development.js\", \"development.js\"],\n      [\"eslintrc\", \".eslintrc\"],\n      [\"gitignore\", \".gitignore\"],\n      [\"nginx.conf\", \"nginx.conf\"],\n      [\"package.json\", \"package.json\"],\n      [\"pm2.json\", \"pm2.json\"],\n      [\"production.js\", \"production.js\"],\n      [\"README.md\", \"README.md\"]\n    ],\n    \"multiModule\": [\n      [\"src/bootstrap\", \"src/common/bootstrap\"],\n      [\"src/config\", \"src/common/config\"],\n      [\"src/config/config.js\", \"src/[moduleName]/config/config.js\"],\n      [\"src/controller/base.js\", \"src/[moduleName]/controller/base.js\"],\n      [\"src/controller/index.js\", \"src/[moduleName]/controller/index.js\"],\n      [\"src/logic\", \"src/[moduleName]/logic\"],\n      [\"src/model\", \"src/[moduleName]/model\"],\n      [\"test/index.js\", \"test/index.js\"],\n      [\"view/index_index.html\", \"view/[moduleName]/index_index.html\"],\n      [\"development.js\", \"development.js\"],\n      [\"eslintrc\", \".eslintrc\"],\n      [\"gitignore\", \".gitignore\"],\n      [\"nginx.conf\", \"nginx.conf\"],\n      [\"package.json\", \"package.json\"],\n      [\"pm2.json\", \"pm2.json\"],\n      [\"production.js\", \"production.js\"],\n      [\"README.md\", \"README.md\"]\n    ]\n  }\n}\n```\n\n### controller\n\nThe `skipCompile` field in the metadata file should be an object hash containing map configuration required to generate a controller from a template. It contain the following fields：\n\n  * `default` - Generate controller mapping configuration\n  * `rest` - Generate rest controller mapping configuration\n\nmapping configuration can access these variables: `action`,`moduleName`, `type`.\n\nExample:\n\n```javascript\n{\n  \"controller\": {\n    \"default\": [\n      [\"src/controller/index.js\", \"src/[moduleName]/controller/[action].js\"],\n      [\"src/logic/index.js\", \"src/[moduleName]/logic/[action].js\"]\n    ],\n    \"rest\": [\n      [\"src/controller/rest.js\", \"src/[moduleName]/controller/rest.js\"],\n      [\"src/controller/restIndex.js\", \"src/[moduleName]/controller/[action].js\"],\n      [\"src/logic/index.js\", \"src/[moduleName]/logic/[action].js\"]\n    ]\n  }\n}\n```\n\n### model\n\nThe `skipCompile` field in the metadata file should be an array containing map configuration required to generate a model from a template. \n\nmapping configuration can access these variables: `action`,`moduleName`, `type`.\n\nExample:\n\n```javascript\n{\n  \"model\": [\n    [\"src/model/index.js\", \"src/[moduleName]/model/[action].js\"]\n  ]\n}\n```\n\n### service\n\nThe `skipCompile` field in the metadata file should be an array containing map configuration required to generate a service from a template. \n\nmapping configuration can access these variables: `action`,`moduleName`, `type`.\n\nExample:\n\n```javascript\n{\n  \"service\": [\n    [\"src/service/index.js\", \"src/[moduleName]/service/[action].js\"]\n  ]\n}\n```\n\n### middleware\n\nThe `skipCompile` field in the metadata file should be an array containing map configuration required to generate a middleware from a template. \n\nmapping configuration can access these variables: `action`,`moduleName`, `type`.\n\nExample:\n\n```javascript\n{\n  \"middleware\": [\n    [\"src/middleware/base.js\", \"src/[moduleName]/middleware/[action].js\"]\n  ]\n}\n```\n\n### adapter\n\nThe `skipCompile` field in the metadata file should be an array containing map configuration required to generate a adapter from a template. \n\nmapping configuration can access these variables: `action`,`moduleName`, `type`.\n\nExample:\n\n```javascript\n{\n  \"adapter\": [\n    [\"src/adapter/base.js\", \"src/[moduleName]/adapter/[type]/[action].js\"]\n  ]\n}\n```\n\n### module\n\nThe `skipCompile` field in the metadata file should be an array containing map configuration required to generate a module from a template. \n\nmapping configuration can access these variables: `action`,`moduleName`, `type`.\n\nExample:\n\n```javascript\n{\n  \"module\": [\n    [\"src/config/config.js\", \"src/[moduleName]/config/config.js\"],\n    [\"src/controller/base.js\", \"src/[moduleName]/controller/base.js\"],\n    [\"src/controller/index.js\", \"src/[moduleName]/controller/index.js\"],\n    [\"src/logic/index.js\", \"src/[moduleName]/logic/index.js\"],\n    [\"src/model/index.js\", \"src/[moduleName]/model/index.js\"],\n    [\"view/index_index.html\", \"view/[moduleName]/index_index.html\"]\n  ]\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkjs%2Fthink-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-cli/lists"}