mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 14:44:31 +00:00
Add default controller generator
This commit is contained in:
parent
95f5f55608
commit
588efe2901
16
packages/strapi-generate-controller/.editorconfig
Executable file
16
packages/strapi-generate-controller/.editorconfig
Executable file
@ -0,0 +1,16 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[{package.json,*.yml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
102
packages/strapi-generate-controller/.gitignore
vendored
Executable file
102
packages/strapi-generate-controller/.gitignore
vendored
Executable file
@ -0,0 +1,102 @@
|
||||
############################
|
||||
# OS X
|
||||
############################
|
||||
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
Icon
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
._*
|
||||
|
||||
|
||||
############################
|
||||
# Linux
|
||||
############################
|
||||
|
||||
*~
|
||||
|
||||
|
||||
############################
|
||||
# Windows
|
||||
############################
|
||||
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
Desktop.ini
|
||||
$RECYCLE.BIN/
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
|
||||
############################
|
||||
# Packages
|
||||
############################
|
||||
|
||||
*.7z
|
||||
*.csv
|
||||
*.dat
|
||||
*.dmg
|
||||
*.gz
|
||||
*.iso
|
||||
*.jar
|
||||
*.rar
|
||||
*.tar
|
||||
*.zip
|
||||
*.com
|
||||
*.class
|
||||
*.dll
|
||||
*.exe
|
||||
*.o
|
||||
*.seed
|
||||
*.so
|
||||
*.swo
|
||||
*.swp
|
||||
*.swn
|
||||
*.swm
|
||||
*.out
|
||||
*.pid
|
||||
|
||||
|
||||
############################
|
||||
# Logs and databases
|
||||
############################
|
||||
|
||||
*.log
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
|
||||
############################
|
||||
# Misc.
|
||||
############################
|
||||
|
||||
*#
|
||||
ssl
|
||||
.idea
|
||||
nbproject
|
||||
|
||||
|
||||
############################
|
||||
# Node.js
|
||||
############################
|
||||
|
||||
lib-cov
|
||||
lcov.info
|
||||
pids
|
||||
logs
|
||||
results
|
||||
build
|
||||
node_modules
|
||||
.node_history
|
||||
|
||||
|
||||
############################
|
||||
# Tests
|
||||
############################
|
||||
|
||||
testApp
|
||||
coverage
|
||||
103
packages/strapi-generate-controller/.npmignore
Executable file
103
packages/strapi-generate-controller/.npmignore
Executable file
@ -0,0 +1,103 @@
|
||||
############################
|
||||
# OS X
|
||||
############################
|
||||
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
Icon
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
._*
|
||||
|
||||
|
||||
############################
|
||||
# Linux
|
||||
############################
|
||||
|
||||
*~
|
||||
|
||||
|
||||
############################
|
||||
# Windows
|
||||
############################
|
||||
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
Desktop.ini
|
||||
$RECYCLE.BIN/
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
|
||||
############################
|
||||
# Packages
|
||||
############################
|
||||
|
||||
*.7z
|
||||
*.csv
|
||||
*.dat
|
||||
*.dmg
|
||||
*.gz
|
||||
*.iso
|
||||
*.jar
|
||||
*.rar
|
||||
*.tar
|
||||
*.zip
|
||||
*.com
|
||||
*.class
|
||||
*.dll
|
||||
*.exe
|
||||
*.o
|
||||
*.seed
|
||||
*.so
|
||||
*.swo
|
||||
*.swp
|
||||
*.swn
|
||||
*.swm
|
||||
*.out
|
||||
*.pid
|
||||
|
||||
|
||||
############################
|
||||
# Logs and databases
|
||||
############################
|
||||
|
||||
*.log
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
|
||||
############################
|
||||
# Misc.
|
||||
############################
|
||||
|
||||
*#
|
||||
ssl
|
||||
.idea
|
||||
nbproject
|
||||
|
||||
|
||||
############################
|
||||
# Node.js
|
||||
############################
|
||||
|
||||
lib-cov
|
||||
lcov.info
|
||||
pids
|
||||
logs
|
||||
results
|
||||
build
|
||||
node_modules
|
||||
.node_history
|
||||
|
||||
|
||||
############################
|
||||
# Tests
|
||||
############################
|
||||
|
||||
test
|
||||
testApp
|
||||
coverage
|
||||
9
packages/strapi-generate-controller/LICENSE.md
Executable file
9
packages/strapi-generate-controller/LICENSE.md
Executable file
@ -0,0 +1,9 @@
|
||||
# MIT License
|
||||
|
||||
Copyright © 2015-2016 Wistity.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
31
packages/strapi-generate-controller/README.md
Executable file
31
packages/strapi-generate-controller/README.md
Executable file
@ -0,0 +1,31 @@
|
||||
# strapi-generate-controller
|
||||
|
||||
[](https://www.npmjs.org/package/strapi-generate-controller)
|
||||
[](https://www.npmjs.org/package/strapi-generate-controller)
|
||||
[](https://david-dm.org/wistityhq/strapi-generate-controller)
|
||||
[](https://travis-ci.org/wistityhq/strapi-generate-controller)
|
||||
[](http://slack.strapi.io)
|
||||
|
||||
This Strapi generator contains the default files for a controller.
|
||||
|
||||
This generator can be called with:
|
||||
|
||||
```bash
|
||||
$ strapi generate:controller controllerName apiName
|
||||
```
|
||||
|
||||
For example if you want to generate a `group` controller for the `user` API:
|
||||
|
||||
```bash
|
||||
$ strapi generate:controller group user
|
||||
```
|
||||
|
||||
## Resources
|
||||
|
||||
- [MIT License](LICENSE.md)
|
||||
|
||||
## Links
|
||||
|
||||
- [Strapi website](http://strapi.io/)
|
||||
- [Strapi community on Slack](http://slack.strapi.io)
|
||||
- [Strapi news on Twitter](https://twitter.com/strapijs)
|
||||
49
packages/strapi-generate-controller/lib/before.js
Executable file
49
packages/strapi-generate-controller/lib/before.js
Executable file
@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
|
||||
/**
|
||||
* This `before` function is run before generating targets.
|
||||
* Validate, configure defaults, get extra dependencies, etc.
|
||||
*
|
||||
* @param {Object} scope
|
||||
* @param {Function} cb
|
||||
*/
|
||||
|
||||
module.exports = function (scope, cb) {
|
||||
if (!scope.rootPath || !scope.args[0]) {
|
||||
return cb.invalid('Usage: `$ strapi generate:controller controllerName apiName`');
|
||||
}
|
||||
|
||||
// `scope.args` are the raw command line arguments.
|
||||
_.defaults(scope, {
|
||||
id: scope.args[0],
|
||||
api: scope.args[1]
|
||||
});
|
||||
|
||||
// Determine default values based on the available scope.
|
||||
_.defaults(scope, {
|
||||
globalID: _.capitalize(scope.id),
|
||||
ext: '.js'
|
||||
});
|
||||
|
||||
// Take another pass to take advantage of the defaults absorbed in previous passes.
|
||||
_.defaults(scope, {
|
||||
rootPath: scope.rootPath,
|
||||
filename: _.capitalize(scope.id + scope.ext)
|
||||
});
|
||||
|
||||
// Humanize output.
|
||||
_.defaults(scope, {
|
||||
humanizeId: scope.args[0],
|
||||
humanizedPath: '`./api/' + scope.api + '/controllers`'
|
||||
});
|
||||
|
||||
// Trigger callback with no error to proceed.
|
||||
return cb();
|
||||
};
|
||||
22
packages/strapi-generate-controller/lib/index.js
Executable file
22
packages/strapi-generate-controller/lib/index.js
Executable file
@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
// Node.js core.
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* Generate a core API
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
templatesDirectory: path.resolve(__dirname, '..', 'templates'),
|
||||
before: require('./before'),
|
||||
targets: {
|
||||
'api/:api/controllers/:filename': {
|
||||
template: 'controller.template'
|
||||
}
|
||||
}
|
||||
};
|
||||
42
packages/strapi-generate-controller/package.json
Executable file
42
packages/strapi-generate-controller/package.json
Executable file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "strapi-generate-controller",
|
||||
"version": "2.0.0",
|
||||
"description": "Generate a controller for a Strapi API.",
|
||||
"homepage": "http://strapi.io",
|
||||
"keywords": [
|
||||
"controller",
|
||||
"generate",
|
||||
"generator",
|
||||
"strapi"
|
||||
],
|
||||
"main": "./lib/index.js",
|
||||
"directories": {
|
||||
"lib": "./lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash": "~4.6.1"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublish": "npm prune"
|
||||
},
|
||||
"author": {
|
||||
"email": "hack@wistity.co",
|
||||
"name": "Wistity team",
|
||||
"url": "http://wistity.co"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Wistity team",
|
||||
"email": "hack@wistity.co",
|
||||
"url": "http://wistity.co"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/wistityhq/strapi.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/wistityhq/strapi/issues"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
9
packages/strapi-generate-controller/templates/controller.template
Executable file
9
packages/strapi-generate-controller/templates/controller.template
Executable file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* A set of functions called "actions" for `<%= globalID %>`
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user