All Projects → thinkjs → think-cli

thinkjs / think-cli

Licence: MIT license
ThinkJS 3.x command line tool

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to think-cli

Nideshop
NideShop 开源微信小程序商城服务端 API(Node.js + ThinkJS)
Stars: ✭ 5,154 (+13829.73%)
Mutual labels:  thinkjs
Cmswing
一款基于ThinkJS(Node.js MVC)和MySQL的功能强大的(PC端,手机端和微信公众平台)电子商务平台及CMS建站系统
Stars: ✭ 1,224 (+3208.11%)
Mutual labels:  thinkjs
cicada
Favorite article collections system
Stars: ✭ 91 (+145.95%)
Mutual labels:  thinkjs
Hioshop Miniprogram
海风小店,开源商城,微信小程序商城
Stars: ✭ 779 (+2005.41%)
Mutual labels:  thinkjs
Mpvue Xbyjshop
前端mpvue🚀后端nodejs🔋+thinkjs+mysql📂微信小程序商城
Stars: ✭ 973 (+2529.73%)
Mutual labels:  thinkjs
Thinkjs2 Demos
demos for ThinkJS 2
Stars: ✭ 101 (+172.97%)
Mutual labels:  thinkjs
Hioshop Admin
海风小店,开源商城,微信小程序商城管理后台,后台管理,VUE
Stars: ✭ 452 (+1121.62%)
Mutual labels:  thinkjs
nodeJSBlog
sau交流学习社区系统,是一个拥有博客功能和社区分享评论功能的一个学习分享平台,后端完全使用nodeJS,数据库使用mysql,基于nodejs的thinkjs框架搭建的 ,前台系统:https://www.mwcxs.top 后台系统:https://www.mwcxs.top/admin
Stars: ✭ 48 (+29.73%)
Mutual labels:  thinkjs
Node Bigpipe
A super easy, lightweight Bigpie Module for Nodejs, Express, Sails, ThinkJS with good intergration for web framework
Stars: ✭ 77 (+108.11%)
Mutual labels:  thinkjs
Thinkjs Vue.js Blog
使用 ThinkJS+Vue.js+mysql 开发的博客程序,演示地址:
Stars: ✭ 190 (+413.51%)
Mutual labels:  thinkjs
Think Html Cache
html-cache middleware for ThinkJS 2.0
Stars: ✭ 6 (-83.78%)
Mutual labels:  thinkjs
Thinkjs Performance Test
ThinkJS 2.x Performance Test vs Koa, Express, Sails.js
Stars: ✭ 14 (-62.16%)
Mutual labels:  thinkjs
Firekylin
A Simple & Fast Node.js Blogging Platform Base On ThinkJS3 & React & ES2015+
Stars: ✭ 1,804 (+4775.68%)
Mutual labels:  thinkjs
Thinkjs
Use full ES2015+ features to develop Node.js applications, Support TypeScript.
Stars: ✭ 5,255 (+14102.7%)
Mutual labels:  thinkjs
harpers
A forum app written by node & thinkJS
Stars: ✭ 12 (-67.57%)
Mutual labels:  thinkjs
My Bookmark
在线书签管理工具
Stars: ✭ 481 (+1200%)
Mutual labels:  thinkjs
Sahx Admin
SAHX-Admin 是套功能较为完整的后台管理系统架构, 以Thinkjs 作为中间层, Vuejs作为前端模块化开发, AdminLET作为前端UI, 实现了前后端分离, 前端组件化, 便于多人协同开发.
Stars: ✭ 80 (+116.22%)
Mutual labels:  thinkjs
thinkjsplus
thinkjs3.0 从入门到实战
Stars: ✭ 100 (+170.27%)
Mutual labels:  thinkjs
structure-admin
技术栈:nodeJS+vue+vuex+mysql+redis,前端使用vue的element-ui的组件库,后端使用nodeJS的服务,数据库mysql,缓存使用的还redis
Stars: ✭ 45 (+21.62%)
Mutual labels:  thinkjs
Www.thinkjs.org
ThinkJS website
Stars: ✭ 171 (+362.16%)
Mutual labels:  thinkjs

think-cli

Build Status AppVeyor Coverage Status

think-cli is a command-line interface for ThinkJS.

Installation

$ npm install -g think-cli

Commands:

  • new - generate a new project from a template
  • list - list available official templates
  • module - add module from a template
  • controller - add controller from a template
  • service - add service from a template
  • model - add model from a template
  • middleware - add middleware from a template
  • adapter - add adapter from a template
  • migrate - migrate the project to think-cli 2.0
  • sync - Synchronize the latest version of the project template to the local cache directory
  • clean - Clear the project template cache

