├── .eslintignore ├── boilerplate ├── .eslintignore ├── .eslintrc ├── config │ ├── config.unittest.js │ ├── plugin.js │ └── config.default.js ├── _.gitignore ├── app │ ├── router.js │ └── controller │ │ └── home.js ├── .autod.conf.js ├── test │ └── app │ │ └── controller │ │ └── home.test.js ├── README.md ├── conf │ └── nginx.conf └── _package.json ├── .eslintrc ├── .gitignore ├── appveyor.yml ├── .travis.yml ├── index.js ├── .autod.conf ├── History.md ├── .github └── PULL_REQUEST_TEMPLATE.md ├── LICENSE ├── package.json └── README.md /.eslintignore: -------------------------------------------------------------------------------- 1 | dist -------------------------------------------------------------------------------- /boilerplate/.eslintignore: -------------------------------------------------------------------------------- 1 | coverage 2 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint-config-egg" 3 | } 4 | -------------------------------------------------------------------------------- /boilerplate/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint-config-egg" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage 2 | .logs 3 | npm-debug.log 4 | npm-debug.log.* 5 | .tmp 6 | tmp 7 | dist 8 | .idea/ 9 | node_modules 10 | logs 11 | run 12 | *.sw* 13 | *.un~ 14 | -------------------------------------------------------------------------------- /boilerplate/config/config.unittest.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | mysql: { 5 | client: { 6 | database: 'unittest', 7 | }, 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /boilerplate/_.gitignore: -------------------------------------------------------------------------------- 1 | logs/ 2 | npm-debug.log 3 | yarn-error.log 4 | node_modules/ 5 | package-lock.json 6 | yarn.lock 7 | coverage/ 8 | .idea/ 9 | run/ 10 | .DS_Store 11 | *.sw* 12 | *.un~ 13 | -------------------------------------------------------------------------------- /boilerplate/config/plugin.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.mysql = { 4 | enable: true, 5 | package: 'egg-mysql', 6 | }; 7 | 8 | exports.mongoose = { 9 | enable: false, 10 | package: 'egg-mongoose', 11 | }; 12 | -------------------------------------------------------------------------------- /boilerplate/app/router.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * @param {Egg.Application} app - egg application 5 | */ 6 | module.exports = app => { 7 | const { router, controller } = app; 8 | router.get('/', controller.home.index); 9 | }; 10 | -------------------------------------------------------------------------------- /boilerplate/app/controller/home.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Controller = require('egg').Controller; 4 | 5 | class HomeController extends Controller { 6 | async index() { 7 | this.ctx.body = 'hi, egg'; 8 | } 9 | } 10 | 11 | module.exports = HomeController; 12 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | matrix: 3 | - nodejs_version: '8' 4 | 5 | install: 6 | - ps: Install-Product node $env:nodejs_version 7 | - npm i npminstall && node_modules\.bin\npminstall 8 | 9 | test_script: 10 | - node --version 11 | - npm --version 12 | - npm run test 13 | 14 | build: off 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '8' 5 | before_install: 6 | - mysql -e 'CREATE DATABASE IF NOT EXISTS unittest;' 7 | - echo "USE mysql;\nUPDATE user SET password=PASSWORD('miniappmysql123') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root 8 | install: 9 | - npm i npminstall && npminstall 10 | script: 11 | - npm run ci 12 | after_script: 13 | - npminstall codecov && codecov 14 | services: 15 | - mysql 16 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | name: { 5 | desc: 'project name', 6 | }, 7 | description: { 8 | desc: 'project description', 9 | }, 10 | author: { 11 | desc: 'project author', 12 | }, 13 | keys: { 14 | desc: 'cookie security keys', 15 | default: Date.now() + '_' + random(100, 10000), 16 | }, 17 | }; 18 | 19 | function random(start, end) { 20 | return Math.floor(Math.random() * (end - start) + start); 21 | } 22 | -------------------------------------------------------------------------------- /.autod.conf: -------------------------------------------------------------------------------- 1 | 'ues strict'; 2 | 3 | module.exports = { 4 | write: true, 5 | prefix: '^', 6 | devprefix: '^', 7 | exclude: [ 8 | 'test/fixtures', 9 | 'boilerplate', 10 | 'dist', 11 | ], 12 | devdep: [ 13 | 'autod', 14 | 'autod-egg', 15 | 'eslint', 16 | 'eslint-config-egg', 17 | 'egg-ci', 18 | 'egg-init', 19 | 'npminstall', 20 | 'webstorm-disable-index', 21 | ], 22 | keep: [ 23 | ], 24 | semver: [ 25 | ], 26 | }; 27 | -------------------------------------------------------------------------------- /boilerplate/.autod.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | write: true, 5 | prefix: '^', 6 | plugin: 'autod-egg', 7 | test: [ 8 | 'test', 9 | 'benchmark', 10 | ], 11 | dep: [ 12 | 'egg', 13 | 'egg-scripts', 14 | ], 15 | devdep: [ 16 | 'egg-ci', 17 | 'egg-bin', 18 | 'egg-mock', 19 | 'autod', 20 | 'autod-egg', 21 | 'eslint', 22 | 'eslint-config-egg', 23 | 'webstorm-disable-index', 24 | ], 25 | exclude: [ 26 | './test/fixtures', 27 | './dist', 28 | ], 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /boilerplate/test/app/controller/home.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const { app, assert } = require('egg-mock/bootstrap'); 4 | 5 | describe('test/app/controller/home.test.js', () => { 6 | 7 | it('should assert', function* () { 8 | const pkg = require('../../../package.json'); 9 | assert(app.config.keys.startsWith(pkg.name)); 10 | 11 | // const ctx = app.mockContext({}); 12 | // yield ctx.service.xx(); 13 | }); 14 | 15 | it('should GET /', () => { 16 | return app.httpRequest() 17 | .get('/') 18 | .expect('hi, egg') 19 | .expect(200); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /boilerplate/README.md: -------------------------------------------------------------------------------- 1 | # {{name}} 2 | 3 | {{description}} 4 | 5 | ## 快速入门 6 | 7 | 8 | 9 | 如需进一步了解,参见 [egg 文档][egg]。 10 | 11 | ### 本地开发 12 | 13 | ```bash 14 | $ npm i 15 | $ npm run dev 16 | $ open http://localhost:7001/ 17 | ``` 18 | 19 | ### 部署 20 | 21 | ```bash 22 | $ npm start 23 | $ npm stop 24 | ``` 25 | 26 | ### 单元测试 27 | 28 | - [egg-bin] 内置了 [mocha], [thunk-mocha], [power-assert], [istanbul] 等框架,让你可以专注于写单元测试,无需理会配套工具。 29 | - 断言库非常推荐使用 [power-assert]。 30 | - 具体参见 [egg 文档 - 单元测试](https://eggjs.org/zh-cn/core/unittest)。 31 | 32 | ### 内置指令 33 | 34 | - 使用 `npm run lint` 来做代码风格检查。 35 | - 使用 `npm test` 来执行单元测试。 36 | - 使用 `npm run autod` 来自动检测依赖更新,详细参见 [autod](https://www.npmjs.com/package/autod) 。 37 | 38 | 39 | [egg]: https://eggjs.org 40 | -------------------------------------------------------------------------------- /boilerplate/conf/nginx.conf: -------------------------------------------------------------------------------- 1 | user admin; 2 | 3 | worker_rlimit_nofile 100000; 4 | 5 | events { 6 | use epoll; 7 | worker_connections 20480; 8 | } 9 | 10 | error_log /home/admin/logs/nginx-error.log; 11 | 12 | http { 13 | default_type application/octet-stream; 14 | index index.html index.htm; 15 | 16 | access_log /home/admin/logs/nginx-access.log; 17 | 18 | upstream nodejs { 19 | server 127.0.0.1:7001; 20 | keepalive 10; 21 | } 22 | 23 | server { 24 | listen 80 default_server; 25 | server_name _; 26 | 27 | location / { 28 | proxy_pass http://nodejs; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /boilerplate/config/config.default.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = appInfo => { 4 | const config = exports = {}; 5 | 6 | // use for cookie sign key, should change to your own and keep security 7 | config.keys = appInfo.name + '_{{keys}}'; 8 | 9 | // add your config here 10 | config.middleware = []; 11 | 12 | config.security = { 13 | csrf: { 14 | ignoreJSON: false, 15 | }, 16 | }; 17 | 18 | config.mysql = { 19 | client: { 20 | host: '127.0.0.1', 21 | port: '3306', 22 | user: 'root', 23 | password: 'miniappmysql123', 24 | database: '', 25 | }, 26 | app: true, 27 | agent: false, 28 | }; 29 | 30 | config.mongoose = { 31 | client: { 32 | url: 'mongodb://127.0.0.1/example', 33 | }, 34 | }; 35 | 36 | return config; 37 | }; 38 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | 1.2.0 / 2018-09-13 3 | ================== 4 | 5 | **features** 6 | * [[`2a18ce6`](http://github.com/eggjs/egg-boilerplate-alipay-tiny/commit/2a18ce66f0ac7c020f49df8a2f81d8ab0fc6ab35)] - feat: add nginx file (#3) (Haoliang Gao <>) 7 | 8 | 1.1.0 / 2018-09-04 9 | ================== 10 | 11 | **features** 12 | * [[`d69ea99`](http://github.com/eggjs/egg-boilerplate-alipay-tiny/commit/d69ea99f8ff792d77d05bbcdbc7e25cf1494921a)] - feat: add mongoose (#2) (Haoliang Gao <>) 13 | 14 | 1.0.0 / 2018-08-15 15 | ================== 16 | 17 | **features** 18 | * [[`85549ae`](http://github.com/eggjs/egg-boilerplate-alipay-tiny/commit/85549aeb235aaf7bb9e577458bddafd92bf34671)] - feat: first implement (#1) (Haoliang Gao <>),fatal: No names found, cannot describe anything. 19 | 20 | **others** 21 | 22 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 10 | 11 | ##### Checklist 12 | 13 | 14 | - [ ] `npm test` passes 15 | - [ ] tests and/or benchmarks are included 16 | - [ ] documentation is changed or added 17 | - [ ] commit message follows commit guidelines 18 | 19 | ##### Affected core subsystem(s) 20 | 21 | 22 | 23 | ##### Description of change 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Alibaba Group Holding Limited and other contributors. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /boilerplate/_package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "{{name}}", 3 | "version": "1.0.0", 4 | "description": "{{description}}", 5 | "private": true, 6 | "dependencies": { 7 | "egg": "^2.2.1", 8 | "egg-mysql": "^3.0.0", 9 | "egg-mongoose": "^3.1.0", 10 | "egg-scripts": "^2.5.0" 11 | }, 12 | "devDependencies": { 13 | "autod": "^3.0.1", 14 | "autod-egg": "^1.0.0", 15 | "egg-bin": "^4.3.5", 16 | "egg-ci": "^1.8.0", 17 | "egg-mock": "^3.14.0", 18 | "eslint": "^4.11.0", 19 | "eslint-config-egg": "^6.0.0", 20 | "webstorm-disable-index": "^1.2.0" 21 | }, 22 | "engines": { 23 | "node": ">=8.9.0" 24 | }, 25 | "scripts": { 26 | "start": "egg-scripts start --daemon --title=egg-server-{{name}}", 27 | "stop": "egg-scripts stop --title=egg-server-{{name}}", 28 | "dev": "egg-bin dev", 29 | "debug": "egg-bin debug", 30 | "test": "npm run lint -- --fix && npm run test-local", 31 | "test-local": "egg-bin test", 32 | "cov": "egg-bin cov", 33 | "lint": "eslint .", 34 | "ci": "npm run lint && npm run cov", 35 | "autod": "autod" 36 | }, 37 | "ci": { 38 | "version": "8" 39 | }, 40 | "repository": { 41 | "type": "git", 42 | "url": "" 43 | }, 44 | "author": "{{author}}", 45 | "license": "MIT" 46 | } 47 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "egg-boilerplate-alipay-tiny", 3 | "version": "1.2.0", 4 | "description": "支付宝小程序服务端脚手架", 5 | "scripts": { 6 | "autod": "autod", 7 | "lint": "eslint .", 8 | "test": "npm run lint -- --fix && npm run test-boilerplate", 9 | "ci": "npm run lint && npm run ci-boilerplate", 10 | "test-boilerplate": "npm run build && npm run install-deps && cd dist && npm test", 11 | "ci-boilerplate": "npm run build && npm run install-deps && cd dist && npm run ci", 12 | "clean": "rm -rf boilerplate/.idea boilerplate/logs boilerplate/node_modules boilerplate/run", 13 | "build": "npm run clean && egg-init dist --force --silent --template=./", 14 | "install-deps": "cd dist && npm i autod-egg && ../node_modules/.bin/autod && npm i" 15 | }, 16 | "homepage": "https://github.com/eggjs/egg-boilerplate-alipay-tiny", 17 | "bugs": "https://github.com/eggjs/egg/issues", 18 | "repository": { 19 | "type": "git", 20 | "url": "git@github.com:eggjs/egg-boilerplate-alipay-tiny.git" 21 | }, 22 | "author": "popomore", 23 | "devDependencies": { 24 | "autod": "^3.0.1", 25 | "autod-egg": "^1.0.0", 26 | "egg-ci": "^1.8.0", 27 | "egg-init": "^1.12.0", 28 | "eslint": "^4.10.0", 29 | "eslint-config-egg": "^5.1.1", 30 | "npminstall": "^3.2.1", 31 | "webstorm-disable-index": "^1.2.0" 32 | }, 33 | "ci": { 34 | "version": "8" 35 | }, 36 | "dependencies": {} 37 | } 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # egg-boilerplate-alipay-tiny 2 | 3 | 支付宝小程序服务端脚手架 4 | 5 | [![NPM version][npm-image]][npm-url] 6 | [![build status][travis-image]][travis-url] 7 | [![Test coverage][codecov-image]][codecov-url] 8 | [![David deps][david-image]][david-url] 9 | [![Known Vulnerabilities][snyk-image]][snyk-url] 10 | [![npm download][download-image]][download-url] 11 | 12 | [npm-image]: https://img.shields.io/npm/v/egg-boilerplate-alipay-tiny.svg?style=flat-square 13 | [npm-url]: https://npmjs.org/package/egg-boilerplate-alipay-tiny 14 | [travis-image]: https://img.shields.io/travis/eggjs/egg-boilerplate-alipay-tiny.svg?style=flat-square 15 | [travis-url]: https://travis-ci.org/eggjs/egg-boilerplate-alipay-tiny 16 | [codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-boilerplate-alipay-tiny.svg?style=flat-square 17 | [codecov-url]: https://codecov.io/gh/eggjs/egg-boilerplate-alipay-tiny 18 | [david-image]: https://img.shields.io/david/eggjs/egg-boilerplate-alipay-tiny.svg?style=flat-square 19 | [david-url]: https://david-dm.org/eggjs/egg-boilerplate-alipay-tiny 20 | [snyk-image]: https://snyk.io/test/npm/egg-boilerplate-alipay-tiny/badge.svg?style=flat-square 21 | [snyk-url]: https://snyk.io/test/npm/egg-boilerplate-alipay-tiny 22 | [download-image]: https://img.shields.io/npm/dm/egg-boilerplate-alipay-tiny.svg?style=flat-square 23 | [download-url]: https://npmjs.org/package/egg-boilerplate-alipay-tiny 24 | 25 | ## Installation 26 | 27 | **Don't `npm i` this directly** 28 | 29 | ```bash 30 | $ npm i -g egg-init 31 | $ egg-init --package egg-boilerplate-alipay-tiny showcase 32 | $ cd showcase 33 | $ npm i 34 | $ npm run dev 35 | $ open http://localhost:7001 36 | ``` 37 | 38 | See [egg-init](https://github.com/eggjs/egg-init) for more detail. 39 | --------------------------------------------------------------------------------