├── .gitignore ├── LICENSE ├── README.md ├── README_en.md ├── generators ├── app │ ├── index.js │ └── templates │ │ └── _index.php ├── controller │ ├── index.js │ └── templates │ │ ├── _base.html │ │ ├── controller.php │ │ └── view.html ├── model │ ├── index.js │ └── templates │ │ └── model.php ├── serve │ └── index.js └── space │ ├── index.js │ └── templates │ ├── controller.php │ └── space │ ├── Common │ └── index.html │ ├── Conf │ ├── config.php │ └── index.html │ ├── Controller │ └── index.html │ ├── Model │ └── index.html │ ├── View │ ├── Index │ │ ├── base.html │ │ └── index.html │ └── index.html │ └── index.html ├── package.json └── test └── create.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | npm-debug.log -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Disney 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Thinkphp Generator | Thinkphp 生成器 2 | 3 | > 利用yeoman自动构建thinkphp应用 - 通过命令行自动创建应用以及 Controller/Model/View. 4 | 5 | [English Doc](/README_en.md) 6 | 7 | ## 使用方法 8 | 9 | 安装 `Composer` [关于 composer](https://getcomposer.org/) 10 | ``` 11 | curl -sS https://getcomposer.org/installer | php 12 | mv composer.phar /usr/local/bin/composer 13 | ``` 14 | 15 | 16 | 安装 `yo` and `generator-thinkphp` [关于 Yeoman](http://yeoman.io/) 17 | ``` 18 | npm install -g yo generator-thinkphp 19 | ``` 20 | 21 | `cd` 进入到你的工作文件夹以进行下一步操作: 22 | ``` 23 | cd [workPlace] 24 | ``` 25 | **`workPlace`是指你平时写代码的文件夹** 26 | 27 | 28 | 输入 `yo thinkphp` 来生成应用,根据指引输入,你可以自定义应用名称,如果你未安装 `Composer` 会有提示是否自动安装: 29 | ``` 30 | yo thinkphp 31 | ``` 32 | 33 | 输入 `cd [appName]` 进入你的应用目录,开始一下步操作: 34 | ``` 35 | cd [appName] 36 | ``` 37 | **`appName`是指你自定义应用的名称** 38 | 39 | 40 | ## 自动生成器 41 | 42 | 已支持的生成器: 43 | 44 | * [thinkphp](#app) (aka [thinkphp:app](#app)) 45 | * [thinkphp:controller](#controller) 46 | * [thinkphp:model](#model) 47 | * [thinkphp:space](#space) 48 | * [thinkphp:serve](#serve) 49 | 50 | ### App 51 | 52 | 创建新的 [ThinkPHP](https://github.com/liu21st/thinkphp) 应用并使用 [Composer](https://getcomposer.org/). 53 | 54 | Example: 55 | ```bash 56 | yo thinkphp 57 | ``` 58 | 59 | ### Controller 60 | 61 | 为你的应用自动生成新的Controller. 例如 `yo thinkphp:controller [classedName] [spaceName]`. 62 | 63 | **`classedName` 为必选项,不能为空.** 64 | 65 | **`spaceName` 默认为 `Home` ,可选项.** 66 | 67 | Example: 68 | ```bash 69 | yo thinkphp:controller Index Home 70 | ``` 71 | 72 | 此命令生成 `Application/Home/Controller/IndexController.class.php`: 73 | ```php 74 | display(); 82 | } 83 | 84 | } 85 | ``` 86 | 87 | 以及 `Application/Home/View/Index/index.html`: 88 | 89 | ```html 90 | 91 | 92 |

Index