new

Usage:

$ thinkjs new <project-name> <template-name>

Example:

$ thinkjs new my-project standard

The above command pulls the template from think-template/standard, prompts for some information, and generates the project at ./my-project/.

  • is optional, defaults to the current working directory
  • is optional, default is the standard template, support offline use

Example:

$ thinkjs new

The above command, prompts for some information, and generates the project at ./ (current working directory), support offline use

If you want to create a multi-module project, you need to add the -m parameter:

$ thinkjs new -m

official templates

thinkjs provide some recommended templates.

All official project templates are repos in the think-template organization. When a new template is added to the organization, you will be able to run thinkjs new <project-name> <template-name> to use that template. You can also run thinkjs list to see all available official templates.

Current available templates include:

  • standard - A full-featured standard template
  • api - API application template
  • vue - ThinkJS Vue Template
  • react - ThinkJS React Template
  • typescript - ThinkJS typescript cli template

Custom Templates

It'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:

$ thinkjs new my-project username/repo

Where username/repo is the GitHub repo shorthand for your fork.

The shorthand repo notation is passed to 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.

If 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.

Local Templates

Instead of a GitHub repo, you can also use a template on your local file system:

$ thinkjs new my-project ~/fs/path/to-custom-template

controller

Usage:

$ thinkjs controller <controller-name> [module-name]

Example:

$ thinkjs controller user home

The above command generates the controller at src/home/controller/user.js

  • 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

You can also add the -r parameter to create a rest type controller

Example:

$ thinkjs controller user -r

service

Usage:

$ thinkjs service <service-name> [module-name]

Example:

$ thinkjs service user home

The above command generates the service at src/home/service/user.js

As with controller, module-name is optional and can only be used in multi-module projects

model

Usage:

$ thinkjs model <model-name> [module-name]

Example:

$ thinkjs model user home

The above command generates the model at src/home/model/user.js

As with controller, module-name is optional and can only be used in multi-module projects

middleware

Usage:

$ thinkjs middleware <middleware-name> [module-name]

Example:

$ thinkjs middleware user home

The above command generates the middleware at src/home/middleware/user.js

As with controller, module-name is optional and can only be used in multi-module projects

adapter

Usage:

$ thinkjs adapter <adapter> [module-name]

Example: create a adapter with the name base type user

$ thinkjs adapter user/base home

The above command generates the adapter at src/home/adapter/user/base.js

adapter name is optional, defaults to the base, Example:

$ thinkjs adapter user

The above command generates the adapter at src/adapter/user/base.js

As with controller, module-name is optional and can only be used in multi-module projects

module

The command can only be used in multi-module projects

Usage:

$ thinkjs module [module-name]

Example:

$ thinkjs module user

The above command generates a module with the name user

As with controller, module-name is optional,defaults to the thinkjs.defaultModule in in the package.json file of project root directory.

migrate

Usage:

$ thinkjs module [module-name]

If 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.

sync

Usage:

$ thinkjs sync

The command will synchronize the latest version of the project template to the local cache directory.

clean

Usage:

$ thinkjs clean

The command will delete the project template cache.

After the template cache is deleted, your next create file command will pull the latest template

Writing Custom Templates from Scratch

  • A template repo must have a template directory that holds the template files.
  • 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:
    • prompts - used to collect user options data;
    • skipCompile - used to skip template compile, usually used for pictures and other resource files;
    • completeMessage - the message to be displayed to the user when the template has been generated. You can include custom instruction here.
    • new - new command mapping configuration
    • controller - controller command mapping configuration
    • model - model command mapping configuration
    • service - service command mapping configuration
    • middleware - middleware command mapping configuration
    • adapter - adapter command mapping configuration
    • module - module command mapping configuration
  • Template can use any parameter carried in the command line

prompts

The 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. Example:

{
  "prompts": {
    "name": {
      "type": "string",
      "required": true,
      "message": "Project name"
    }
  }
}

After all prompts are finished, all files inside template will be rendered using Ejs, with the prompt results as the data.

skipCompile

The project template is not always some code file, there are also some resource files, such as pictures, fonts, etc.

Only 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.

The skipCompile field in the metadata file should be a minimatch glob pattern. The files matched should skip rendering. Example:

{
  "skipCompile": "src/**/*.png"
}

or

{
  "skipCompile": [
    "src/**/*.css",
    "src/**/*.png"
  ]
}

completeMessage

The skipCompile field in the metadata file, it can access the variables in the template, as well as all the syntax provided by EJS. Example:

