ThinkJS 2.0 supports two kinds of plugins: Middleware and Adapter.
Run the following command to create a plugin, and the plugin name begin with
think- is suggested:
thinkjs plugin think-xxx
After runing, the
think-xxx directory will be created, and it may includes the following content:
create : think-xxx/
create : think-xxx/src
create : think-xxx/src/index.js
create : think-xxx/test
create : think-xxx/test/index.js
create : think-xxx/.eslintrc
create : think-xxx/.npmignore
create : think-xxx/.travis.yml
create : think-xxx/package.json
create : think-xxx/README.md
$ cd think-xxx/
$ npm install
$ npm run watch-compile
$ npm run test-cov
src/ place the source code, using ES6/7 features
test/ for unit testing
.eslintrc configuration file eslint needed
.npmignore files to ignore when npm launching
.travis.yml configuration file for travis continuous integration
package.json npm configuration file
npm install --verbose
The code file is
src/index.js, the generated file by default only contain a basic class, has not inherited any other class yet.
If it is Middleware, you may want to inherit
think.middleware.base, if it is Adapter, you may want to inherit
Before developing, run
npm run watch-compile to make the edited files be compiled in real time.
Unit Testing code should be written in
test/index.js, the test framework is mocha, and run the following command to view the unit testing result:
npm run test-cov
After developing and testing, please write the notes in the README.md.
npm publish to publish the plugin into the npm repository (you may be asked to create account and password if it is your very first publish).
Then, you can inform ThinkJS team. After confirmed, your plugins will be added into the offical plugin list and you can get the gift.