93 |
94 | ``` 95 | 96 | 以及 `Application/Home/View/Index/base.html`: 97 | 98 | ```html 99 | 100 | 101 | 102 | 103 | 104 | Home 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | ``` 114 | 115 | ### Model 116 | 117 | 和Controller命令基本一样, 为你的应用自动生成新的Model. 118 | 119 | Example: 120 | ```bash 121 | yo thinkphp:model User Home 122 | ``` 123 | 124 | 生成 `Application/Home/Model/UserModel.class.php`: 125 | ```php 126 | Yeoman generator for ThinkPHP - Create ThinkPHP Project and generate Controller/Model/View for it. 4 | 5 | [中文文档](/README.md) 6 | 7 | ## Usage 8 | 9 | Install `Composer` [Read more about composer](https://getcomposer.org/) 10 | ``` 11 | curl -sS https://getcomposer.org/installer | php 12 | mv composer.phar /usr/local/bin/composer 13 | ``` 14 | 15 | 16 | Install `yo` and `generator-thinkphp` [Read more about Yeoman](http://yeoman.io/) 17 | ``` 18 | npm install -g yo generator-thinkphp 19 | ``` 20 | 21 | Then `cd` into your workplace: 22 | ``` 23 | cd [workPlace] 24 | ``` 25 | **The `workPlace` means any folder that you would like to put your codes in.** 26 | 27 | Run `yo thinkphp` to init your project, and follow the steps,you can name your app & install `Composer` and so on: 28 | ``` 29 | yo thinkphp 30 | ``` 31 | 32 | type `cd [appName]` get into your app and start coding: 33 | ``` 34 | cd [appName] 35 | ``` 36 | **`appName` is your custome app name** 37 | 38 | ## Generators 39 | 40 | Available generators: 41 | 42 | * [thinkphp](#Application) (aka [thinkphp:Application](#Application)) 43 | * [thinkphp:controller](#controller) 44 | * [thinkphp:model](#model) 45 | * [thinkphp:space](#space) 46 | * [thinkphp:serve](#serve) 47 | 48 | ### App 49 | 50 | Create a new project using [ThinkPHP](https://github.com/liu21st/thinkphp) and using [Composer](https://getcomposer.org/). 51 | 52 | Example: 53 | ```bash 54 | yo thinkphp 55 | ``` 56 | 57 | ### Controller 58 | 59 | Generates a controller and view for your Application. Command like `yo thinkphp:controller [classedName] [spaceName]`. 60 | 61 | **The `classedName` is required value, without it will get error.** 62 | 63 | **The default `spaceName` is `Home` and it's optional.** 64 | 65 | Example: 66 | ```bash 67 | yo thinkphp:controller Index Home 68 | ``` 69 | 70 | Produces `Application/Home/Controller/IndexController.class.php`: 71 | ```php 72 | display(); 80 | } 81 | 82 | } 83 | ``` 84 | 85 | Produces `Application/Home/View/Index/index.html`: 86 | 87 | ```html 88 | 89 | 90 |

Index

91 |
92 | ``` 93 | 94 | Produces `Application/Home/View/Index/base.html`: 95 | 96 | ```html 97 | 98 | 99 | 100 | 101 | 102 | Home 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | ``` 112 | 113 | ### Model 114 | 115 | Much like Controller generator, it generates a plain model for your Project. 116 | 117 | Example: 118 | ```bash 119 | yo thinkphp:model User Home 120 | ``` 121 | 122 | Produces `Application/Home/Model/UserModel.class.php`: 123 | ```php 124 | 11 | // +---------------------------------------------------------------------- 12 | 13 | // 应用入口文件 14 | 15 | // 检测PHP环境 16 | if (version_compare(PHP_VERSION, '5.3.0', '<')) { 17 | die('require PHP > 5.3.0 !'); 18 | } 19 | 20 | // 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false 21 | define('APP_DEBUG', true); 22 | 23 | // 定义应用目录 24 | define('APP_PATH', './Application/'); 25 | 26 | // 引入ThinkPHP入口文件 27 | require './ThinkPHP/ThinkPHP.php'; 28 | 29 | // 亲^_^ 后面不需要任何代码了 就是如此简单 30 | -------------------------------------------------------------------------------- /generators/controller/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var generators = require('yeoman-generator'); 3 | var _ = require('lodash'); 4 | 5 | module.exports = generators.Base.extend({ 6 | constructor: function () { 7 | generators.Base.apply(this, arguments); 8 | // This makes `arguments` a required argument. 9 | this.argument('classedName', { type: String, required: true }); 10 | this.argument('spaceName', { type: String, optional: true, defaults: 'Home' }); 11 | // And you can then access it later on this way; e.g. CamelCased 12 | this.classedName = _.startCase(this.classedName); 13 | this.spaceName = _.startCase(this.spaceName); 14 | }, 15 | 16 | writing: function () { 17 | this.template('controller.php', this.destinationPath('Application/') + this.spaceName + '/Controller/' + this.classedName + 'Controller.class.php'), 18 | { classedName: this.classedName, spaceName: this.spaceName }; 19 | this.template('view.html', this.destinationPath('Application/') + this.spaceName + '/View/'+ this.classedName + '/index.html'), 20 | { classedName: this.classedName }; 21 | this.template('_base.html', this.destinationPath('Application/') + this.spaceName + '/View/'+ this.classedName + '/base.html'), 22 | { classedName: this.classedName }; 23 | }, 24 | }); 25 | -------------------------------------------------------------------------------- /generators/controller/templates/_base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= classedName %> 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /generators/controller/templates/controller.php: -------------------------------------------------------------------------------- 1 | \Controller; 3 | use Think\Controller; 4 | class <%= classedName %>Controller extends Controller { 5 | 6 | public function index(){ 7 | $this->display(); 8 | } 9 | 10 | 11 | } -------------------------------------------------------------------------------- /generators/controller/templates/view.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

