├── .editorconfig ├── .gitignore ├── .snyk ├── .travis.yml ├── AUTHORS.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── generators ├── adapter │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ └── index.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ ├── Adapter.js │ │ └── Adapter.test.js ├── app │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ ├── adapter.js │ │ ├── app.js │ │ ├── authentication.js │ │ ├── blueprint.js │ │ ├── config.js │ │ ├── controller.js │ │ ├── cron.js │ │ ├── hook.js │ │ ├── index.js │ │ ├── logger.js │ │ ├── model.js │ │ ├── policy.js │ │ ├── response.js │ │ ├── service.js │ │ └── swagger.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ ├── .snyk │ │ ├── Dockerfile │ │ ├── README.md │ │ ├── app.js │ │ ├── editorconfig │ │ ├── esdoc.json │ │ ├── gitignore │ │ ├── package.json │ │ ├── sailsrc │ │ └── test │ │ ├── bootstrap.js │ │ └── mocha.opts ├── authentication │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ └── index.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ ├── api │ │ ├── controllers │ │ │ ├── AuthController.js │ │ │ └── UserController.js │ │ ├── models │ │ │ └── User.js │ │ └── policies │ │ │ └── isAuthenticated.js │ │ ├── config │ │ ├── passport.js │ │ └── policies.js │ │ └── test │ │ └── unit │ │ ├── controllers │ │ ├── AuthController.test.js │ │ └── UserController.test.js │ │ ├── models │ │ └── User.test.js │ │ └── policies │ │ └── isAuthenticated.test.js ├── blueprint │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ └── index.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ ├── Blueprint.js │ │ ├── Blueprint.test.js │ │ ├── api │ │ └── blueprints │ │ │ ├── add.js │ │ │ ├── create.js │ │ │ ├── destroy.js │ │ │ ├── find.js │ │ │ ├── findone.js │ │ │ ├── populate.js │ │ │ ├── remove.js │ │ │ └── update.js │ │ └── test │ │ └── unit │ │ └── blueprints │ │ ├── add.test.js │ │ ├── create.test.js │ │ ├── destroy.test.js │ │ ├── find.test.js │ │ ├── findone.test.js │ │ ├── populate.test.js │ │ ├── remove.test.js │ │ └── update.test.js ├── config │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ └── index.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ └── config │ │ ├── blueprints.js │ │ ├── bootstrap.js │ │ ├── connections.js │ │ ├── cors.js │ │ ├── env │ │ ├── development.js │ │ ├── production.js │ │ └── test.js │ │ ├── errors.js │ │ ├── globals.js │ │ ├── http.js │ │ ├── models.js │ │ └── routes.js ├── controller │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ └── index.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ ├── Controller.js │ │ ├── Controller.test.js │ │ ├── api │ │ └── controllers │ │ │ ├── PingController.js │ │ │ └── SearchController.js │ │ └── test │ │ └── unit │ │ └── controllers │ │ ├── PingController.test.js │ │ └── SearchController.test.js ├── cron │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ └── index.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ └── cron.template ├── hook │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ └── index.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ ├── Hook.js │ │ ├── Hook.test.js │ │ ├── api │ │ └── hooks │ │ │ ├── CountHook.js │ │ │ └── PluralizeHook.js │ │ └── test │ │ └── unit │ │ └── hooks │ │ ├── CountHook.test.js │ │ └── PluralizeHook.test.js ├── logger │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ └── index.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ ├── bunyanConfig.js │ │ ├── defaultConfig.js │ │ └── winstonConfig.js ├── model │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ └── index.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ ├── Controller.js │ │ ├── Controller.test.js │ │ ├── Model.js │ │ ├── Model.test.js │ │ └── ModelFixture.js ├── policy │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ └── index.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ ├── Policy.js │ │ └── Policy.test.js ├── response │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ └── index.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ ├── Response.js │ │ ├── Response.test.js │ │ ├── api │ │ └── responses │ │ │ ├── badRequest.js │ │ │ ├── created.js │ │ │ ├── forbidden.js │ │ │ ├── negotiate.js │ │ │ ├── notFound.js │ │ │ ├── ok.js │ │ │ ├── serverError.js │ │ │ └── unauthorized.js │ │ └── test │ │ └── unit │ │ └── responses │ │ ├── badRequest.test.js │ │ ├── created.test.js │ │ ├── forbidden.test.js │ │ ├── negotiate.test.js │ │ ├── notFound.test.js │ │ ├── ok.test.js │ │ ├── serverError.test.js │ │ └── unauthorized.test.js ├── service │ ├── arguments │ │ └── index.js │ ├── index.js │ ├── options │ │ └── index.js │ ├── questions │ │ └── index.js │ ├── steps │ │ ├── configuring.js │ │ ├── conflicts.js │ │ ├── default.js │ │ ├── end.js │ │ ├── index.js │ │ ├── initializing.js │ │ ├── install.js │ │ ├── prompting.js │ │ └── writing.js │ └── templates │ │ ├── Service.js │ │ ├── Service.test.js │ │ ├── ServiceConfig.js │ │ ├── api │ │ └── services │ │ │ ├── CipherService.js │ │ │ ├── HashService.js │ │ │ ├── ImageService.js │ │ │ ├── LocationService.js │ │ │ ├── MailerService.js │ │ │ ├── PaymentService.js │ │ │ ├── PusherService.js │ │ │ ├── SmsService.js │ │ │ ├── SocialService.js │ │ │ └── StorageService.js │ │ ├── config │ │ └── services │ │ │ ├── cipher.js │ │ │ ├── hash.js │ │ │ ├── image.js │ │ │ ├── location.js │ │ │ ├── mailer.js │ │ │ ├── payment.js │ │ │ ├── pusher.js │ │ │ ├── sms.js │ │ │ ├── social.js │ │ │ └── storage.js │ │ └── test │ │ └── unit │ │ └── services │ │ ├── CipherService.test.js │ │ ├── HashService.test.js │ │ ├── ImageService.test.js │ │ ├── LocationService.test.js │ │ ├── MailerService.test.js │ │ ├── PaymentService.test.js │ │ ├── PusherService.test.js │ │ ├── SmsService.test.js │ │ ├── SocialService.test.js │ │ └── StorageService.test.js └── swagger │ ├── arguments │ └── index.js │ ├── index.js │ ├── options │ └── index.js │ ├── questions │ └── index.js │ ├── steps │ ├── configuring.js │ ├── conflicts.js │ ├── default.js │ ├── end.js │ ├── index.js │ ├── initializing.js │ ├── install.js │ ├── prompting.js │ └── writing.js │ └── templates │ ├── api │ ├── controllers │ │ └── DocsController.js │ └── hooks │ │ └── swagger │ │ ├── index.js │ │ └── lib │ │ ├── spec.js │ │ └── xfmr.js │ ├── config │ └── swagger.js │ └── explorer │ ├── css │ ├── print.css │ ├── reset.css │ ├── screen.css │ ├── style.css │ └── typography.css │ ├── fonts │ ├── droid-sans-v6-latin-700.eot │ ├── droid-sans-v6-latin-700.svg │ ├── droid-sans-v6-latin-700.ttf │ ├── droid-sans-v6-latin-700.woff │ ├── droid-sans-v6-latin-700.woff2 │ ├── droid-sans-v6-latin-regular.eot │ ├── droid-sans-v6-latin-regular.svg │ ├── droid-sans-v6-latin-regular.ttf │ ├── droid-sans-v6-latin-regular.woff │ └── droid-sans-v6-latin-regular.woff2 │ ├── images │ ├── explorer_icons.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── favicon.ico │ ├── logo_small.png │ ├── pet_store_api.png │ ├── throbber.gif │ └── wordnik_api.png │ ├── index.html │ ├── lang │ ├── en.js │ ├── es.js │ ├── ja.js │ ├── pt.js │ ├── ru.js │ ├── tr.js │ ├── translator.js │ └── zh-cn.js │ ├── lib │ ├── backbone-min.js │ ├── handlebars-2.0.0.js │ ├── jquery-1.8.0.min.js │ ├── jquery.ba-bbq.min.js │ ├── jquery.slideto.min.js │ ├── jquery.wiggle.min.js │ ├── marked.js │ └── swagger-oauth.js │ ├── o2c.html │ ├── swagger-ui.js │ └── swagger-ui.min.js ├── package.json └── test ├── mocha.opts └── unit ├── adapter.test.js ├── app.test.js ├── authentication.test.js ├── blueprint.test.js ├── config.test.js ├── controller.test.js ├── cron.test.js ├── hook.test.js ├── logger.test.js ├── model.test.js ├── policy.test.js ├── response.test.js ├── service.test.js └── swagger.test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | node_modules 27 | 28 | # Miscellaneous 29 | *~ 30 | *# 31 | .DS_STORE 32 | .netbeans 33 | nbproject 34 | .idea 35 | .node_history 36 | -------------------------------------------------------------------------------- /.snyk: -------------------------------------------------------------------------------- 1 | # Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. 2 | version: v1.14.1 3 | ignore: {} 4 | # patches apply the minimum changes required to fix a vulnerability 5 | patch: 6 | SNYK-JS-LODASH-567746: 7 | - yeoman-generator > lodash: 8 | patched: '2020-05-01T03:34:24.051Z' 9 | - yeoman-generator > async > lodash: 10 | patched: '2020-05-01T03:34:24.051Z' 11 | - yeoman-generator > yeoman-environment > lodash: 12 | patched: '2020-05-01T03:34:24.051Z' 13 | - yeoman-generator > yeoman-environment > grouped-queue > lodash: 14 | patched: '2020-05-01T03:34:24.051Z' 15 | - yeoman-generator > yeoman-environment > inquirer > lodash: 16 | patched: '2020-05-01T03:34:24.051Z' 17 | - yeoman-generator > yeoman-environment > yeoman-generator > lodash: 18 | patched: '2020-05-01T03:34:24.051Z' 19 | - yeoman-generator > yeoman-environment > yeoman-generator > async > lodash: 20 | patched: '2020-05-01T03:34:24.051Z' 21 | - yeoman-generator > yeoman-environment > yeoman-generator > grouped-queue > lodash: 22 | patched: '2020-05-01T03:34:24.051Z' 23 | - yeoman-generator > yeoman-environment > yeoman-generator > yeoman-environment > lodash: 24 | patched: '2020-05-01T03:34:24.051Z' 25 | - yeoman-generator > yeoman-environment > yeoman-generator > yeoman-environment > grouped-queue > lodash: 26 | patched: '2020-05-01T03:34:24.051Z' 27 | - yeoman-generator > yeoman-environment > yeoman-generator > yeoman-environment > inquirer > lodash: 28 | patched: '2020-05-01T03:34:24.051Z' 29 | - yeoman-generator > grouped-queue > lodash: 30 | patched: '2020-06-10T08:56:56.208Z' 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | cache: 4 | directories: 5 | - node_modules 6 | notifications: 7 | email: true 8 | node_js: 9 | - stable 10 | before_script: 11 | - npm prune 12 | after_success: 13 | - npm run coveralls 14 | - npm run semantic-release 15 | branches: 16 | except: 17 | - /^v\d+\.\d+\.\d+$/ 18 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | | Eugene Obrezkov | Dmitry Akulich | 2 | |:-------------------------------------------------------------------------------------:|:----------------------------------------:| 3 | | ![Eugene Obrezkov](http://gravatar.com/avatar/be299f224394ab488001c9cab12eae2c?s=100) | | 4 | | Lead developer of this project | Maintainer | 5 | | Get in touch with me via [@ghaiklor](https://twitter.com/ghaiklor) | [@IncoCode](https://github.com/IncoCode) | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2017 Eugene Obrezkov (aka ghaiklor) 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 | -------------------------------------------------------------------------------- /generators/adapter/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = { 20 | 'adapter-name': { 21 | required: true, 22 | type: String 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /generators/adapter/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class AdapterGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = 'Scaffolds a new adapter'; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/adapter/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'skip-install': { 20 | desc: 'Do not automatically install dependencies', 21 | type: Boolean, 22 | defaults: false, 23 | hide: false 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /generators/adapter/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/adapter/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/adapter/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/adapter/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/adapter/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/adapter/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/adapter/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/adapter/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/adapter/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/adapter/steps/writing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 5 5 | * Where you write the generator specific files (routes, controllers, etc) 6 | */ 7 | 8 | const SOURCE_ADAPTER = `Adapter.js`; 9 | const SOURCE_ADAPTER_TEST = `Adapter.test.js`; 10 | 11 | const DESTINATION_ADAPTER = name => `api/adapters/${name}Adapter.js`; 12 | const DESTINATION_ADAPTER_TEST = name => `test/unit/adapters/${name}Adapter.test.js`; 13 | 14 | module.exports = function () { 15 | const name = (this.options['adapter-name'].charAt(0).toUpperCase() + this.options['adapter-name'].slice(1)).replace(/Adapter/, ''); 16 | 17 | this.fs.copyTpl(this.templatePath(SOURCE_ADAPTER), this.destinationPath(DESTINATION_ADAPTER(name)), {name}); 18 | this.fs.copyTpl(this.templatePath(SOURCE_ADAPTER_TEST), this.destinationPath(DESTINATION_ADAPTER_TEST(name)), {name}); 19 | }; 20 | -------------------------------------------------------------------------------- /generators/adapter/templates/Adapter.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const sinon = require('sinon'); 5 | const Adapter = require('../../../api/adapters/<%= name %>Adapter'); 6 | 7 | describe('adapters:<%= name %>Adapter', () => { 8 | it('Should be tested', () => { 9 | assert(false); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /generators/app/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = {}; 20 | -------------------------------------------------------------------------------- /generators/app/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class AppGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | } 15 | 16 | get configuring() { 17 | return generatorSteps.configuring; 18 | } 19 | 20 | get conflicts() { 21 | return generatorSteps.conflicts; 22 | } 23 | 24 | get default() { 25 | return generatorSteps.default; 26 | } 27 | 28 | get end() { 29 | return generatorSteps.end; 30 | } 31 | 32 | get initializing() { 33 | return generatorSteps.initializing 34 | } 35 | 36 | get install() { 37 | return generatorSteps.install; 38 | } 39 | 40 | get prompting() { 41 | return generatorSteps.prompting 42 | } 43 | 44 | get writing() { 45 | return generatorSteps.writing; 46 | } 47 | }; 48 | -------------------------------------------------------------------------------- /generators/app/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'skip-update': { 20 | desc: `Do not check for generator\'s updates`, 21 | type: Boolean, 22 | defaults: false, 23 | hide: false 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /generators/app/questions/adapter.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/app/questions/app.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = [{ 16 | type: 'input', 17 | name: 'app:name', 18 | message: 'Application name', 19 | default: 'sails-rest-api' 20 | }]; 21 | -------------------------------------------------------------------------------- /generators/app/questions/authentication.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | const crypto = require('crypto'); 16 | 17 | module.exports = [{ 18 | type: 'confirm', 19 | name: 'authentication:enabled', 20 | message: 'Do you need authentication layer?', 21 | default: true 22 | }, { 23 | type: 'input', 24 | name: 'authentication:secret-key', 25 | message: 'Secret key', 26 | default: crypto.randomBytes(32).toString('hex'), 27 | when: answers => answers['authentication:enabled'] 28 | }]; 29 | -------------------------------------------------------------------------------- /generators/app/questions/blueprint.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = [{ 16 | type: 'confirm', 17 | name: 'blueprint:all', 18 | message: 'Use overridden blueprints?', 19 | default: true 20 | }]; 21 | -------------------------------------------------------------------------------- /generators/app/questions/controller.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = [{ 16 | type: 'checkbox', 17 | name: 'controller:chosen', 18 | message: 'Choose which predefined controllers you want to copy', 19 | default: ['PingController', 'SearchController'], 20 | choices: [ 21 | 'PingController', 22 | 'SearchController' 23 | ] 24 | }]; 25 | -------------------------------------------------------------------------------- /generators/app/questions/cron.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = [{ 16 | type: 'confirm', 17 | name: 'cron:enabled', 18 | message: 'Do you need cron?', 19 | default: true 20 | }]; 21 | -------------------------------------------------------------------------------- /generators/app/questions/hook.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = [{ 16 | type: 'checkbox', 17 | name: 'hook:chosen', 18 | message: 'Choose which predefined hooks you want to copy', 19 | default: ['CountHook', 'PluralizeHook'], 20 | choices: [ 21 | 'CountHook', 22 | 'PluralizeHook' 23 | ] 24 | }]; 25 | -------------------------------------------------------------------------------- /generators/app/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | adapter: require('./adapter'), 5 | app: require('./app'), 6 | authentication: require('./authentication'), 7 | blueprint: require('./blueprint'), 8 | config: require('./config'), 9 | controller: require('./controller'), 10 | cron: require('./cron'), 11 | hook: require('./hook'), 12 | logger: require('./logger'), 13 | model: require('./model'), 14 | policy: require('./policy'), 15 | response: require('./response'), 16 | service: require('./service'), 17 | swagger: require('./swagger') 18 | }; 19 | -------------------------------------------------------------------------------- /generators/app/questions/logger.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = [{ 16 | type: 'list', 17 | name: 'logger:chosen', 18 | message: 'Choose which logger you want to configure', 19 | default: 'Winston', 20 | choices: [ 21 | 'Bunyan', 22 | 'Default', 23 | 'Winston' 24 | ] 25 | }]; 26 | -------------------------------------------------------------------------------- /generators/app/questions/model.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/app/questions/policy.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/app/questions/response.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * export default [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/app/questions/swagger.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = [{ 16 | type: 'confirm', 17 | name: 'swagger:enabled', 18 | message: 'Do you need Swagger UI Explorer?', 19 | default: true 20 | }]; 21 | -------------------------------------------------------------------------------- /generators/app/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/app/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/app/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | const chalk = require('chalk'); 9 | const printMessage = require('print-message'); 10 | 11 | module.exports = function () { 12 | printMessage([ 13 | `Enjoy your ${chalk.red('Sails REST API')} project!`, 14 | `---`, 15 | `Next steps:`, 16 | `${chalk.yellow('1)')} Create a model in your app:`, 17 | chalk.blue('yo sails-rest-api:model Ticket'), 18 | `${chalk.yellow('2)')} Compose your API and run:`, 19 | chalk.blue('npm start') 20 | ], { 21 | printFn: this.log 22 | }); 23 | }; 24 | -------------------------------------------------------------------------------- /generators/app/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/app/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | const chalk = require('chalk'); 9 | const updateNotifier = require('update-notifier'); 10 | const printMessage = require('print-message'); 11 | const yosay = require('yosay'); 12 | 13 | function _onUpdateNotifier(done, error, update) { 14 | if (update && update.type !== 'latest') { 15 | printMessage([ 16 | 'Update available: ' + chalk.green.bold(update.latest) + chalk.dim(' (current: ' + update.current + ')'), 17 | 'Run ' + chalk.blue('npm update -g ' + update.name) + ' to update.' 18 | ], { 19 | printFn: this.log 20 | }); 21 | } 22 | 23 | done(); 24 | } 25 | 26 | module.exports = { 27 | loadPackageInfo: function () { 28 | this.pkg = require('../../../package.json'); 29 | }, 30 | 31 | sayHello: function () { 32 | this.log(yosay('Welcome to the laudable ' + chalk.red('Sails REST API') + ' generator!')); 33 | }, 34 | 35 | checkUpdates: function () { 36 | if (!this.options['skip-update']) { 37 | this.log(chalk.yellow('Checking for updates...')); 38 | updateNotifier({ 39 | pkg: this.pkg, 40 | callback: _onUpdateNotifier.bind(this, this.async()) 41 | }); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /generators/app/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | module.exports = function () { 9 | this.npmInstall(); 10 | }; 11 | -------------------------------------------------------------------------------- /generators/app/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const chalk = require('chalk'); 9 | const questions = require('../questions'); 10 | 11 | function askQuestions(title, questions, done) { 12 | this.log(chalk.yellow(`\n${title} questions:`)); 13 | 14 | return this 15 | .prompt(questions) 16 | .then(answers => { 17 | this.answers = Object.assign(this.answers || {}, answers); 18 | done(); 19 | }); 20 | } 21 | 22 | module.exports = { 23 | askApp: function () { 24 | askQuestions.call(this, 'Application', questions.app, this.async()); 25 | }, 26 | 27 | askConfig: function () { 28 | askQuestions.call(this, 'Configuration', questions.config, this.async()); 29 | }, 30 | 31 | askLogger: function () { 32 | askQuestions.call(this, 'Logger', questions.logger, this.async()); 33 | }, 34 | 35 | askBlueprint: function () { 36 | askQuestions.call(this, 'Blueprint', questions.blueprint, this.async()); 37 | }, 38 | 39 | askController: function () { 40 | askQuestions.call(this, 'Controller', questions.controller, this.async()); 41 | }, 42 | 43 | askHook: function () { 44 | askQuestions.call(this, 'Hook', questions.hook, this.async()); 45 | }, 46 | 47 | askCron: function () { 48 | askQuestions.call(this, 'Cron', questions.cron, this.async()); 49 | }, 50 | 51 | askSwagger: function () { 52 | askQuestions.call(this, 'Swagger', questions.swagger, this.async()); 53 | }, 54 | 55 | askAuthentication: function () { 56 | askQuestions.call(this, 'Authentication', questions.authentication, this.async()); 57 | }, 58 | 59 | askService: function () { 60 | askQuestions.call(this, 'Service', questions.service, this.async()); 61 | } 62 | }; 63 | -------------------------------------------------------------------------------- /generators/app/steps/writing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 5 5 | * Where you write the generator specific files (routes, controllers, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | this.fs.copyTpl(this.templatePath('test/**/*'), this.destinationPath('test'), {answers: this.answers}); 10 | this.fs.copyTpl(this.templatePath('app.js'), this.destinationPath('app.js'), {answers: this.answers}); 11 | this.fs.copyTpl(this.templatePath('Dockerfile'), this.destinationPath('Dockerfile'), {answers: this.answers}); 12 | this.fs.copyTpl(this.templatePath('editorconfig'), this.destinationPath('.editorconfig'), {answers: this.answers}); 13 | this.fs.copyTpl(this.templatePath('esdoc.json'), this.destinationPath('esdoc.json'), {answers: this.answers}); 14 | this.fs.copyTpl(this.templatePath('gitignore'), this.destinationPath('.gitignore'), {answers: this.answers}); 15 | this.fs.copyTpl(this.templatePath('package.json'), this.destinationPath('package.json'), {answers: this.answers}); 16 | this.fs.copyTpl(this.templatePath('README.md'), this.destinationPath('README.md'), {answers: this.answers}); 17 | this.fs.copyTpl(this.templatePath('sailsrc'), this.destinationPath('.sailsrc'), {answers: this.answers}); 18 | }; 19 | -------------------------------------------------------------------------------- /generators/app/templates/.snyk: -------------------------------------------------------------------------------- 1 | # Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. 2 | version: v1.16.0 3 | ignore: {} 4 | # patches apply the minimum changes required to fix a vulnerability 5 | patch: 6 | SNYK-JS-LODASH-567746: 7 | - sails > grunt-contrib-less > lodash: 8 | patched: '2020-05-01T07:02:05.242Z' 9 | - sails > grunt-contrib-uglify > lodash: 10 | patched: '2020-05-01T07:02:05.242Z' 11 | - sails > grunt > grunt-legacy-log > lodash: 12 | patched: '2020-05-01T07:02:05.242Z' 13 | - sails > sails-generate > sails-generate-generator > lodash: 14 | patched: '2020-05-01T07:02:05.242Z' 15 | - sails > skipper > async > lodash: 16 | patched: '2020-05-01T07:02:05.242Z' 17 | - sails > grunt-contrib-watch > gaze > globule > lodash: 18 | patched: '2020-05-01T07:02:05.242Z' 19 | 'npm:lodash:20180130': 20 | - sails > machinepack-process > machine > lodash: 21 | patched: '2020-07-16T09:42:06.655Z' 22 | - sails > machinepack-process > machinepack-json > machine > lodash: 23 | patched: '2020-07-16T09:42:06.655Z' 24 | - sails > machinepack-redis > machine > include-all > lodash: 25 | patched: '2020-07-16T09:42:06.655Z' 26 | -------------------------------------------------------------------------------- /generators/app/templates/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:slim 2 | 3 | MAINTAINER Eugene Obrezkov 4 | 5 | RUN mkdir /app 6 | VOLUME ["/app"] 7 | WORKDIR /app 8 | EXPOSE 3000 9 | 10 | CMD npm start 11 | -------------------------------------------------------------------------------- /generators/app/templates/README.md: -------------------------------------------------------------------------------- 1 | # <%= answers['app:name'] %> 2 | 3 | ## Installation 4 | 5 | Clone the repository and run the following commands under your project root: 6 | 7 | ```shell 8 | npm install 9 | npm start 10 | ``` 11 | -------------------------------------------------------------------------------- /generators/app/templates/app.js: -------------------------------------------------------------------------------- 1 | require('sails').lift(require('rc')('sails')); 2 | -------------------------------------------------------------------------------- /generators/app/templates/editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | indent_size = 2 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | -------------------------------------------------------------------------------- /generators/app/templates/esdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "<%= answers['app:name'] %>", 3 | "source": "./api", 4 | "destination": "./docs", 5 | "coverage": true, 6 | "test": { 7 | "type": "mocha", 8 | "source": "./test" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /generators/app/templates/gitignore: -------------------------------------------------------------------------------- 1 | # Local 2 | config/local.js 3 | 4 | # Logs 5 | logs 6 | *.log 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | 13 | # Directory for instrumented libs generated by jscoverage/JSCover 14 | lib-cov 15 | 16 | # Coverage directory used by tools like istanbul 17 | coverage 18 | 19 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 20 | .grunt 21 | 22 | # node-waf configuration 23 | .lock-wscript 24 | 25 | # Compiled binary addons (http://nodejs.org/api/addons.html) 26 | build/Release 27 | 28 | # Dependency directory 29 | node_modules 30 | 31 | # Documentation folder 32 | docs 33 | 34 | # Miscellaneous 35 | *~ 36 | *# 37 | .DS_STORE 38 | .netbeans 39 | nbproject 40 | .idea 41 | .node_history 42 | .tmp 43 | -------------------------------------------------------------------------------- /generators/app/templates/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= answers['app:name'] %>", 3 | "version": "0.1.0", 4 | "main": "app.js", 5 | "dependencies": { 6 | "rc": "1.2.8", 7 | "sails": "1.4.2", 8 | "snyk": "^1.362.0" 9 | }, 10 | "devDependencies": { 11 | "esdoc": "0.4.3", 12 | "chai": "3.4.1", 13 | "istanbul": "0.4.2", 14 | "mocha": "2.3.4", 15 | "sails-memory": "0.10.5", 16 | "sinon": "1.17.2" 17 | }, 18 | "scripts": { 19 | "clean": "rm -rf ./.tmp", 20 | "debug": "node debug app.js", 21 | "docs": "esdoc -c esdoc.json", 22 | "start": "node app.js", 23 | "test": "istanbul cover _mocha", 24 | "snyk-protect": "snyk protect", 25 | "prepublish": "npm run snyk-protect" 26 | }, 27 | "snyk": true 28 | } 29 | -------------------------------------------------------------------------------- /generators/app/templates/sailsrc: -------------------------------------------------------------------------------- 1 | { 2 | "generators": { 3 | "modules": { 4 | } 5 | }, 6 | "hooks": { 7 | "csrf": false, 8 | "grunt": false, 9 | "i18n": false, 10 | "pubsub": false, 11 | "session": false, 12 | "sockets": false, 13 | "views": false 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /generators/app/templates/test/bootstrap.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Sails = require('sails'); 4 | const config = require('../config/env/test'); 5 | 6 | before(done => { 7 | Sails.load(config, (server, error) => { 8 | if (error) return done(error); 9 | done(); 10 | }); 11 | }); 12 | 13 | after(done => Sails.lower(done)); 14 | -------------------------------------------------------------------------------- /generators/app/templates/test/mocha.opts: -------------------------------------------------------------------------------- 1 | ./test/bootstrap.js 2 | ./test/unit/**/*.test.js 3 | --reporter spec 4 | --recursive 5 | -------------------------------------------------------------------------------- /generators/authentication/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = {}; 20 | -------------------------------------------------------------------------------- /generators/authentication/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class AuthenticationGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = 'Scaffolds a new authentication layer'; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/authentication/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'secret-key': { 20 | desc: 'Specifies a secret key', 21 | type: String, 22 | defaults: 'DEFAULT_SECRET_KEY' 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /generators/authentication/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/authentication/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/authentication/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/authentication/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/authentication/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/authentication/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/authentication/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/authentication/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | const PASSPORT_DEPENDENCIES = { 9 | local: ['passport-local'], 10 | jwt: ['passport-jwt'], 11 | facebook: ['passport-facebook-token'], 12 | twitter: ['passport-twitter-token'], 13 | vkontakte: ['passport-vkontakte-token'], 14 | foursquare: ['passport-foursquare-token'], 15 | github: ['passport-github-token'], 16 | instagram: ['passport-instagram-token'], 17 | paypal: ['passport-paypal-token'], 18 | reddit: ['passport-reddit-token'], 19 | soundcloud: ['passport-soundcloud-token'], 20 | windowsLive: ['passport-windows-live-token'], 21 | twitch: ['passport-twitch-token'], 22 | yandex: ['passport-yandex-token'], 23 | amazon: ['passport-amazon-token'], 24 | googlePlus: ['passport-google-plus-token'], 25 | yahoo: ['passport-yahoo-token'] 26 | }; 27 | 28 | const DEPENDENCIES = [ 29 | 'passport' 30 | ]; 31 | 32 | module.exports = function () { 33 | const passportDependencies = Object.keys(PASSPORT_DEPENDENCIES).reduce((deps, strategy) => deps.concat(PASSPORT_DEPENDENCIES[strategy]), []); 34 | 35 | this.npmInstall(DEPENDENCIES.concat(passportDependencies), {save: true}); 36 | }; 37 | -------------------------------------------------------------------------------- /generators/authentication/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/authentication/steps/writing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 5 5 | * Where you write the generator specific files (routes, controllers, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | this.fs.copyTpl(this.templatePath('api/**/*'), this.destinationPath('api'), {options: this.options}); 10 | this.fs.copyTpl(this.templatePath('config/**/*'), this.destinationPath('config'), {options: this.options}); 11 | this.fs.copyTpl(this.templatePath('test/**/*'), this.destinationPath('test'), {options: this.options}); 12 | }; 13 | -------------------------------------------------------------------------------- /generators/authentication/templates/api/controllers/UserController.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * UserController 5 | * @description :: Server-side logic for manage users 6 | */ 7 | 8 | module.exports = {}; 9 | -------------------------------------------------------------------------------- /generators/authentication/templates/api/models/User.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * User 5 | * @description :: Model for storing users 6 | */ 7 | 8 | module.exports = { 9 | schema: true, 10 | 11 | attributes: { 12 | username: { 13 | type: 'string', 14 | required: true, 15 | unique: true, 16 | alphanumericdashed: true 17 | }, 18 | 19 | password: { 20 | type: 'string' 21 | }, 22 | 23 | email: { 24 | type: 'email', 25 | required: true, 26 | unique: true 27 | }, 28 | 29 | firstName: { 30 | type: 'string', 31 | defaultsTo: '' 32 | }, 33 | 34 | lastName: { 35 | type: 'string', 36 | defaultsTo: '' 37 | }, 38 | 39 | photo: { 40 | type: 'string', 41 | defaultsTo: '', 42 | url: true 43 | }, 44 | 45 | socialProfiles: { 46 | type: 'object', 47 | defaultsTo: {} 48 | }, 49 | 50 | toJSON() { 51 | let obj = this.toObject(); 52 | 53 | delete obj.password; 54 | delete obj.socialProfiles; 55 | 56 | return obj; 57 | } 58 | }, 59 | 60 | beforeUpdate(values, next) { 61 | if (false === values.hasOwnProperty('password')) return next(); 62 | if (/^\$2[aby]\$[0-9]{2}\$.{53}$/.test(values.password)) return next(); 63 | 64 | return HashService.bcrypt.hash(values.password) 65 | .then(hash => { 66 | values.password = hash; 67 | next(); 68 | }) 69 | .catch(next); 70 | }, 71 | 72 | beforeCreate(values, next) { 73 | if (false === values.hasOwnProperty('password')) return next(); 74 | 75 | return HashService.bcrypt.hash(values.password) 76 | .then(hash => { 77 | values.password = hash; 78 | next(); 79 | }) 80 | .catch(next); 81 | } 82 | }; 83 | -------------------------------------------------------------------------------- /generators/authentication/templates/api/policies/isAuthenticated.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * isAuthenticated 5 | * @description :: Policy that inject user in `req` via JSON Web Token 6 | */ 7 | 8 | const passport = require('passport'); 9 | 10 | module.exports = (req, res, next) => { 11 | passport.authenticate('jwt', (error, user, info) => { 12 | 13 | if (info.name === 'TokenExpiredError') info.status = 401; 14 | if (info.name === 'JsonWebTokenError') info.status = 401; 15 | if (error || !user) return res.negotiate(error || info); 16 | 17 | req.user = user; 18 | 19 | next(); 20 | })(req, res); 21 | }; 22 | -------------------------------------------------------------------------------- /generators/authentication/templates/config/policies.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Policy Mappings 5 | * 6 | * Policies are simple functions which run before your controllers. 7 | * You can apply one or more policies to a given controller, or protect 8 | * its actions individually. 9 | * 10 | * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed 11 | * below by its filename, minus the extension, (e.g. "authenticated") 12 | */ 13 | 14 | module.exports = { 15 | policies: { 16 | '*': ['isAuthenticated'], 17 | 18 | AuthController: { 19 | '*': true 20 | } 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /generators/authentication/templates/test/unit/controllers/AuthController.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('controllers:AuthController', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/authentication/templates/test/unit/controllers/UserController.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('controllers:UserController', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/authentication/templates/test/unit/models/User.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | const newUser = { 6 | username: 'modelTest', 7 | password: 'password', 8 | email: 'modelTest@gmail.com' 9 | }; 10 | 11 | describe('models:User', () => { 12 | it('Should create new user', done => { 13 | User 14 | .create(newUser) 15 | .then(user => { 16 | assert.equal(user.username, newUser.username); 17 | done(); 18 | }) 19 | .catch(done); 20 | }); 21 | 22 | it('Should remove user', done => { 23 | User 24 | .destroy({username: newUser.username}) 25 | .then(users => { 26 | assert.equal(users[0].username, newUser.username); 27 | done(); 28 | }) 29 | .catch(done); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /generators/authentication/templates/test/unit/policies/isAuthenticated.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('policies:isAuthenticated', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/blueprint/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = { 20 | 'blueprint-name': { 21 | required: false, 22 | type: String, 23 | defaults: '' 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /generators/blueprint/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class BlueprintGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = 'Scaffolds a new blueprint'; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/blueprint/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'new': { 20 | desc: 'Scaffolds a clean blueprint (not predefined)', 21 | alias: 'n', 22 | type: Boolean, 23 | defaults: false, 24 | hide: false 25 | }, 26 | 27 | 'all': { 28 | desc: 'Copies all the overridden blueprints at once', 29 | alias: 'a', 30 | type: Boolean, 31 | defaults: false, 32 | hide: false 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /generators/blueprint/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/blueprint/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/blueprint/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/blueprint/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/blueprint/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/blueprint/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/blueprint/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/blueprint/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | const DEPENDENCIES = [ 9 | 'lodash' 10 | ]; 11 | 12 | module.exports = function () { 13 | this.npmInstall(DEPENDENCIES, {save: true}); 14 | }; 15 | -------------------------------------------------------------------------------- /generators/blueprint/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/blueprint/steps/writing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 5 5 | * Where you write the generator specific files (routes, controllers, etc) 6 | */ 7 | 8 | const fs = require('fs'); 9 | 10 | const SOURCE_BLUEPRINT = name => name ? `api/blueprints/${name}.js` : `Blueprint.js`; 11 | const SOURCE_BLUEPRINT_TEST = name => name ? `test/unit/blueprints/${name}.test.js` : `Blueprint.test.js`; 12 | 13 | const DESTINATION_BLUEPRINT = name => `api/blueprints/${name}.js`; 14 | const DESTINATION_BLUEPRINT_TEST = name => `test/unit/blueprints/${name}.test.js`; 15 | 16 | module.exports = function () { 17 | const name = this.options['blueprint-name'].replace(/Blueprint/, '').toLowerCase(); 18 | const isNew = this.options['new']; 19 | const isAll = !name || this.options['all']; 20 | 21 | if (isAll) { 22 | this.fs.copyTpl(this.templatePath(`api/blueprints/**/*`), this.destinationPath(`api/blueprints`)); 23 | this.fs.copyTpl(this.templatePath(`test/unit/blueprints/**/*`), this.destinationPath(`test/unit/blueprints`)); 24 | } else if (isNew) { 25 | this.fs.copyTpl(this.templatePath(SOURCE_BLUEPRINT()), this.destinationPath(DESTINATION_BLUEPRINT(name)), {name}); 26 | this.fs.copyTpl(this.templatePath(SOURCE_BLUEPRINT_TEST()), this.destinationPath(DESTINATION_BLUEPRINT_TEST(name)), {name}); 27 | } else { 28 | const blueprintTemplate = fs.existsSync(this.templatePath(SOURCE_BLUEPRINT(name))) ? SOURCE_BLUEPRINT(name) : SOURCE_BLUEPRINT(); 29 | const testTemplate = fs.existsSync(this.templatePath(SOURCE_BLUEPRINT_TEST(name))) ? SOURCE_BLUEPRINT_TEST(name) : SOURCE_BLUEPRINT_TEST(); 30 | 31 | this.fs.copyTpl(this.templatePath(blueprintTemplate), this.destinationPath(DESTINATION_BLUEPRINT(name)), {name}); 32 | this.fs.copyTpl(this.templatePath(testTemplate), this.destinationPath(DESTINATION_BLUEPRINT_TEST(name)), {name}); 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /generators/blueprint/templates/Blueprint.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const _ = require('lodash'); 4 | const actionUtil = require('sails/lib/hooks/blueprints/actionUtil'); 5 | 6 | module.exports = (req, res) => { 7 | const Model = actionUtil.parseModel(req); 8 | 9 | res.ok(); 10 | }; 11 | -------------------------------------------------------------------------------- /generators/blueprint/templates/Blueprint.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const blueprint = require('../../../api/blueprints/<%= name %>'); 5 | 6 | describe('blueprints:<%= name %>', () => { 7 | it('Should properly export', () => { 8 | assert.isFunction(blueprint); 9 | }) 10 | }); 11 | -------------------------------------------------------------------------------- /generators/blueprint/templates/api/blueprints/add.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Add Record To Collection 5 | * POST /:model/:id/:collectionAttr/:childId 6 | * 7 | * Associate one record with the collection attribute of another. 8 | * If the record being added has a primary key value already, it will just be linked. 9 | * If it doesn't, a new record will be created, then linked appropriately. 10 | * In either case, the association is bidirectional. 11 | */ 12 | 13 | module.exports = require('sails/lib/hooks/blueprints/actions/add'); 14 | -------------------------------------------------------------------------------- /generators/blueprint/templates/api/blueprints/create.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const _ = require('lodash'); 4 | const actionUtil = require('sails/lib/hooks/blueprints/actionUtil'); 5 | 6 | /** 7 | * Create Record 8 | * POST /:model 9 | * 10 | * An API call to create and return a single model instance using the specified parameters. 11 | */ 12 | module.exports = (req, res) => { 13 | const Model = actionUtil.parseModel(req); 14 | const values = actionUtil.parseValues(req); 15 | 16 | Model 17 | .create(_.omit(values, 'id')) 18 | .then(res.created) 19 | .catch(res.negotiate); 20 | }; 21 | -------------------------------------------------------------------------------- /generators/blueprint/templates/api/blueprints/destroy.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const actionUtil = require('sails/lib/hooks/blueprints/actionUtil'); 4 | 5 | /** 6 | * Destroy One Record 7 | * DELETE /:model/:id 8 | * 9 | * Destroys the single model instance with the specified `id` from the data adapter for the given model if it exists. 10 | */ 11 | module.exports = (req, res) => { 12 | const Model = actionUtil.parseModel(req); 13 | const pk = actionUtil.requirePk(req); 14 | 15 | Model 16 | .destroy(pk) 17 | .then(records => records[0] ? res.ok(records[0]) : res.notFound()) 18 | .catch(res.negotiate); 19 | }; 20 | -------------------------------------------------------------------------------- /generators/blueprint/templates/api/blueprints/find.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const _ = require('lodash'); 4 | const actionUtil = require('sails/lib/hooks/blueprints/actionUtil'); 5 | 6 | const takeAlias = _.partial(_.map, _, item => item.alias); 7 | const populateAlias = (model, alias) => model.populate(alias); 8 | 9 | /** 10 | * Find Records 11 | * GET /:model 12 | * 13 | * An API call to find and return model instances from the data adapter using the specified criteria. 14 | * If an id was specified, just the instance with that unique id will be returned. 15 | */ 16 | module.exports = (req, res) => { 17 | _.set(req.options, 'criteria.blacklist', ['fields', 'populate', 'limit', 'skip', 'page', 'sort']); 18 | 19 | const fields = req.param('fields') ? req.param('fields').replace(/ /g, '').split(',') : []; 20 | const populate = req.param('populate') ? req.param('populate').replace(/ /g, '').split(',') : []; 21 | const Model = actionUtil.parseModel(req); 22 | const where = actionUtil.parseCriteria(req); 23 | const limit = actionUtil.parseLimit(req); 24 | const skip = req.param('page') * limit || actionUtil.parseSkip(req); 25 | const sort = actionUtil.parseSort(req); 26 | const query = Model.find(null, fields.length > 0 ? {select: fields} : null).where(where).limit(limit).skip(skip).sort(sort); 27 | const findQuery = _.reduce(_.intersection(populate, takeAlias(Model.associations)), populateAlias, query); 28 | 29 | findQuery 30 | .then(records => [records, { 31 | root: { 32 | criteria: where, 33 | limit: limit, 34 | start: skip, 35 | end: skip + limit, 36 | page: Math.floor(skip / limit) 37 | } 38 | }]) 39 | .spread(res.ok) 40 | .catch(res.negotiate); 41 | }; 42 | -------------------------------------------------------------------------------- /generators/blueprint/templates/api/blueprints/findone.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const _ = require('lodash'); 4 | const actionUtil = require('sails/lib/hooks/blueprints/actionUtil'); 5 | 6 | const takeAliases = _.partial(_.map, _, item => item.alias); 7 | const populateAliases = (model, alias) => model.populate(alias); 8 | 9 | /** 10 | * Find One Record 11 | * GET /:model/:id 12 | * 13 | * An API call to find and return a single model instance from the data adapter using the specified id. 14 | */ 15 | module.exports = (req, res) => { 16 | _.set(req.options, 'criteria.blacklist', ['fields', 'populate', 'limit', 'skip', 'page', 'sort']); 17 | 18 | const fields = req.param('fields') ? req.param('fields').replace(/ /g, '').split(',') : []; 19 | const populate = req.param('populate') ? req.param('populate').replace(/ /g, '').split(',') : []; 20 | const Model = actionUtil.parseModel(req); 21 | const pk = actionUtil.requirePk(req); 22 | const query = Model.find(pk, fields.length > 0 ? {select: fields} : null); 23 | const findQuery = _.reduce(_.intersection(populate, takeAliases(Model.associations)), populateAliases, query); 24 | 25 | findQuery 26 | .then(record => record[0] ? res.ok(record[0]) : res.notFound()) 27 | .catch(res.negotiate); 28 | }; 29 | -------------------------------------------------------------------------------- /generators/blueprint/templates/api/blueprints/populate.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Populate an association 3 | * GET /:model/:parentId/:relation 4 | * GET /:model/:parentId/:relation/:id 5 | * 6 | * Expand response with populated data from relations in models. 7 | */ 8 | 9 | module.exports = require('sails/lib/hooks/blueprints/actions/populate'); 10 | -------------------------------------------------------------------------------- /generators/blueprint/templates/api/blueprints/remove.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Remove a member from an association 3 | * DELETE /:model/:parentId/:collectionAttr/:id 4 | * 5 | * Removes associated record from collection. 6 | */ 7 | 8 | module.exports = require('sails/lib/hooks/blueprints/actions/remove'); 9 | -------------------------------------------------------------------------------- /generators/blueprint/templates/api/blueprints/update.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const _ = require('lodash'); 4 | const actionUtil = require('sails/lib/hooks/blueprints/actionUtil'); 5 | 6 | /** 7 | * Update One Record 8 | * PUT /:model/:id 9 | * 10 | * An API call to update a model instance with the specified `id`, treating the other unbound parameters as attributes. 11 | */ 12 | module.exports = (req, res) => { 13 | const Model = actionUtil.parseModel(req); 14 | const pk = actionUtil.requirePk(req); 15 | const values = actionUtil.parseValues(req); 16 | const pkName = Model.primaryKey; 17 | const criteria = {}; 18 | criteria[pkName] = pk; 19 | 20 | Model 21 | .update(criteria, _.omit(values, pkName)) 22 | .then(records => records[0] ? res.ok(records[0]) : res.notFound()) 23 | .catch(res.negotiate); 24 | }; 25 | -------------------------------------------------------------------------------- /generators/blueprint/templates/test/unit/blueprints/add.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('blueprints:add', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/blueprint/templates/test/unit/blueprints/create.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('blueprints:create', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/blueprint/templates/test/unit/blueprints/destroy.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('blueprints:destroy', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/blueprint/templates/test/unit/blueprints/find.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('blueprints:find', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/blueprint/templates/test/unit/blueprints/findone.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('blueprints:findone', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/blueprint/templates/test/unit/blueprints/populate.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('blueprints:populate', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/blueprint/templates/test/unit/blueprints/remove.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('blueprints:remove', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/blueprint/templates/test/unit/blueprints/update.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('blueprints:update', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/config/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = {}; 20 | -------------------------------------------------------------------------------- /generators/config/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class ConfigGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = 'Scaffolds a new configuration'; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/config/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'database-adapter': { 20 | desc: 'Specifies an adapter for your database', 21 | type: String, 22 | defaults: 'Mongo' 23 | }, 24 | 25 | 'database-host': { 26 | desc: 'Specifies a host of your database', 27 | type: String, 28 | defaults: 'localhost' 29 | }, 30 | 31 | 'database-name': { 32 | desc: 'Specifies a name of your database', 33 | type: String, 34 | defaults: 'sails-rest-api' 35 | }, 36 | 37 | 'database-username': { 38 | desc: 'Specifies an username of your database', 39 | type: String, 40 | defaults: '' 41 | }, 42 | 43 | 'database-password': { 44 | desc: 'Specifies a password of your database', 45 | type: String, 46 | defaults: '' 47 | }, 48 | 49 | 'dynamo-access-key-id': { 50 | desc: 'Specifies an Access Key ID for DynamoDB', 51 | type: String, 52 | defaults: '' 53 | }, 54 | 55 | 'dynamo-secret-access-key': { 56 | desc: 'Specifies a Secret Key for DynamoDB', 57 | type: String, 58 | defaults: '' 59 | }, 60 | 61 | 'dynamo-region': { 62 | desc: 'Specifies a region for DynamoDB', 63 | type: String, 64 | defaults: 'us-west-1' 65 | }, 66 | 67 | 'cors': { 68 | desc: 'Enable CORS by default', 69 | type: Boolean, 70 | defaults: false 71 | } 72 | }; 73 | -------------------------------------------------------------------------------- /generators/config/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/config/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/config/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/config/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/config/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/config/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/config/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/config/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | const DEPENDENCIES = [ 9 | 'sails-disk', 10 | 'sails-memory' 11 | ]; 12 | 13 | module.exports = function () { 14 | const adapter = `sails-${this.options['database-adapter'].toLowerCase()}`; 15 | 16 | this.npmInstall(DEPENDENCIES.concat([adapter]), {save: true}); 17 | }; 18 | -------------------------------------------------------------------------------- /generators/config/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/config/steps/writing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 5 5 | * Where you write the generator specific files (routes, controllers, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | this.fs.copyTpl(this.templatePath(`config/**/*`), this.destinationPath(`config`), {options: this.options}); 10 | }; 11 | -------------------------------------------------------------------------------- /generators/config/templates/config/bootstrap.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * An asynchronous bootstrap function that runs before your Sails app gets lifted. 5 | * This gives you an opportunity to set up your data model, run jobs, or perform some special logic. 6 | * @param {Function} cb This function should always be called, so DON'T REMOVE IT 7 | */ 8 | 9 | module.exports = { 10 | bootstrap: cb => cb() 11 | }; 12 | -------------------------------------------------------------------------------- /generators/config/templates/config/cors.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Cross-Origin Resource Sharing (CORS) Settings 5 | * 6 | * CORS is like a more modern version of JSONP-- it allows your server/API 7 | * to successfully respond to requests from client-side JavaScript code 8 | * running on some other domain (e.g. google.com) 9 | */ 10 | 11 | module.exports = { 12 | cors: { 13 | /** 14 | * Allow CORS on all routes by default? 15 | */ 16 | allRoutes: <%= options["cors"] %>, 17 | 18 | /** 19 | * Which domains which are allowed CORS access? 20 | */ 21 | origin: '*', 22 | 23 | /** 24 | * Allow cookies to be shared for CORS requests? 25 | */ 26 | credentials: true, 27 | 28 | /** 29 | * Which methods should be allowed for CORS requests? 30 | */ 31 | methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD', 32 | 33 | /** 34 | * Which headers should be allowed for CORS requests? 35 | */ 36 | headers: 'content-type, authorization' 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /generators/config/templates/config/env/development.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Development environment settings 5 | * @description :: This section overrides all other config values ONLY in development environment 6 | */ 7 | 8 | module.exports = { 9 | port: 3000, 10 | log: { 11 | level: 'verbose' 12 | }, 13 | models: { 14 | connection: 'disk' 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /generators/config/templates/config/env/production.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Production environment settings 5 | * @description :: This section overrides all other config values ONLY in production environment 6 | */ 7 | 8 | module.exports = { 9 | port: 80, 10 | log: { 11 | level: 'info' 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /generators/config/templates/config/env/test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Test environment settings 5 | * @description :: This section overrides all other config values ONLY in test environment 6 | */ 7 | 8 | module.exports = { 9 | log: { 10 | level: 'silent' 11 | }, 12 | models: { 13 | connection: 'memory', 14 | migrate: 'drop' 15 | }, 16 | policies: { 17 | '*': true 18 | }, 19 | hooks: { 20 | csrf: false, 21 | grunt: false, 22 | i18n: false, 23 | pubsub: false, 24 | session: false, 25 | sockets: false, 26 | views: false 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /generators/config/templates/config/errors.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Configuration file where you can store error codes for responses 5 | * 6 | * It's just a storage where you can define your custom API errors and their description. 7 | * You can call then in your action res.ok(data, sails.config.errors.USER_NOT_FOUND); 8 | */ 9 | 10 | module.exports = { 11 | errors: { 12 | BAD_REQUEST: { 13 | code: 'E_BAD_REQUEST', 14 | message: 'The request cannot be fulfilled due to bad syntax', 15 | status: 400 16 | }, 17 | 18 | CREATED: { 19 | code: 'CREATED', 20 | message: 'The request has been fulfilled and resulted in a new resource being created', 21 | status: 201 22 | }, 23 | 24 | FORBIDDEN: { 25 | code: 'E_FORBIDDEN', 26 | message: 'User not authorized to perform the operation', 27 | status: 403 28 | }, 29 | 30 | NOT_FOUND: { 31 | code: 'E_NOT_FOUND', 32 | message: 'The requested resource could not be found but may be available again in the future', 33 | status: 404 34 | }, 35 | 36 | OK: { 37 | code: 'OK', 38 | message: 'Operation is successfully executed', 39 | status: 200 40 | }, 41 | 42 | SERVER_ERROR: { 43 | code: 'E_INTERNAL_SERVER_ERROR', 44 | message: 'Something bad happened on the server', 45 | status: 500 46 | }, 47 | 48 | UNAUTHORIZED: { 49 | code: 'E_UNAUTHORIZED', 50 | message: 'Missing or invalid authentication token', 51 | status: 401 52 | }, 53 | 54 | USER_NOT_FOUND: { 55 | code: 'E_USER_NOT_FOUND', 56 | message: 'User with specified credentials is not found', 57 | status: 401 58 | } 59 | } 60 | }; 61 | -------------------------------------------------------------------------------- /generators/config/templates/config/globals.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Global Variable Configuration 5 | * Configure which global variables which will be exposed automatically by Sails. 6 | */ 7 | 8 | module.exports = { 9 | globals: { 10 | /** 11 | * Expose the lodash installed in Sails core as a global variable 12 | * @type {Boolean} 13 | */ 14 | _: false, 15 | 16 | /** 17 | * Expose the async installed in Sails core as a global variable 18 | * @type {Boolean} 19 | */ 20 | async: false, 21 | 22 | /** 23 | * Expose the sails instance representing your app 24 | * @type {Boolean} 25 | */ 26 | sails: true, 27 | 28 | /** 29 | * Expose each of your app's services as global variables 30 | * @type {Boolean} 31 | */ 32 | services: true, 33 | 34 | /** 35 | * Expose each of your app's models as global variables 36 | * @type {Boolean} 37 | */ 38 | models: true 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /generators/config/templates/config/models.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Default model configuration 5 | * 6 | * Unless you override them, the following properties will be included in each of your models. 7 | */ 8 | 9 | module.exports = { 10 | models: { 11 | /** 12 | * Your app's default connection 13 | * @type {String} 14 | */ 15 | connection: '<%= options["database-adapter"].toLowerCase() %>', 16 | 17 | /** 18 | * How and whether Sails will attempt to automatically rebuild the tables/collections/etc. in your schema 19 | * Available values is `safe`, `alter` or `drop` 20 | * @type {String} 21 | */ 22 | migrate: 'alter' 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /generators/config/templates/config/routes.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Route Mappings 5 | * 6 | * Your routes map URLs to views and controllers 7 | */ 8 | 9 | module.exports = { 10 | routes: {} 11 | }; 12 | -------------------------------------------------------------------------------- /generators/controller/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = { 20 | 'controller-name': { 21 | required: false, 22 | type: String, 23 | defaults: '' 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /generators/controller/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class ControllerGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = 'Scaffolds a new controller'; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/controller/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'new': { 20 | desc: 'Scaffolds a clean controller (not predefined)', 21 | alias: 'n', 22 | type: Boolean, 23 | defaults: false, 24 | hide: false 25 | }, 26 | 27 | 'all': { 28 | desc: 'Copies all the overridden controllers at once', 29 | alias: 'a', 30 | type: Boolean, 31 | defaults: false, 32 | hide: false 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /generators/controller/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/controller/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/controller/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/controller/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/controller/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/controller/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/controller/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/controller/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | const DEPENDENCIES = { 9 | search: ['lodash', 'bluebird'] 10 | }; 11 | 12 | module.exports = function () { 13 | const name = this.options['controller-name'].replace(/Controller/, '').toLowerCase(); 14 | 15 | if (DEPENDENCIES[name]) { 16 | this.npmInstall(DEPENDENCIES[name], {save: true}); 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /generators/controller/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/controller/templates/Controller.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * <%= name %>Controller 5 | * @description :: Server-side logic for ... 6 | */ 7 | 8 | module.exports = { 9 | index(req, res) { 10 | res.ok(); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /generators/controller/templates/Controller.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const Controller = require('../../../api/controllers/<%= name %>Controller'); 5 | 6 | describe('controllers:<%= name %>Controller', () => { 7 | it('Should be tested', () => { 8 | assert(false); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/controller/templates/api/controllers/PingController.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * PingController 5 | * @description :: Server-side logic that checks if app is alive 6 | */ 7 | 8 | module.exports = { 9 | index(req, res) { 10 | res.ok(req.allParams(), {message: 'HTTP server is working'}); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /generators/controller/templates/api/controllers/SearchController.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * SearchController 5 | * @description :: Server-side logic for searching within records in database 6 | */ 7 | 8 | const _ = require('lodash'); 9 | const Promise = require('bluebird'); 10 | 11 | const toLowerCase = _.partial(_.result, _, 'toLowerCase'); 12 | const parseModels = _.flow(toLowerCase, _.method('split', ',')); 13 | 14 | module.exports = { 15 | index(req, res) { 16 | const q = req.param('q'); 17 | if (!q) return res.badRequest(null, {message: 'You should specify a "q" parameter!'}); 18 | 19 | const models = parseModels(req.param('models')) || _.keys(sails.models); 20 | 21 | Promise.reduce(models, (res, modelName) => { 22 | const model = sails.models[modelName]; 23 | 24 | if (!model) return res; 25 | 26 | const where = _.transform(model.definition, (result, val, key) => result.or.push(_.set({}, key, {contains: q})), {or: []}); 27 | 28 | return Promise.join(modelName, model.find(where), _.partial(_.set, res)); 29 | }, {}) 30 | .then(res.ok) 31 | .catch(res.negotiate); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /generators/controller/templates/test/unit/controllers/PingController.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('controllers:PingController', () => { 6 | it('Should return message that HTTP server is working', done => { 7 | sails.request({ 8 | method: 'GET', 9 | url: '/v1/ping' 10 | }, (error, res, body) => { 11 | if (error) return done(error); 12 | 13 | assert.equal(res.statusCode, 200); 14 | assert.equal(body.message, 'HTTP server is working'); 15 | 16 | done(); 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /generators/controller/templates/test/unit/controllers/SearchController.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('controllers:SearchController', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/cron/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = { 20 | 'cron-jobs': { 21 | desc: `Jobs' names`, 22 | required: false, 23 | type: Array, 24 | defaults: [] 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /generators/cron/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class CronGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = 'Scaffolds a configuration for cron jobs'; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/cron/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'skip-install': { 20 | desc: 'Do not automatically install dependencies', 21 | type: Boolean, 22 | defaults: false, 23 | hide: false 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /generators/cron/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/cron/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/cron/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/cron/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/cron/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/cron/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/cron/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/cron/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | const DEPENDENCIES = [ 9 | 'sails-hook-cron' 10 | ]; 11 | 12 | module.exports = function () { 13 | this.npmInstall(DEPENDENCIES, {save: true}); 14 | }; 15 | -------------------------------------------------------------------------------- /generators/cron/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/cron/steps/writing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 5 5 | * Where you write the generator specific files (routes, controllers, etc) 6 | */ 7 | 8 | const SOURCE_CRON = `cron.template`; 9 | 10 | const DESTINATION_CRON = `config/cron.js`; 11 | 12 | module.exports = function () { 13 | const jobs = this.options['cron-jobs']; 14 | 15 | this.fs.copyTpl(this.templatePath(SOURCE_CRON), this.destinationPath(DESTINATION_CRON), {jobs}); 16 | }; 17 | -------------------------------------------------------------------------------- /generators/cron/templates/cron.template: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Cron configuration where you can define cron tasks with range time and callbacks. 5 | * Look here for detailed examples https://github.com/ghaiklor/sails-hook-cron 6 | * 7 | * @example 8 | * module.exports = { 9 | * cron: { 10 | * jobExample: { 11 | * schedule: '* * * * * *', 12 | * onTick: () => doSomething(), 13 | * onComplete: () => doSomething(), 14 | * start: true, 15 | * timezone: 'Ukraine/Kiev', 16 | * context: undefined 17 | * } 18 | * } 19 | * } 20 | */ 21 | 22 | module.exports = { 23 | cron: { 24 | <% jobs.forEach(function(job) { %> 25 | '<%= job %>': { 26 | schedule: '* * * * * *', 27 | onTick: () => false, 28 | onComplete: () => false, 29 | start: true, 30 | timezone: undefined, 31 | context: undefined 32 | } 33 | <% }) %> 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /generators/hook/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = { 20 | 'hook-name': { 21 | required: false, 22 | type: String, 23 | defaults: '' 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /generators/hook/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class HookGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = 'Scaffolds a new hook'; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/hook/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'new': { 20 | desc: 'Scaffolds a clean hook (not predefined)', 21 | alias: 'n', 22 | type: Boolean, 23 | defaults: false, 24 | hide: false 25 | }, 26 | 27 | 'all': { 28 | desc: 'Copies all the overridden hooks at once', 29 | alias: 'a', 30 | type: Boolean, 31 | defaults: false, 32 | hide: false 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /generators/hook/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/hook/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/hook/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/hook/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/hook/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/hook/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/hook/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/hook/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | const DEPENDENCIES = { 9 | count: ['lodash', 'pluralize'], 10 | pluralize: ['lodash'] 11 | }; 12 | 13 | module.exports = function () { 14 | const name = this.options['hook-name'].replace(/Hook/, '').toLowerCase(); 15 | 16 | if (DEPENDENCIES[name]) { 17 | this.npmInstall(DEPENDENCIES[name], {save: true}); 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /generators/hook/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/hook/steps/writing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 5 5 | * Where you write the generator specific files (routes, controllers, etc) 6 | */ 7 | 8 | const fs = require('fs'); 9 | 10 | const SOURCE_HOOK = name => name ? `api/hooks/${name}Hook.js` : `Hook.js`; 11 | const SOURCE_HOOK_TEST = name => name ? `test/unit/hooks/${name}Hook.test.js` : `Hook.test.js`; 12 | 13 | const DESTINATION_HOOK = name => `api/hooks/${name}Hook.js`; 14 | const DESTINATION_HOOK_TEST = name => `test/unit/hooks/${name}Hook.test.js`; 15 | 16 | module.exports = function () { 17 | const name = (this.options['hook-name'].charAt(0).toUpperCase() + this.options['hook-name'].slice(1)).replace(/Hook/, ''); 18 | const isNew = this.options['new']; 19 | const isAll = !name || this.options['all']; 20 | 21 | if (isAll) { 22 | this.fs.copyTpl(this.templatePath(`api/hooks/**/*`), this.destinationPath(`api/hooks`)); 23 | this.fs.copyTpl(this.templatePath(`test/unit/hooks/**/*`), this.destinationPath(`test/unit/hooks`)); 24 | } else if (isNew) { 25 | this.fs.copyTpl(this.templatePath(SOURCE_HOOK()), this.destinationPath(DESTINATION_HOOK(name)), {name}); 26 | this.fs.copyTpl(this.templatePath(SOURCE_HOOK_TEST()), this.destinationPath(DESTINATION_HOOK_TEST(name)), {name}); 27 | } else { 28 | const hookTemplate = fs.existsSync(this.templatePath(SOURCE_HOOK(name))) ? SOURCE_HOOK(name) : SOURCE_HOOK(); 29 | const testTemplate = fs.existsSync(this.templatePath(SOURCE_HOOK_TEST(name))) ? SOURCE_HOOK_TEST(name) : SOURCE_HOOK_TEST(); 30 | 31 | this.fs.copyTpl(this.templatePath(hookTemplate), this.destinationPath(DESTINATION_HOOK(name)), {name}); 32 | this.fs.copyTpl(this.templatePath(testTemplate), this.destinationPath(DESTINATION_HOOK_TEST(name)), {name}); 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /generators/hook/templates/Hook.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * <%= name %>Hook 5 | * Hook that ... 6 | */ 7 | 8 | module.exports = sails => { 9 | return { 10 | configure: () => true, 11 | 12 | defaults: config => config, 13 | 14 | initialize: cb => cb(), 15 | 16 | routes: { 17 | before: {}, 18 | after: {} 19 | } 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /generators/hook/templates/Hook.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const Hook = require('../../../api/hooks/<%= name %>Hook'); 5 | 6 | describe('hooks:<%= name %>', () => { 7 | it('Should be tested', () => { 8 | assert(false); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/hook/templates/api/hooks/CountHook.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Adds support for count blueprint and binds :model/count route for each RESTful model. 5 | */ 6 | 7 | const _ = require('lodash'); 8 | const actionUtil = require('sails/lib/hooks/blueprints/actionUtil'); 9 | const pluralize = require('pluralize'); 10 | 11 | const defaultCountBlueprint = (req, res) => { 12 | const Model = actionUtil.parseModel(req); 13 | const countQuery = Model.count(); 14 | 15 | countQuery.then(count => res.ok({count})); 16 | }; 17 | 18 | module.exports = sails => { 19 | return { 20 | initialize: cb => { 21 | const config = sails.config.blueprints; 22 | const countFn = _.get(sails.middleware, 'blueprints.count') || defaultCountBlueprint; 23 | 24 | sails.on('router:before', () => { 25 | _.forEach(sails.models, model => { 26 | const controller = sails.middleware.controllers[model.identity]; 27 | 28 | if (!controller) return; 29 | 30 | let baseRoute = [config.prefix, model.identity].join('/'); 31 | 32 | if (config.pluralize && _.get(controller, '_config.pluralize', true)) { 33 | baseRoute = pluralize(baseRoute); 34 | } 35 | 36 | const route = baseRoute + '/count'; 37 | 38 | sails.router.bind(route, countFn, null, {controller: model.identity}); 39 | }); 40 | 41 | }); 42 | 43 | cb(); 44 | } 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /generators/hook/templates/api/hooks/PluralizeHook.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Pluralize only routes that have controller and model pair. 5 | * If controller or model doesn't exist then applies default route. 6 | */ 7 | 8 | const _ = require('lodash'); 9 | 10 | module.exports = sails => { 11 | return { 12 | initialize: cb => { 13 | sails.on('router:before', () => { 14 | if (!_.get(sails, 'config.blueprints.pluralize')) return; 15 | 16 | _.forEach(sails.middleware.controllers, (controller, name) => { 17 | if (!_.get(sails.models, name, false) && !_.get(controller, '_config.pluralize', false)) { 18 | _.set(controller, '_config.pluralize', false); 19 | } 20 | }); 21 | }); 22 | 23 | cb(); 24 | } 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /generators/hook/templates/test/unit/hooks/CountHook.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('hooks:CountHook', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/hook/templates/test/unit/hooks/PluralizeHook.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | 5 | describe('hooks:PluralizeHook', () => { 6 | }); 7 | -------------------------------------------------------------------------------- /generators/logger/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = { 20 | 'logger-name': { 21 | desc: `Specifies the logger (bunyan, default, winston)`, 22 | required: false, 23 | type: String, 24 | defaults: `winston` 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /generators/logger/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class LoggerGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = `Scaffolds a new logger configuration`; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/logger/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'skip-install': { 20 | desc: 'Do not automatically install dependencies', 21 | type: Boolean, 22 | defaults: false, 23 | hide: false 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /generators/logger/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/logger/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/logger/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/logger/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/logger/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/logger/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/logger/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/logger/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | const DEPENDENCIES = { 9 | bunyan: ['sails-hook-bunyan'], 10 | winston: ['sails-hook-winston'] 11 | }; 12 | 13 | module.exports = function () { 14 | const logger = this['logger-name']; 15 | 16 | if (DEPENDENCIES[logger]) { 17 | this.npmInstall(DEPENDENCIES[logger], {save: true}); 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /generators/logger/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/logger/steps/writing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 5 5 | * Where you write the generator specific files (routes, controllers, etc) 6 | */ 7 | 8 | const SOURCE_CONFIG = name => `${name}Config.js`; 9 | 10 | const DESTINATION_CONFIG = `config/log.js`; 11 | 12 | module.exports = function () { 13 | const logger = this.options['logger-name'].toLowerCase(); 14 | 15 | this.fs.copyTpl(this.templatePath(SOURCE_CONFIG(logger)), this.destinationPath(DESTINATION_CONFIG), {logger}); 16 | }; 17 | -------------------------------------------------------------------------------- /generators/logger/templates/bunyanConfig.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Bunyan Logger Configuration 5 | * For detailed documentation you can take a look here - https://github.com/building5/sails-hook-bunyan 6 | */ 7 | 8 | module.exports = { 9 | log: { 10 | /** 11 | * Bunyan logging level 12 | * @type {String} 13 | */ 14 | level: 'verbose', 15 | 16 | /** 17 | * Injects child logger on each request 18 | * @type {Boolean} 19 | */ 20 | injectRequestLogger: true, 21 | 22 | /** 23 | * Logs uncaughtExceptions and terminate the process 24 | * @type {Boolean} 25 | */ 26 | logUncaughtException: true, 27 | 28 | /** 29 | * Signal to listen on for file rotation 30 | * @type {String} 31 | */ 32 | rotationSignal: null, 33 | 34 | /** 35 | * Convenience setting to log to file 36 | * @type {String} 37 | */ 38 | filePath: null, 39 | 40 | bunyan: { 41 | /** 42 | * Logger name 43 | * @type {String} 44 | */ 45 | name: 'app', 46 | 47 | /** 48 | * Bunyan serializers 49 | * @type {Object} 50 | */ 51 | serializers: null, 52 | 53 | /** 54 | * Output streams 55 | * @type {Array} 56 | */ 57 | streams: null 58 | } 59 | } 60 | }; 61 | -------------------------------------------------------------------------------- /generators/logger/templates/defaultConfig.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Built-in Log Configuration 5 | * (sails.config.log) 6 | * 7 | * Configure the log level for your app, as well as the transport 8 | * (Underneath the covers, Sails uses Winston for logging, which 9 | * allows for some pretty neat custom transports/adapters for log messages) 10 | */ 11 | 12 | module.exports = { 13 | log: { 14 | /** 15 | * The order of precedence for log levels from lowest to highest is: 16 | * silly, verbose, info, debug, warn, error, silent 17 | * @type {String} 18 | */ 19 | level: 'verbose' 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /generators/logger/templates/winstonConfig.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Winston Logger Configuration 5 | * For detailed information take a look here - https://github.com/Kikobeats/sails-hook-winston 6 | */ 7 | 8 | module.exports = { 9 | log: { 10 | /** 11 | * Winston logging level for the console transport 12 | * @type {String} 13 | */ 14 | level: 'verbose', 15 | 16 | /** 17 | * Outputs the timestamp in the console transport 18 | * @type {Boolean} 19 | */ 20 | timestamp: true, 21 | 22 | /** 23 | * Custom Winston transports 24 | * More information here - https://github.com/winstonjs/winston/blob/master/docs/transports.md 25 | * @example 26 | * transports: [{ 27 | * module: require('winston-mongodb').MongoDB, 28 | * config: {} 29 | * }] 30 | */ 31 | transports: [] 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /generators/model/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = { 20 | 'model-name': { 21 | required: true, 22 | type: String 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /generators/model/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class ModelGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = 'Scaffolds a new model'; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/model/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'rest': { 20 | desc: 'Exposes REST interface to this model', 21 | type: Boolean, 22 | defaults: true, 23 | hide: false 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /generators/model/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/model/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/model/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/model/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/model/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/model/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/model/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/model/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/model/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/model/steps/writing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 5 5 | * Where you write the generator specific files (routes, controllers, etc) 6 | */ 7 | 8 | const fs = require('fs'); 9 | 10 | const SOURCE_CONTROLLER = `Controller.js`; 11 | const SOURCE_CONTROLLER_TEST = `Controller.test.js`; 12 | const SOURCE_MODEL = `Model.js`; 13 | const SOURCE_MODEL_TEST = `Model.test.js`; 14 | const SOURCE_MODEL_FIXTURE = `ModelFixture.js`; 15 | 16 | const DESTINATION_CONTROLLER = name => `api/controllers/${name}Controller.js`; 17 | const DESTINATION_CONTROLLER_TEST = name => `test/unit/controllers/${name}Controller.test.js`; 18 | const DESTINATION_MODEL = name => `api/models/${name}.js`; 19 | const DESTINATION_MODEL_TEST = name => `test/unit/models/${name}.test.js`; 20 | const DESTINATION_MODEL_FIXTURE = name => `test/fixtures/${name}Fixture.js`; 21 | 22 | module.exports = function () { 23 | const name = (this.options['model-name'].charAt(0).toUpperCase() + this.options['model-name'].slice(1)).replace(/Model/, ''); 24 | const isREST = this.options['rest']; 25 | 26 | if (isREST && !fs.existsSync(this.destinationPath(DESTINATION_CONTROLLER(name)))) { 27 | this.fs.copyTpl(this.templatePath(SOURCE_CONTROLLER), this.destinationPath(DESTINATION_CONTROLLER(name)), {name}); 28 | this.fs.copyTpl(this.templatePath(SOURCE_CONTROLLER_TEST), this.destinationPath(DESTINATION_CONTROLLER_TEST(name)), {name}); 29 | } 30 | 31 | this.fs.copyTpl(this.templatePath(SOURCE_MODEL), this.destinationPath(DESTINATION_MODEL(name)), {name}); 32 | this.fs.copyTpl(this.templatePath(SOURCE_MODEL_TEST), this.destinationPath(DESTINATION_MODEL_TEST(name)), {name}); 33 | this.fs.copyTpl(this.templatePath(SOURCE_MODEL_FIXTURE), this.destinationPath(DESTINATION_MODEL_FIXTURE(name)), {name}); 34 | }; 35 | -------------------------------------------------------------------------------- /generators/model/templates/Controller.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * <%= name %>Controller 5 | * @description :: Server-side logic for ... 6 | */ 7 | 8 | module.exports = {}; 9 | -------------------------------------------------------------------------------- /generators/model/templates/Controller.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const Controller = require('../../../api/controllers/<%= name %>Controller'); 5 | 6 | describe('controllers:<%= name %>Controller', () => { 7 | it('Should be tested', () => { 8 | assert(false); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/model/templates/Model.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * <%= name %> 5 | * @description :: Model for storing <%= name %> records 6 | */ 7 | 8 | module.exports = { 9 | schema: true, 10 | 11 | attributes: { 12 | // Fill your attributes here 13 | 14 | toJSON() { 15 | return this.toObject(); 16 | } 17 | }, 18 | 19 | beforeUpdate: (values, next) => next(), 20 | beforeCreate: (values, next) => next() 21 | }; 22 | -------------------------------------------------------------------------------- /generators/model/templates/Model.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const Model = require('../../../api/models/<%= name %>'); 5 | const Fixture = require('../../fixtures/<%= name %>Fixture'); 6 | 7 | describe('models:<%= name %>', () => { 8 | it('Should be tested', () => { 9 | assert(false); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /generators/model/templates/ModelFixture.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Fixtures for <%= name %> 5 | */ 6 | 7 | module.exports = {}; 8 | -------------------------------------------------------------------------------- /generators/policy/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = { 20 | 'policy-name': { 21 | required: true, 22 | type: String 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /generators/policy/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class PolicyGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = 'Scaffolds a new policy'; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/policy/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'skip-install': { 20 | desc: 'Do not automatically install dependencies', 21 | type: Boolean, 22 | defaults: false, 23 | hide: false 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /generators/policy/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/policy/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/policy/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/policy/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/policy/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/policy/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/policy/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/policy/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/policy/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/policy/steps/writing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 5 5 | * Where you write the generator specific files (routes, controllers, etc) 6 | */ 7 | 8 | const SOURCE_POLICY = 'Policy.js'; 9 | const SOURCE_POLICY_TEST = 'Policy.test.js'; 10 | 11 | const DESTINATION_POLICY = name => `api/policies/${name}.js`; 12 | const DESTINATION_POLICY_TEST = name => `test/unit/policies/${name}.test.js`; 13 | 14 | module.exports = function () { 15 | const name = (this.options['policy-name'].charAt(0).toLowerCase() + this.options['policy-name'].slice(1)).replace(/Policy/, ''); 16 | 17 | this.fs.copyTpl(this.templatePath(SOURCE_POLICY), this.destinationPath(DESTINATION_POLICY(name)), {name}); 18 | this.fs.copyTpl(this.templatePath(SOURCE_POLICY_TEST), this.destinationPath(DESTINATION_POLICY_TEST(name)), {name}); 19 | }; 20 | -------------------------------------------------------------------------------- /generators/policy/templates/Policy.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * <%= name %> 5 | * @description :: Policy that ... 6 | */ 7 | 8 | module.exports = (req, res, next) => { 9 | // Do your logic here... 10 | 11 | next(); 12 | }; 13 | -------------------------------------------------------------------------------- /generators/policy/templates/Policy.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const sinon = require('sinon'); 5 | const Policy = require('../../../api/policies/<%= name %>'); 6 | 7 | describe('policies:<%= name %>', () => { 8 | it('Should be tested', () => { 9 | assert(false); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /generators/response/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = { 20 | 'response-name': { 21 | required: false, 22 | type: String, 23 | defaults: '' 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /generators/response/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class ResponseGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = 'Scaffold a new response'; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/response/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'new': { 20 | desc: 'Scaffolds a clean response (not predefined)', 21 | alias: 'n', 22 | type: Boolean, 23 | defaults: false 24 | }, 25 | 26 | 'all': { 27 | desc: 'Copies all the overridden responses at once', 28 | alias: 'a', 29 | type: Boolean, 30 | defaults: false 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /generators/response/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/response/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/response/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/response/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/response/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/response/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/response/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/response/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | const DEPENDENCIES = [ 9 | 'lodash' 10 | ]; 11 | 12 | module.exports = function () { 13 | this.npmInstall(DEPENDENCIES, {save: true}); 14 | }; 15 | -------------------------------------------------------------------------------- /generators/response/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/response/steps/writing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 5 5 | * Where you write the generator specific files (routes, controllers, etc) 6 | */ 7 | 8 | const fs = require('fs'); 9 | 10 | const SOURCE_RESPONSE = name => name ? `api/responses/${name}.js` : `Response.js`; 11 | const SOURCE_RESPONSE_TEST = name => name ? `test/unit/responses/${name}.test.js` : `Response.test.js`; 12 | 13 | const DESTINATION_RESPONSE = name => `api/responses/${name}.js`; 14 | const DESTINATION_RESPONSE_TEST = name => `test/unit/responses/${name}.test.js`; 15 | 16 | module.exports = function () { 17 | const name = (this.options['response-name'].charAt(0).toLowerCase() + this.options['response-name'].slice(1)).replace(/Response/, ''); 18 | const isNew = this.options['new']; 19 | const isAll = !name || this.options['all']; 20 | 21 | if (isAll) { 22 | this.fs.copyTpl(this.templatePath(`api/responses/**/*`), this.destinationPath(`api/responses`)); 23 | this.fs.copyTpl(this.templatePath(`test/unit/responses/**/*`), this.destinationPath(`test/unit/responses`)); 24 | } else if (isNew) { 25 | this.fs.copyTpl(this.templatePath(SOURCE_RESPONSE()), this.destinationPath(DESTINATION_RESPONSE(name)), {name}); 26 | this.fs.copyTpl(this.templatePath(SOURCE_RESPONSE_TEST()), this.destinationPath(DESTINATION_RESPONSE_TEST(name)), {name}); 27 | } else { 28 | const responseTemplate = fs.existsSync(this.templatePath(SOURCE_RESPONSE(name))) ? SOURCE_RESPONSE(name) : SOURCE_RESPONSE(); 29 | const testTemplate = fs.existsSync(this.templatePath(SOURCE_RESPONSE_TEST(name))) ? SOURCE_RESPONSE_TEST(name) : SOURCE_RESPONSE_TEST(); 30 | 31 | this.fs.copyTpl(this.templatePath(responseTemplate), this.destinationPath(DESTINATION_RESPONSE(name)), {name}); 32 | this.fs.copyTpl(this.templatePath(testTemplate), this.destinationPath(DESTINATION_RESPONSE_TEST(name)), {name}); 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /generators/response/templates/Response.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = data => { 4 | const response = data; 5 | 6 | this.res.status(200); 7 | this.res.jsonx(response); 8 | }; 9 | -------------------------------------------------------------------------------- /generators/response/templates/Response.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const sinon = require('sinon'); 5 | const Response = require('../../../api/responses/<%= name %>'); 6 | 7 | const context = { 8 | res: { 9 | status: sinon.spy(), 10 | jsonx: sinon.spy() 11 | } 12 | }; 13 | 14 | describe('responses:<%= name %>', () => { 15 | it('Should be tested', () => { 16 | assert(false); 17 | }) 18 | }); 19 | -------------------------------------------------------------------------------- /generators/response/templates/api/responses/badRequest.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * 400 (Bad Request) Response 5 | * 6 | * The request cannot be fulfilled due to bad syntax. 7 | * General error when fulfilling the request would cause an invalid state. 8 | * Domain validation errors, missing data, etc. 9 | */ 10 | 11 | const _ = require('lodash'); 12 | 13 | module.exports = function (data, config) { 14 | const response = _.assign({ 15 | code: _.get(config, 'code', 'E_BAD_REQUEST'), 16 | message: _.get(config, 'message', 'The request cannot be fulfilled due to bad syntax'), 17 | data: data || {} 18 | }, _.get(config, 'root', {})); 19 | 20 | this.res.status(400); 21 | this.res.jsonx(response); 22 | }; 23 | -------------------------------------------------------------------------------- /generators/response/templates/api/responses/created.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * 201 (Created) Response 5 | * 6 | * The request has been fulfilled and resulted in a new resource being created. 7 | * Successful creation occurred (via either POST or PUT). 8 | * Set the Location header to contain a link to the newly-created resource (on POST). 9 | * Response body content may or may not be present. 10 | */ 11 | 12 | const _ = require('lodash'); 13 | 14 | module.exports = function (data, config) { 15 | const response = _.assign({ 16 | code: _.get(config, 'code', 'CREATED'), 17 | message: _.get(config, 'message', 'The request has been fulfilled and resulted in a new resource being created'), 18 | data: data || {} 19 | }, _.get(config, 'root', {})); 20 | 21 | this.res.status(201); 22 | this.res.jsonx(response); 23 | }; 24 | -------------------------------------------------------------------------------- /generators/response/templates/api/responses/forbidden.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * 403 (Forbidden) Response 5 | * 6 | * The request was a legal request, but the server is refusing to respond to it. 7 | * Unlike a 401 Unauthorized response, authenticating will make no difference. 8 | * Error code for user not authorized to perform the operation or the resource is unavailable for some reason. 9 | */ 10 | 11 | const _ = require('lodash'); 12 | 13 | module.exports = function (data, config) { 14 | const response = _.assign({ 15 | code: _.get(config, 'code', 'E_FORBIDDEN'), 16 | message: _.get(config, 'message', 'User not authorized to perform the operation'), 17 | data: data || {} 18 | }, _.get(config, 'root', {})); 19 | 20 | this.res.status(403); 21 | this.res.jsonx(response); 22 | }; 23 | -------------------------------------------------------------------------------- /generators/response/templates/api/responses/negotiate.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Generic Error Handler 5 | * 6 | * Calls the appropriate custom response for a given error 7 | */ 8 | 9 | const _ = require('lodash'); 10 | 11 | module.exports = function (error) { 12 | const res = this.res; 13 | const code = _.get(error, 'code'); 14 | const message = _.get(error, 'reason') || _.get(error, 'message'); 15 | const root = _.get(error, 'root'); 16 | const data = _.get(error, 'invalidAttributes') || _.omit(error, ['name', 'code', 'reason', 'message', 'root', 'status', 'oauthError']); 17 | const statusCode = _.get(error, 'status') || _.get(error, 'oauthError') || 500; 18 | const config = {code, message, root}; 19 | 20 | if (statusCode === 401) return res.unauthorized(data, config); 21 | if (statusCode === 403) return res.forbidden(data, config); 22 | if (statusCode === 404) return res.notFound(data, config); 23 | if (statusCode >= 400 && statusCode < 500) return res.badRequest(data, config); 24 | 25 | return res.serverError(data, config); 26 | }; 27 | -------------------------------------------------------------------------------- /generators/response/templates/api/responses/notFound.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * 404 (Not Found) Response 5 | * 6 | * The requested resource could not be found but may be available again in the future. 7 | * Subsequent requests by the client are permissible. 8 | * Used when the requested resource is not found, whether it doesn't exist. 9 | */ 10 | 11 | const _ = require('lodash'); 12 | 13 | module.exports = function (data, config) { 14 | const response = _.assign({ 15 | code: _.get(config, 'code', 'E_NOT_FOUND'), 16 | message: _.get(config, 'message', 'The requested resource could not be found but may be available again in the future'), 17 | data: data || {} 18 | }, _.get(config, 'root', {})); 19 | 20 | this.res.status(404); 21 | this.res.jsonx(response); 22 | }; 23 | -------------------------------------------------------------------------------- /generators/response/templates/api/responses/ok.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * 200 (OK) Response 5 | * 6 | * General status code. Most common code used to indicate success. 7 | * The actual response will depend on the request method used. 8 | * In a GET request, the response will contain an entity corresponding to the requested resource. 9 | * In a POST request the response will contain an entity describing or containing the result of the action. 10 | */ 11 | 12 | const _ = require('lodash'); 13 | 14 | module.exports = function (data, config) { 15 | const response = _.assign({ 16 | code: _.get(config, 'code', 'OK'), 17 | message: _.get(config, 'message', 'Operation is successfully executed'), 18 | data: data || {} 19 | }, _.get(config, 'root', {})); 20 | 21 | this.res.status(200); 22 | this.res.jsonx(response); 23 | }; 24 | -------------------------------------------------------------------------------- /generators/response/templates/api/responses/serverError.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * 500 (Internal Server Error) Response 5 | * 6 | * A generic error message, given when no more specific message is suitable. 7 | * The general catch-all error when the server-side throws an exception. 8 | */ 9 | 10 | const _ = require('lodash'); 11 | 12 | module.exports = function (data, config) { 13 | const response = _.assign({ 14 | code: _.get(config, 'code', 'E_INTERNAL_SERVER_ERROR'), 15 | message: _.get(config, 'message', 'Something bad happened on the server'), 16 | data: data || {} 17 | }, _.get(config, 'root', {})); 18 | 19 | this.res.status(500); 20 | this.res.jsonx(response); 21 | }; 22 | -------------------------------------------------------------------------------- /generators/response/templates/api/responses/unauthorized.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * 401 (Unauthorized) Response 5 | * 6 | * Similar to 403 Forbidden. 7 | * Specifically for use when authentication is possible but has failed or not yet been provided. 8 | * Error code response for missing or invalid authentication token. 9 | */ 10 | 11 | const _ = require('lodash'); 12 | 13 | module.exports = function (data, config) { 14 | const response = _.assign({ 15 | code: _.get(config, 'code', 'E_UNAUTHORIZED'), 16 | message: _.get(config, 'message', 'Missing or invalid authentication token'), 17 | data: data || {} 18 | }, _.get(config, 'root', {})); 19 | 20 | this.res.status(401); 21 | this.res.jsonx(response); 22 | }; 23 | -------------------------------------------------------------------------------- /generators/response/templates/test/unit/responses/badRequest.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const sinon = require('sinon'); 5 | const badRequest = require('../../../api/responses/badRequest'); 6 | 7 | const context = { 8 | res: { 9 | status: sinon.spy(), 10 | jsonx: sinon.spy() 11 | } 12 | }; 13 | 14 | describe('responses:badRequest', () => { 15 | it('Should generate response with no params', () => { 16 | badRequest.call(context); 17 | assert.ok(context.res.status.calledWith(400)); 18 | assert.ok(context.res.jsonx.calledWith({ 19 | code: 'E_BAD_REQUEST', 20 | message: 'The request cannot be fulfilled due to bad syntax', 21 | data: {} 22 | })); 23 | }); 24 | 25 | it('Should generate response with data param', () => { 26 | badRequest.call(context, 'MY_DATA'); 27 | assert.ok(context.res.status.calledWith(400)); 28 | assert.ok(context.res.jsonx.calledWith({ 29 | code: 'E_BAD_REQUEST', 30 | message: 'The request cannot be fulfilled due to bad syntax', 31 | data: 'MY_DATA' 32 | })); 33 | }); 34 | 35 | it('Should generate response with config param', () => { 36 | badRequest.call(context, 'MY_DATA', {code: 'MY_CODE', message: 'MY_MESSAGE', root: {root: 'MY_ROOT'}}); 37 | assert.ok(context.res.status.calledWith(400)); 38 | assert.ok(context.res.jsonx.calledWith({ 39 | code: 'MY_CODE', 40 | message: 'MY_MESSAGE', 41 | data: 'MY_DATA', 42 | root: 'MY_ROOT' 43 | })); 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /generators/response/templates/test/unit/responses/created.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const sinon = require('sinon'); 5 | const created = require('../../../api/responses/created'); 6 | 7 | const context = { 8 | res: { 9 | status: sinon.spy(), 10 | jsonx: sinon.spy() 11 | } 12 | }; 13 | 14 | describe('responses:created', () => { 15 | it('Should generate response with no params', () => { 16 | created.call(context); 17 | assert.ok(context.res.status.calledWith(201)); 18 | assert.ok(context.res.jsonx.calledWith({ 19 | code: 'CREATED', 20 | message: 'The request has been fulfilled and resulted in a new resource being created', 21 | data: {} 22 | })); 23 | }); 24 | 25 | it('Should generate response with data param', () => { 26 | created.call(context, 'MY_DATA'); 27 | assert.ok(context.res.status.calledWith(201)); 28 | assert.ok(context.res.jsonx.calledWith({ 29 | code: 'CREATED', 30 | message: 'The request has been fulfilled and resulted in a new resource being created', 31 | data: 'MY_DATA' 32 | })); 33 | }); 34 | 35 | it('Should generate response with config param', () => { 36 | created.call(context, 'MY_DATA', {code: 'MY_CODE', message: 'MY_MESSAGE', root: {root: 'MY_ROOT'}}); 37 | assert.ok(context.res.status.calledWith(201)); 38 | assert.ok(context.res.jsonx.calledWith({ 39 | code: 'MY_CODE', 40 | message: 'MY_MESSAGE', 41 | data: 'MY_DATA', 42 | root: 'MY_ROOT' 43 | })); 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /generators/response/templates/test/unit/responses/forbidden.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const sinon = require('sinon'); 5 | const forbidden = require('../../../api/responses/forbidden'); 6 | 7 | const context = { 8 | res: { 9 | status: sinon.spy(), 10 | jsonx: sinon.spy() 11 | } 12 | }; 13 | 14 | describe('responses:forbidden', () => { 15 | it('Should generate response with no params', () => { 16 | forbidden.call(context); 17 | assert.ok(context.res.status.calledWith(403)); 18 | assert.ok(context.res.jsonx.calledWith({ 19 | code: 'E_FORBIDDEN', 20 | message: 'User not authorized to perform the operation', 21 | data: {} 22 | })); 23 | }); 24 | 25 | it('Should generate response with data param', () => { 26 | forbidden.call(context, 'MY_DATA'); 27 | assert.ok(context.res.status.calledWith(403)); 28 | assert.ok(context.res.jsonx.calledWith({ 29 | code: 'E_FORBIDDEN', 30 | message: 'User not authorized to perform the operation', 31 | data: 'MY_DATA' 32 | })); 33 | }); 34 | 35 | it('Should generate response with config param', () => { 36 | forbidden.call(context, 'MY_DATA', {code: 'MY_CODE', message: 'MY_MESSAGE', root: {root: 'MY_ROOT'}}); 37 | assert.ok(context.res.status.calledWith(403)); 38 | assert.ok(context.res.jsonx.calledWith({ 39 | code: 'MY_CODE', 40 | message: 'MY_MESSAGE', 41 | data: 'MY_DATA', 42 | root: 'MY_ROOT' 43 | })); 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /generators/response/templates/test/unit/responses/notFound.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const sinon = require('sinon'); 5 | const notFound = require('../../../api/responses/notFound'); 6 | 7 | const context = { 8 | res: { 9 | status: sinon.spy(), 10 | jsonx: sinon.spy() 11 | } 12 | }; 13 | 14 | describe('responses:notFound', () => { 15 | it('Should generate response with no params', () => { 16 | notFound.call(context); 17 | assert.ok(context.res.status.calledWith(404)); 18 | assert.ok(context.res.jsonx.calledWith({ 19 | code: 'E_NOT_FOUND', 20 | message: 'The requested resource could not be found but may be available again in the future', 21 | data: {} 22 | })); 23 | }); 24 | 25 | it('Should generate response with data param', () => { 26 | notFound.call(context, 'MY_DATA'); 27 | assert.ok(context.res.status.calledWith(404)); 28 | assert.ok(context.res.jsonx.calledWith({ 29 | code: 'E_NOT_FOUND', 30 | message: 'The requested resource could not be found but may be available again in the future', 31 | data: 'MY_DATA' 32 | })); 33 | }); 34 | 35 | it('Should generate response with config param', () => { 36 | notFound.call(context, 'MY_DATA', {code: 'MY_CODE', message: 'MY_MESSAGE', root: {root: 'MY_ROOT'}}); 37 | assert.ok(context.res.status.calledWith(404)); 38 | assert.ok(context.res.jsonx.calledWith({ 39 | code: 'MY_CODE', 40 | message: 'MY_MESSAGE', 41 | data: 'MY_DATA', 42 | root: 'MY_ROOT' 43 | })); 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /generators/response/templates/test/unit/responses/ok.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const sinon = require('sinon'); 5 | const ok = require('../../../api/responses/ok'); 6 | 7 | const context = { 8 | res: { 9 | status: sinon.spy(), 10 | jsonx: sinon.spy() 11 | } 12 | }; 13 | 14 | describe('responses:ok', () => { 15 | it('Should generate response with no params', () => { 16 | ok.call(context); 17 | assert.ok(context.res.status.calledWith(200)); 18 | assert.ok(context.res.jsonx.calledWith({ 19 | code: 'OK', 20 | message: 'Operation is successfully executed', 21 | data: {} 22 | })); 23 | }); 24 | 25 | it('Should generate response with data param', () => { 26 | ok.call(context, 'MY_DATA'); 27 | assert.ok(context.res.status.calledWith(200)); 28 | assert.ok(context.res.jsonx.calledWith({ 29 | code: 'OK', 30 | message: 'Operation is successfully executed', 31 | data: 'MY_DATA' 32 | })); 33 | }); 34 | 35 | it('Should generate response with config param', () => { 36 | ok.call(context, 'MY_DATA', {code: 'MY_CODE', message: 'MY_MESSAGE', root: {root: 'MY_ROOT'}}); 37 | assert.ok(context.res.status.calledWith(200)); 38 | assert.ok(context.res.jsonx.calledWith({ 39 | code: 'MY_CODE', 40 | message: 'MY_MESSAGE', 41 | data: 'MY_DATA', 42 | root: 'MY_ROOT' 43 | })); 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /generators/response/templates/test/unit/responses/serverError.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const sinon = require('sinon'); 5 | const serverError = require('../../../api/responses/serverError'); 6 | 7 | const context = { 8 | res: { 9 | status: sinon.spy(), 10 | jsonx: sinon.spy() 11 | } 12 | }; 13 | 14 | describe('responses:serverError', () => { 15 | it('Should generate response with no params', () => { 16 | serverError.call(context); 17 | assert.ok(context.res.status.calledWith(500)); 18 | assert.ok(context.res.jsonx.calledWith({ 19 | code: 'E_INTERNAL_SERVER_ERROR', 20 | message: 'Something bad happened on the server', 21 | data: {} 22 | })); 23 | }); 24 | 25 | it('Should generate response with data param', () => { 26 | serverError.call(context, 'MY_DATA'); 27 | assert.ok(context.res.status.calledWith(500)); 28 | assert.ok(context.res.jsonx.calledWith({ 29 | code: 'E_INTERNAL_SERVER_ERROR', 30 | message: 'Something bad happened on the server', 31 | data: 'MY_DATA' 32 | })); 33 | }); 34 | 35 | it('Should generate response with config param', () => { 36 | serverError.call(context, 'MY_DATA', {code: 'MY_CODE', message: 'MY_MESSAGE', root: {root: 'MY_ROOT'}}); 37 | assert.ok(context.res.status.calledWith(500)); 38 | assert.ok(context.res.jsonx.calledWith({ 39 | code: 'MY_CODE', 40 | message: 'MY_MESSAGE', 41 | data: 'MY_DATA', 42 | root: 'MY_ROOT' 43 | })); 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /generators/response/templates/test/unit/responses/unauthorized.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const sinon = require('sinon'); 5 | const unauthorized = require('../../../api/responses/unauthorized'); 6 | 7 | const context = { 8 | res: { 9 | status: sinon.spy(), 10 | jsonx: sinon.spy() 11 | } 12 | }; 13 | 14 | describe('responses:unauthorized', () => { 15 | it('Should generate response with no params', () => { 16 | unauthorized.call(context); 17 | assert.ok(context.res.status.calledWith(401)); 18 | assert.ok(context.res.jsonx.calledWith({ 19 | code: 'E_UNAUTHORIZED', 20 | message: 'Missing or invalid authentication token', 21 | data: {} 22 | })); 23 | }); 24 | 25 | it('Should generate response with data param', () => { 26 | unauthorized.call(context, 'MY_DATA'); 27 | assert.ok(context.res.status.calledWith(401)); 28 | assert.ok(context.res.jsonx.calledWith({ 29 | code: 'E_UNAUTHORIZED', 30 | message: 'Missing or invalid authentication token', 31 | data: 'MY_DATA' 32 | })); 33 | }); 34 | 35 | it('Should generate response with config param', () => { 36 | unauthorized.call(context, 'MY_DATA', {code: 'MY_CODE', message: 'MY_MESSAGE', root: {root: 'MY_ROOT'}}); 37 | assert.ok(context.res.status.calledWith(401)); 38 | assert.ok(context.res.jsonx.calledWith({ 39 | code: 'MY_CODE', 40 | message: 'MY_MESSAGE', 41 | data: 'MY_DATA', 42 | root: 'MY_ROOT' 43 | })); 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /generators/service/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = { 20 | 'service-name': { 21 | required: false, 22 | type: String, 23 | defaults: '' 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /generators/service/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class ServiceGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = 'Scaffolds a new service'; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/service/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/service/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/service/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/service/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/service/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/service/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/service/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/service/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | const DEPENDENCIES = { 9 | cipher: ['sails-service-cipher'], 10 | hash: ['sails-service-hash'], 11 | image: ['sails-service-image'], 12 | location: ['sails-service-location'], 13 | mailer: ['sails-service-mailer'], 14 | payment: ['sails-service-payment'], 15 | pusher: ['sails-service-pusher'], 16 | sms: ['sails-service-sms'], 17 | social: ['sails-service-social'], 18 | storage: ['sails-service-storage'] 19 | }; 20 | 21 | module.exports = function () { 22 | const name = this.options['service-name'].replace(/Service/, '').toLowerCase(); 23 | const isNew = this.options['new']; 24 | const isAll = !name || this.options['all']; 25 | 26 | if (isNew) return; 27 | 28 | if (isAll) { 29 | return this.npmInstall(Object.keys(DEPENDENCIES).reduce((dependencies, service) => dependencies.concat(DEPENDENCIES[service]), []), {save: true}); 30 | } else { 31 | return DEPENDENCIES[name] ? this.npmInstall(DEPENDENCIES[name], {save: true}) : true; 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /generators/service/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/service/templates/Service.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = {}; 4 | -------------------------------------------------------------------------------- /generators/service/templates/Service.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const Service = require('../../../api/services/<%= name %>Service'); 5 | 6 | describe('services:<%= name %>Service', () => { 7 | it('Should properly export', () => { 8 | assert.isObject(Service); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/service/templates/ServiceConfig.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | services: { 5 | <%= name.toLowerCase() %>: {} 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /generators/service/templates/api/services/CipherService.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const cipher = require('sails-service-cipher'); 4 | const config = require('../../config/services/cipher'); 5 | 6 | module.exports = { 7 | jwt: cipher('jwt', config.services.cipher.jwt) 8 | }; 9 | -------------------------------------------------------------------------------- /generators/service/templates/api/services/HashService.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const hash = require('sails-service-hash'); 4 | const config = require('../../config/services/hash'); 5 | 6 | module.exports = { 7 | bcrypt: hash('bcrypt', config.services.hash.bcrypt) 8 | }; 9 | -------------------------------------------------------------------------------- /generators/service/templates/api/services/ImageService.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const image = require('sails-service-image'); 4 | const config = require('../../config/services/image'); 5 | 6 | module.exports = image('<%= options["image-provider"] %>', config.services.image); 7 | -------------------------------------------------------------------------------- /generators/service/templates/api/services/LocationService.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const location = require('sails-service-location'); 4 | const config = require('../../config/services/location'); 5 | 6 | module.exports = location('<%= options["location-provider"] %>', config.services.location); 7 | -------------------------------------------------------------------------------- /generators/service/templates/api/services/MailerService.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const mailer = require('sails-service-mailer'); 4 | const config = require('../../config/services/mailer'); 5 | 6 | module.exports = mailer('<%= options["mailer-provider"] %>', config.services.mailer); 7 | -------------------------------------------------------------------------------- /generators/service/templates/api/services/PaymentService.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const payment = require('sails-service-payment'); 4 | const config = require('../../config/services/payment'); 5 | 6 | module.exports = payment('<%= options["payment-provider"] %>', config.services.payment); 7 | -------------------------------------------------------------------------------- /generators/service/templates/api/services/PusherService.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const pusher = require('sails-service-pusher'); 4 | const config = require('../../config/services/pusher'); 5 | 6 | module.exports = { 7 | android: pusher('android', config.services.pusher.android), 8 | ios: pusher('ios', config.services.pusher.ios) 9 | }; 10 | -------------------------------------------------------------------------------- /generators/service/templates/api/services/SmsService.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const sms = require('sails-service-sms'); 4 | const config = require('../../config/services/sms'); 5 | 6 | module.exports = sms('<%= options["sms-provider"] %>', config.services.sms); 7 | -------------------------------------------------------------------------------- /generators/service/templates/api/services/SocialService.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const social = require('sails-service-social'); 4 | const config = require('../../config/services/social'); 5 | 6 | module.exports = { 7 | facebook: social('facebook', config.services.social.facebook) 8 | }; 9 | -------------------------------------------------------------------------------- /generators/service/templates/api/services/StorageService.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const storage = require('sails-service-storage'); 4 | const config = require('../../config/services/storage'); 5 | 6 | module.exports = storage('<%= options["storage-provider"] %>', config.services.storage); 7 | -------------------------------------------------------------------------------- /generators/service/templates/config/services/cipher.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | services: { 5 | cipher: { 6 | jwt: { 7 | secretKey: '<%= options["cipher-secret-key"] %>' 8 | } 9 | } 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /generators/service/templates/config/services/hash.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | services: { 5 | hash: { 6 | bcrypt: {} 7 | } 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /generators/service/templates/config/services/image.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | services: { 5 | image: {} 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /generators/service/templates/config/services/location.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | services: { 5 | location: {} 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /generators/service/templates/config/services/mailer.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | services: { 5 | mailer: {} 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /generators/service/templates/config/services/payment.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | services: { 5 | payment: {} 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /generators/service/templates/config/services/pusher.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | services: { 5 | pusher: { 6 | android: {}, 7 | ios: {} 8 | } 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /generators/service/templates/config/services/sms.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | services: { 5 | sms: {} 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /generators/service/templates/config/services/social.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | services: { 5 | social: { 6 | facebook: {} 7 | } 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /generators/service/templates/config/services/storage.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | services: { 5 | storage: {} 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /generators/service/templates/test/unit/services/CipherService.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const CipherService = require('../../../api/services/CipherService'); 5 | 6 | describe('services:CipherService', () => { 7 | it('Should properly export', () => { 8 | assert.isObject(CipherService); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/service/templates/test/unit/services/HashService.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const HashService = require('../../../api/services/HashService'); 5 | 6 | describe('services:HashService', () => { 7 | it('Should properly export', () => { 8 | assert.isObject(HashService); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/service/templates/test/unit/services/ImageService.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const ImageService = require('../../../api/services/ImageService'); 5 | 6 | describe('services:ImageService', () => { 7 | it('Should properly export', () => { 8 | assert.isObject(ImageService); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/service/templates/test/unit/services/LocationService.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const LocationService = require('../../../api/services/LocationService'); 5 | 6 | describe('services:LocationService', () => { 7 | it('Should properly export', () => { 8 | assert.isObject(LocationService); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/service/templates/test/unit/services/MailerService.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const MailerService = require('../../../api/services/MailerService'); 5 | 6 | describe('services:MailerService', () => { 7 | it('Should properly export', () => { 8 | assert.isObject(MailerService); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/service/templates/test/unit/services/PaymentService.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const PaymentService = require('../../../api/services/PaymentService'); 5 | 6 | describe('services:PaymentService', () => { 7 | it('Should properly export', () => { 8 | assert.isObject(PaymentService); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/service/templates/test/unit/services/PusherService.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const PusherService = require('../../../api/services/PusherService'); 5 | 6 | describe('services:PusherService', () => { 7 | it('Should properly export', () => { 8 | assert.isObject(PusherService); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/service/templates/test/unit/services/SmsService.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const SmsService = require('../../../api/services/SmsService'); 5 | 6 | describe('services:SmsService', () => { 7 | it('Should properly export', () => { 8 | assert.isObject(SmsService); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/service/templates/test/unit/services/SocialService.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const SocialService = require('../../../api/services/SocialService'); 5 | 6 | describe('services:SocialService', () => { 7 | it('Should properly export', () => { 8 | assert.isObject(SocialService); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/service/templates/test/unit/services/StorageService.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require('chai').assert; 4 | const StorageService = require('../../../api/services/StorageService'); 5 | 6 | describe('services:StorageService', () => { 7 | it('Should properly export', () => { 8 | assert.isObject(StorageService); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /generators/swagger/arguments/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of arguments as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * argumentName: { 9 | * desc: 'Description for the argument', 10 | * required: false, 11 | * optional: true, 12 | * type: String || Number || Array || Object, 13 | * defaults: 'Default value for this argument', 14 | * banner: 'String to show on usage notes' 15 | * } 16 | * }; 17 | */ 18 | 19 | module.exports = {}; 20 | -------------------------------------------------------------------------------- /generators/swagger/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const Base = require('yeoman-generator'); 4 | const generatorArguments = require('./arguments'); 5 | const generatorOptions = require('./options'); 6 | const generatorSteps = require('./steps'); 7 | 8 | module.exports = class SwaggerGenerator extends Base { 9 | constructor(args, options) { 10 | super(args, options); 11 | 12 | Object.keys(generatorArguments).forEach(key => this.argument(key, generatorArguments[key])); 13 | Object.keys(generatorOptions).forEach(key => this.option(key, generatorOptions[key])); 14 | 15 | this.description = 'Scaffolds the Swagger UI Explorer'; 16 | } 17 | 18 | get configuring() { 19 | return generatorSteps.configuring; 20 | } 21 | 22 | get conflicts() { 23 | return generatorSteps.conflicts; 24 | } 25 | 26 | get default() { 27 | return generatorSteps.default; 28 | } 29 | 30 | get end() { 31 | return generatorSteps.end; 32 | } 33 | 34 | get initializing() { 35 | return generatorSteps.initializing 36 | } 37 | 38 | get install() { 39 | return generatorSteps.install; 40 | } 41 | 42 | get prompting() { 43 | return generatorSteps.prompting 44 | } 45 | 46 | get writing() { 47 | return generatorSteps.writing; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/swagger/options/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains names of options as a key and their configuration objects as a value 5 | * 6 | * @example 7 | * module.exports = { 8 | * optionName: { 9 | * desc: 'Description for the option', 10 | * alias: 'Short name for the option', 11 | * type: Boolean || String || Number, 12 | * defaults: 'Default value', 13 | * hide: false 14 | * } 15 | * }; 16 | */ 17 | 18 | module.exports = { 19 | 'skip-install': { 20 | desc: 'Do not automatically install dependencies', 21 | type: Boolean, 22 | defaults: false, 23 | hide: false 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /generators/swagger/questions/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports array that contains questions for prompting. 5 | * The array with questions is an array of Inquirer prompt objects - https://github.com/SBoudrias/Inquirer.js#prompts-type 6 | * 7 | * @example 8 | * module.exports = [{ 9 | * type: 'input', 10 | * name: 'inputName', 11 | * message: 'Message for the input' 12 | * }]; 13 | */ 14 | 15 | module.exports = []; 16 | -------------------------------------------------------------------------------- /generators/swagger/steps/configuring.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 3 5 | * Saving configurations and configure the project 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/swagger/steps/conflicts.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 6 5 | * Where conflicts are handled (used internally) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/swagger/steps/default.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 4 5 | * Default priority in run loop 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/swagger/steps/end.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 8 5 | * Called last, cleanup, say good bye, etc 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/swagger/steps/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Exports object that contains each of priority steps of yeoman run loop 5 | */ 6 | 7 | module.exports = { 8 | configuring: require('./configuring'), 9 | conflicts: require('./conflicts'), 10 | default: require('./default'), 11 | end: require('./end'), 12 | initializing: require('./initializing'), 13 | install: require('./install'), 14 | prompting: require('./prompting'), 15 | writing: require('./writing') 16 | }; 17 | -------------------------------------------------------------------------------- /generators/swagger/steps/initializing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 1 5 | * Your initialization methods (checking current project state, getting configs, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | }; 10 | -------------------------------------------------------------------------------- /generators/swagger/steps/install.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 7 5 | * Where installation are run (npm, bower) 6 | */ 7 | 8 | const DEPENDENCIES = [ 9 | 'hoek', 10 | 'lodash', 11 | 'pluralize' 12 | ]; 13 | 14 | module.exports = function () { 15 | this.npmInstall(DEPENDENCIES, {save: true}); 16 | }; 17 | -------------------------------------------------------------------------------- /generators/swagger/steps/prompting.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 2 5 | * Where you prompt users for options (where you'd call this.prompt()). 6 | */ 7 | 8 | const questions = require('../questions'); 9 | 10 | module.exports = function () { 11 | }; 12 | -------------------------------------------------------------------------------- /generators/swagger/steps/writing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * Step 5 5 | * Where you write the generator specific files (routes, controllers, etc) 6 | */ 7 | 8 | module.exports = function () { 9 | this.fs.copyTpl(this.templatePath('api/**/*'), this.destinationPath('api')); 10 | this.fs.copyTpl(this.templatePath('config/**/*'), this.destinationPath('config')); 11 | this.fs.copy(this.templatePath('explorer/**/*'), this.destinationPath('explorer')); 12 | }; 13 | -------------------------------------------------------------------------------- /generators/swagger/templates/api/controllers/DocsController.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | index(req, res) { 5 | res.status(200).jsonx(sails.hooks.swagger.doc); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /generators/swagger/templates/api/hooks/swagger/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * https://github.com/tjwebb/sails-swagger 5 | */ 6 | 7 | const _ = require('lodash'); 8 | const xfmr = require('./lib/xfmr'); 9 | const express = require('express'); 10 | 11 | module.exports = sails => { 12 | return { 13 | defaults(overrides) { 14 | this.bindExplorerRoute(); 15 | 16 | return { 17 | 'swagger': { 18 | pkg: { 19 | name: 'No package information', 20 | description: 'You should set sails.config.swagger.pkg to retrieve the content of the package.json file', 21 | version: '0.0.1' 22 | } 23 | } 24 | }; 25 | }, 26 | 27 | initialize(cb) { 28 | let hook = sails.hooks.swagger; 29 | 30 | sails.after('lifted', () => { 31 | hook.doc = xfmr.getSwagger(sails, sails.config.swagger.pkg); 32 | }); 33 | 34 | cb(); 35 | }, 36 | 37 | bindExplorerRoute() { 38 | let originalCustomMiddleware = _.get(sails.config, 'http.customMiddleware'); 39 | let customMiddleware = app => { 40 | app.use('/explorer', express.static(process.cwd() + '/explorer')); 41 | if (_.isFunction(originalCustomMiddleware)) { 42 | originalCustomMiddleware(app); 43 | } 44 | }; 45 | _.set(sails.config, 'http.customMiddleware', customMiddleware); 46 | } 47 | 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /generators/swagger/templates/api/hooks/swagger/lib/spec.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /** 4 | * https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#dataTypeFormat 5 | */ 6 | 7 | const types = { 8 | integer: { 9 | type: 'integer', 10 | format: 'int32' 11 | }, 12 | float: { 13 | type: 'number', 14 | format: 'float' 15 | }, 16 | double: { 17 | type: 'number', 18 | format: 'double' 19 | }, 20 | string: { 21 | type: 'string', 22 | format: 'string' 23 | }, 24 | binary: { 25 | type: 'string', 26 | format: 'binary' 27 | }, 28 | boolean: { 29 | type: 'boolean' 30 | }, 31 | date: { 32 | type: 'string', 33 | format: 'date' 34 | }, 35 | datetime: { 36 | type: 'string', 37 | format: 'date-time' 38 | } 39 | }; 40 | 41 | const typeMap = { 42 | text: 'string', 43 | json: 'string' 44 | }; 45 | 46 | const Spec = { 47 | getPropertyType (wltype) { 48 | return types[typeMap[wltype] || wltype]; 49 | } 50 | }; 51 | 52 | module.exports = Spec; 53 | -------------------------------------------------------------------------------- /generators/swagger/templates/config/swagger.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | swagger: { 5 | pkg: { 6 | name: 'No package information', 7 | description: 'You should configure config/swagger.js to retrieve the content of the package.json file', 8 | version: '0.0.1' 9 | } 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/css/reset.css: -------------------------------------------------------------------------------- 1 | /* http://meyerweb.com/eric/tools/css/reset/ v2.0 | 20110126 */ 2 | html, 3 | body, 4 | div, 5 | span, 6 | applet, 7 | object, 8 | iframe, 9 | h1, 10 | h2, 11 | h3, 12 | h4, 13 | h5, 14 | h6, 15 | p, 16 | blockquote, 17 | pre, 18 | a, 19 | abbr, 20 | acronym, 21 | address, 22 | big, 23 | cite, 24 | code, 25 | del, 26 | dfn, 27 | em, 28 | img, 29 | ins, 30 | kbd, 31 | q, 32 | s, 33 | samp, 34 | small, 35 | strike, 36 | strong, 37 | sub, 38 | sup, 39 | tt, 40 | var, 41 | b, 42 | u, 43 | i, 44 | center, 45 | dl, 46 | dt, 47 | dd, 48 | ol, 49 | ul, 50 | li, 51 | fieldset, 52 | form, 53 | label, 54 | legend, 55 | table, 56 | caption, 57 | tbody, 58 | tfoot, 59 | thead, 60 | tr, 61 | th, 62 | td, 63 | article, 64 | aside, 65 | canvas, 66 | details, 67 | embed, 68 | figure, 69 | figcaption, 70 | footer, 71 | header, 72 | hgroup, 73 | menu, 74 | nav, 75 | output, 76 | ruby, 77 | section, 78 | summary, 79 | time, 80 | mark, 81 | audio, 82 | video { 83 | margin: 0; 84 | padding: 0; 85 | border: 0; 86 | font-size: 100%; 87 | font: inherit; 88 | vertical-align: baseline; 89 | } 90 | /* HTML5 display-role reset for older browsers */ 91 | article, 92 | aside, 93 | details, 94 | figcaption, 95 | figure, 96 | footer, 97 | header, 98 | hgroup, 99 | menu, 100 | nav, 101 | section { 102 | display: block; 103 | } 104 | body { 105 | line-height: 1; 106 | } 107 | ol, 108 | ul { 109 | list-style: none; 110 | } 111 | blockquote, 112 | q { 113 | quotes: none; 114 | } 115 | blockquote:before, 116 | blockquote:after, 117 | q:before, 118 | q:after { 119 | content: ''; 120 | content: none; 121 | } 122 | table { 123 | border-collapse: collapse; 124 | border-spacing: 0; 125 | } 126 | -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/css/typography.css: -------------------------------------------------------------------------------- 1 | /* droid-sans-regular - latin */ 2 | @font-face { 3 | font-family: 'Droid Sans'; 4 | font-style: normal; 5 | font-weight: 400; 6 | src: url('../fonts/droid-sans-v6-latin-regular.eot'); /* IE9 Compat Modes */ 7 | src: local('Droid Sans'), local('DroidSans'), 8 | url('../fonts/droid-sans-v6-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ 9 | url('../fonts/droid-sans-v6-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */ 10 | url('../fonts/droid-sans-v6-latin-regular.woff') format('woff'), /* Modern Browsers */ 11 | url('../fonts/droid-sans-v6-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */ 12 | url('../fonts/droid-sans-v6-latin-regular.svg#DroidSans') format('svg'); /* Legacy iOS */ 13 | } 14 | /* droid-sans-700 - latin */ 15 | @font-face { 16 | font-family: 'Droid Sans'; 17 | font-style: normal; 18 | font-weight: 700; 19 | src: url('../fonts/droid-sans-v6-latin-700.eot'); /* IE9 Compat Modes */ 20 | src: local('Droid Sans Bold'), local('DroidSans-Bold'), 21 | url('../fonts/droid-sans-v6-latin-700.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ 22 | url('../fonts/droid-sans-v6-latin-700.woff2') format('woff2'), /* Super Modern Browsers */ 23 | url('../fonts/droid-sans-v6-latin-700.woff') format('woff'), /* Modern Browsers */ 24 | url('../fonts/droid-sans-v6-latin-700.ttf') format('truetype'), /* Safari, Android, iOS */ 25 | url('../fonts/droid-sans-v6-latin-700.svg#DroidSans') format('svg'); /* Legacy iOS */ 26 | } 27 | -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-700.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-700.eot -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-700.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-700.ttf -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-700.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-700.woff -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-700.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-700.woff2 -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-regular.eot -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-regular.ttf -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-regular.woff -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/fonts/droid-sans-v6-latin-regular.woff2 -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/images/explorer_icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/images/explorer_icons.png -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/images/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/images/favicon-16x16.png -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/images/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/images/favicon-32x32.png -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/images/favicon.ico -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/images/logo_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/images/logo_small.png -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/images/pet_store_api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/images/pet_store_api.png -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/images/throbber.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/images/throbber.gif -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/images/wordnik_api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaiklor/generator-sails-rest-api/094764036f0acc8b4e963a480acbf9cae9bdeed9/generators/swagger/templates/explorer/images/wordnik_api.png -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/lang/translator.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Translator for documentation pages. 5 | * 6 | * To enable translation you should include one of language-files in your index.html 7 | * after . 8 | * For example - 9 | * 10 | * If you wish to translate some new texsts you should do two things: 11 | * 1. Add a new phrase pair ("New Phrase": "New Translation") into your language file (for example lang/ru.js). It will be great if you add it in other language files too. 12 | * 2. Mark that text it templates this way New Phrase or . 13 | * The main thing here is attribute data-sw-translate. Only inner html, title-attribute and value-attribute are going to translate. 14 | * 15 | */ 16 | window.SwaggerTranslator = { 17 | 18 | _words:[], 19 | 20 | translate: function(sel) { 21 | var $this = this; 22 | sel = sel || '[data-sw-translate]'; 23 | 24 | $(sel).each(function() { 25 | $(this).html($this._tryTranslate($(this).html())); 26 | 27 | $(this).val($this._tryTranslate($(this).val())); 28 | $(this).attr('title', $this._tryTranslate($(this).attr('title'))); 29 | }); 30 | }, 31 | 32 | _tryTranslate: function(word) { 33 | return this._words[$.trim(word)] !== undefined ? this._words[$.trim(word)] : word; 34 | }, 35 | 36 | learn: function(wordsMap) { 37 | this._words = wordsMap; 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/lib/jquery.slideto.min.js: -------------------------------------------------------------------------------- 1 | (function(b){b.fn.slideto=function(a){a=b.extend({slide_duration:"slow",highlight_duration:3E3,highlight:true,highlight_color:"#FFFF99"},a);return this.each(function(){obj=b(this);b("body").animate({scrollTop:obj.offset().top},a.slide_duration,function(){a.highlight&&b.ui.version&&obj.effect("highlight",{color:a.highlight_color},a.highlight_duration)})})}})(jQuery); 2 | -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/lib/jquery.wiggle.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | jQuery Wiggle 3 | Author: WonderGroup, Jordan Thomas 4 | URL: http://labs.wondergroup.com/demos/mini-ui/index.html 5 | License: MIT (http://en.wikipedia.org/wiki/MIT_License) 6 | */ 7 | jQuery.fn.wiggle=function(o){var d={speed:50,wiggles:3,travel:5,callback:null};var o=jQuery.extend(d,o);return this.each(function(){var cache=this;var wrap=jQuery(this).wrap('
').css("position","relative");var calls=0;for(i=1;i<=o.wiggles;i++){jQuery(this).animate({left:"-="+o.travel},o.speed).animate({left:"+="+o.travel*2},o.speed*2).animate({left:"-="+o.travel},o.speed,function(){calls++;if(jQuery(cache).parent().hasClass('wiggle-wrap')){jQuery(cache).parent().replaceWith(cache);} 8 | if(calls==o.wiggles&&jQuery.isFunction(o.callback)){o.callback();}});}});}; -------------------------------------------------------------------------------- /generators/swagger/templates/explorer/o2c.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | ./test/unit/**/*.test.js 2 | --reporter nyan 3 | --recursive 4 | -------------------------------------------------------------------------------- /test/unit/adapter.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const path = require('path'); 4 | const assert = require('yeoman-assert'); 5 | const test = require('yeoman-test'); 6 | 7 | describe('sails-rest-api:adapter', () => { 8 | describe('Should properly scaffold adapter', () => { 9 | before(() => test.run(path.join(__dirname, '../../generators/adapter')).withArguments(['mongo'])); 10 | 11 | it('Should properly create api files', () => { 12 | assert.file([ 13 | 'api/adapters/MongoAdapter.js' 14 | ]); 15 | 16 | assert.fileContent('api/adapters/MongoAdapter.js', /let connections = \{\};/); 17 | }); 18 | 19 | it('Should properly create test files', () => { 20 | assert.file([ 21 | 'test/unit/adapters/MongoAdapter.test.js' 22 | ]); 23 | 24 | assert.fileContent('test/unit/adapters/MongoAdapter.test.js', /const Adapter = require\('\.\.\/\.\.\/\.\.\/api\/adapters\/MongoAdapter'\)/); 25 | }); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /test/unit/cron.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const path = require('path'); 4 | const assert = require('yeoman-assert'); 5 | const test = require('yeoman-test'); 6 | 7 | describe('sails-rest-api:cron', () => { 8 | describe('Should properly scaffold empty cron configuration file', () => { 9 | before(() => test.run(path.join(__dirname, '../../generators/cron'))); 10 | 11 | it('Should properly create configuration files', () => { 12 | assert.file([ 13 | 'config/cron.js' 14 | ]); 15 | 16 | assert.noFileContent('config/cron.js', /testJob:/); 17 | }); 18 | }); 19 | 20 | describe('Should properly scaffold cron configuration file with predefined jobs', () => { 21 | before(() => { 22 | return test 23 | .run(path.join(__dirname, '../../generators/cron')) 24 | .withArguments(['testJob', 'anotherJob']) 25 | }); 26 | 27 | it('Should properly create configuration files', () => { 28 | assert.file([ 29 | 'config/cron.js' 30 | ]); 31 | 32 | assert.fileContent('config/cron.js', /'testJob':/); 33 | assert.fileContent('config/cron.js', /'anotherJob':/); 34 | }); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /test/unit/policy.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const path = require('path'); 4 | const assert = require('yeoman-assert'); 5 | const test = require('yeoman-test'); 6 | 7 | describe('sails-rest-api:policy', () => { 8 | describe('Should properly scaffold policy', () => { 9 | before(() => { 10 | return test 11 | .run(path.join(__dirname, '../../generators/policy')) 12 | .withArguments(['IsAdmin']) 13 | }); 14 | 15 | it('Should properly create api files', () => { 16 | assert.file([ 17 | 'api/policies/isAdmin.js' 18 | ]); 19 | 20 | assert.fileContent('api/policies/isAdmin.js', /module.exports = \(req, res, next\)/); 21 | }); 22 | 23 | it('Should properly create test files', () => { 24 | assert.file([ 25 | 'test/unit/policies/isAdmin.test.js' 26 | ]); 27 | 28 | assert.fileContent('test/unit/policies/isAdmin.test.js', /const Policy = require\('\.\.\/\.\.\/\.\.\/api\/policies\/isAdmin'\)/); 29 | }); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /test/unit/swagger.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const path = require('path'); 4 | const assert = require('yeoman-assert'); 5 | const test = require('yeoman-test'); 6 | 7 | describe('sails-rest-api:swagger', () => { 8 | describe('Should properly scaffold swagger support with default configuration', () => { 9 | before(() => test.run(path.join(__dirname, '../../generators/swagger'))); 10 | 11 | it('Should properly create api files', () => { 12 | assert.file([ 13 | 'config/swagger.js', 14 | 'api/controllers/DocsController.js', 15 | 'api/hooks/swagger/index.js', 16 | 'api/hooks/swagger/lib/spec.js', 17 | 'api/hooks/swagger/lib/xfmr.js' 18 | ]); 19 | }); 20 | 21 | it('Should properly create explorer folder', () => { 22 | assert.file([ 23 | 'explorer' 24 | ]); 25 | }) 26 | }); 27 | }); 28 | --------------------------------------------------------------------------------