{
  "completeMessage": "To get started:\n\n<% if (!inPlace) { %># enter path\n$ cd <%= destDirName %>\n\n<% } %># install dependencies:\n$ npm install\n\n# run the app\n$ npm start"
}

new

The 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:

  • default - Generate single module project mapping configuration
  • multiModule - Generate multi-module project mapping configuration

mapping configuration can access these variables: action,moduleName, type.

Example:

{
  "new": {
    "default": [
      ["src/bootstrap", "src/bootstrap"],
      ["src/config", "src/config"],
      ["src/controller/base.js", "src/controller/base.js"],
      ["src/controller/index.js", "src/controller/index.js"],
      ["src/logic", "src/logic"],
      ["src/model", "src/model"],
      ["test/index.js", "test/index.js"],
      ["view/index_index.html", "view/index_index.html"],
      ["development.js", "development.js"],
      ["eslintrc", ".eslintrc"],
      ["gitignore", ".gitignore"],
      ["nginx.conf", "nginx.conf"],
      ["package.json", "package.json"],
      ["pm2.json", "pm2.json"],
      ["production.js", "production.js"],
      ["README.md", "README.md"]
    ],
    "multiModule": [
      ["src/bootstrap", "src/common/bootstrap"],
      ["src/config", "src/common/config"],
      ["src/config/config.js", "src/[moduleName]/config/config.js"],
      ["src/controller/base.js", "src/[moduleName]/controller/base.js"],
      ["src/controller/index.js", "src/[moduleName]/controller/index.js"],
      ["src/logic", "src/[moduleName]/logic"],
      ["src/model", "src/[moduleName]/model"],
      ["test/index.js", "test/index.js"],
      ["view/index_index.html", "view/[moduleName]/index_index.html"],
      ["development.js", "development.js"],
      ["eslintrc", ".eslintrc"],
      ["gitignore", ".gitignore"],
      ["nginx.conf", "nginx.conf"],
      ["package.json", "package.json"],
      ["pm2.json", "pm2.json"],
      ["production.js", "production.js"],
      ["README.md", "README.md"]
    ]
  }
}

controller

The 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:

  • default - Generate controller mapping configuration
  • rest - Generate rest controller mapping configuration

mapping configuration can access these variables: action,moduleName, type.

Example:

{
  "controller": {
    "default": [
      ["src/controller/index.js", "src/[moduleName]/controller/[action].js"],
      ["src/logic/index.js", "src/[moduleName]/logic/[action].js"]
    ],
    "rest": [
      ["src/controller/rest.js", "src/[moduleName]/controller/rest.js"],
      ["src/controller/restIndex.js", "src/[moduleName]/controller/[action].js"],
      ["src/logic/index.js", "src/[moduleName]/logic/[action].js"]
    ]
  }
}

model

The skipCompile field in the metadata file should be an array containing map configuration required to generate a model from a template.

mapping configuration can access these variables: action,moduleName, type.

Example:

{
  "model": [
    ["src/model/index.js", "src/[moduleName]/model/[action].js"]
  ]
}

service

The skipCompile field in the metadata file should be an array containing map configuration required to generate a service from a template.

mapping configuration can access these variables: action,moduleName, type.

Example:

{
  "service": [
    ["src/service/index.js", "src/[moduleName]/service/[action].js"]
  ]
}

middleware

The skipCompile field in the metadata file should be an array containing map configuration required to generate a middleware from a template.

mapping configuration can access these variables: action,moduleName, type.

Example:

{
  "middleware": [
    ["src/middleware/base.js", "src/[moduleName]/middleware/[action].js"]
  ]
}

adapter

The skipCompile field in the metadata file should be an array containing map configuration required to generate a adapter from a template.

mapping configuration can access these variables: action,moduleName, type.

Example:

{
  "adapter": [
    ["src/adapter/base.js", "src/[moduleName]/adapter/[type]/[action].js"]
  ]
}

module

The skipCompile field in the metadata file should be an array containing map configuration required to generate a module from a template.

mapping configuration can access these variables: action,moduleName, type.

Example:

{
  "module": [
    ["src/config/config.js", "src/[moduleName]/config/config.js"],
    ["src/controller/base.js", "src/[moduleName]/controller/base.js"],
    ["src/controller/index.js", "src/[moduleName]/controller/index.js"],
    ["src/logic/index.js", "src/[moduleName]/logic/index.js"],
    ["src/model/index.js", "src/[moduleName]/model/index.js"],
    ["view/index_index.html", "view/[moduleName]/index_index.html"]
  ]
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].