<%= classedName %>

4 |
-------------------------------------------------------------------------------- /generators/model/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var generators = require('yeoman-generator'); 3 | var _ = require('lodash'); 4 | 5 | module.exports = generators.Base.extend({ 6 | constructor: function () { 7 | generators.Base.apply(this, arguments); 8 | // This makes `arguments` a required argument. 9 | this.argument('classedName', { type: String, required: true }); 10 | this.argument('spaceName', { type: String, optional: true, defaults: 'Home' }); 11 | // And you can then access it later on this way; e.g. CamelCased 12 | this.classedName = _.startCase(this.classedName); 13 | this.spaceName = _.startCase(this.spaceName); 14 | }, 15 | 16 | writing: function () { 17 | this.template('model.php', this.destinationPath('Application/') + this.spaceName + '/Model/' + this.classedName + 'Model.class.php'), 18 | { classedName: this.classedName, spaceName: this.spaceName }; 19 | 20 | }, 21 | }); 22 | -------------------------------------------------------------------------------- /generators/model/templates/model.php: -------------------------------------------------------------------------------- 1 | \Model; 3 | use Think\Model; 4 | class <%= classedName %>Model extends Model { 5 | 6 | protected $tableName = '<%= classedName %>'; 7 | 8 | 9 | } -------------------------------------------------------------------------------- /generators/serve/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var generators = require('yeoman-generator'); 3 | var chalk = require('chalk'); 4 | 5 | module.exports = generators.Base.extend({ 6 | 7 | 8 | initializing: function () { 9 | this.log(chalk.green.bold('PHP test Server is running!')); 10 | 11 | }, 12 | 13 | end: function () { 14 | this.spawnCommand('php', ['-S', '127.0.0.1:3000']); 15 | 16 | } 17 | 18 | }); -------------------------------------------------------------------------------- /generators/space/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var generators = require('yeoman-generator'); 3 | var _ = require('lodash'); 4 | 5 | module.exports = generators.Base.extend({ 6 | constructor: function () { 7 | generators.Base.apply(this, arguments); 8 | // This makes `spacename` a required argument. 9 | this.argument('spaceName', { type: String, required: true, defaults: 'Admin' }); 10 | // And you can then access it later on this way; e.g. CamelCased 11 | this.spaceName = _.startCase(this.spaceName); 12 | 13 | }, 14 | 15 | 16 | writing: function () { 17 | 18 | this.directory('space', this.destinationPath('Application/') + this.spaceName), 19 | { spaceName: this.spaceName }; 20 | this.template('controller.php', this.destinationPath('Application/') + this.spaceName + '/Controller/IndexController.class.php'), 21 | { spaceName: this.spaceName }; 22 | 23 | }, 24 | 25 | }); 26 | -------------------------------------------------------------------------------- /generators/space/templates/controller.php: -------------------------------------------------------------------------------- 1 | \Controller; 3 | use Think\Controller; 4 | class IndexController extends Controller { 5 | public function index(){ 6 | $this->display(); 7 | } 8 | } -------------------------------------------------------------------------------- /generators/space/templates/space/Common/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /generators/space/templates/space/Conf/config.php: -------------------------------------------------------------------------------- 1 | '配置值' 4 | ); -------------------------------------------------------------------------------- /generators/space/templates/space/Conf/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /generators/space/templates/space/Controller/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /generators/space/templates/space/Model/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /generators/space/templates/space/View/Index/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= spaceName %> 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /generators/space/templates/space/View/Index/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

<%= spaceName %>

4 |
-------------------------------------------------------------------------------- /generators/space/templates/space/View/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /generators/space/templates/space/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-thinkphp", 3 | "version": "0.2.50", 4 | "description": "Yeoman generator for thinkphp", 5 | "main": "index.js", 6 | "files": [ 7 | "generators", 8 | "test" 9 | ], 10 | "keywords": [ 11 | "yeoman-generator", 12 | "generator", 13 | "thinkphp" 14 | ], 15 | "author": { 16 | "name": "discountry" 17 | }, 18 | "license": "MIT", 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/discountry/generator-thinkphp.git" 22 | }, 23 | "scripts": { 24 | "test": "mocha" 25 | }, 26 | "dependencies": { 27 | "chalk": "^1.1.1", 28 | "lodash": "^3.10.1", 29 | "mkdirp": "^0.5.1", 30 | "mocha": "*", 31 | "yeoman-generator": "^0.20.1", 32 | "yeoman-welcome": "^1.0.1" 33 | }, 34 | "gitHead": "c26aafc524fa8645195490d65a11e5e33d9a66ef", 35 | "bugs": { 36 | "url": "https://github.com/discountry/generator-thinkphp/issues" 37 | }, 38 | "homepage": "https://github.com/discountry/generator-thinkphp#readme", 39 | "_id": "generator-thinkphp@0.2.32", 40 | "_shasum": "80db3e3cf52a632562f9f07eeaf378b5cf1d2c8d", 41 | "_from": "generator-thinkphp@*", 42 | "_npmVersion": "2.9.1", 43 | "_nodeVersion": "0.12.3", 44 | "_npmUser": { 45 | "name": "discountry", 46 | "email": "feibilanceon@gmail.com" 47 | }, 48 | "dist": { 49 | "shasum": "80db3e3cf52a632562f9f07eeaf378b5cf1d2c8d", 50 | "tarball": "http://registry.npmjs.org/generator-thinkphp/-/generator-thinkphp-0.2.32.tgz" 51 | }, 52 | "maintainers": [ 53 | { 54 | "name": "discountry", 55 | "email": "feibilanceon@gmail.com" 56 | } 57 | ], 58 | "directories": {}, 59 | "_resolved": "https://registry.npmjs.org/generator-thinkphp/-/generator-thinkphp-0.2.32.tgz" 60 | } 61 | -------------------------------------------------------------------------------- /test/create.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var path = require('path'); 3 | var helpers = require('yeoman-generator').test; 4 | var assert = require('yeoman-assert'); 5 | 6 | describe('general', function () { 7 | before(function (done) { 8 | helpers.run(path.join(__dirname, '../app')) 9 | .inDir(path.join(__dirname, 'temp')) 10 | .on('end', done); 11 | }); 12 | 13 | it('the generator can be required without throwing', function () { 14 | // not testing the actual run of generators yet 15 | require('../app'); 16 | }); 17 | 18 | it('creates expected files', function () { 19 | assert.file([ 20 | 'index.php', 21 | 'composer.json', 22 | '.yo-rc.json', 23 | '.htaccess' 24 | ]); 25 | }); 26 | }); 27 | --------------------------------------------------------------------------------