From 655e63e1ff2bc86f827dc73db5df8406b4501d0c Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 20 Feb 2015 12:19:07 +0200 Subject: [PATCH 001/118] Update roadmap --- ROADMAP.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 00ace78f..ccb192ba 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -5,12 +5,14 @@ - [ ] Add **apn** and **gcm** push notifications; - [ ] Add social service **Twitter**; - [ ] Add support for **Amazon** mailer, **sendmail** mailer; -- [ ] Sub generators for each service; - [ ] Test coverage for all `api` files; -- [ ] Add questions list where you can choose which service need to include and copy only needed; -- [ ] Make swagger documentation as part of Sails generator; -## Next version +## Next minor version + +- [ ] Improve stability (too much new features is appears in previous version); +- [ ] Freeze architecture (only bug-fixes and adding new features); +- [ ] Make swagger documentation as part of Sails generator; +- [ ] Add questions list where you can choose which service need to include and copy only needed; ## Version 0.5.0 (released) From c1de6e5168824e509fd73194139fa1d6a5d31768 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 20 Feb 2015 13:00:56 +0200 Subject: [PATCH 002/118] Update deps in package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 85889872..4bec1069 100644 --- a/package.json +++ b/package.json @@ -36,10 +36,10 @@ "url": "https://github.com/ghaiklor/generator-sails-rest-api.git" }, "dependencies": { - "chalk": "^0.5.0", + "chalk": "^0.5.1", "print-message": "^1.1.0", "update-notifier": "^0.3.0", - "yeoman-generator": "^0.18.0", + "yeoman-generator": "^0.18.9", "yosay": "^1.0.2" }, "devDependencies": { From d264f299d776acd0cf1486456b26c459d23182c8 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 20 Feb 2015 13:36:56 +0200 Subject: [PATCH 003/118] Cleaning up in Authors --- AUTHORS.md | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index c8f2dba2..f11122bf 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -2,20 +2,10 @@ Here we add short biography of each contributor to this project. -### Eugene Obrezkov (aka ghaiklor) +## Core developers -![Eugene Obrezkov](http://gravatar.com/avatar/be299f224394ab488001c9cab12eae2c?s=100) - -Lead developer of this project. - -JavaScript developer with experience about 4+ years. - -You can contact me via links below: - -+ [VK](http://vk.com/ghaiklor_xakep) -+ [Facebook](https://www.facebook.com/ghaiklor) -+ [Twitter](https://twitter.com/ghaiklor) -+ [GMail](mailto:ghaiklor@gmail.com) -+ [Habrahabr](http://habrahabr.ru/users/ghaiklor/) -+ [Stack Overflow](http://stackoverflow.com/users/2357633/eugene-obrezkov) -+ [GitHub](https://github.com/ghaiklor) +| Eugene Obrezkov | +|:-------------------------------------------------------------------------------------:| +| ![Eugene Obrezkov](http://gravatar.com/avatar/be299f224394ab488001c9cab12eae2c?s=100) | +| Lead developer of this project | +| Get in touch with me via [@ghaiklor](https://twitter.com/ghaiklor) | From e4772cab405189ba5a7a8080a2467f8e90e9cfc0 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 20 Feb 2015 13:39:06 +0200 Subject: [PATCH 004/118] Add message we dont have contributors to authors --- AUTHORS.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index f11122bf..d74261a2 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -1,7 +1,3 @@ -# Authors and contributors - -Here we add short biography of each contributor to this project. - ## Core developers | Eugene Obrezkov | @@ -9,3 +5,7 @@ Here we add short biography of each contributor to this project. | ![Eugene Obrezkov](http://gravatar.com/avatar/be299f224394ab488001c9cab12eae2c?s=100) | | Lead developer of this project | | Get in touch with me via [@ghaiklor](https://twitter.com/ghaiklor) | + +## Contributors + +We don't have contributors yet... From 6db20c4e950083fc9a91027f5d01e87b86d0a607 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 20 Feb 2015 13:45:12 +0200 Subject: [PATCH 005/118] Add todo in generator tests --- test/app.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/app.js b/test/app.js index 92f95185..25fc5f68 100644 --- a/test/app.js +++ b/test/app.js @@ -11,6 +11,8 @@ describe('sails-rest-api:app', function () { .on('end', done); }); + // TODO: write normal tests for generator + it('Should properly create root files', function () { assert.file([ '.editorconfig', From 011a4bedd792e1b8bd2355abde81ee90a8ef49b9 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 20 Feb 2015 13:55:34 +0200 Subject: [PATCH 006/118] Add deps-up-to-date badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c31aff18..81bbd49c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # generator-sails-rest-api -[![npm version](https://badge.fury.io/js/generator-sails-rest-api.svg)](http://badge.fury.io/js/generator-sails-rest-api) [![Build Status](https://secure.travis-ci.org/ghaiklor/generator-sails-rest-api.png?branch=master)](https://travis-ci.org/ghaiklor/generator-sails-rest-api) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ghaiklor/generator-sails-rest-api?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [Documentation](https://github.com/ghaiklor/generator-sails-rest-api/wiki) +[![npm version](https://badge.fury.io/js/generator-sails-rest-api.svg)](http://badge.fury.io/js/generator-sails-rest-api) ![Dependencies is up to date](https://david-dm.org/ghaiklor/generator-sails-rest-api.svg) [![Build Status](https://secure.travis-ci.org/ghaiklor/generator-sails-rest-api.png)](https://travis-ci.org/ghaiklor/generator-sails-rest-api) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ghaiklor/generator-sails-rest-api?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [Documentation](https://github.com/ghaiklor/generator-sails-rest-api/wiki) > Stability: 2 - Unstable From 6bd75a8a955d4e3206126ba8d67652c28670aad8 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 20 Feb 2015 13:57:51 +0200 Subject: [PATCH 007/118] Fix travis badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81bbd49c..4eeb70ed 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # generator-sails-rest-api -[![npm version](https://badge.fury.io/js/generator-sails-rest-api.svg)](http://badge.fury.io/js/generator-sails-rest-api) ![Dependencies is up to date](https://david-dm.org/ghaiklor/generator-sails-rest-api.svg) [![Build Status](https://secure.travis-ci.org/ghaiklor/generator-sails-rest-api.png)](https://travis-ci.org/ghaiklor/generator-sails-rest-api) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ghaiklor/generator-sails-rest-api?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [Documentation](https://github.com/ghaiklor/generator-sails-rest-api/wiki) +[![npm version](https://badge.fury.io/js/generator-sails-rest-api.svg)](http://badge.fury.io/js/generator-sails-rest-api) ![Dependencies is up to date](https://david-dm.org/ghaiklor/generator-sails-rest-api.svg) [![Build Status](https://travis-ci.org/ghaiklor/generator-sails-rest-api.svg?branch=master)](https://travis-ci.org/ghaiklor/generator-sails-rest-api) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ghaiklor/generator-sails-rest-api?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [Documentation](https://github.com/ghaiklor/generator-sails-rest-api/wiki) > Stability: 2 - Unstable From b9523b1f93e34406a5d3018a048a8d7567dcb357 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 21 Feb 2015 11:58:26 +0200 Subject: [PATCH 008/118] Add more questions --- app/index.js | 176 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 125 insertions(+), 51 deletions(-) diff --git a/app/index.js b/app/index.js index aecfdf48..1a6a169f 100644 --- a/app/index.js +++ b/app/index.js @@ -11,71 +11,145 @@ var crypto = require('crypto'), * @private */ var QUESTIONS_LIST = [{ - type: 'input', - name: 'project:name', - message: 'Type your project name', - default: 'sails-rest-api' + type: "input", + name: "application:name", + message: "Type your application name", + default: "sails-rest-api" }, { - type: 'list', - name: 'database:adapter', - message: 'Choose database adapter', + type: "list", + name: "database:adapter", + message: "Choose database adapter", + default: 1, choices: [ - 'MySQL', - 'Mongo', - 'PostgreSQL', - 'Redis' - ], - default: 1 + "MySQL", + "Mongo", + "PostgreSQL", + "Redis" + ] }, { - type: 'input', - name: 'database:user', - message: 'Type database username', - default: '' + type: "input", + name: "database:user", + message: "Type database username", + default: "" }, { - type: 'password', - name: 'database:password', - message: 'Type database password', - default: '' + type: "password", + name: "database:password", + message: "Type database password", + default: "" }, { - type: 'input', - name: 'database:host', - message: 'Type database host', - default: 'localhost' + type: "input", + name: "database:host", + message: "Type database host", + default: "localhost" }, { - type: 'input', - name: 'database:name', - message: 'Type database name', - default: 'sails-rest-api' + type: "input", + name: "database:name", + message: "Type database name", + default: "sails-rest-api" }, { - type: 'input', - name: 'application:app-secret-token', - message: 'Type private application token', + type: "input", + name: "application:app-secret-token", + message: "Type private application token", default: crypto.randomBytes(16).toString('hex') }, { - type: 'input', - name: 'application:jwt-secret-token', - message: 'Type private token for JSON Web Token', + type: "input", + name: "application:jwt-secret-token", + message: "Type private token for JSON Web Token", default: crypto.randomBytes(16).toString('hex') }, { - type: 'input', - name: 'application:facebook-client-id', - message: 'Type Facebook Client ID', - default: '-' + type: "input", + name: "application:facebook-client-id", + message: "Type Facebook Client ID", + default: "-" }, { - type: 'input', - name: 'application:facebook-client-secret', - message: 'Type Facebook Client Secret', - default: '-' + type: "input", + name: "application:facebook-client-secret", + message: "Type Facebook Client Secret", + default: "-" }, { - type: 'input', - name: 'application:twitter-consumer-key', - message: 'Type Twitter Consumer Key', - default: '-' + type: "input", + name: "application:twitter-consumer-key", + message: "Type Twitter Consumer Key", + default: "-" }, { - type: 'input', - name: 'application:twitter-consumer-secret', - message: 'Type Twitter Consumer Secret', - default: '-' + type: "input", + name: "application:twitter-consumer-secret", + message: "Type Twitter Consumer Secret", + default: "-" +}, { + type: "checkbox", + name: "services:cipher", + message: "Choose which Cipher services you want to include", + default: ["bcrypt", "jwt"], + choices: [ + "bcrypt", + "jwt" + ] +}, { + type: "checkbox", + name: "services:mailer", + message: "Choose which Mailer services you want to include", + default: [], + choices: [ + "Mandrill" + ] +}, { + type: "checkbox", + name: "services:payment", + message: "Choose which Payment services you want to include", + default: [], + choices: [ + "Stripe" + ] +}, { + type: "checkbox", + name: "services:pusher", + message: "Choose which Pusher services you want to include", + default: ["Apple Push Notification", "Google Cloud Messaging"], + choices: [ + "Apple Push Notification", + "Google Cloud Messaging" + ] +}, { + type: "checkbox", + name: "services:sms", + message: "Choose which SMS services you want to include", + default: [], + choices: [ + "Twilio" + ] +}, { + type: "checkbox", + name: "services:social", + message: "Choose which Social services you want to include", + default: [], + choices: [ + "Facebook" + ] +}, { + type: "checkbox", + name: "services:storage", + message: "Choose which Storage services you want to include", + default: [], + choices: [ + "Amazon S3", + "Google Cloud Storage" + ] +}, { + type: "confirm", + name: "application:include-doc", + message: "Include Swagger documentation to project?", + default: true +}, { + type: "confirm", + name: "application:include-tests", + message: "Include tests to project?", + default: true +}, { + type: "confirm", + name: "application:include-tools", + message: "Include diagnostic tools to project?", + default: true }]; module.exports = yeoman.generators.Base.extend({ From 93e19df0939f839f6e22f061cf31767457bf64e1 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 23 Feb 2015 18:17:33 +0200 Subject: [PATCH 009/118] Last fixes in questions list --- app/index.js | 80 +++++++++---------- .../policies/{isOurApp.js => isAllowed.js} | 4 +- .../api/services/cipher/JwtCipher.js | 2 +- app/templates/config/passport.js | 2 +- app/templates/package.json | 2 +- 5 files changed, 45 insertions(+), 45 deletions(-) rename app/templates/api/policies/{isOurApp.js => isAllowed.js} (76%) diff --git a/app/index.js b/app/index.js index 1a6a169f..882c2cee 100644 --- a/app/index.js +++ b/app/index.js @@ -11,11 +11,6 @@ var crypto = require('crypto'), * @private */ var QUESTIONS_LIST = [{ - type: "input", - name: "application:name", - message: "Type your application name", - default: "sails-rest-api" -}, { type: "list", name: "database:adapter", message: "Choose database adapter", @@ -26,60 +21,65 @@ var QUESTIONS_LIST = [{ "PostgreSQL", "Redis" ] +}, { + type: "input", + name: "database:host", + message: "Type your database host", + default: "localhost" +}, { + type: "input", + name: "database:name", + message: "Type your database name", + default: "sails-rest-api" }, { type: "input", name: "database:user", - message: "Type database username", + message: "Type your database username", default: "" }, { type: "password", name: "database:password", - message: "Type database password", + message: "Type your database password", default: "" }, { type: "input", - name: "database:host", - message: "Type database host", - default: "localhost" -}, { - type: "input", - name: "database:name", - message: "Type database name", + name: "application:name", + message: "Type your application name", default: "sails-rest-api" }, { type: "input", - name: "application:app-secret-token", - message: "Type private application token", - default: crypto.randomBytes(16).toString('hex') + name: "application:api-secret-key", + message: "Type your private API key", + default: crypto.randomBytes(32).toString("hex") }, { type: "input", - name: "application:jwt-secret-token", - message: "Type private token for JSON Web Token", - default: crypto.randomBytes(16).toString('hex') + name: "application:jwt-secret", + message: "Type your private key for JSON Web Token", + default: crypto.randomBytes(32).toString("hex") }, { type: "input", - name: "application:facebook-client-id", - message: "Type Facebook Client ID", + name: "application:facebook-app-id", + message: "Type your Facebook App ID", default: "-" }, { type: "input", - name: "application:facebook-client-secret", - message: "Type Facebook Client Secret", + name: "application:facebook-app-secret", + message: "Type your Facebook App Secret", default: "-" }, { type: "input", name: "application:twitter-consumer-key", - message: "Type Twitter Consumer Key", + message: "Type your Twitter Consumer Key", default: "-" }, { type: "input", name: "application:twitter-consumer-secret", - message: "Type Twitter Consumer Secret", + message: "Type your Twitter Consumer Secret", default: "-" }, { type: "checkbox", name: "services:cipher", - message: "Choose which Cipher services you want to include", + message: "Choose which Cipher services you want", default: ["bcrypt", "jwt"], choices: [ "bcrypt", @@ -88,7 +88,7 @@ var QUESTIONS_LIST = [{ }, { type: "checkbox", name: "services:mailer", - message: "Choose which Mailer services you want to include", + message: "Choose which Mailer services you want", default: [], choices: [ "Mandrill" @@ -96,7 +96,7 @@ var QUESTIONS_LIST = [{ }, { type: "checkbox", name: "services:payment", - message: "Choose which Payment services you want to include", + message: "Choose which Payment services you want", default: [], choices: [ "Stripe" @@ -104,8 +104,8 @@ var QUESTIONS_LIST = [{ }, { type: "checkbox", name: "services:pusher", - message: "Choose which Pusher services you want to include", - default: ["Apple Push Notification", "Google Cloud Messaging"], + message: "Choose which Pusher services you want", + default: [], choices: [ "Apple Push Notification", "Google Cloud Messaging" @@ -113,7 +113,7 @@ var QUESTIONS_LIST = [{ }, { type: "checkbox", name: "services:sms", - message: "Choose which SMS services you want to include", + message: "Choose which SMS services you want", default: [], choices: [ "Twilio" @@ -121,7 +121,7 @@ var QUESTIONS_LIST = [{ }, { type: "checkbox", name: "services:social", - message: "Choose which Social services you want to include", + message: "Choose which Social services you want", default: [], choices: [ "Facebook" @@ -129,7 +129,7 @@ var QUESTIONS_LIST = [{ }, { type: "checkbox", name: "services:storage", - message: "Choose which Storage services you want to include", + message: "Choose which Storage services you want", default: [], choices: [ "Amazon S3", @@ -137,18 +137,18 @@ var QUESTIONS_LIST = [{ ] }, { type: "confirm", - name: "application:include-doc", - message: "Include Swagger documentation to project?", + name: "docs:include", + message: "Is Swagger documentation needed for project?", default: true }, { type: "confirm", - name: "application:include-tests", - message: "Include tests to project?", + name: "tests:include", + message: "Is Mocha tests needed for project?", default: true }, { type: "confirm", - name: "application:include-tools", - message: "Include diagnostic tools to project?", + name: "tools:include", + message: "Is diagnostic tools needed for project?", default: true }]; diff --git a/app/templates/api/policies/isOurApp.js b/app/templates/api/policies/isAllowed.js similarity index 76% rename from app/templates/api/policies/isOurApp.js rename to app/templates/api/policies/isAllowed.js index fcd64c22..103f2b55 100644 --- a/app/templates/api/policies/isOurApp.js +++ b/app/templates/api/policies/isAllowed.js @@ -1,12 +1,12 @@ /** - * isOurApp + * isAllowed * @description :: Policy to check if this request goes from our applications */ module.exports = function (req, res, next) { var token = req.headers["application-token"]; - if (token && token === "<%= answers['application:app-secret-token'] %>") { + if (token && token === "<%= answers['application:api-secret-key'] %>") { next(); } else { res.unauthorized(null, null, "You must provide application token"); diff --git a/app/templates/api/services/cipher/JwtCipher.js b/app/templates/api/services/cipher/JwtCipher.js index a74ff95c..96521719 100644 --- a/app/templates/api/services/cipher/JwtCipher.js +++ b/app/templates/api/services/cipher/JwtCipher.js @@ -8,7 +8,7 @@ var util = require('util'), * @type {String} * @private */ -var SECRET_KEY = "<%= answers['application:jwt-secret-token'] %>"; +var SECRET_KEY = "<%= answers['application:jwt-secret'] %>"; /** * Algorithm that using for signing JWT diff --git a/app/templates/config/passport.js b/app/templates/config/passport.js index f02df78f..804cf3a3 100644 --- a/app/templates/config/passport.js +++ b/app/templates/config/passport.js @@ -45,7 +45,7 @@ passport.use(new LocalStrategy({ }); })); -passport.use(new JwtStrategy("<%= answers['application:jwt-secret-token'] %>", { +passport.use(new JwtStrategy("<%= answers['application:jwt-secret'] %>", { tokenBodyField: 'jwt-token', tokenHeader: 'JWT' }, function (payload, next) { diff --git a/app/templates/package.json b/app/templates/package.json index 84df42ee..e7aa6323 100644 --- a/app/templates/package.json +++ b/app/templates/package.json @@ -1,5 +1,5 @@ { - "name": "<%= answers['project:name'] %>", + "name": "<%= answers['application:name'] %>", "private": true, "version": "0.1.0", "main": "app.js", From 9c1d5a949015cbe5e5e29536e7d2ae0c44a6ac55 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 23 Feb 2015 18:35:50 +0200 Subject: [PATCH 010/118] Fix rendering passport' --- app/templates/config/passport.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/templates/config/passport.js b/app/templates/config/passport.js index 804cf3a3..544478a8 100644 --- a/app/templates/config/passport.js +++ b/app/templates/config/passport.js @@ -70,8 +70,8 @@ passport.use(new JwtStrategy("<%= answers['application:jwt-secret'] %>", { })); passport.use(new FacebookTokenStrategy({ - clientID: "<%= answers['application:facebook-client-id'] %>", - clientSecret: "<%= answers['application:facebook-client-secret'] %>", + clientID: "<%= answers['application:facebook-app-id'] %>", + clientSecret: "<%= answers['application:facebook-app-secret'] %>", passReqToCallback: true }, function (req, accessToken, refreshToken, profile, next) { if (!req.user) { From 073d2226c0dd2584be31fc86cb0f5dee79409c6f Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 23 Feb 2015 18:36:27 +0200 Subject: [PATCH 011/118] Fix policies list --- app/templates/config/policies.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/templates/config/policies.js b/app/templates/config/policies.js index 6500e82e..d1189d80 100644 --- a/app/templates/config/policies.js +++ b/app/templates/config/policies.js @@ -10,9 +10,9 @@ */ module.exports.policies = { - '*': ['isOurApp', 'isAuthenticated'], + '*': ['isAllowed', 'isAuthenticated'], AuthController: { - '*': 'isOurApp' + '*': 'isAllowed' } }; From 91c045f33b0306532475527907ef16c6c2c2b0cf Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 23 Feb 2015 18:37:23 +0200 Subject: [PATCH 012/118] Fix rendering doc --- app/templates/doc/api.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/templates/doc/api.json b/app/templates/doc/api.json index 33a4c65d..a5da31b6 100644 --- a/app/templates/doc/api.json +++ b/app/templates/doc/api.json @@ -1,11 +1,11 @@ { "swagger": "2.0", "info": { - "title": "<%= answers['project:name'] %>", - "description": "Move your app forward with the <%= answers['project:name'] %> API", + "title": "<%= answers['application:name'] %>", + "description": "Move your app forward with the <%= answers['application:name'] %> API", "version": "1.0.0" }, - "host": "api.<%= answers['project:name'] %>.com", + "host": "api.<%= answers['application:name'] %>.com", "schemes": [ "https" ], From 799c3d4ad977f3328c2d5cf1b077619903eae719 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 23 Feb 2015 18:38:25 +0200 Subject: [PATCH 013/118] Fix test for policy --- app/templates/test/policies/{isOurApp.js => isAllowed.js} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename app/templates/test/policies/{isOurApp.js => isAllowed.js} (52%) diff --git a/app/templates/test/policies/isOurApp.js b/app/templates/test/policies/isAllowed.js similarity index 52% rename from app/templates/test/policies/isOurApp.js rename to app/templates/test/policies/isAllowed.js index 2a7f5cf6..98cfab90 100644 --- a/app/templates/test/policies/isOurApp.js +++ b/app/templates/test/policies/isAllowed.js @@ -1,7 +1,7 @@ var assert = require('assert'), - isOurApp = require('../../api/policies/isOurApp'); + isAllowed = require('../../api/policies/isAllowed'); -describe("policies:isOurApp", function () { +describe("policies:isAllowed", function () { it("TODO: write this test", function () { assert(true); }); From d28801668c89f927e8f28a1566ad194c1a224353 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 23 Feb 2015 19:43:08 +0200 Subject: [PATCH 014/118] Add gitkeep files to test folder --- app/templates/test/adapters/.gitkeep | 0 app/templates/test/blueprints/.gitkeep | 0 app/templates/test/controllers/.gitkeep | 0 app/templates/test/hooks/.gitkeep | 0 app/templates/test/models/.gitkeep | 0 app/templates/test/policies/.gitkeep | 0 app/templates/test/responses/.gitkeep | 0 app/templates/test/services/.gitkeep | 0 8 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/templates/test/adapters/.gitkeep create mode 100644 app/templates/test/blueprints/.gitkeep create mode 100644 app/templates/test/controllers/.gitkeep create mode 100644 app/templates/test/hooks/.gitkeep create mode 100644 app/templates/test/models/.gitkeep create mode 100644 app/templates/test/policies/.gitkeep create mode 100644 app/templates/test/responses/.gitkeep create mode 100644 app/templates/test/services/.gitkeep diff --git a/app/templates/test/adapters/.gitkeep b/app/templates/test/adapters/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/app/templates/test/blueprints/.gitkeep b/app/templates/test/blueprints/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/app/templates/test/controllers/.gitkeep b/app/templates/test/controllers/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/app/templates/test/hooks/.gitkeep b/app/templates/test/hooks/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/app/templates/test/models/.gitkeep b/app/templates/test/models/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/app/templates/test/policies/.gitkeep b/app/templates/test/policies/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/app/templates/test/responses/.gitkeep b/app/templates/test/responses/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/app/templates/test/services/.gitkeep b/app/templates/test/services/.gitkeep new file mode 100644 index 00000000..e69de29b From d35a63a0315367ad33527a82173158e7c850ff5d Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 23 Feb 2015 19:44:01 +0200 Subject: [PATCH 015/118] Update chalk version --- app/templates/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/package.json b/app/templates/package.json index e7aa6323..b7407064 100644 --- a/app/templates/package.json +++ b/app/templates/package.json @@ -5,7 +5,7 @@ "main": "app.js", "dependencies": {}, "devDependencies": { - "chalk": "^0.5.1", + "chalk": "^1.0.0", "dependency-check": "^2.2.2", "mocha": "^2.1.0", "npm-check": "^3.2.7", From 3549ed0243ee2175bf997bb9c9ff2eb1da5121ea Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 23 Feb 2015 19:48:38 +0200 Subject: [PATCH 016/118] Update roadmap --- ROADMAP.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index ccb192ba..c435f052 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -2,9 +2,12 @@ ## Faraway -- [ ] Add **apn** and **gcm** push notifications; -- [ ] Add social service **Twitter**; -- [ ] Add support for **Amazon** mailer, **sendmail** mailer; +- [ ] Add `md5`, `crc` Ciphers; +- [ ] Add `sendmail`, `Amazon` Mailer; +- [ ] Add `braintreepayments`, `PayPal` Payment; +- [ ] Add `Windows Phone` Pusher; +- [ ] Add `Twitter`, `VK`, `Google +` Social; +- [ ] Add `Local` Storage; - [ ] Test coverage for all `api` files; ## Next minor version From d0515524fce2c689a55227b7deb3ce994735a86d Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 23 Feb 2015 19:49:24 +0200 Subject: [PATCH 017/118] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f44427e8..d3b56e50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Edge version +- Improvement: Cleaning up in questions; + ## Version 0.5.1 - Hotfix: Bug when with `skip-all` generator is freeze up; From 63c3f89ebcc3328cf689dacbf849b81dd885c9fc Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Tue, 24 Feb 2015 15:04:21 +0200 Subject: [PATCH 018/118] Add get started to readme --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 4eeb70ed..eaa70d42 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,34 @@ Yeoman generator that provides already configured and optimized Sails REST API w - Integrated Swagger doc specification in `doc` folder; - Integrated Mocha tests for all `blueprints`, `controllers`, `models`, `policies`, `responses` and `services`. After generating you can execute `npm test`; +## Getting Started + +Start using generator is very simple. + +First of all, you need install **yeoman** and **generator-sails-rest-api**: + +```bash +npm install -g yo generator-sails-rest-api +``` + +Then create project directory and initiate the generator under the project directory: + +```bash +mkdir my-project +cd my-project +yo sails-rest-api +``` + +You will be prompted for questions. Answer to those questions that generator is asks and you will get configured Sails project. + +After scaffolding the project you can use this project as before. Just run the `app.js` file and all. + +```bash +node app.js +``` + +Congratulations, you just have setup your first Sails REST API :+1: + ## ready-2-use services | Service Name | Implemented providers | From 206eecf3f21ada1a8bef80b7865794a1941500af Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Tue, 24 Feb 2015 15:05:36 +0200 Subject: [PATCH 019/118] Update chalk in package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4bec1069..db3ddd73 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "url": "https://github.com/ghaiklor/generator-sails-rest-api.git" }, "dependencies": { - "chalk": "^0.5.1", + "chalk": "^1.0.0", "print-message": "^1.1.0", "update-notifier": "^0.3.0", "yeoman-generator": "^0.18.9", From 6b32dff37bf5d40b7ad7b173b7a214cf54faca34 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Tue, 24 Feb 2015 15:40:49 +0200 Subject: [PATCH 020/118] Add separators with notification to questions --- app/index.js | 92 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 32 deletions(-) diff --git a/app/index.js b/app/index.js index 882c2cee..3d9df748 100644 --- a/app/index.js +++ b/app/index.js @@ -3,7 +3,8 @@ var crypto = require('crypto'), printMessage = require('print-message'), updateNotifier = require('update-notifier'), yeoman = require('yeoman-generator'), - yosay = require('yosay'); + yosay = require('yosay'), + inquirer = require('yo/node_modules/inquirer'); /** * List of questions @@ -80,61 +81,88 @@ var QUESTIONS_LIST = [{ type: "checkbox", name: "services:cipher", message: "Choose which Cipher services you want", - default: ["bcrypt", "jwt"], - choices: [ - "bcrypt", - "jwt" - ] + choices: [{ + name: "bcrypt", + checked: true + }, { + name: "jwt", + checked: true + }, new inquirer.Separator(), { + name: "More Cipher is coming", + disabled: "Wait for it..." + }] }, { type: "checkbox", name: "services:mailer", message: "Choose which Mailer services you want", - default: [], - choices: [ - "Mandrill" - ] + choices: [{ + name: "Mandrill", + checked: false + }, new inquirer.Separator(), { + name: "More Mailer is coming", + disabled: "Wait for it..." + }] }, { type: "checkbox", name: "services:payment", message: "Choose which Payment services you want", - default: [], - choices: [ - "Stripe" - ] + choices: [{ + name: "Stripe", + checked: false + }, new inquirer.Separator(), { + name: "More Payment is coming", + disabled: "Wait for it..." + }] }, { type: "checkbox", name: "services:pusher", message: "Choose which Pusher services you want", - default: [], - choices: [ - "Apple Push Notification", - "Google Cloud Messaging" - ] + choices: [{ + name: "Apple Push Notification", + checked: false + }, { + name: "Google Cloud Messaging", + checked: false + }, new inquirer.Separator(), { + name: "More Pusher is coming", + disabled: "Wait for it..." + }] }, { type: "checkbox", name: "services:sms", message: "Choose which SMS services you want", - default: [], - choices: [ - "Twilio" - ] + choices: [{ + name: "Twilio", + checked: false + }, new inquirer.Separator(), { + name: "More SMS is coming", + disabled: "Wait for it..." + }] }, { type: "checkbox", name: "services:social", message: "Choose which Social services you want", - default: [], - choices: [ - "Facebook" - ] + choices: [{ + name: "Facebook", + checked: false + }, new inquirer.Separator(), { + name: "More Social is coming", + disabled: "Wait for it..." + }] }, { type: "checkbox", name: "services:storage", message: "Choose which Storage services you want", - default: [], - choices: [ - "Amazon S3", - "Google Cloud Storage" - ] + choices: [{ + name: "Amazon S3", + checked: false + }, { + name: "Google Cloud Storage", + checked: false + }, new inquirer.Separator(), { + name: "More Storage is coming", + disabled: "Wait for it..." + }] }, { type: "confirm", name: "docs:include", From 9584e28f05e237d06bade48ca01c955898bc17c0 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Tue, 24 Feb 2015 16:55:16 +0200 Subject: [PATCH 021/118] Add comments to yeoman flow --- app/index.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/app/index.js b/app/index.js index 3d9df748..b1a1c4ec 100644 --- a/app/index.js +++ b/app/index.js @@ -232,10 +232,16 @@ module.exports = yeoman.generators.Base.extend({ * @type {Object} */ initializing: { + /** + * Load package.json + */ loadPackageInfo: function () { this.pkg = require('../package.json'); }, + /** + * Notify about updates of generator-sails-rest-api + */ notifyAboutGeneratorUpdate: function () { if (!(this.options['skip-generator-update'] || this.options['skip-all'])) { var done = this.async(); @@ -265,6 +271,9 @@ module.exports = yeoman.generators.Base.extend({ } }, + /** + * Say yeoman hello + */ sayHello: function () { if (!(this.options["skip-generator-welcome"] || this.options["skip-all"])) { this.log(yosay('Welcome to the laudable ' + chalk.red('Sails REST API') + ' generator!')); @@ -277,9 +286,14 @@ module.exports = yeoman.generators.Base.extend({ * Where you prompt users for options (where you'd call this.prompt()) */ prompting: { + /** + * Ask base questions + */ askBaseQuestions: function () { var done = this.async(); + // TODO: split into separate functions + this.prompt(QUESTIONS_LIST, function (answers) { this.answers = answers; done(); @@ -303,7 +317,11 @@ module.exports = yeoman.generators.Base.extend({ * Where you write the generator specific files (routes, controllers, etc) */ writing: { + /** + * Copy template directory to source root + */ copyDirectory: function () { + // TODO: split into separate functions this.directory( this.sourceRoot(), this.destinationRoot() @@ -322,7 +340,10 @@ module.exports = yeoman.generators.Base.extend({ * Where installation are run (npm, bower) */ install: { - installNpmDeps: function () { + /** + * Install npm dependencies + */ + installNpmDependencies: function () { if (!(this.options['skip-project-install'] || this.options["skip-all"])) { this.log(chalk.yellow("\nStart installing npm dependencies, please wait...\n")); this.npmInstall(); @@ -335,6 +356,9 @@ module.exports = yeoman.generators.Base.extend({ * Called last, cleanup, say good bye, etc */ end: { + /** + * Run diagnostic tools + */ runDiagnostic: function () { if (!(this.options["skip-project-diagnostic"] || this.options["skip-all"])) { var done = this.async(); @@ -347,6 +371,9 @@ module.exports = yeoman.generators.Base.extend({ } }, + /** + * Say warning that this generator is under development + */ sayUnderDevelopmentWarning: function () { printMessage([ "This generator under heavy development", @@ -361,6 +388,9 @@ module.exports = yeoman.generators.Base.extend({ }); }, + /** + * Warn user if he skip installing dependencies + */ sayNotInstalledNpmDepsWarning: function () { if (this.options['skip-project-install'] || this.options["skip-all"]) { printMessage([ From f6db86c6611965f307d4bca3196fe30dedb1b82e Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Tue, 24 Feb 2015 17:22:44 +0200 Subject: [PATCH 022/118] Split prompting to sections --- app/index.js | 104 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 11 deletions(-) diff --git a/app/index.js b/app/index.js index b1a1c4ec..8af8565c 100644 --- a/app/index.js +++ b/app/index.js @@ -7,11 +7,11 @@ var crypto = require('crypto'), inquirer = require('yo/node_modules/inquirer'); /** - * List of questions + * Questions for database section * @type {Array} * @private */ -var QUESTIONS_LIST = [{ +var DATABASE_QUESTIONS = [{ type: "list", name: "database:adapter", message: "Choose database adapter", @@ -42,7 +42,14 @@ var QUESTIONS_LIST = [{ name: "database:password", message: "Type your database password", default: "" -}, { +}]; + +/** + * Questions for application section + * @type {Array} + * @private + */ +var APPLICATION_QUESTIONS = [{ type: "input", name: "application:name", message: "Type your application name", @@ -77,7 +84,14 @@ var QUESTIONS_LIST = [{ name: "application:twitter-consumer-secret", message: "Type your Twitter Consumer Secret", default: "-" -}, { +}]; + +/** + * Questions for services section + * @type {Array} + * @private + */ +var SERVICES_QUESTIONS = [{ type: "checkbox", name: "services:cipher", message: "Choose which Cipher services you want", @@ -163,7 +177,14 @@ var QUESTIONS_LIST = [{ name: "More Storage is coming", disabled: "Wait for it..." }] -}, { +}]; + +/** + * Questions for miscellaneous section + * @type {Array} + * @private + */ +var MISCELLANEOUS_QUESTIONS = [{ type: "confirm", name: "docs:include", message: "Is Swagger documentation needed for project?", @@ -180,6 +201,25 @@ var QUESTIONS_LIST = [{ default: true }]; +/** + * Extend target object with source object + * @param {Object} _target Target object + * @param {Object} _source Source object + * @returns {Object} + * @private + */ +function _extend(_target, _source) { + var target = _target || {}, + source = _source || {}, + keys = Object.keys(source); + + for (var i = 0; i < keys.length; i++) { + target[keys[i]] = source[keys[i]]; + } + + return target; +} + module.exports = yeoman.generators.Base.extend({ /** * Special methods may do things like set up important state controls and may not function outside of the constructor @@ -287,17 +327,59 @@ module.exports = yeoman.generators.Base.extend({ */ prompting: { /** - * Ask base questions + * Ask database questions */ - askBaseQuestions: function () { + askDatabaseQuestions: function () { var done = this.async(); - // TODO: split into separate functions + this.log(chalk.yellow("\nDatabase questions:")); - this.prompt(QUESTIONS_LIST, function (answers) { - this.answers = answers; + this.prompt(DATABASE_QUESTIONS, function (answers) { + this.answers = _extend(this.answers, answers); done(); - }.bind(this)); + }); + }, + + /** + * Ask application questions + */ + askApplicationQuestions: function () { + var done = this.async(); + + this.log(chalk.yellow("\nApplication questions:")); + + this.prompt(APPLICATION_QUESTIONS, function (answers) { + this.answers = _extend(this.answers, answers); + done(); + }); + }, + + /** + * Ask services questions + */ + askServiceQuestions: function () { + var done = this.async(); + + this.log(chalk.yellow("\nService questions:")); + + this.prompt(SERVICES_QUESTIONS, function (answers) { + this.answers = _extend(this.answers, answers); + done(); + }); + }, + + /** + * Ask miscellaneous questions + */ + askMiscellaneousSections: function () { + var done = this.async(); + + this.log(chalk.yellow("\nMiscellaneous questions:")); + + this.prompt(MISCELLANEOUS_QUESTIONS, function (answers) { + this.answers = _extend(this.answers, answers); + done(); + }); } }, From 36a8274e6f8dd433802abe76adc0decd9a7eb083 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Tue, 24 Feb 2015 17:25:23 +0200 Subject: [PATCH 023/118] Remove new lines from log --- app/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/index.js b/app/index.js index 8af8565c..6ee1571e 100644 --- a/app/index.js +++ b/app/index.js @@ -427,7 +427,7 @@ module.exports = yeoman.generators.Base.extend({ */ installNpmDependencies: function () { if (!(this.options['skip-project-install'] || this.options["skip-all"])) { - this.log(chalk.yellow("\nStart installing npm dependencies, please wait...\n")); + this.log(chalk.yellow("Start installing npm dependencies, please wait...")); this.npmInstall(); } } @@ -445,7 +445,7 @@ module.exports = yeoman.generators.Base.extend({ if (!(this.options["skip-project-diagnostic"] || this.options["skip-all"])) { var done = this.async(); - this.log(chalk.yellow("\nStarting diagnostic, please wait...\n")); + this.log(chalk.yellow("Starting diagnostic, please wait...")); this.spawnCommand('node', ['tools/fix-deps.js']).on('close', function () { this.spawnCommand('node', ['tools/update-deps.js']).on('close', done); From fa3da507bf61943c68325c804addc1b28157da55 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 25 Feb 2015 18:05:32 +0200 Subject: [PATCH 024/118] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3b56e50..e40475d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Edge version -- Improvement: Cleaning up in questions; +- Improvement: Cleaning up in questions and split out them to sections; ## Version 0.5.1 From 38d3ad3a3bd18c1d0fc454e734f71bb93fda4774 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 25 Feb 2015 18:09:29 +0200 Subject: [PATCH 025/118] Update roadmap and changelog --- CHANGELOG.md | 1 + ROADMAP.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e40475d7..c4b34fff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Edge version +- Improvement: Frozen structure of generator and project. Any serious changes in project structure; - Improvement: Cleaning up in questions and split out them to sections; ## Version 0.5.1 diff --git a/ROADMAP.md b/ROADMAP.md index c435f052..b0fe687d 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -12,8 +12,8 @@ ## Next minor version +- [x] Freeze architecture (only bug-fixes and adding new features); - [ ] Improve stability (too much new features is appears in previous version); -- [ ] Freeze architecture (only bug-fixes and adding new features); - [ ] Make swagger documentation as part of Sails generator; - [ ] Add questions list where you can choose which service need to include and copy only needed; From a192b4c4057e30bd3516b47dd3478222fe05d90f Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 17:50:41 +0200 Subject: [PATCH 026/118] Move from app folder to generators folderg --- {app => generators/app}/index.js | 0 {app => generators/app}/templates/.editorconfig | 0 {app => generators/app}/templates/.gitignore | 0 {app => generators/app}/templates/.sailsrc | 0 {app => generators/app}/templates/api/adapters/.gitkeep | 0 {app => generators/app}/templates/api/blueprints/.gitkeep | 0 {app => generators/app}/templates/api/blueprints/add.js | 0 {app => generators/app}/templates/api/blueprints/create.js | 0 {app => generators/app}/templates/api/blueprints/destroy.js | 0 {app => generators/app}/templates/api/blueprints/find.js | 0 {app => generators/app}/templates/api/blueprints/findOne.js | 0 {app => generators/app}/templates/api/blueprints/populate.js | 0 {app => generators/app}/templates/api/blueprints/remove.js | 0 {app => generators/app}/templates/api/blueprints/update.js | 0 {app => generators/app}/templates/api/controllers/.gitkeep | 0 .../app}/templates/api/controllers/AuthController.js | 0 .../app}/templates/api/controllers/UserController.js | 0 {app => generators/app}/templates/api/hooks/.gitkeep | 0 {app => generators/app}/templates/api/models/.gitkeep | 0 {app => generators/app}/templates/api/models/User.js | 0 {app => generators/app}/templates/api/policies/.gitkeep | 0 {app => generators/app}/templates/api/policies/isAllowed.js | 0 {app => generators/app}/templates/api/policies/isAuthenticated.js | 0 {app => generators/app}/templates/api/responses/.gitkeep | 0 {app => generators/app}/templates/api/responses/badRequest.js | 0 {app => generators/app}/templates/api/responses/created.js | 0 {app => generators/app}/templates/api/responses/forbidden.js | 0 {app => generators/app}/templates/api/responses/notFound.js | 0 {app => generators/app}/templates/api/responses/ok.js | 0 {app => generators/app}/templates/api/responses/serverError.js | 0 {app => generators/app}/templates/api/responses/unauthorized.js | 0 {app => generators/app}/templates/api/services/.gitkeep | 0 {app => generators/app}/templates/api/services/CipherService.js | 0 {app => generators/app}/templates/api/services/MailerService.js | 0 {app => generators/app}/templates/api/services/PaymentService.js | 0 {app => generators/app}/templates/api/services/PusherService.js | 0 {app => generators/app}/templates/api/services/SmsService.js | 0 {app => generators/app}/templates/api/services/SocialService.js | 0 {app => generators/app}/templates/api/services/StorageService.js | 0 .../app}/templates/api/services/cipher/BCryptCipher.js | 0 .../app}/templates/api/services/cipher/BaseCipher.js | 0 .../app}/templates/api/services/cipher/CipherFactory.js | 0 .../app}/templates/api/services/cipher/JwtCipher.js | 0 .../app}/templates/api/services/mailer/BaseMailer.js | 0 .../app}/templates/api/services/mailer/MailerFactory.js | 0 .../app}/templates/api/services/mailer/MandrillMailer.js | 0 .../app}/templates/api/services/payment/PaymentFactory.js | 0 .../app}/templates/api/services/payment/StripePayment.js | 0 .../app}/templates/api/services/pusher/APNPushNotification.js | 0 .../app}/templates/api/services/pusher/BasePushNotification.js | 0 .../app}/templates/api/services/pusher/GCMPushNotification.js | 0 .../app}/templates/api/services/pusher/PusherFactory.js | 0 {app => generators/app}/templates/api/services/sms/BaseSms.js | 0 {app => generators/app}/templates/api/services/sms/SmsFactory.js | 0 {app => generators/app}/templates/api/services/sms/TwilioSms.js | 0 .../app}/templates/api/services/social/FacebookSocial.js | 0 .../app}/templates/api/services/social/SocialFactory.js | 0 .../app}/templates/api/services/storage/AmazonStorage.js | 0 .../app}/templates/api/services/storage/BaseStorage.js | 0 .../app}/templates/api/services/storage/GCloudStorage.js | 0 .../app}/templates/api/services/storage/StorageFactory.js | 0 {app => generators/app}/templates/app.js | 0 {app => generators/app}/templates/config/blueprints.js | 0 {app => generators/app}/templates/config/bootstrap.js | 0 {app => generators/app}/templates/config/connections.js | 0 {app => generators/app}/templates/config/env/development.js | 0 {app => generators/app}/templates/config/env/production.js | 0 {app => generators/app}/templates/config/globals.js | 0 {app => generators/app}/templates/config/http.js | 0 {app => generators/app}/templates/config/log.js | 0 {app => generators/app}/templates/config/models.js | 0 {app => generators/app}/templates/config/passport.js | 0 {app => generators/app}/templates/config/policies.js | 0 {app => generators/app}/templates/config/routes.js | 0 {app => generators/app}/templates/doc/api.json | 0 {app => generators/app}/templates/package.json | 0 {app => generators/app}/templates/test/adapters/.gitkeep | 0 {app => generators/app}/templates/test/blueprints/.gitkeep | 0 {app => generators/app}/templates/test/blueprints/add.js | 0 {app => generators/app}/templates/test/blueprints/create.js | 0 {app => generators/app}/templates/test/blueprints/destroy.js | 0 {app => generators/app}/templates/test/blueprints/find.js | 0 {app => generators/app}/templates/test/blueprints/findOne.js | 0 {app => generators/app}/templates/test/blueprints/populate.js | 0 {app => generators/app}/templates/test/blueprints/remove.js | 0 {app => generators/app}/templates/test/blueprints/update.js | 0 {app => generators/app}/templates/test/controllers/.gitkeep | 0 .../app}/templates/test/controllers/AuthController.js | 0 .../app}/templates/test/controllers/UserController.js | 0 {app => generators/app}/templates/test/hooks/.gitkeep | 0 {app => generators/app}/templates/test/models/.gitkeep | 0 {app => generators/app}/templates/test/models/User.js | 0 {app => generators/app}/templates/test/policies/.gitkeep | 0 {app => generators/app}/templates/test/policies/isAllowed.js | 0 .../app}/templates/test/policies/isAuthenticated.js | 0 {app => generators/app}/templates/test/responses/.gitkeep | 0 {app => generators/app}/templates/test/responses/badRequest.js | 0 {app => generators/app}/templates/test/responses/created.js | 0 {app => generators/app}/templates/test/responses/forbidden.js | 0 {app => generators/app}/templates/test/responses/notFound.js | 0 {app => generators/app}/templates/test/responses/ok.js | 0 {app => generators/app}/templates/test/responses/serverError.js | 0 {app => generators/app}/templates/test/responses/unauthorized.js | 0 {app => generators/app}/templates/test/services/.gitkeep | 0 {app => generators/app}/templates/test/services/CipherService.js | 0 {app => generators/app}/templates/test/services/MailerService.js | 0 {app => generators/app}/templates/test/services/PaymentService.js | 0 {app => generators/app}/templates/test/services/PusherService.js | 0 {app => generators/app}/templates/test/services/SmsService.js | 0 {app => generators/app}/templates/test/services/SocialService.js | 0 {app => generators/app}/templates/test/services/StorageService.js | 0 .../app}/templates/test/services/cipher/BCryptCipher.js | 0 .../app}/templates/test/services/cipher/BaseCipher.js | 0 .../app}/templates/test/services/cipher/CipherFactory.js | 0 .../app}/templates/test/services/cipher/JwtCipher.js | 0 .../app}/templates/test/services/mailer/BaseMailer.js | 0 .../app}/templates/test/services/mailer/MailerFactory.js | 0 .../app}/templates/test/services/mailer/MandrillMailer.js | 0 .../app}/templates/test/services/payment/PaymentFactory.js | 0 .../app}/templates/test/services/payment/StripePayment.js | 0 .../app}/templates/test/services/pusher/APNPushNotification.js | 0 .../app}/templates/test/services/pusher/BasePushNotification.js | 0 .../app}/templates/test/services/pusher/GCMPushNotification.js | 0 .../app}/templates/test/services/pusher/PusherFactory.js | 0 {app => generators/app}/templates/test/services/sms/BaseSms.js | 0 {app => generators/app}/templates/test/services/sms/SmsFactory.js | 0 {app => generators/app}/templates/test/services/sms/TwilioSms.js | 0 .../app}/templates/test/services/social/FacebookSocial.js | 0 .../app}/templates/test/services/social/SocialFactory.js | 0 .../app}/templates/test/services/storage/AmazonStorage.js | 0 .../app}/templates/test/services/storage/BaseStorage.js | 0 .../app}/templates/test/services/storage/GCloudStorage.js | 0 .../app}/templates/test/services/storage/StorageFactory.js | 0 {app => generators/app}/templates/tools/fix-deps.js | 0 {app => generators/app}/templates/tools/update-deps.js | 0 135 files changed, 0 insertions(+), 0 deletions(-) rename {app => generators/app}/index.js (100%) rename {app => generators/app}/templates/.editorconfig (100%) rename {app => generators/app}/templates/.gitignore (100%) rename {app => generators/app}/templates/.sailsrc (100%) rename {app => generators/app}/templates/api/adapters/.gitkeep (100%) rename {app => generators/app}/templates/api/blueprints/.gitkeep (100%) rename {app => generators/app}/templates/api/blueprints/add.js (100%) rename {app => generators/app}/templates/api/blueprints/create.js (100%) rename {app => generators/app}/templates/api/blueprints/destroy.js (100%) rename {app => generators/app}/templates/api/blueprints/find.js (100%) rename {app => generators/app}/templates/api/blueprints/findOne.js (100%) rename {app => generators/app}/templates/api/blueprints/populate.js (100%) rename {app => generators/app}/templates/api/blueprints/remove.js (100%) rename {app => generators/app}/templates/api/blueprints/update.js (100%) rename {app => generators/app}/templates/api/controllers/.gitkeep (100%) rename {app => generators/app}/templates/api/controllers/AuthController.js (100%) rename {app => generators/app}/templates/api/controllers/UserController.js (100%) rename {app => generators/app}/templates/api/hooks/.gitkeep (100%) rename {app => generators/app}/templates/api/models/.gitkeep (100%) rename {app => generators/app}/templates/api/models/User.js (100%) rename {app => generators/app}/templates/api/policies/.gitkeep (100%) rename {app => generators/app}/templates/api/policies/isAllowed.js (100%) rename {app => generators/app}/templates/api/policies/isAuthenticated.js (100%) rename {app => generators/app}/templates/api/responses/.gitkeep (100%) rename {app => generators/app}/templates/api/responses/badRequest.js (100%) rename {app => generators/app}/templates/api/responses/created.js (100%) rename {app => generators/app}/templates/api/responses/forbidden.js (100%) rename {app => generators/app}/templates/api/responses/notFound.js (100%) rename {app => generators/app}/templates/api/responses/ok.js (100%) rename {app => generators/app}/templates/api/responses/serverError.js (100%) rename {app => generators/app}/templates/api/responses/unauthorized.js (100%) rename {app => generators/app}/templates/api/services/.gitkeep (100%) rename {app => generators/app}/templates/api/services/CipherService.js (100%) rename {app => generators/app}/templates/api/services/MailerService.js (100%) rename {app => generators/app}/templates/api/services/PaymentService.js (100%) rename {app => generators/app}/templates/api/services/PusherService.js (100%) rename {app => generators/app}/templates/api/services/SmsService.js (100%) rename {app => generators/app}/templates/api/services/SocialService.js (100%) rename {app => generators/app}/templates/api/services/StorageService.js (100%) rename {app => generators/app}/templates/api/services/cipher/BCryptCipher.js (100%) rename {app => generators/app}/templates/api/services/cipher/BaseCipher.js (100%) rename {app => generators/app}/templates/api/services/cipher/CipherFactory.js (100%) rename {app => generators/app}/templates/api/services/cipher/JwtCipher.js (100%) rename {app => generators/app}/templates/api/services/mailer/BaseMailer.js (100%) rename {app => generators/app}/templates/api/services/mailer/MailerFactory.js (100%) rename {app => generators/app}/templates/api/services/mailer/MandrillMailer.js (100%) rename {app => generators/app}/templates/api/services/payment/PaymentFactory.js (100%) rename {app => generators/app}/templates/api/services/payment/StripePayment.js (100%) rename {app => generators/app}/templates/api/services/pusher/APNPushNotification.js (100%) rename {app => generators/app}/templates/api/services/pusher/BasePushNotification.js (100%) rename {app => generators/app}/templates/api/services/pusher/GCMPushNotification.js (100%) rename {app => generators/app}/templates/api/services/pusher/PusherFactory.js (100%) rename {app => generators/app}/templates/api/services/sms/BaseSms.js (100%) rename {app => generators/app}/templates/api/services/sms/SmsFactory.js (100%) rename {app => generators/app}/templates/api/services/sms/TwilioSms.js (100%) rename {app => generators/app}/templates/api/services/social/FacebookSocial.js (100%) rename {app => generators/app}/templates/api/services/social/SocialFactory.js (100%) rename {app => generators/app}/templates/api/services/storage/AmazonStorage.js (100%) rename {app => generators/app}/templates/api/services/storage/BaseStorage.js (100%) rename {app => generators/app}/templates/api/services/storage/GCloudStorage.js (100%) rename {app => generators/app}/templates/api/services/storage/StorageFactory.js (100%) rename {app => generators/app}/templates/app.js (100%) rename {app => generators/app}/templates/config/blueprints.js (100%) rename {app => generators/app}/templates/config/bootstrap.js (100%) rename {app => generators/app}/templates/config/connections.js (100%) rename {app => generators/app}/templates/config/env/development.js (100%) rename {app => generators/app}/templates/config/env/production.js (100%) rename {app => generators/app}/templates/config/globals.js (100%) rename {app => generators/app}/templates/config/http.js (100%) rename {app => generators/app}/templates/config/log.js (100%) rename {app => generators/app}/templates/config/models.js (100%) rename {app => generators/app}/templates/config/passport.js (100%) rename {app => generators/app}/templates/config/policies.js (100%) rename {app => generators/app}/templates/config/routes.js (100%) rename {app => generators/app}/templates/doc/api.json (100%) rename {app => generators/app}/templates/package.json (100%) rename {app => generators/app}/templates/test/adapters/.gitkeep (100%) rename {app => generators/app}/templates/test/blueprints/.gitkeep (100%) rename {app => generators/app}/templates/test/blueprints/add.js (100%) rename {app => generators/app}/templates/test/blueprints/create.js (100%) rename {app => generators/app}/templates/test/blueprints/destroy.js (100%) rename {app => generators/app}/templates/test/blueprints/find.js (100%) rename {app => generators/app}/templates/test/blueprints/findOne.js (100%) rename {app => generators/app}/templates/test/blueprints/populate.js (100%) rename {app => generators/app}/templates/test/blueprints/remove.js (100%) rename {app => generators/app}/templates/test/blueprints/update.js (100%) rename {app => generators/app}/templates/test/controllers/.gitkeep (100%) rename {app => generators/app}/templates/test/controllers/AuthController.js (100%) rename {app => generators/app}/templates/test/controllers/UserController.js (100%) rename {app => generators/app}/templates/test/hooks/.gitkeep (100%) rename {app => generators/app}/templates/test/models/.gitkeep (100%) rename {app => generators/app}/templates/test/models/User.js (100%) rename {app => generators/app}/templates/test/policies/.gitkeep (100%) rename {app => generators/app}/templates/test/policies/isAllowed.js (100%) rename {app => generators/app}/templates/test/policies/isAuthenticated.js (100%) rename {app => generators/app}/templates/test/responses/.gitkeep (100%) rename {app => generators/app}/templates/test/responses/badRequest.js (100%) rename {app => generators/app}/templates/test/responses/created.js (100%) rename {app => generators/app}/templates/test/responses/forbidden.js (100%) rename {app => generators/app}/templates/test/responses/notFound.js (100%) rename {app => generators/app}/templates/test/responses/ok.js (100%) rename {app => generators/app}/templates/test/responses/serverError.js (100%) rename {app => generators/app}/templates/test/responses/unauthorized.js (100%) rename {app => generators/app}/templates/test/services/.gitkeep (100%) rename {app => generators/app}/templates/test/services/CipherService.js (100%) rename {app => generators/app}/templates/test/services/MailerService.js (100%) rename {app => generators/app}/templates/test/services/PaymentService.js (100%) rename {app => generators/app}/templates/test/services/PusherService.js (100%) rename {app => generators/app}/templates/test/services/SmsService.js (100%) rename {app => generators/app}/templates/test/services/SocialService.js (100%) rename {app => generators/app}/templates/test/services/StorageService.js (100%) rename {app => generators/app}/templates/test/services/cipher/BCryptCipher.js (100%) rename {app => generators/app}/templates/test/services/cipher/BaseCipher.js (100%) rename {app => generators/app}/templates/test/services/cipher/CipherFactory.js (100%) rename {app => generators/app}/templates/test/services/cipher/JwtCipher.js (100%) rename {app => generators/app}/templates/test/services/mailer/BaseMailer.js (100%) rename {app => generators/app}/templates/test/services/mailer/MailerFactory.js (100%) rename {app => generators/app}/templates/test/services/mailer/MandrillMailer.js (100%) rename {app => generators/app}/templates/test/services/payment/PaymentFactory.js (100%) rename {app => generators/app}/templates/test/services/payment/StripePayment.js (100%) rename {app => generators/app}/templates/test/services/pusher/APNPushNotification.js (100%) rename {app => generators/app}/templates/test/services/pusher/BasePushNotification.js (100%) rename {app => generators/app}/templates/test/services/pusher/GCMPushNotification.js (100%) rename {app => generators/app}/templates/test/services/pusher/PusherFactory.js (100%) rename {app => generators/app}/templates/test/services/sms/BaseSms.js (100%) rename {app => generators/app}/templates/test/services/sms/SmsFactory.js (100%) rename {app => generators/app}/templates/test/services/sms/TwilioSms.js (100%) rename {app => generators/app}/templates/test/services/social/FacebookSocial.js (100%) rename {app => generators/app}/templates/test/services/social/SocialFactory.js (100%) rename {app => generators/app}/templates/test/services/storage/AmazonStorage.js (100%) rename {app => generators/app}/templates/test/services/storage/BaseStorage.js (100%) rename {app => generators/app}/templates/test/services/storage/GCloudStorage.js (100%) rename {app => generators/app}/templates/test/services/storage/StorageFactory.js (100%) rename {app => generators/app}/templates/tools/fix-deps.js (100%) rename {app => generators/app}/templates/tools/update-deps.js (100%) diff --git a/app/index.js b/generators/app/index.js similarity index 100% rename from app/index.js rename to generators/app/index.js diff --git a/app/templates/.editorconfig b/generators/app/templates/.editorconfig similarity index 100% rename from app/templates/.editorconfig rename to generators/app/templates/.editorconfig diff --git a/app/templates/.gitignore b/generators/app/templates/.gitignore similarity index 100% rename from app/templates/.gitignore rename to generators/app/templates/.gitignore diff --git a/app/templates/.sailsrc b/generators/app/templates/.sailsrc similarity index 100% rename from app/templates/.sailsrc rename to generators/app/templates/.sailsrc diff --git a/app/templates/api/adapters/.gitkeep b/generators/app/templates/api/adapters/.gitkeep similarity index 100% rename from app/templates/api/adapters/.gitkeep rename to generators/app/templates/api/adapters/.gitkeep diff --git a/app/templates/api/blueprints/.gitkeep b/generators/app/templates/api/blueprints/.gitkeep similarity index 100% rename from app/templates/api/blueprints/.gitkeep rename to generators/app/templates/api/blueprints/.gitkeep diff --git a/app/templates/api/blueprints/add.js b/generators/app/templates/api/blueprints/add.js similarity index 100% rename from app/templates/api/blueprints/add.js rename to generators/app/templates/api/blueprints/add.js diff --git a/app/templates/api/blueprints/create.js b/generators/app/templates/api/blueprints/create.js similarity index 100% rename from app/templates/api/blueprints/create.js rename to generators/app/templates/api/blueprints/create.js diff --git a/app/templates/api/blueprints/destroy.js b/generators/app/templates/api/blueprints/destroy.js similarity index 100% rename from app/templates/api/blueprints/destroy.js rename to generators/app/templates/api/blueprints/destroy.js diff --git a/app/templates/api/blueprints/find.js b/generators/app/templates/api/blueprints/find.js similarity index 100% rename from app/templates/api/blueprints/find.js rename to generators/app/templates/api/blueprints/find.js diff --git a/app/templates/api/blueprints/findOne.js b/generators/app/templates/api/blueprints/findOne.js similarity index 100% rename from app/templates/api/blueprints/findOne.js rename to generators/app/templates/api/blueprints/findOne.js diff --git a/app/templates/api/blueprints/populate.js b/generators/app/templates/api/blueprints/populate.js similarity index 100% rename from app/templates/api/blueprints/populate.js rename to generators/app/templates/api/blueprints/populate.js diff --git a/app/templates/api/blueprints/remove.js b/generators/app/templates/api/blueprints/remove.js similarity index 100% rename from app/templates/api/blueprints/remove.js rename to generators/app/templates/api/blueprints/remove.js diff --git a/app/templates/api/blueprints/update.js b/generators/app/templates/api/blueprints/update.js similarity index 100% rename from app/templates/api/blueprints/update.js rename to generators/app/templates/api/blueprints/update.js diff --git a/app/templates/api/controllers/.gitkeep b/generators/app/templates/api/controllers/.gitkeep similarity index 100% rename from app/templates/api/controllers/.gitkeep rename to generators/app/templates/api/controllers/.gitkeep diff --git a/app/templates/api/controllers/AuthController.js b/generators/app/templates/api/controllers/AuthController.js similarity index 100% rename from app/templates/api/controllers/AuthController.js rename to generators/app/templates/api/controllers/AuthController.js diff --git a/app/templates/api/controllers/UserController.js b/generators/app/templates/api/controllers/UserController.js similarity index 100% rename from app/templates/api/controllers/UserController.js rename to generators/app/templates/api/controllers/UserController.js diff --git a/app/templates/api/hooks/.gitkeep b/generators/app/templates/api/hooks/.gitkeep similarity index 100% rename from app/templates/api/hooks/.gitkeep rename to generators/app/templates/api/hooks/.gitkeep diff --git a/app/templates/api/models/.gitkeep b/generators/app/templates/api/models/.gitkeep similarity index 100% rename from app/templates/api/models/.gitkeep rename to generators/app/templates/api/models/.gitkeep diff --git a/app/templates/api/models/User.js b/generators/app/templates/api/models/User.js similarity index 100% rename from app/templates/api/models/User.js rename to generators/app/templates/api/models/User.js diff --git a/app/templates/api/policies/.gitkeep b/generators/app/templates/api/policies/.gitkeep similarity index 100% rename from app/templates/api/policies/.gitkeep rename to generators/app/templates/api/policies/.gitkeep diff --git a/app/templates/api/policies/isAllowed.js b/generators/app/templates/api/policies/isAllowed.js similarity index 100% rename from app/templates/api/policies/isAllowed.js rename to generators/app/templates/api/policies/isAllowed.js diff --git a/app/templates/api/policies/isAuthenticated.js b/generators/app/templates/api/policies/isAuthenticated.js similarity index 100% rename from app/templates/api/policies/isAuthenticated.js rename to generators/app/templates/api/policies/isAuthenticated.js diff --git a/app/templates/api/responses/.gitkeep b/generators/app/templates/api/responses/.gitkeep similarity index 100% rename from app/templates/api/responses/.gitkeep rename to generators/app/templates/api/responses/.gitkeep diff --git a/app/templates/api/responses/badRequest.js b/generators/app/templates/api/responses/badRequest.js similarity index 100% rename from app/templates/api/responses/badRequest.js rename to generators/app/templates/api/responses/badRequest.js diff --git a/app/templates/api/responses/created.js b/generators/app/templates/api/responses/created.js similarity index 100% rename from app/templates/api/responses/created.js rename to generators/app/templates/api/responses/created.js diff --git a/app/templates/api/responses/forbidden.js b/generators/app/templates/api/responses/forbidden.js similarity index 100% rename from app/templates/api/responses/forbidden.js rename to generators/app/templates/api/responses/forbidden.js diff --git a/app/templates/api/responses/notFound.js b/generators/app/templates/api/responses/notFound.js similarity index 100% rename from app/templates/api/responses/notFound.js rename to generators/app/templates/api/responses/notFound.js diff --git a/app/templates/api/responses/ok.js b/generators/app/templates/api/responses/ok.js similarity index 100% rename from app/templates/api/responses/ok.js rename to generators/app/templates/api/responses/ok.js diff --git a/app/templates/api/responses/serverError.js b/generators/app/templates/api/responses/serverError.js similarity index 100% rename from app/templates/api/responses/serverError.js rename to generators/app/templates/api/responses/serverError.js diff --git a/app/templates/api/responses/unauthorized.js b/generators/app/templates/api/responses/unauthorized.js similarity index 100% rename from app/templates/api/responses/unauthorized.js rename to generators/app/templates/api/responses/unauthorized.js diff --git a/app/templates/api/services/.gitkeep b/generators/app/templates/api/services/.gitkeep similarity index 100% rename from app/templates/api/services/.gitkeep rename to generators/app/templates/api/services/.gitkeep diff --git a/app/templates/api/services/CipherService.js b/generators/app/templates/api/services/CipherService.js similarity index 100% rename from app/templates/api/services/CipherService.js rename to generators/app/templates/api/services/CipherService.js diff --git a/app/templates/api/services/MailerService.js b/generators/app/templates/api/services/MailerService.js similarity index 100% rename from app/templates/api/services/MailerService.js rename to generators/app/templates/api/services/MailerService.js diff --git a/app/templates/api/services/PaymentService.js b/generators/app/templates/api/services/PaymentService.js similarity index 100% rename from app/templates/api/services/PaymentService.js rename to generators/app/templates/api/services/PaymentService.js diff --git a/app/templates/api/services/PusherService.js b/generators/app/templates/api/services/PusherService.js similarity index 100% rename from app/templates/api/services/PusherService.js rename to generators/app/templates/api/services/PusherService.js diff --git a/app/templates/api/services/SmsService.js b/generators/app/templates/api/services/SmsService.js similarity index 100% rename from app/templates/api/services/SmsService.js rename to generators/app/templates/api/services/SmsService.js diff --git a/app/templates/api/services/SocialService.js b/generators/app/templates/api/services/SocialService.js similarity index 100% rename from app/templates/api/services/SocialService.js rename to generators/app/templates/api/services/SocialService.js diff --git a/app/templates/api/services/StorageService.js b/generators/app/templates/api/services/StorageService.js similarity index 100% rename from app/templates/api/services/StorageService.js rename to generators/app/templates/api/services/StorageService.js diff --git a/app/templates/api/services/cipher/BCryptCipher.js b/generators/app/templates/api/services/cipher/BCryptCipher.js similarity index 100% rename from app/templates/api/services/cipher/BCryptCipher.js rename to generators/app/templates/api/services/cipher/BCryptCipher.js diff --git a/app/templates/api/services/cipher/BaseCipher.js b/generators/app/templates/api/services/cipher/BaseCipher.js similarity index 100% rename from app/templates/api/services/cipher/BaseCipher.js rename to generators/app/templates/api/services/cipher/BaseCipher.js diff --git a/app/templates/api/services/cipher/CipherFactory.js b/generators/app/templates/api/services/cipher/CipherFactory.js similarity index 100% rename from app/templates/api/services/cipher/CipherFactory.js rename to generators/app/templates/api/services/cipher/CipherFactory.js diff --git a/app/templates/api/services/cipher/JwtCipher.js b/generators/app/templates/api/services/cipher/JwtCipher.js similarity index 100% rename from app/templates/api/services/cipher/JwtCipher.js rename to generators/app/templates/api/services/cipher/JwtCipher.js diff --git a/app/templates/api/services/mailer/BaseMailer.js b/generators/app/templates/api/services/mailer/BaseMailer.js similarity index 100% rename from app/templates/api/services/mailer/BaseMailer.js rename to generators/app/templates/api/services/mailer/BaseMailer.js diff --git a/app/templates/api/services/mailer/MailerFactory.js b/generators/app/templates/api/services/mailer/MailerFactory.js similarity index 100% rename from app/templates/api/services/mailer/MailerFactory.js rename to generators/app/templates/api/services/mailer/MailerFactory.js diff --git a/app/templates/api/services/mailer/MandrillMailer.js b/generators/app/templates/api/services/mailer/MandrillMailer.js similarity index 100% rename from app/templates/api/services/mailer/MandrillMailer.js rename to generators/app/templates/api/services/mailer/MandrillMailer.js diff --git a/app/templates/api/services/payment/PaymentFactory.js b/generators/app/templates/api/services/payment/PaymentFactory.js similarity index 100% rename from app/templates/api/services/payment/PaymentFactory.js rename to generators/app/templates/api/services/payment/PaymentFactory.js diff --git a/app/templates/api/services/payment/StripePayment.js b/generators/app/templates/api/services/payment/StripePayment.js similarity index 100% rename from app/templates/api/services/payment/StripePayment.js rename to generators/app/templates/api/services/payment/StripePayment.js diff --git a/app/templates/api/services/pusher/APNPushNotification.js b/generators/app/templates/api/services/pusher/APNPushNotification.js similarity index 100% rename from app/templates/api/services/pusher/APNPushNotification.js rename to generators/app/templates/api/services/pusher/APNPushNotification.js diff --git a/app/templates/api/services/pusher/BasePushNotification.js b/generators/app/templates/api/services/pusher/BasePushNotification.js similarity index 100% rename from app/templates/api/services/pusher/BasePushNotification.js rename to generators/app/templates/api/services/pusher/BasePushNotification.js diff --git a/app/templates/api/services/pusher/GCMPushNotification.js b/generators/app/templates/api/services/pusher/GCMPushNotification.js similarity index 100% rename from app/templates/api/services/pusher/GCMPushNotification.js rename to generators/app/templates/api/services/pusher/GCMPushNotification.js diff --git a/app/templates/api/services/pusher/PusherFactory.js b/generators/app/templates/api/services/pusher/PusherFactory.js similarity index 100% rename from app/templates/api/services/pusher/PusherFactory.js rename to generators/app/templates/api/services/pusher/PusherFactory.js diff --git a/app/templates/api/services/sms/BaseSms.js b/generators/app/templates/api/services/sms/BaseSms.js similarity index 100% rename from app/templates/api/services/sms/BaseSms.js rename to generators/app/templates/api/services/sms/BaseSms.js diff --git a/app/templates/api/services/sms/SmsFactory.js b/generators/app/templates/api/services/sms/SmsFactory.js similarity index 100% rename from app/templates/api/services/sms/SmsFactory.js rename to generators/app/templates/api/services/sms/SmsFactory.js diff --git a/app/templates/api/services/sms/TwilioSms.js b/generators/app/templates/api/services/sms/TwilioSms.js similarity index 100% rename from app/templates/api/services/sms/TwilioSms.js rename to generators/app/templates/api/services/sms/TwilioSms.js diff --git a/app/templates/api/services/social/FacebookSocial.js b/generators/app/templates/api/services/social/FacebookSocial.js similarity index 100% rename from app/templates/api/services/social/FacebookSocial.js rename to generators/app/templates/api/services/social/FacebookSocial.js diff --git a/app/templates/api/services/social/SocialFactory.js b/generators/app/templates/api/services/social/SocialFactory.js similarity index 100% rename from app/templates/api/services/social/SocialFactory.js rename to generators/app/templates/api/services/social/SocialFactory.js diff --git a/app/templates/api/services/storage/AmazonStorage.js b/generators/app/templates/api/services/storage/AmazonStorage.js similarity index 100% rename from app/templates/api/services/storage/AmazonStorage.js rename to generators/app/templates/api/services/storage/AmazonStorage.js diff --git a/app/templates/api/services/storage/BaseStorage.js b/generators/app/templates/api/services/storage/BaseStorage.js similarity index 100% rename from app/templates/api/services/storage/BaseStorage.js rename to generators/app/templates/api/services/storage/BaseStorage.js diff --git a/app/templates/api/services/storage/GCloudStorage.js b/generators/app/templates/api/services/storage/GCloudStorage.js similarity index 100% rename from app/templates/api/services/storage/GCloudStorage.js rename to generators/app/templates/api/services/storage/GCloudStorage.js diff --git a/app/templates/api/services/storage/StorageFactory.js b/generators/app/templates/api/services/storage/StorageFactory.js similarity index 100% rename from app/templates/api/services/storage/StorageFactory.js rename to generators/app/templates/api/services/storage/StorageFactory.js diff --git a/app/templates/app.js b/generators/app/templates/app.js similarity index 100% rename from app/templates/app.js rename to generators/app/templates/app.js diff --git a/app/templates/config/blueprints.js b/generators/app/templates/config/blueprints.js similarity index 100% rename from app/templates/config/blueprints.js rename to generators/app/templates/config/blueprints.js diff --git a/app/templates/config/bootstrap.js b/generators/app/templates/config/bootstrap.js similarity index 100% rename from app/templates/config/bootstrap.js rename to generators/app/templates/config/bootstrap.js diff --git a/app/templates/config/connections.js b/generators/app/templates/config/connections.js similarity index 100% rename from app/templates/config/connections.js rename to generators/app/templates/config/connections.js diff --git a/app/templates/config/env/development.js b/generators/app/templates/config/env/development.js similarity index 100% rename from app/templates/config/env/development.js rename to generators/app/templates/config/env/development.js diff --git a/app/templates/config/env/production.js b/generators/app/templates/config/env/production.js similarity index 100% rename from app/templates/config/env/production.js rename to generators/app/templates/config/env/production.js diff --git a/app/templates/config/globals.js b/generators/app/templates/config/globals.js similarity index 100% rename from app/templates/config/globals.js rename to generators/app/templates/config/globals.js diff --git a/app/templates/config/http.js b/generators/app/templates/config/http.js similarity index 100% rename from app/templates/config/http.js rename to generators/app/templates/config/http.js diff --git a/app/templates/config/log.js b/generators/app/templates/config/log.js similarity index 100% rename from app/templates/config/log.js rename to generators/app/templates/config/log.js diff --git a/app/templates/config/models.js b/generators/app/templates/config/models.js similarity index 100% rename from app/templates/config/models.js rename to generators/app/templates/config/models.js diff --git a/app/templates/config/passport.js b/generators/app/templates/config/passport.js similarity index 100% rename from app/templates/config/passport.js rename to generators/app/templates/config/passport.js diff --git a/app/templates/config/policies.js b/generators/app/templates/config/policies.js similarity index 100% rename from app/templates/config/policies.js rename to generators/app/templates/config/policies.js diff --git a/app/templates/config/routes.js b/generators/app/templates/config/routes.js similarity index 100% rename from app/templates/config/routes.js rename to generators/app/templates/config/routes.js diff --git a/app/templates/doc/api.json b/generators/app/templates/doc/api.json similarity index 100% rename from app/templates/doc/api.json rename to generators/app/templates/doc/api.json diff --git a/app/templates/package.json b/generators/app/templates/package.json similarity index 100% rename from app/templates/package.json rename to generators/app/templates/package.json diff --git a/app/templates/test/adapters/.gitkeep b/generators/app/templates/test/adapters/.gitkeep similarity index 100% rename from app/templates/test/adapters/.gitkeep rename to generators/app/templates/test/adapters/.gitkeep diff --git a/app/templates/test/blueprints/.gitkeep b/generators/app/templates/test/blueprints/.gitkeep similarity index 100% rename from app/templates/test/blueprints/.gitkeep rename to generators/app/templates/test/blueprints/.gitkeep diff --git a/app/templates/test/blueprints/add.js b/generators/app/templates/test/blueprints/add.js similarity index 100% rename from app/templates/test/blueprints/add.js rename to generators/app/templates/test/blueprints/add.js diff --git a/app/templates/test/blueprints/create.js b/generators/app/templates/test/blueprints/create.js similarity index 100% rename from app/templates/test/blueprints/create.js rename to generators/app/templates/test/blueprints/create.js diff --git a/app/templates/test/blueprints/destroy.js b/generators/app/templates/test/blueprints/destroy.js similarity index 100% rename from app/templates/test/blueprints/destroy.js rename to generators/app/templates/test/blueprints/destroy.js diff --git a/app/templates/test/blueprints/find.js b/generators/app/templates/test/blueprints/find.js similarity index 100% rename from app/templates/test/blueprints/find.js rename to generators/app/templates/test/blueprints/find.js diff --git a/app/templates/test/blueprints/findOne.js b/generators/app/templates/test/blueprints/findOne.js similarity index 100% rename from app/templates/test/blueprints/findOne.js rename to generators/app/templates/test/blueprints/findOne.js diff --git a/app/templates/test/blueprints/populate.js b/generators/app/templates/test/blueprints/populate.js similarity index 100% rename from app/templates/test/blueprints/populate.js rename to generators/app/templates/test/blueprints/populate.js diff --git a/app/templates/test/blueprints/remove.js b/generators/app/templates/test/blueprints/remove.js similarity index 100% rename from app/templates/test/blueprints/remove.js rename to generators/app/templates/test/blueprints/remove.js diff --git a/app/templates/test/blueprints/update.js b/generators/app/templates/test/blueprints/update.js similarity index 100% rename from app/templates/test/blueprints/update.js rename to generators/app/templates/test/blueprints/update.js diff --git a/app/templates/test/controllers/.gitkeep b/generators/app/templates/test/controllers/.gitkeep similarity index 100% rename from app/templates/test/controllers/.gitkeep rename to generators/app/templates/test/controllers/.gitkeep diff --git a/app/templates/test/controllers/AuthController.js b/generators/app/templates/test/controllers/AuthController.js similarity index 100% rename from app/templates/test/controllers/AuthController.js rename to generators/app/templates/test/controllers/AuthController.js diff --git a/app/templates/test/controllers/UserController.js b/generators/app/templates/test/controllers/UserController.js similarity index 100% rename from app/templates/test/controllers/UserController.js rename to generators/app/templates/test/controllers/UserController.js diff --git a/app/templates/test/hooks/.gitkeep b/generators/app/templates/test/hooks/.gitkeep similarity index 100% rename from app/templates/test/hooks/.gitkeep rename to generators/app/templates/test/hooks/.gitkeep diff --git a/app/templates/test/models/.gitkeep b/generators/app/templates/test/models/.gitkeep similarity index 100% rename from app/templates/test/models/.gitkeep rename to generators/app/templates/test/models/.gitkeep diff --git a/app/templates/test/models/User.js b/generators/app/templates/test/models/User.js similarity index 100% rename from app/templates/test/models/User.js rename to generators/app/templates/test/models/User.js diff --git a/app/templates/test/policies/.gitkeep b/generators/app/templates/test/policies/.gitkeep similarity index 100% rename from app/templates/test/policies/.gitkeep rename to generators/app/templates/test/policies/.gitkeep diff --git a/app/templates/test/policies/isAllowed.js b/generators/app/templates/test/policies/isAllowed.js similarity index 100% rename from app/templates/test/policies/isAllowed.js rename to generators/app/templates/test/policies/isAllowed.js diff --git a/app/templates/test/policies/isAuthenticated.js b/generators/app/templates/test/policies/isAuthenticated.js similarity index 100% rename from app/templates/test/policies/isAuthenticated.js rename to generators/app/templates/test/policies/isAuthenticated.js diff --git a/app/templates/test/responses/.gitkeep b/generators/app/templates/test/responses/.gitkeep similarity index 100% rename from app/templates/test/responses/.gitkeep rename to generators/app/templates/test/responses/.gitkeep diff --git a/app/templates/test/responses/badRequest.js b/generators/app/templates/test/responses/badRequest.js similarity index 100% rename from app/templates/test/responses/badRequest.js rename to generators/app/templates/test/responses/badRequest.js diff --git a/app/templates/test/responses/created.js b/generators/app/templates/test/responses/created.js similarity index 100% rename from app/templates/test/responses/created.js rename to generators/app/templates/test/responses/created.js diff --git a/app/templates/test/responses/forbidden.js b/generators/app/templates/test/responses/forbidden.js similarity index 100% rename from app/templates/test/responses/forbidden.js rename to generators/app/templates/test/responses/forbidden.js diff --git a/app/templates/test/responses/notFound.js b/generators/app/templates/test/responses/notFound.js similarity index 100% rename from app/templates/test/responses/notFound.js rename to generators/app/templates/test/responses/notFound.js diff --git a/app/templates/test/responses/ok.js b/generators/app/templates/test/responses/ok.js similarity index 100% rename from app/templates/test/responses/ok.js rename to generators/app/templates/test/responses/ok.js diff --git a/app/templates/test/responses/serverError.js b/generators/app/templates/test/responses/serverError.js similarity index 100% rename from app/templates/test/responses/serverError.js rename to generators/app/templates/test/responses/serverError.js diff --git a/app/templates/test/responses/unauthorized.js b/generators/app/templates/test/responses/unauthorized.js similarity index 100% rename from app/templates/test/responses/unauthorized.js rename to generators/app/templates/test/responses/unauthorized.js diff --git a/app/templates/test/services/.gitkeep b/generators/app/templates/test/services/.gitkeep similarity index 100% rename from app/templates/test/services/.gitkeep rename to generators/app/templates/test/services/.gitkeep diff --git a/app/templates/test/services/CipherService.js b/generators/app/templates/test/services/CipherService.js similarity index 100% rename from app/templates/test/services/CipherService.js rename to generators/app/templates/test/services/CipherService.js diff --git a/app/templates/test/services/MailerService.js b/generators/app/templates/test/services/MailerService.js similarity index 100% rename from app/templates/test/services/MailerService.js rename to generators/app/templates/test/services/MailerService.js diff --git a/app/templates/test/services/PaymentService.js b/generators/app/templates/test/services/PaymentService.js similarity index 100% rename from app/templates/test/services/PaymentService.js rename to generators/app/templates/test/services/PaymentService.js diff --git a/app/templates/test/services/PusherService.js b/generators/app/templates/test/services/PusherService.js similarity index 100% rename from app/templates/test/services/PusherService.js rename to generators/app/templates/test/services/PusherService.js diff --git a/app/templates/test/services/SmsService.js b/generators/app/templates/test/services/SmsService.js similarity index 100% rename from app/templates/test/services/SmsService.js rename to generators/app/templates/test/services/SmsService.js diff --git a/app/templates/test/services/SocialService.js b/generators/app/templates/test/services/SocialService.js similarity index 100% rename from app/templates/test/services/SocialService.js rename to generators/app/templates/test/services/SocialService.js diff --git a/app/templates/test/services/StorageService.js b/generators/app/templates/test/services/StorageService.js similarity index 100% rename from app/templates/test/services/StorageService.js rename to generators/app/templates/test/services/StorageService.js diff --git a/app/templates/test/services/cipher/BCryptCipher.js b/generators/app/templates/test/services/cipher/BCryptCipher.js similarity index 100% rename from app/templates/test/services/cipher/BCryptCipher.js rename to generators/app/templates/test/services/cipher/BCryptCipher.js diff --git a/app/templates/test/services/cipher/BaseCipher.js b/generators/app/templates/test/services/cipher/BaseCipher.js similarity index 100% rename from app/templates/test/services/cipher/BaseCipher.js rename to generators/app/templates/test/services/cipher/BaseCipher.js diff --git a/app/templates/test/services/cipher/CipherFactory.js b/generators/app/templates/test/services/cipher/CipherFactory.js similarity index 100% rename from app/templates/test/services/cipher/CipherFactory.js rename to generators/app/templates/test/services/cipher/CipherFactory.js diff --git a/app/templates/test/services/cipher/JwtCipher.js b/generators/app/templates/test/services/cipher/JwtCipher.js similarity index 100% rename from app/templates/test/services/cipher/JwtCipher.js rename to generators/app/templates/test/services/cipher/JwtCipher.js diff --git a/app/templates/test/services/mailer/BaseMailer.js b/generators/app/templates/test/services/mailer/BaseMailer.js similarity index 100% rename from app/templates/test/services/mailer/BaseMailer.js rename to generators/app/templates/test/services/mailer/BaseMailer.js diff --git a/app/templates/test/services/mailer/MailerFactory.js b/generators/app/templates/test/services/mailer/MailerFactory.js similarity index 100% rename from app/templates/test/services/mailer/MailerFactory.js rename to generators/app/templates/test/services/mailer/MailerFactory.js diff --git a/app/templates/test/services/mailer/MandrillMailer.js b/generators/app/templates/test/services/mailer/MandrillMailer.js similarity index 100% rename from app/templates/test/services/mailer/MandrillMailer.js rename to generators/app/templates/test/services/mailer/MandrillMailer.js diff --git a/app/templates/test/services/payment/PaymentFactory.js b/generators/app/templates/test/services/payment/PaymentFactory.js similarity index 100% rename from app/templates/test/services/payment/PaymentFactory.js rename to generators/app/templates/test/services/payment/PaymentFactory.js diff --git a/app/templates/test/services/payment/StripePayment.js b/generators/app/templates/test/services/payment/StripePayment.js similarity index 100% rename from app/templates/test/services/payment/StripePayment.js rename to generators/app/templates/test/services/payment/StripePayment.js diff --git a/app/templates/test/services/pusher/APNPushNotification.js b/generators/app/templates/test/services/pusher/APNPushNotification.js similarity index 100% rename from app/templates/test/services/pusher/APNPushNotification.js rename to generators/app/templates/test/services/pusher/APNPushNotification.js diff --git a/app/templates/test/services/pusher/BasePushNotification.js b/generators/app/templates/test/services/pusher/BasePushNotification.js similarity index 100% rename from app/templates/test/services/pusher/BasePushNotification.js rename to generators/app/templates/test/services/pusher/BasePushNotification.js diff --git a/app/templates/test/services/pusher/GCMPushNotification.js b/generators/app/templates/test/services/pusher/GCMPushNotification.js similarity index 100% rename from app/templates/test/services/pusher/GCMPushNotification.js rename to generators/app/templates/test/services/pusher/GCMPushNotification.js diff --git a/app/templates/test/services/pusher/PusherFactory.js b/generators/app/templates/test/services/pusher/PusherFactory.js similarity index 100% rename from app/templates/test/services/pusher/PusherFactory.js rename to generators/app/templates/test/services/pusher/PusherFactory.js diff --git a/app/templates/test/services/sms/BaseSms.js b/generators/app/templates/test/services/sms/BaseSms.js similarity index 100% rename from app/templates/test/services/sms/BaseSms.js rename to generators/app/templates/test/services/sms/BaseSms.js diff --git a/app/templates/test/services/sms/SmsFactory.js b/generators/app/templates/test/services/sms/SmsFactory.js similarity index 100% rename from app/templates/test/services/sms/SmsFactory.js rename to generators/app/templates/test/services/sms/SmsFactory.js diff --git a/app/templates/test/services/sms/TwilioSms.js b/generators/app/templates/test/services/sms/TwilioSms.js similarity index 100% rename from app/templates/test/services/sms/TwilioSms.js rename to generators/app/templates/test/services/sms/TwilioSms.js diff --git a/app/templates/test/services/social/FacebookSocial.js b/generators/app/templates/test/services/social/FacebookSocial.js similarity index 100% rename from app/templates/test/services/social/FacebookSocial.js rename to generators/app/templates/test/services/social/FacebookSocial.js diff --git a/app/templates/test/services/social/SocialFactory.js b/generators/app/templates/test/services/social/SocialFactory.js similarity index 100% rename from app/templates/test/services/social/SocialFactory.js rename to generators/app/templates/test/services/social/SocialFactory.js diff --git a/app/templates/test/services/storage/AmazonStorage.js b/generators/app/templates/test/services/storage/AmazonStorage.js similarity index 100% rename from app/templates/test/services/storage/AmazonStorage.js rename to generators/app/templates/test/services/storage/AmazonStorage.js diff --git a/app/templates/test/services/storage/BaseStorage.js b/generators/app/templates/test/services/storage/BaseStorage.js similarity index 100% rename from app/templates/test/services/storage/BaseStorage.js rename to generators/app/templates/test/services/storage/BaseStorage.js diff --git a/app/templates/test/services/storage/GCloudStorage.js b/generators/app/templates/test/services/storage/GCloudStorage.js similarity index 100% rename from app/templates/test/services/storage/GCloudStorage.js rename to generators/app/templates/test/services/storage/GCloudStorage.js diff --git a/app/templates/test/services/storage/StorageFactory.js b/generators/app/templates/test/services/storage/StorageFactory.js similarity index 100% rename from app/templates/test/services/storage/StorageFactory.js rename to generators/app/templates/test/services/storage/StorageFactory.js diff --git a/app/templates/tools/fix-deps.js b/generators/app/templates/tools/fix-deps.js similarity index 100% rename from app/templates/tools/fix-deps.js rename to generators/app/templates/tools/fix-deps.js diff --git a/app/templates/tools/update-deps.js b/generators/app/templates/tools/update-deps.js similarity index 100% rename from app/templates/tools/update-deps.js rename to generators/app/templates/tools/update-deps.js From e14e126ed546bd469aa7c149537d7ace69285e78 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 17:52:08 +0200 Subject: [PATCH 027/118] Fix bug with package.json not found --- generators/app/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/app/index.js b/generators/app/index.js index 6ee1571e..9190c32f 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -276,7 +276,7 @@ module.exports = yeoman.generators.Base.extend({ * Load package.json */ loadPackageInfo: function () { - this.pkg = require('../package.json'); + this.pkg = require('../../package.json'); }, /** From c276e2501866d58343479dd7026af84b572e5452 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 18:05:01 +0200 Subject: [PATCH 028/118] Resolve #36 --- generators/app/index.js | 189 ++-------------------- generators/app/questions/application.js | 38 +++++ generators/app/questions/database.js | 32 ++++ generators/app/questions/miscellaneous.js | 16 ++ generators/app/questions/services.js | 89 ++++++++++ 5 files changed, 185 insertions(+), 179 deletions(-) create mode 100644 generators/app/questions/application.js create mode 100644 generators/app/questions/database.js create mode 100644 generators/app/questions/miscellaneous.js create mode 100644 generators/app/questions/services.js diff --git a/generators/app/index.js b/generators/app/index.js index 9190c32f..90b80398 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -1,205 +1,36 @@ -var crypto = require('crypto'), - chalk = require('chalk'), +var chalk = require('chalk'), printMessage = require('print-message'), updateNotifier = require('update-notifier'), yeoman = require('yeoman-generator'), - yosay = require('yosay'), - inquirer = require('yo/node_modules/inquirer'); + yosay = require('yosay'); /** - * Questions for database section + * Questions for application section * @type {Array} * @private */ -var DATABASE_QUESTIONS = [{ - type: "list", - name: "database:adapter", - message: "Choose database adapter", - default: 1, - choices: [ - "MySQL", - "Mongo", - "PostgreSQL", - "Redis" - ] -}, { - type: "input", - name: "database:host", - message: "Type your database host", - default: "localhost" -}, { - type: "input", - name: "database:name", - message: "Type your database name", - default: "sails-rest-api" -}, { - type: "input", - name: "database:user", - message: "Type your database username", - default: "" -}, { - type: "password", - name: "database:password", - message: "Type your database password", - default: "" -}]; +var APPLICATION_QUESTIONS = require('./questions/application.js'); /** - * Questions for application section + * Questions for database section * @type {Array} * @private */ -var APPLICATION_QUESTIONS = [{ - type: "input", - name: "application:name", - message: "Type your application name", - default: "sails-rest-api" -}, { - type: "input", - name: "application:api-secret-key", - message: "Type your private API key", - default: crypto.randomBytes(32).toString("hex") -}, { - type: "input", - name: "application:jwt-secret", - message: "Type your private key for JSON Web Token", - default: crypto.randomBytes(32).toString("hex") -}, { - type: "input", - name: "application:facebook-app-id", - message: "Type your Facebook App ID", - default: "-" -}, { - type: "input", - name: "application:facebook-app-secret", - message: "Type your Facebook App Secret", - default: "-" -}, { - type: "input", - name: "application:twitter-consumer-key", - message: "Type your Twitter Consumer Key", - default: "-" -}, { - type: "input", - name: "application:twitter-consumer-secret", - message: "Type your Twitter Consumer Secret", - default: "-" -}]; +var DATABASE_QUESTIONS = require('./questions/database.js'); /** - * Questions for services section + * Questions for miscellaneous section * @type {Array} * @private */ -var SERVICES_QUESTIONS = [{ - type: "checkbox", - name: "services:cipher", - message: "Choose which Cipher services you want", - choices: [{ - name: "bcrypt", - checked: true - }, { - name: "jwt", - checked: true - }, new inquirer.Separator(), { - name: "More Cipher is coming", - disabled: "Wait for it..." - }] -}, { - type: "checkbox", - name: "services:mailer", - message: "Choose which Mailer services you want", - choices: [{ - name: "Mandrill", - checked: false - }, new inquirer.Separator(), { - name: "More Mailer is coming", - disabled: "Wait for it..." - }] -}, { - type: "checkbox", - name: "services:payment", - message: "Choose which Payment services you want", - choices: [{ - name: "Stripe", - checked: false - }, new inquirer.Separator(), { - name: "More Payment is coming", - disabled: "Wait for it..." - }] -}, { - type: "checkbox", - name: "services:pusher", - message: "Choose which Pusher services you want", - choices: [{ - name: "Apple Push Notification", - checked: false - }, { - name: "Google Cloud Messaging", - checked: false - }, new inquirer.Separator(), { - name: "More Pusher is coming", - disabled: "Wait for it..." - }] -}, { - type: "checkbox", - name: "services:sms", - message: "Choose which SMS services you want", - choices: [{ - name: "Twilio", - checked: false - }, new inquirer.Separator(), { - name: "More SMS is coming", - disabled: "Wait for it..." - }] -}, { - type: "checkbox", - name: "services:social", - message: "Choose which Social services you want", - choices: [{ - name: "Facebook", - checked: false - }, new inquirer.Separator(), { - name: "More Social is coming", - disabled: "Wait for it..." - }] -}, { - type: "checkbox", - name: "services:storage", - message: "Choose which Storage services you want", - choices: [{ - name: "Amazon S3", - checked: false - }, { - name: "Google Cloud Storage", - checked: false - }, new inquirer.Separator(), { - name: "More Storage is coming", - disabled: "Wait for it..." - }] -}]; +var MISCELLANEOUS_QUESTIONS = require('./questions/miscellaneous'); /** - * Questions for miscellaneous section + * Questions for services section * @type {Array} * @private */ -var MISCELLANEOUS_QUESTIONS = [{ - type: "confirm", - name: "docs:include", - message: "Is Swagger documentation needed for project?", - default: true -}, { - type: "confirm", - name: "tests:include", - message: "Is Mocha tests needed for project?", - default: true -}, { - type: "confirm", - name: "tools:include", - message: "Is diagnostic tools needed for project?", - default: true -}]; +var SERVICES_QUESTIONS = require('./questions/services.js'); /** * Extend target object with source object diff --git a/generators/app/questions/application.js b/generators/app/questions/application.js new file mode 100644 index 00000000..cb920859 --- /dev/null +++ b/generators/app/questions/application.js @@ -0,0 +1,38 @@ +var crypto = require('crypto'); + +module.exports = [{ + type: "input", + name: "application:name", + message: "Type your application name", + default: "sails-rest-api" +}, { + type: "input", + name: "application:api-secret-key", + message: "Type your private API key", + default: crypto.randomBytes(32).toString("hex") +}, { + type: "input", + name: "application:jwt-secret", + message: "Type your private key for JSON Web Token", + default: crypto.randomBytes(32).toString("hex") +}, { + type: "input", + name: "application:facebook-app-id", + message: "Type your Facebook App ID", + default: "-" +}, { + type: "input", + name: "application:facebook-app-secret", + message: "Type your Facebook App Secret", + default: "-" +}, { + type: "input", + name: "application:twitter-consumer-key", + message: "Type your Twitter Consumer Key", + default: "-" +}, { + type: "input", + name: "application:twitter-consumer-secret", + message: "Type your Twitter Consumer Secret", + default: "-" +}]; diff --git a/generators/app/questions/database.js b/generators/app/questions/database.js new file mode 100644 index 00000000..03854b2b --- /dev/null +++ b/generators/app/questions/database.js @@ -0,0 +1,32 @@ +module.exports = [{ + "type": "list", + "name": "database:adapter", + "message": "Choose database adapter", + "default": 1, + "choices": [ + "MySQL", + "Mongo", + "PostgreSQL", + "Redis" + ] +}, { + "type": "input", + "name": "database:host", + "message": "Type your database host", + "default": "localhost" +}, { + "type": "input", + "name": "database:name", + "message": "Type your database name", + "default": "sails-rest-api" +}, { + "type": "input", + "name": "database:user", + "message": "Type your database username", + "default": "" +}, { + "type": "password", + "name": "database:password", + "message": "Type your database password", + "default": "" +}]; diff --git a/generators/app/questions/miscellaneous.js b/generators/app/questions/miscellaneous.js new file mode 100644 index 00000000..eb1b899b --- /dev/null +++ b/generators/app/questions/miscellaneous.js @@ -0,0 +1,16 @@ +module.exports = [{ + type: "confirm", + name: "docs:include", + message: "Is Swagger documentation needed for project?", + default: true +}, { + type: "confirm", + name: "tests:include", + message: "Is Mocha tests needed for project?", + default: true +}, { + type: "confirm", + name: "tools:include", + message: "Is diagnostic tools needed for project?", + default: true +}]; diff --git a/generators/app/questions/services.js b/generators/app/questions/services.js new file mode 100644 index 00000000..4447f393 --- /dev/null +++ b/generators/app/questions/services.js @@ -0,0 +1,89 @@ +var inquirer = require('yo/node_modules/inquirer'); + +module.exports = [{ + type: "checkbox", + name: "services:cipher", + message: "Choose which Cipher services you want", + choices: [{ + name: "bcrypt", + checked: true + }, { + name: "jwt", + checked: true + }, new inquirer.Separator(), { + name: "More Cipher is coming", + disabled: "Wait for it..." + }] +}, { + type: "checkbox", + name: "services:mailer", + message: "Choose which Mailer services you want", + choices: [{ + name: "Mandrill", + checked: false + }, new inquirer.Separator(), { + name: "More Mailer is coming", + disabled: "Wait for it..." + }] +}, { + type: "checkbox", + name: "services:payment", + message: "Choose which Payment services you want", + choices: [{ + name: "Stripe", + checked: false + }, new inquirer.Separator(), { + name: "More Payment is coming", + disabled: "Wait for it..." + }] +}, { + type: "checkbox", + name: "services:pusher", + message: "Choose which Pusher services you want", + choices: [{ + name: "Apple Push Notification", + checked: false + }, { + name: "Google Cloud Messaging", + checked: false + }, new inquirer.Separator(), { + name: "More Pusher is coming", + disabled: "Wait for it..." + }] +}, { + type: "checkbox", + name: "services:sms", + message: "Choose which SMS services you want", + choices: [{ + name: "Twilio", + checked: false + }, new inquirer.Separator(), { + name: "More SMS is coming", + disabled: "Wait for it..." + }] +}, { + type: "checkbox", + name: "services:social", + message: "Choose which Social services you want", + choices: [{ + name: "Facebook", + checked: false + }, new inquirer.Separator(), { + name: "More Social is coming", + disabled: "Wait for it..." + }] +}, { + type: "checkbox", + name: "services:storage", + message: "Choose which Storage services you want", + choices: [{ + name: "Amazon S3", + checked: false + }, { + name: "Google Cloud Storage", + checked: false + }, new inquirer.Separator(), { + name: "More Storage is coming", + disabled: "Wait for it..." + }] +}]; From 3e930b589bbc6477a6a870e21de80ed5904b85bc Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 18:14:22 +0200 Subject: [PATCH 029/118] Move CLI options to separate folder --- generators/app/index.js | 44 +++++++------------------------ generators/app/options/index.json | 32 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 generators/app/options/index.json diff --git a/generators/app/index.js b/generators/app/index.js index 90b80398..5f5d492d 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -32,6 +32,13 @@ var MISCELLANEOUS_QUESTIONS = require('./questions/miscellaneous'); */ var SERVICES_QUESTIONS = require('./questions/services.js'); +/** + * CLI options for generator + * @type {Object} + * @private + */ +var GENERATOR_OPTIONS = require('./options/index.json'); + /** * Extend target object with source object * @param {Object} _target Target object @@ -59,40 +66,9 @@ module.exports = yeoman.generators.Base.extend({ constructor: function () { yeoman.generators.Base.apply(this, arguments); - this.option("skip-generator-update", { - desc: "Skip checking for generator updates on running", - type: Boolean, - defaults: false, - hide: false - }); - - this.option("skip-generator-welcome", { - desc: "Skip saying welcome when generator is running", - type: Boolean, - defaults: false, - hide: false - }); - - this.option("skip-project-install", { - desc: "Skip installing npm dependencies in project", - type: Boolean, - defaults: false, - hide: false - }); - - this.option("skip-project-diagnostic", { - desc: "Skip running diagnostic tools in project", - type: Boolean, - defaults: false, - hide: false - }); - - this.option("skip-all", { - desc: "Skip everything, just project scaffolding", - type: Boolean, - defaults: false, - hide: false - }); + Object.keys(GENERATOR_OPTIONS).forEach(function (optionName) { + this.option(optionName, GENERATOR_OPTIONS[optionName]); + }.bind(this)); this.config.save(); }, diff --git a/generators/app/options/index.json b/generators/app/options/index.json new file mode 100644 index 00000000..519573f5 --- /dev/null +++ b/generators/app/options/index.json @@ -0,0 +1,32 @@ +{ + "skip-generator-update": { + "desc": "Skip checking for generator updates on running", + "type": "Boolean", + "defaults": false, + "hide": false + }, + "skip-generator-welcome": { + "desc": "Skip saying welcome when generator is running", + "type": "Boolean", + "defaults": false, + "hide": false + }, + "skip-project-install": { + "desc": "Skip installing npm dependencies in project", + "type": "Boolean", + "defaults": false, + "hide": false + }, + "skip-project-diagnostic": { + "desc": "Skip running diagnostic tools in project", + "type": "Boolean", + "defaults": false, + "hide": false + }, + "skip-all": { + "desc": "Skip everything, just project scaffolding", + "type": "Boolean", + "defaults": false, + "hide": false + } +} From 7ea1b9185a5ee6a1c75b072389c35ed1e6f918dd Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 18:21:14 +0200 Subject: [PATCH 030/118] Move CLI options to another folder. Rename questions folder to cli-questsion --- generators/app/{options => cli-options}/index.json | 0 .../app/{questions => cli-questions}/application.js | 0 .../app/{questions => cli-questions}/database.js | 0 .../app/{questions => cli-questions}/miscellaneous.js | 0 .../app/{questions => cli-questions}/services.js | 0 generators/app/index.js | 10 +++++----- 6 files changed, 5 insertions(+), 5 deletions(-) rename generators/app/{options => cli-options}/index.json (100%) rename generators/app/{questions => cli-questions}/application.js (100%) rename generators/app/{questions => cli-questions}/database.js (100%) rename generators/app/{questions => cli-questions}/miscellaneous.js (100%) rename generators/app/{questions => cli-questions}/services.js (100%) diff --git a/generators/app/options/index.json b/generators/app/cli-options/index.json similarity index 100% rename from generators/app/options/index.json rename to generators/app/cli-options/index.json diff --git a/generators/app/questions/application.js b/generators/app/cli-questions/application.js similarity index 100% rename from generators/app/questions/application.js rename to generators/app/cli-questions/application.js diff --git a/generators/app/questions/database.js b/generators/app/cli-questions/database.js similarity index 100% rename from generators/app/questions/database.js rename to generators/app/cli-questions/database.js diff --git a/generators/app/questions/miscellaneous.js b/generators/app/cli-questions/miscellaneous.js similarity index 100% rename from generators/app/questions/miscellaneous.js rename to generators/app/cli-questions/miscellaneous.js diff --git a/generators/app/questions/services.js b/generators/app/cli-questions/services.js similarity index 100% rename from generators/app/questions/services.js rename to generators/app/cli-questions/services.js diff --git a/generators/app/index.js b/generators/app/index.js index 5f5d492d..38440da0 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -9,35 +9,35 @@ var chalk = require('chalk'), * @type {Array} * @private */ -var APPLICATION_QUESTIONS = require('./questions/application.js'); +var APPLICATION_QUESTIONS = require('./cli-questions/application.js'); /** * Questions for database section * @type {Array} * @private */ -var DATABASE_QUESTIONS = require('./questions/database.js'); +var DATABASE_QUESTIONS = require('./cli-questions/database.js'); /** * Questions for miscellaneous section * @type {Array} * @private */ -var MISCELLANEOUS_QUESTIONS = require('./questions/miscellaneous'); +var MISCELLANEOUS_QUESTIONS = require('./cli-questions/miscellaneous'); /** * Questions for services section * @type {Array} * @private */ -var SERVICES_QUESTIONS = require('./questions/services.js'); +var SERVICES_QUESTIONS = require('./cli-questions/services.js'); /** * CLI options for generator * @type {Object} * @private */ -var GENERATOR_OPTIONS = require('./options/index.json'); +var GENERATOR_OPTIONS = require('./cli-options/index.json'); /** * Extend target object with source object From e35d715c8eb80bf70b488caedd1829f0e49479bf Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 18:40:33 +0200 Subject: [PATCH 031/118] Resolve #37 --- generators/app/index.js | 297 +---------------------- generators/app/run-steps/configuring.js | 6 + generators/app/run-steps/conflicts.js | 6 + generators/app/run-steps/end.js | 57 +++++ generators/app/run-steps/initializing.js | 60 +++++ generators/app/run-steps/install.js | 16 ++ generators/app/run-steps/prompting.js | 87 +++++++ generators/app/run-steps/writing.js | 17 ++ 8 files changed, 261 insertions(+), 285 deletions(-) create mode 100644 generators/app/run-steps/configuring.js create mode 100644 generators/app/run-steps/conflicts.js create mode 100644 generators/app/run-steps/end.js create mode 100644 generators/app/run-steps/initializing.js create mode 100644 generators/app/run-steps/install.js create mode 100644 generators/app/run-steps/prompting.js create mode 100644 generators/app/run-steps/writing.js diff --git a/generators/app/index.js b/generators/app/index.js index 38440da0..2b740fa7 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -1,296 +1,23 @@ -var chalk = require('chalk'), - printMessage = require('print-message'), - updateNotifier = require('update-notifier'), - yeoman = require('yeoman-generator'), - yosay = require('yosay'); - -/** - * Questions for application section - * @type {Array} - * @private - */ -var APPLICATION_QUESTIONS = require('./cli-questions/application.js'); - -/** - * Questions for database section - * @type {Array} - * @private - */ -var DATABASE_QUESTIONS = require('./cli-questions/database.js'); - -/** - * Questions for miscellaneous section - * @type {Array} - * @private - */ -var MISCELLANEOUS_QUESTIONS = require('./cli-questions/miscellaneous'); - -/** - * Questions for services section - * @type {Array} - * @private - */ -var SERVICES_QUESTIONS = require('./cli-questions/services.js'); - -/** - * CLI options for generator - * @type {Object} - * @private - */ -var GENERATOR_OPTIONS = require('./cli-options/index.json'); - -/** - * Extend target object with source object - * @param {Object} _target Target object - * @param {Object} _source Source object - * @returns {Object} - * @private - */ -function _extend(_target, _source) { - var target = _target || {}, - source = _source || {}, - keys = Object.keys(source); - - for (var i = 0; i < keys.length; i++) { - target[keys[i]] = source[keys[i]]; - } - - return target; -} +var yeoman = require('yeoman-generator'); module.exports = yeoman.generators.Base.extend({ - /** - * Special methods may do things like set up important state controls and may not function outside of the constructor - * @type {Function} - */ constructor: function () { + var options = require('./cli-options/index'); + yeoman.generators.Base.apply(this, arguments); - Object.keys(GENERATOR_OPTIONS).forEach(function (optionName) { - this.option(optionName, GENERATOR_OPTIONS[optionName]); + Object.keys(options).forEach(function (optionName) { + this.option(optionName, options[optionName]); }.bind(this)); this.config.save(); }, - /** - * Step 1 - * Your initialization methods (checking current project state, getting configs, etc) - * @type {Object} - */ - initializing: { - /** - * Load package.json - */ - loadPackageInfo: function () { - this.pkg = require('../../package.json'); - }, - - /** - * Notify about updates of generator-sails-rest-api - */ - notifyAboutGeneratorUpdate: function () { - if (!(this.options['skip-generator-update'] || this.options['skip-all'])) { - var done = this.async(); - - this.log(chalk.yellow("Checking for updates...")); - - updateNotifier({ - pkg: this.pkg, - callback: function (error, update) { - if (update && update.type && update.type !== 'latest') { - printMessage([ - "Update available: " + chalk.green.bold(update.latest) + chalk.dim(" (current: " + update.current + ")"), - "Run " + chalk.blue("npm update -g " + update.name) + " to update." - ], { - marginTop: 0, - marginBottom: 0, - printFn: this.log - }); - - process.exit(0); - } else { - this.log(chalk.yellow("OK... You're using the latest version " + chalk.green.bold(update.current))); - done(); - } - }.bind(this) - }); - } - }, - - /** - * Say yeoman hello - */ - sayHello: function () { - if (!(this.options["skip-generator-welcome"] || this.options["skip-all"])) { - this.log(yosay('Welcome to the laudable ' + chalk.red('Sails REST API') + ' generator!')); - } - } - }, - - /** - * Step 2 - * Where you prompt users for options (where you'd call this.prompt()) - */ - prompting: { - /** - * Ask database questions - */ - askDatabaseQuestions: function () { - var done = this.async(); - - this.log(chalk.yellow("\nDatabase questions:")); - - this.prompt(DATABASE_QUESTIONS, function (answers) { - this.answers = _extend(this.answers, answers); - done(); - }); - }, - - /** - * Ask application questions - */ - askApplicationQuestions: function () { - var done = this.async(); - - this.log(chalk.yellow("\nApplication questions:")); - - this.prompt(APPLICATION_QUESTIONS, function (answers) { - this.answers = _extend(this.answers, answers); - done(); - }); - }, - - /** - * Ask services questions - */ - askServiceQuestions: function () { - var done = this.async(); - - this.log(chalk.yellow("\nService questions:")); - - this.prompt(SERVICES_QUESTIONS, function (answers) { - this.answers = _extend(this.answers, answers); - done(); - }); - }, - - /** - * Ask miscellaneous questions - */ - askMiscellaneousSections: function () { - var done = this.async(); - - this.log(chalk.yellow("\nMiscellaneous questions:")); - - this.prompt(MISCELLANEOUS_QUESTIONS, function (answers) { - this.answers = _extend(this.answers, answers); - done(); - }); - } - }, - - /** - * Step 3 - * Saving configurations and configure the project (creating .editorconfig files and other metadata files) - */ - configuring: {}, - - /** - * Step 4 - * Default priority - */ - - /** - * Step 5 - * Where you write the generator specific files (routes, controllers, etc) - */ - writing: { - /** - * Copy template directory to source root - */ - copyDirectory: function () { - // TODO: split into separate functions - this.directory( - this.sourceRoot(), - this.destinationRoot() - ); - } - }, - - /** - * Step 6 - * Where conflicts are handled (used internally) - */ - conflicts: {}, - - /** - * Step 7 - * Where installation are run (npm, bower) - */ - install: { - /** - * Install npm dependencies - */ - installNpmDependencies: function () { - if (!(this.options['skip-project-install'] || this.options["skip-all"])) { - this.log(chalk.yellow("Start installing npm dependencies, please wait...")); - this.npmInstall(); - } - } - }, - - /** - * Step 8 - * Called last, cleanup, say good bye, etc - */ - end: { - /** - * Run diagnostic tools - */ - runDiagnostic: function () { - if (!(this.options["skip-project-diagnostic"] || this.options["skip-all"])) { - var done = this.async(); - - this.log(chalk.yellow("Starting diagnostic, please wait...")); - - this.spawnCommand('node', ['tools/fix-deps.js']).on('close', function () { - this.spawnCommand('node', ['tools/update-deps.js']).on('close', done); - }.bind(this)); - } - }, - - /** - * Say warning that this generator is under development - */ - sayUnderDevelopmentWarning: function () { - printMessage([ - "This generator under heavy development", - "If you found any bugs or have proposals, feel free to create issue", - chalk.red(this.pkg.bugs.url), - "Or you can write me the letter", - chalk.red(this.pkg.bugs.email) - ], { - marginTop: 0, - marginBottom: 0, - printFn: this.log - }); - }, - - /** - * Warn user if he skip installing dependencies - */ - sayNotInstalledNpmDepsWarning: function () { - if (this.options['skip-project-install'] || this.options["skip-all"]) { - printMessage([ - "You have skipped installing npm modules", - "Install them manually via " + chalk.blue("npm install") - ], { - marginTop: 0, - marginBottom: 0, - printFn: this.log - }); - } - } - } + initializing: require('./run-steps/initializing'), + prompting: require('./run-steps/prompting.js'), + configuring: require('./run-steps/configuring.js'), + writing: require('./run-steps/writing.js'), + conflicts: require('./run-steps/conflicts.js'), + install: require('./run-steps/install.js'), + end: require('./run-steps/end.js') }); diff --git a/generators/app/run-steps/configuring.js b/generators/app/run-steps/configuring.js new file mode 100644 index 00000000..675b1cbf --- /dev/null +++ b/generators/app/run-steps/configuring.js @@ -0,0 +1,6 @@ +/** + * Step 3 + * Saving configurations and configure the project (creating .editorconfig files and other metadata files) + */ + +module.exports = {}; diff --git a/generators/app/run-steps/conflicts.js b/generators/app/run-steps/conflicts.js new file mode 100644 index 00000000..7314763a --- /dev/null +++ b/generators/app/run-steps/conflicts.js @@ -0,0 +1,6 @@ +/** + * Step 6 + * Where conflicts are handled (used internally) + */ + +module.exports = {}; diff --git a/generators/app/run-steps/end.js b/generators/app/run-steps/end.js new file mode 100644 index 00000000..5d05cd5a --- /dev/null +++ b/generators/app/run-steps/end.js @@ -0,0 +1,57 @@ +/** + * Step 8 + * Called last, cleanup, say good bye, etc + */ + +var chalk = require('chalk'), + printMessage = require('print-message'); + +module.exports = { + /** + * Run diagnostic tools + */ + runDiagnostic: function () { + if (!(this.options["skip-project-diagnostic"] || this.options["skip-all"])) { + var done = this.async(); + + this.log(chalk.yellow("Starting diagnostic, please wait...")); + + this.spawnCommand('node', ['tools/fix-deps.js']).on('close', function () { + this.spawnCommand('node', ['tools/update-deps.js']).on('close', done); + }.bind(this)); + } + }, + + /** + * Say warning that this generator is under development + */ + sayUnderDevelopmentWarning: function () { + printMessage([ + "This generator under heavy development", + "If you found any bugs or have proposals, feel free to create issue", + chalk.red(this.pkg.bugs.url), + "Or you can write me the letter", + chalk.red(this.pkg.bugs.email) + ], { + marginTop: 0, + marginBottom: 0, + printFn: this.log + }); + }, + + /** + * Warn user if he skip installing dependencies + */ + sayNotInstalledNpmDepsWarning: function () { + if (this.options['skip-project-install'] || this.options["skip-all"]) { + printMessage([ + "You have skipped installing npm modules", + "Install them manually via " + chalk.blue("npm install") + ], { + marginTop: 0, + marginBottom: 0, + printFn: this.log + }); + } + } +}; diff --git a/generators/app/run-steps/initializing.js b/generators/app/run-steps/initializing.js new file mode 100644 index 00000000..bd25f0cc --- /dev/null +++ b/generators/app/run-steps/initializing.js @@ -0,0 +1,60 @@ +/** + * Step 1 + * Your initialization methods (checking current project state, getting configs, etc) + * @type {Object} + */ + +var chalk = require('chalk'), + updateNotifier = require('update-notifier'), + printMessage = require('print-message'), + yosay = require('yosay'); + +module.exports = { + /** + * Load package.json + */ + loadPackageInfo: function () { + this.pkg = require('../../../package.json'); + }, + + /** + * Notify about updates of generator-sails-rest-api + */ + notifyAboutGeneratorUpdate: function () { + if (!(this.options['skip-generator-update'] || this.options['skip-all'])) { + var done = this.async(); + + this.log(chalk.yellow("Checking for updates...")); + + updateNotifier({ + pkg: this.pkg, + callback: function (error, update) { + if (update && update.type && update.type !== 'latest') { + printMessage([ + "Update available: " + chalk.green.bold(update.latest) + chalk.dim(" (current: " + update.current + ")"), + "Run " + chalk.blue("npm update -g " + update.name) + " to update." + ], { + marginTop: 0, + marginBottom: 0, + printFn: this.log + }); + + process.exit(0); + } else { + this.log(chalk.yellow("OK... You're using the latest version " + chalk.green.bold(update.current))); + done(); + } + }.bind(this) + }); + } + }, + + /** + * Say yeoman hello + */ + sayHello: function () { + if (!(this.options["skip-generator-welcome"] || this.options["skip-all"])) { + this.log(yosay('Welcome to the laudable ' + chalk.red('Sails REST API') + ' generator!')); + } + } +}; diff --git a/generators/app/run-steps/install.js b/generators/app/run-steps/install.js new file mode 100644 index 00000000..b505e6fb --- /dev/null +++ b/generators/app/run-steps/install.js @@ -0,0 +1,16 @@ +/** + * Step 7 + * Where installation are run (npm, bower) + */ + +module.exports = { + /** + * Install npm dependencies + */ + installNpmDependencies: function () { + if (!(this.options['skip-project-install'] || this.options["skip-all"])) { + this.log(chalk.yellow("Start installing npm dependencies, please wait...")); + this.npmInstall(); + } + } +}; diff --git a/generators/app/run-steps/prompting.js b/generators/app/run-steps/prompting.js new file mode 100644 index 00000000..7c5bfea0 --- /dev/null +++ b/generators/app/run-steps/prompting.js @@ -0,0 +1,87 @@ +/** + * Step 2 + * Where you prompt users for options (where you'd call this.prompt()) + */ + +var chalk = require('chalk'), + APPLICATION_QUESTIONS = require('../cli-questions/application.js'), + DATABASE_QUESTIONS = require('../cli-questions/database.js'), + MISCELLANEOUS_QUESTIONS = require('../cli-questions/miscellaneous'), + SERVICES_QUESTIONS = require('../cli-questions/services.js'); + +/** + * Extend target object with source object + * @param {Object} _target Target object + * @param {Object} _source Source object + * @returns {Object} + * @private + */ +function _extend(_target, _source) { + var target = _target || {}, + source = _source || {}, + keys = Object.keys(source); + + for (var i = 0; i < keys.length; i++) { + target[keys[i]] = source[keys[i]]; + } + + return target; +} + +module.exports = { + /** + * Ask database questions + */ + askDatabaseQuestions: function () { + var done = this.async(); + + this.log(chalk.yellow("\nDatabase questions:")); + + this.prompt(DATABASE_QUESTIONS, function (answers) { + this.answers = _extend(this.answers, answers); + done(); + }); + }, + + /** + * Ask application questions + */ + askApplicationQuestions: function () { + var done = this.async(); + + this.log(chalk.yellow("\nApplication questions:")); + + this.prompt(APPLICATION_QUESTIONS, function (answers) { + this.answers = _extend(this.answers, answers); + done(); + }); + }, + + /** + * Ask services questions + */ + askServiceQuestions: function () { + var done = this.async(); + + this.log(chalk.yellow("\nService questions:")); + + this.prompt(SERVICES_QUESTIONS, function (answers) { + this.answers = _extend(this.answers, answers); + done(); + }); + }, + + /** + * Ask miscellaneous questions + */ + askMiscellaneousSections: function () { + var done = this.async(); + + this.log(chalk.yellow("\nMiscellaneous questions:")); + + this.prompt(MISCELLANEOUS_QUESTIONS, function (answers) { + this.answers = _extend(this.answers, answers); + done(); + }); + } +}; diff --git a/generators/app/run-steps/writing.js b/generators/app/run-steps/writing.js new file mode 100644 index 00000000..46878732 --- /dev/null +++ b/generators/app/run-steps/writing.js @@ -0,0 +1,17 @@ +/** + * Step 5 + * Where you write the generator specific files (routes, controllers, etc) + */ + +module.exports = { + /** + * Copy template directory to source root + */ + copyDirectory: function () { + // TODO: split into separate functions + this.directory( + this.sourceRoot(), + this.destinationRoot() + ); + } +}; From 02878f3251f041bae0fa44a98f539817ffaa4f0e Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 18:44:13 +0200 Subject: [PATCH 032/118] Rename all folders with yo prefix --- generators/app/index.js | 16 ++++++++-------- .../app/{cli-options => yo-options}/index.json | 0 .../application.js | 0 .../{cli-questions => yo-questions}/database.js | 0 .../miscellaneous.js | 0 .../{cli-questions => yo-questions}/services.js | 0 .../app/{run-steps => yo-steps}/configuring.js | 0 .../app/{run-steps => yo-steps}/conflicts.js | 0 generators/app/{run-steps => yo-steps}/end.js | 0 .../app/{run-steps => yo-steps}/initializing.js | 0 .../app/{run-steps => yo-steps}/install.js | 0 .../app/{run-steps => yo-steps}/prompting.js | 8 ++++---- .../app/{run-steps => yo-steps}/writing.js | 0 13 files changed, 12 insertions(+), 12 deletions(-) rename generators/app/{cli-options => yo-options}/index.json (100%) rename generators/app/{cli-questions => yo-questions}/application.js (100%) rename generators/app/{cli-questions => yo-questions}/database.js (100%) rename generators/app/{cli-questions => yo-questions}/miscellaneous.js (100%) rename generators/app/{cli-questions => yo-questions}/services.js (100%) rename generators/app/{run-steps => yo-steps}/configuring.js (100%) rename generators/app/{run-steps => yo-steps}/conflicts.js (100%) rename generators/app/{run-steps => yo-steps}/end.js (100%) rename generators/app/{run-steps => yo-steps}/initializing.js (100%) rename generators/app/{run-steps => yo-steps}/install.js (100%) rename generators/app/{run-steps => yo-steps}/prompting.js (87%) rename generators/app/{run-steps => yo-steps}/writing.js (100%) diff --git a/generators/app/index.js b/generators/app/index.js index 2b740fa7..f7d408e0 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -2,7 +2,7 @@ var yeoman = require('yeoman-generator'); module.exports = yeoman.generators.Base.extend({ constructor: function () { - var options = require('./cli-options/index'); + var options = require('./yo-options/index'); yeoman.generators.Base.apply(this, arguments); @@ -13,11 +13,11 @@ module.exports = yeoman.generators.Base.extend({ this.config.save(); }, - initializing: require('./run-steps/initializing'), - prompting: require('./run-steps/prompting.js'), - configuring: require('./run-steps/configuring.js'), - writing: require('./run-steps/writing.js'), - conflicts: require('./run-steps/conflicts.js'), - install: require('./run-steps/install.js'), - end: require('./run-steps/end.js') + initializing: require('./yo-steps/initializing'), + prompting: require('./yo-steps/prompting.js'), + configuring: require('./yo-steps/configuring.js'), + writing: require('./yo-steps/writing.js'), + conflicts: require('./yo-steps/conflicts.js'), + install: require('./yo-steps/install.js'), + end: require('./yo-steps/end.js') }); diff --git a/generators/app/cli-options/index.json b/generators/app/yo-options/index.json similarity index 100% rename from generators/app/cli-options/index.json rename to generators/app/yo-options/index.json diff --git a/generators/app/cli-questions/application.js b/generators/app/yo-questions/application.js similarity index 100% rename from generators/app/cli-questions/application.js rename to generators/app/yo-questions/application.js diff --git a/generators/app/cli-questions/database.js b/generators/app/yo-questions/database.js similarity index 100% rename from generators/app/cli-questions/database.js rename to generators/app/yo-questions/database.js diff --git a/generators/app/cli-questions/miscellaneous.js b/generators/app/yo-questions/miscellaneous.js similarity index 100% rename from generators/app/cli-questions/miscellaneous.js rename to generators/app/yo-questions/miscellaneous.js diff --git a/generators/app/cli-questions/services.js b/generators/app/yo-questions/services.js similarity index 100% rename from generators/app/cli-questions/services.js rename to generators/app/yo-questions/services.js diff --git a/generators/app/run-steps/configuring.js b/generators/app/yo-steps/configuring.js similarity index 100% rename from generators/app/run-steps/configuring.js rename to generators/app/yo-steps/configuring.js diff --git a/generators/app/run-steps/conflicts.js b/generators/app/yo-steps/conflicts.js similarity index 100% rename from generators/app/run-steps/conflicts.js rename to generators/app/yo-steps/conflicts.js diff --git a/generators/app/run-steps/end.js b/generators/app/yo-steps/end.js similarity index 100% rename from generators/app/run-steps/end.js rename to generators/app/yo-steps/end.js diff --git a/generators/app/run-steps/initializing.js b/generators/app/yo-steps/initializing.js similarity index 100% rename from generators/app/run-steps/initializing.js rename to generators/app/yo-steps/initializing.js diff --git a/generators/app/run-steps/install.js b/generators/app/yo-steps/install.js similarity index 100% rename from generators/app/run-steps/install.js rename to generators/app/yo-steps/install.js diff --git a/generators/app/run-steps/prompting.js b/generators/app/yo-steps/prompting.js similarity index 87% rename from generators/app/run-steps/prompting.js rename to generators/app/yo-steps/prompting.js index 7c5bfea0..da0a768d 100644 --- a/generators/app/run-steps/prompting.js +++ b/generators/app/yo-steps/prompting.js @@ -4,10 +4,10 @@ */ var chalk = require('chalk'), - APPLICATION_QUESTIONS = require('../cli-questions/application.js'), - DATABASE_QUESTIONS = require('../cli-questions/database.js'), - MISCELLANEOUS_QUESTIONS = require('../cli-questions/miscellaneous'), - SERVICES_QUESTIONS = require('../cli-questions/services.js'); + APPLICATION_QUESTIONS = require('./application.js'), + DATABASE_QUESTIONS = require('./database.js'), + MISCELLANEOUS_QUESTIONS = require('./miscellaneous'), + SERVICES_QUESTIONS = require('./services.js'); /** * Extend target object with source object diff --git a/generators/app/run-steps/writing.js b/generators/app/yo-steps/writing.js similarity index 100% rename from generators/app/run-steps/writing.js rename to generators/app/yo-steps/writing.js From 4c38f8746d4eceee9567768e2480bc3171407926 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 18:46:55 +0200 Subject: [PATCH 033/118] Cleans up in index --- generators/app/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/generators/app/index.js b/generators/app/index.js index f7d408e0..c4e56568 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -6,18 +6,18 @@ module.exports = yeoman.generators.Base.extend({ yeoman.generators.Base.apply(this, arguments); - Object.keys(options).forEach(function (optionName) { - this.option(optionName, options[optionName]); + Object.keys(options).forEach(function (name) { + this.option(name, options[name]); }.bind(this)); this.config.save(); }, initializing: require('./yo-steps/initializing'), - prompting: require('./yo-steps/prompting.js'), - configuring: require('./yo-steps/configuring.js'), - writing: require('./yo-steps/writing.js'), - conflicts: require('./yo-steps/conflicts.js'), - install: require('./yo-steps/install.js'), - end: require('./yo-steps/end.js') + prompting: require('./yo-steps/prompting'), + configuring: require('./yo-steps/configuring'), + writing: require('./yo-steps/writing'), + conflicts: require('./yo-steps/conflicts'), + install: require('./yo-steps/install'), + end: require('./yo-steps/end') }); From 0edac21aa745409c579d5eb7b12cdaa3d115e7a1 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 18:51:51 +0200 Subject: [PATCH 034/118] Fix questions loading --- generators/app/yo-steps/prompting.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/generators/app/yo-steps/prompting.js b/generators/app/yo-steps/prompting.js index da0a768d..1e33a343 100644 --- a/generators/app/yo-steps/prompting.js +++ b/generators/app/yo-steps/prompting.js @@ -4,10 +4,10 @@ */ var chalk = require('chalk'), - APPLICATION_QUESTIONS = require('./application.js'), - DATABASE_QUESTIONS = require('./database.js'), - MISCELLANEOUS_QUESTIONS = require('./miscellaneous'), - SERVICES_QUESTIONS = require('./services.js'); + APPLICATION_QUESTIONS = require('../yo-questions/application.js'), + DATABASE_QUESTIONS = require('../yo-questions/database.js'), + MISCELLANEOUS_QUESTIONS = require('../yo-questions/miscellaneous'), + SERVICES_QUESTIONS = require('../yo-questions/services.js'); /** * Extend target object with source object From 1137d22e553748ce2c363e6a21f6953de008fd27 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 19:01:30 +0200 Subject: [PATCH 035/118] Fix bug with context in prompting --- generators/app/yo-steps/prompting.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/generators/app/yo-steps/prompting.js b/generators/app/yo-steps/prompting.js index 1e33a343..521e0f41 100644 --- a/generators/app/yo-steps/prompting.js +++ b/generators/app/yo-steps/prompting.js @@ -40,7 +40,7 @@ module.exports = { this.prompt(DATABASE_QUESTIONS, function (answers) { this.answers = _extend(this.answers, answers); done(); - }); + }.bind(this)); }, /** @@ -54,7 +54,7 @@ module.exports = { this.prompt(APPLICATION_QUESTIONS, function (answers) { this.answers = _extend(this.answers, answers); done(); - }); + }.bind(this)); }, /** @@ -68,7 +68,7 @@ module.exports = { this.prompt(SERVICES_QUESTIONS, function (answers) { this.answers = _extend(this.answers, answers); done(); - }); + }.bind(this)); }, /** @@ -82,6 +82,6 @@ module.exports = { this.prompt(MISCELLANEOUS_QUESTIONS, function (answers) { this.answers = _extend(this.answers, answers); done(); - }); + }.bind(this)); } }; From bde6ad7067e571f2617e7ae508c37065b5fa66b0 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 19:05:44 +0200 Subject: [PATCH 036/118] Remove prefix yo from folders name --- generators/app/index.js | 16 ++++++++-------- .../app/{yo-options => options}/index.json | 0 .../{yo-questions => questions}/application.js | 0 .../app/{yo-questions => questions}/database.js | 0 .../{yo-questions => questions}/miscellaneous.js | 0 .../app/{yo-questions => questions}/services.js | 0 .../app/{yo-steps => steps}/configuring.js | 0 generators/app/{yo-steps => steps}/conflicts.js | 0 generators/app/{yo-steps => steps}/end.js | 0 .../app/{yo-steps => steps}/initializing.js | 1 - generators/app/{yo-steps => steps}/install.js | 0 generators/app/{yo-steps => steps}/prompting.js | 8 ++++---- generators/app/{yo-steps => steps}/writing.js | 0 13 files changed, 12 insertions(+), 13 deletions(-) rename generators/app/{yo-options => options}/index.json (100%) rename generators/app/{yo-questions => questions}/application.js (100%) rename generators/app/{yo-questions => questions}/database.js (100%) rename generators/app/{yo-questions => questions}/miscellaneous.js (100%) rename generators/app/{yo-questions => questions}/services.js (100%) rename generators/app/{yo-steps => steps}/configuring.js (100%) rename generators/app/{yo-steps => steps}/conflicts.js (100%) rename generators/app/{yo-steps => steps}/end.js (100%) rename generators/app/{yo-steps => steps}/initializing.js (99%) rename generators/app/{yo-steps => steps}/install.js (100%) rename generators/app/{yo-steps => steps}/prompting.js (87%) rename generators/app/{yo-steps => steps}/writing.js (100%) diff --git a/generators/app/index.js b/generators/app/index.js index c4e56568..278a6bdf 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -2,7 +2,7 @@ var yeoman = require('yeoman-generator'); module.exports = yeoman.generators.Base.extend({ constructor: function () { - var options = require('./yo-options/index'); + var options = require('./options/index'); yeoman.generators.Base.apply(this, arguments); @@ -13,11 +13,11 @@ module.exports = yeoman.generators.Base.extend({ this.config.save(); }, - initializing: require('./yo-steps/initializing'), - prompting: require('./yo-steps/prompting'), - configuring: require('./yo-steps/configuring'), - writing: require('./yo-steps/writing'), - conflicts: require('./yo-steps/conflicts'), - install: require('./yo-steps/install'), - end: require('./yo-steps/end') + initializing: require('./steps/initializing'), + prompting: require('./steps/prompting'), + configuring: require('./steps/configuring'), + writing: require('./steps/writing'), + conflicts: require('./steps/conflicts'), + install: require('./steps/install'), + end: require('./steps/end') }); diff --git a/generators/app/yo-options/index.json b/generators/app/options/index.json similarity index 100% rename from generators/app/yo-options/index.json rename to generators/app/options/index.json diff --git a/generators/app/yo-questions/application.js b/generators/app/questions/application.js similarity index 100% rename from generators/app/yo-questions/application.js rename to generators/app/questions/application.js diff --git a/generators/app/yo-questions/database.js b/generators/app/questions/database.js similarity index 100% rename from generators/app/yo-questions/database.js rename to generators/app/questions/database.js diff --git a/generators/app/yo-questions/miscellaneous.js b/generators/app/questions/miscellaneous.js similarity index 100% rename from generators/app/yo-questions/miscellaneous.js rename to generators/app/questions/miscellaneous.js diff --git a/generators/app/yo-questions/services.js b/generators/app/questions/services.js similarity index 100% rename from generators/app/yo-questions/services.js rename to generators/app/questions/services.js diff --git a/generators/app/yo-steps/configuring.js b/generators/app/steps/configuring.js similarity index 100% rename from generators/app/yo-steps/configuring.js rename to generators/app/steps/configuring.js diff --git a/generators/app/yo-steps/conflicts.js b/generators/app/steps/conflicts.js similarity index 100% rename from generators/app/yo-steps/conflicts.js rename to generators/app/steps/conflicts.js diff --git a/generators/app/yo-steps/end.js b/generators/app/steps/end.js similarity index 100% rename from generators/app/yo-steps/end.js rename to generators/app/steps/end.js diff --git a/generators/app/yo-steps/initializing.js b/generators/app/steps/initializing.js similarity index 99% rename from generators/app/yo-steps/initializing.js rename to generators/app/steps/initializing.js index bd25f0cc..53d46fbe 100644 --- a/generators/app/yo-steps/initializing.js +++ b/generators/app/steps/initializing.js @@ -1,7 +1,6 @@ /** * Step 1 * Your initialization methods (checking current project state, getting configs, etc) - * @type {Object} */ var chalk = require('chalk'), diff --git a/generators/app/yo-steps/install.js b/generators/app/steps/install.js similarity index 100% rename from generators/app/yo-steps/install.js rename to generators/app/steps/install.js diff --git a/generators/app/yo-steps/prompting.js b/generators/app/steps/prompting.js similarity index 87% rename from generators/app/yo-steps/prompting.js rename to generators/app/steps/prompting.js index 521e0f41..42aa4780 100644 --- a/generators/app/yo-steps/prompting.js +++ b/generators/app/steps/prompting.js @@ -4,10 +4,10 @@ */ var chalk = require('chalk'), - APPLICATION_QUESTIONS = require('../yo-questions/application.js'), - DATABASE_QUESTIONS = require('../yo-questions/database.js'), - MISCELLANEOUS_QUESTIONS = require('../yo-questions/miscellaneous'), - SERVICES_QUESTIONS = require('../yo-questions/services.js'); + APPLICATION_QUESTIONS = require('../questions/application.js'), + DATABASE_QUESTIONS = require('../questions/database.js'), + MISCELLANEOUS_QUESTIONS = require('../questions/miscellaneous'), + SERVICES_QUESTIONS = require('../questions/services.js'); /** * Extend target object with source object diff --git a/generators/app/yo-steps/writing.js b/generators/app/steps/writing.js similarity index 100% rename from generators/app/yo-steps/writing.js rename to generators/app/steps/writing.js From ce75ba9a99e5fc3012822d6159beac34f6fbb86d Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 19:09:09 +0200 Subject: [PATCH 037/118] Fix bug with chalk undefined --- generators/app/steps/install.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/generators/app/steps/install.js b/generators/app/steps/install.js index b505e6fb..d2c4fb15 100644 --- a/generators/app/steps/install.js +++ b/generators/app/steps/install.js @@ -3,6 +3,8 @@ * Where installation are run (npm, bower) */ +var chalk = require('chalk'); + module.exports = { /** * Install npm dependencies From 79492cbf7b60f327a8281d4f99db30b178bf3598 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 19:28:56 +0200 Subject: [PATCH 038/118] Move extend to util --- generators/app/steps/prompting.js | 28 +++++----------------------- generators/app/util/extend.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 23 deletions(-) create mode 100644 generators/app/util/extend.js diff --git a/generators/app/steps/prompting.js b/generators/app/steps/prompting.js index 42aa4780..4424e4ce 100644 --- a/generators/app/steps/prompting.js +++ b/generators/app/steps/prompting.js @@ -4,30 +4,12 @@ */ var chalk = require('chalk'), + extend = require('../util/extend'), APPLICATION_QUESTIONS = require('../questions/application.js'), DATABASE_QUESTIONS = require('../questions/database.js'), MISCELLANEOUS_QUESTIONS = require('../questions/miscellaneous'), SERVICES_QUESTIONS = require('../questions/services.js'); -/** - * Extend target object with source object - * @param {Object} _target Target object - * @param {Object} _source Source object - * @returns {Object} - * @private - */ -function _extend(_target, _source) { - var target = _target || {}, - source = _source || {}, - keys = Object.keys(source); - - for (var i = 0; i < keys.length; i++) { - target[keys[i]] = source[keys[i]]; - } - - return target; -} - module.exports = { /** * Ask database questions @@ -38,7 +20,7 @@ module.exports = { this.log(chalk.yellow("\nDatabase questions:")); this.prompt(DATABASE_QUESTIONS, function (answers) { - this.answers = _extend(this.answers, answers); + this.answers = extend(this.answers, answers); done(); }.bind(this)); }, @@ -52,7 +34,7 @@ module.exports = { this.log(chalk.yellow("\nApplication questions:")); this.prompt(APPLICATION_QUESTIONS, function (answers) { - this.answers = _extend(this.answers, answers); + this.answers = extend(this.answers, answers); done(); }.bind(this)); }, @@ -66,7 +48,7 @@ module.exports = { this.log(chalk.yellow("\nService questions:")); this.prompt(SERVICES_QUESTIONS, function (answers) { - this.answers = _extend(this.answers, answers); + this.answers = extend(this.answers, answers); done(); }.bind(this)); }, @@ -80,7 +62,7 @@ module.exports = { this.log(chalk.yellow("\nMiscellaneous questions:")); this.prompt(MISCELLANEOUS_QUESTIONS, function (answers) { - this.answers = _extend(this.answers, answers); + this.answers = extend(this.answers, answers); done(); }.bind(this)); } diff --git a/generators/app/util/extend.js b/generators/app/util/extend.js new file mode 100644 index 00000000..3e8e9d67 --- /dev/null +++ b/generators/app/util/extend.js @@ -0,0 +1,17 @@ +/** + * Extend target object with source object + * @param {Object} _target Target object + * @param {Object} _source Source object + * @returns {Object} + */ +module.exports = function extend(_target, _source) { + var target = _target || {}, + source = _source || {}, + keys = Object.keys(source); + + for (var i = 0; i < keys.length; i++) { + target[keys[i]] = source[keys[i]]; + } + + return target; +}; From 7fd28620e82764b3a72f1211922bdb027acb8afc Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 19:51:17 +0200 Subject: [PATCH 039/118] Implement require-folder in util --- generators/app/steps/prompting.js | 18 +++++++++--------- generators/app/util/require-folder.js | 12 ++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 generators/app/util/require-folder.js diff --git a/generators/app/steps/prompting.js b/generators/app/steps/prompting.js index 4424e4ce..34f65683 100644 --- a/generators/app/steps/prompting.js +++ b/generators/app/steps/prompting.js @@ -3,14 +3,14 @@ * Where you prompt users for options (where you'd call this.prompt()) */ -var chalk = require('chalk'), +var path = require('path'), + chalk = require('chalk'), extend = require('../util/extend'), - APPLICATION_QUESTIONS = require('../questions/application.js'), - DATABASE_QUESTIONS = require('../questions/database.js'), - MISCELLANEOUS_QUESTIONS = require('../questions/miscellaneous'), - SERVICES_QUESTIONS = require('../questions/services.js'); + requireFolder = require('../util/require-folder'), + questions = requireFolder(path.resolve(__dirname, '../questions')); module.exports = { + // TODO: write auto loading of questions /** * Ask database questions */ @@ -19,7 +19,7 @@ module.exports = { this.log(chalk.yellow("\nDatabase questions:")); - this.prompt(DATABASE_QUESTIONS, function (answers) { + this.prompt(questions.database, function (answers) { this.answers = extend(this.answers, answers); done(); }.bind(this)); @@ -33,7 +33,7 @@ module.exports = { this.log(chalk.yellow("\nApplication questions:")); - this.prompt(APPLICATION_QUESTIONS, function (answers) { + this.prompt(questions.application, function (answers) { this.answers = extend(this.answers, answers); done(); }.bind(this)); @@ -47,7 +47,7 @@ module.exports = { this.log(chalk.yellow("\nService questions:")); - this.prompt(SERVICES_QUESTIONS, function (answers) { + this.prompt(questions.services, function (answers) { this.answers = extend(this.answers, answers); done(); }.bind(this)); @@ -61,7 +61,7 @@ module.exports = { this.log(chalk.yellow("\nMiscellaneous questions:")); - this.prompt(MISCELLANEOUS_QUESTIONS, function (answers) { + this.prompt(questions.miscellaneous, function (answers) { this.answers = extend(this.answers, answers); done(); }.bind(this)); diff --git a/generators/app/util/require-folder.js b/generators/app/util/require-folder.js new file mode 100644 index 00000000..e5118c77 --- /dev/null +++ b/generators/app/util/require-folder.js @@ -0,0 +1,12 @@ +var fs = require('fs'); + +module.exports = function requireFolder(dirname) { + var files = fs.readdirSync(dirname), + modules = {}; + + files.forEach(function (file) { + modules[file.replace('.js', '')] = require(dirname + '/' + file); + }); + + return modules; +}; From c6dbceb8f5833704a04274283042fb0735a44500 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 26 Feb 2015 19:53:04 +0200 Subject: [PATCH 040/118] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4b34fff..d16b0803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Edge version - Improvement: Frozen structure of generator and project. Any serious changes in project structure; +- Improvement: Split CLI options, questions and steps to separate modules, so generator is more maintainable; - Improvement: Cleaning up in questions and split out them to sections; ## Version 0.5.1 From 74c1f8a4405fad61ebbfb3a1ad2f03ad3a236688 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 14:47:36 +0200 Subject: [PATCH 041/118] Rename extend to assign --- generators/app/steps/prompting.js | 10 +++++----- generators/app/util/{extend.js => assign.js} | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) rename generators/app/util/{extend.js => assign.js} (87%) diff --git a/generators/app/steps/prompting.js b/generators/app/steps/prompting.js index 34f65683..b80ac617 100644 --- a/generators/app/steps/prompting.js +++ b/generators/app/steps/prompting.js @@ -5,7 +5,7 @@ var path = require('path'), chalk = require('chalk'), - extend = require('../util/extend'), + assign = require('../util/assign'), requireFolder = require('../util/require-folder'), questions = requireFolder(path.resolve(__dirname, '../questions')); @@ -20,7 +20,7 @@ module.exports = { this.log(chalk.yellow("\nDatabase questions:")); this.prompt(questions.database, function (answers) { - this.answers = extend(this.answers, answers); + this.answers = assign(this.answers, answers); done(); }.bind(this)); }, @@ -34,7 +34,7 @@ module.exports = { this.log(chalk.yellow("\nApplication questions:")); this.prompt(questions.application, function (answers) { - this.answers = extend(this.answers, answers); + this.answers = assign(this.answers, answers); done(); }.bind(this)); }, @@ -48,7 +48,7 @@ module.exports = { this.log(chalk.yellow("\nService questions:")); this.prompt(questions.services, function (answers) { - this.answers = extend(this.answers, answers); + this.answers = assign(this.answers, answers); done(); }.bind(this)); }, @@ -62,7 +62,7 @@ module.exports = { this.log(chalk.yellow("\nMiscellaneous questions:")); this.prompt(questions.miscellaneous, function (answers) { - this.answers = extend(this.answers, answers); + this.answers = assign(this.answers, answers); done(); }.bind(this)); } diff --git a/generators/app/util/extend.js b/generators/app/util/assign.js similarity index 87% rename from generators/app/util/extend.js rename to generators/app/util/assign.js index 3e8e9d67..ddc11db4 100644 --- a/generators/app/util/extend.js +++ b/generators/app/util/assign.js @@ -4,7 +4,7 @@ * @param {Object} _source Source object * @returns {Object} */ -module.exports = function extend(_target, _source) { +module.exports = function assign(_target, _source) { var target = _target || {}, source = _source || {}, keys = Object.keys(source); From dc40b67c19fe099ea240e9a3778a9983a36e9017 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 14:56:08 +0200 Subject: [PATCH 042/118] Replace forEach with for loop --- generators/app/util/require-folder.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/generators/app/util/require-folder.js b/generators/app/util/require-folder.js index e5118c77..75daea6d 100644 --- a/generators/app/util/require-folder.js +++ b/generators/app/util/require-folder.js @@ -1,12 +1,17 @@ var fs = require('fs'); -module.exports = function requireFolder(dirname) { - var files = fs.readdirSync(dirname), +/** + * Require all files within folder + * @param {String} dirName Directory name + * @returns {Object} + */ +module.exports = function requireFolder(dirName) { + var files = fs.readdirSync(dirName), modules = {}; - files.forEach(function (file) { - modules[file.replace('.js', '')] = require(dirname + '/' + file); - }); + for (var i = 0; i < files.length; i++) { + modules[files[i].replace('.js', '')] = require(dirName + '/' + files[i]); + } return modules; }; From f2cb912e6330e4a952db4042254208f6bbf5a353 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 14:56:46 +0200 Subject: [PATCH 043/118] Fix test --- test/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/app.js b/test/app.js index 25fc5f68..7bb8e4ce 100644 --- a/test/app.js +++ b/test/app.js @@ -5,7 +5,7 @@ var path = require('path'), describe('sails-rest-api:app', function () { before(function (done) { - helpers.run(path.join(__dirname, '../app')) + helpers.run(path.join(__dirname, '../generators/app')) .inDir(path.join(os.tmpdir(), './temp-test')) .withOptions({"skip-all": true}) .on('end', done); From 3acb204a04b77e3cf0ea09e523921c7bec602629 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 15:22:32 +0200 Subject: [PATCH 044/118] Remove TODO from changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d16b0803..b7b2523b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,7 +49,7 @@ - Improvement: Frozen stability of the whole project, so work is going only in `services`, `test` and `doc` folder; - Improvement: Add blank tests for each `controllers`, `models`, `policies`, `responses`, `services`; -- Improvement: Each test case named **TODO: write this test** as reminder and include `assert(true)`; +- Improvement: Each test case named **write this test** as reminder and include `assert(true)`; - Improvement: Add JSON Web Token as part of `CipherService`; - Improvement: Support for `skip-install` flag. You can skip `npm install` executing; - Improvement: Add `customMiddleware` support in `config/http.js`; From 9454c7d1b950e66b4bc6925840ee7f8cdb48e86d Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 15:38:35 +0200 Subject: [PATCH 045/118] Small fixes in update-deps --- CHANGELOG.md | 1 + generators/app/templates/tools/update-deps.js | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7b2523b..2c68269b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Improvement: Frozen structure of generator and project. Any serious changes in project structure; - Improvement: Split CLI options, questions and steps to separate modules, so generator is more maintainable; - Improvement: Cleaning up in questions and split out them to sections; +- Improvement: Add options to `update-deps.js` tool; ## Version 0.5.1 diff --git a/generators/app/templates/tools/update-deps.js b/generators/app/templates/tools/update-deps.js index a8563e20..4d4f9e84 100644 --- a/generators/app/templates/tools/update-deps.js +++ b/generators/app/templates/tools/update-deps.js @@ -1,14 +1,21 @@ #!/usr/bin/env node -var npmCheck = require('npm-check'), - update = require('npm-check/lib/update'), - chalk = require('chalk'); +var chalk = require('chalk'), + npmCheck = require('npm-check'), + update = require('npm-check/lib/update'); -console.log(chalk.yellow("\nStart checking package.json for updates, please wait...\n")); +console.log(chalk.yellow("Start checking package.json for updates, please wait...")); npmCheck({ - update: true + global: false, + update: true, + skipUnused: false, + ignoreDev: false, + path: process.cwd(), + debug: true }).then(function (data) { - // TODO: expand with more params to update() - update(data, {}); + update(data, {debug: false}); +}).catch(function (error) { + console.error(error.stack || error); + process.exit(1); }).done(); From 2fb47ea01ff2235c2b5c046a113166fdc05173df Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 15:46:28 +0200 Subject: [PATCH 046/118] Rename update-deps to check-updates --- CHANGELOG.md | 2 +- generators/app/steps/end.js | 2 +- .../app/templates/tools/{update-deps.js => check-updates.js} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename generators/app/templates/tools/{update-deps.js => check-updates.js} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c68269b..ba9a9bd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - Improvement: Frozen structure of generator and project. Any serious changes in project structure; - Improvement: Split CLI options, questions and steps to separate modules, so generator is more maintainable; - Improvement: Cleaning up in questions and split out them to sections; -- Improvement: Add options to `update-deps.js` tool; +- Improvement: Add options to `check-updates.js` tool; ## Version 0.5.1 diff --git a/generators/app/steps/end.js b/generators/app/steps/end.js index 5d05cd5a..d9269078 100644 --- a/generators/app/steps/end.js +++ b/generators/app/steps/end.js @@ -17,7 +17,7 @@ module.exports = { this.log(chalk.yellow("Starting diagnostic, please wait...")); this.spawnCommand('node', ['tools/fix-deps.js']).on('close', function () { - this.spawnCommand('node', ['tools/update-deps.js']).on('close', done); + this.spawnCommand('node', ['tools/check-updates.js']).on('close', done); }.bind(this)); } }, diff --git a/generators/app/templates/tools/update-deps.js b/generators/app/templates/tools/check-updates.js similarity index 100% rename from generators/app/templates/tools/update-deps.js rename to generators/app/templates/tools/check-updates.js From 544c8472cc4e6f0024d986d85d8265ebbaea3719 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 16:35:07 +0200 Subject: [PATCH 047/118] Make colorful print out --- generators/app/templates/tools/fix-deps.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/generators/app/templates/tools/fix-deps.js b/generators/app/templates/tools/fix-deps.js index 6d05fda1..40c57b85 100644 --- a/generators/app/templates/tools/fix-deps.js +++ b/generators/app/templates/tools/fix-deps.js @@ -7,11 +7,11 @@ var path = require('path'), checkDependencies = require('dependency-check'), recursive = require('recursive-readdir'); -console.log(chalk.yellow("\nStart fixing package.json, please wait...\n")); +console.log(chalk.yellow("Start fixing package.json, please wait...")); recursive('./', ['node_modules'], function (error, files) { if (error) { - console.error(error); + console.error(error.stack || error); return process.exit(1); } @@ -24,7 +24,7 @@ recursive('./', ['node_modules'], function (error, files) { entries: files }, function (error, data) { if (error) { - console.error(error); + console.error(error.stack || error); return process.exit(1); } @@ -66,9 +66,7 @@ recursive('./', ['node_modules'], function (error, files) { marginBottom: 0 }); - var npmInstall = spawn('npm', ['install', '--save'].concat(missingDependencies)); - - // TODO: make colorful piping + var npmInstall = spawn('npm', ['install', '--save', '--color', 'always'].concat(missingDependencies)); npmInstall.stdout.pipe(process.stdout); npmInstall.stderr.pipe(process.stderr); npmInstall.on('close', process.exit); From 3004ec62a6342b9da19542a2f8a102279fce7742 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 16:42:17 +0200 Subject: [PATCH 048/118] Add tools to npm scripts --- generators/app/templates/package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/generators/app/templates/package.json b/generators/app/templates/package.json index b7407064..3823d4dd 100644 --- a/generators/app/templates/package.json +++ b/generators/app/templates/package.json @@ -15,6 +15,8 @@ "scripts": { "start": "node app.js", "debug": "node debug app.js", - "test": "mocha --recursive" + "test": "mocha --recursive", + "check-updates": "node ./tools/check-updates.js", + "fix-deps": "node ./tools/fix-deps.js" } } From db36204e5b799203b3e185fa4ad390dd0dab4eb0 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 16:43:52 +0200 Subject: [PATCH 049/118] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba9a9bd7..cf30727b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - Improvement: Split CLI options, questions and steps to separate modules, so generator is more maintainable; - Improvement: Cleaning up in questions and split out them to sections; - Improvement: Add options to `check-updates.js` tool; +- Improvement: Add tools to npm scripts, so you can call `npm run-script check-updates` now; +- Fix: Bug with no colorful print in `fix-deps.js`; ## Version 0.5.1 From cbf836256a8f88d35059cb1bc6fa1ec422dc9bf6 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 16:48:27 +0200 Subject: [PATCH 050/118] Fix bug with total count when get records --- CHANGELOG.md | 1 + generators/app/templates/api/blueprints/find.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf30727b..4b45d2b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Improvement: Add options to `check-updates.js` tool; - Improvement: Add tools to npm scripts, so you can call `npm run-script check-updates` now; - Fix: Bug with no colorful print in `fix-deps.js`; +- Fix: Bug when returns total count of records even with `where` criteria; ## Version 0.5.1 diff --git a/generators/app/templates/api/blueprints/find.js b/generators/app/templates/api/blueprints/find.js index aad348bd..355992a2 100644 --- a/generators/app/templates/api/blueprints/find.js +++ b/generators/app/templates/api/blueprints/find.js @@ -27,7 +27,7 @@ module.exports = function (req, res) { } Model - .count() + .count(where) .exec(function (error, count) { if (error) { return res.serverError(error); @@ -41,8 +41,8 @@ module.exports = function (req, res) { criteria: where }; - // TODO: improve with more data in headers and more correct metainfo res.set('Content-Range', metaInfo.start + '-' + metaInfo.end + '/' + metaInfo.total); + return res.ok(records, null, null, metaInfo); }); }); From 02bb93999e2adfb66e8df813456cb46032e0592c Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 16:54:21 +0200 Subject: [PATCH 051/118] Remove todo --- generators/app/templates/api/models/User.js | 5 ----- generators/app/templates/config/passport.js | 1 - 2 files changed, 6 deletions(-) diff --git a/generators/app/templates/api/models/User.js b/generators/app/templates/api/models/User.js index 25b12913..0489636b 100644 --- a/generators/app/templates/api/models/User.js +++ b/generators/app/templates/api/models/User.js @@ -67,11 +67,6 @@ module.exports = { } }, - beforeValidate: function (values, next) { - // TODO: maybe here we need put duplicate checking - next(); - }, - beforeUpdate: function (values, next) { if (values.password) { values.password = CipherService.create('bcrypt', values.password).hashSync(); diff --git a/generators/app/templates/config/passport.js b/generators/app/templates/config/passport.js index 544478a8..d9a3f80e 100644 --- a/generators/app/templates/config/passport.js +++ b/generators/app/templates/config/passport.js @@ -3,7 +3,6 @@ * @description :: Configuration file where you configure your passport authentication */ -// TODO: add more strategies var passport = require('passport'), LocalStrategy = require('passport-local').Strategy, JwtStrategy = require('passport-jwt').Strategy, From 196a61c379c700fda3b92081132eda7e668d6183 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 16:59:59 +0200 Subject: [PATCH 052/118] Update roadmap --- ROADMAP.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index b0fe687d..f9b90f4c 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -13,9 +13,8 @@ ## Next minor version - [x] Freeze architecture (only bug-fixes and adding new features); +- [x] Add questions list where you can choose which service need to include; - [ ] Improve stability (too much new features is appears in previous version); -- [ ] Make swagger documentation as part of Sails generator; -- [ ] Add questions list where you can choose which service need to include and copy only needed; ## Version 0.5.0 (released) From 7d0ff226d16592cac1f3750c1aaeb9c20fac994b Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 17:09:17 +0200 Subject: [PATCH 053/118] Replace spawn node with npm --- generators/app/steps/end.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generators/app/steps/end.js b/generators/app/steps/end.js index d9269078..17a3d6ba 100644 --- a/generators/app/steps/end.js +++ b/generators/app/steps/end.js @@ -16,8 +16,8 @@ module.exports = { this.log(chalk.yellow("Starting diagnostic, please wait...")); - this.spawnCommand('node', ['tools/fix-deps.js']).on('close', function () { - this.spawnCommand('node', ['tools/check-updates.js']).on('close', done); + this.spawnCommand('npm', ['run-script', 'fix-deps']).on('close', function () { + this.spawnCommand('npm', ['run-script', 'check-updates']).on('close', done); }.bind(this)); } }, From c4dfeaebb66615bb48692acff73e374d4a48fcc2 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 17:10:16 +0200 Subject: [PATCH 054/118] Replace relative path with resolve --- generators/app/steps/initializing.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/generators/app/steps/initializing.js b/generators/app/steps/initializing.js index 53d46fbe..a3043c89 100644 --- a/generators/app/steps/initializing.js +++ b/generators/app/steps/initializing.js @@ -3,7 +3,8 @@ * Your initialization methods (checking current project state, getting configs, etc) */ -var chalk = require('chalk'), +var path = require('path'), + chalk = require('chalk'), updateNotifier = require('update-notifier'), printMessage = require('print-message'), yosay = require('yosay'); @@ -13,7 +14,7 @@ module.exports = { * Load package.json */ loadPackageInfo: function () { - this.pkg = require('../../../package.json'); + this.pkg = require(path.resolve(__dirname, '../../../package.json')); }, /** From a48f3582c53fb94a936657fff9bc1e4ba63cb53f Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 17:25:36 +0200 Subject: [PATCH 055/118] Add color always to installing step --- generators/app/steps/install.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/generators/app/steps/install.js b/generators/app/steps/install.js index d2c4fb15..25ffa27c 100644 --- a/generators/app/steps/install.js +++ b/generators/app/steps/install.js @@ -12,7 +12,9 @@ module.exports = { installNpmDependencies: function () { if (!(this.options['skip-project-install'] || this.options["skip-all"])) { this.log(chalk.yellow("Start installing npm dependencies, please wait...")); - this.npmInstall(); + this.npmInstall([], { + color: "always" + }); } } }; From 3ca234039233d9b998818b395500fbeae9683762 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 17:26:14 +0200 Subject: [PATCH 056/118] Remove todo --- generators/app/steps/prompting.js | 1 - 1 file changed, 1 deletion(-) diff --git a/generators/app/steps/prompting.js b/generators/app/steps/prompting.js index b80ac617..582a38f7 100644 --- a/generators/app/steps/prompting.js +++ b/generators/app/steps/prompting.js @@ -10,7 +10,6 @@ var path = require('path'), questions = requireFolder(path.resolve(__dirname, '../questions')); module.exports = { - // TODO: write auto loading of questions /** * Ask database questions */ From 532fe08c042ba8d93265427a15d63853a0dcdefb Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 17:27:08 +0200 Subject: [PATCH 057/118] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b45d2b7..69d7b50f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Improvement: Add options to `check-updates.js` tool; - Improvement: Add tools to npm scripts, so you can call `npm run-script check-updates` now; - Fix: Bug with no colorful print in `fix-deps.js`; +- Fix: Bug with no colorful print in installing step in generator; - Fix: Bug when returns total count of records even with `where` criteria; ## Version 0.5.1 From 867a750c808847352077cf89f9dccab4a127d29c Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Fri, 27 Feb 2015 18:22:41 +0200 Subject: [PATCH 058/118] Change log level --- CHANGELOG.md | 1 + generators/app/templates/config/env/production.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69d7b50f..83e6c56b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Fix: Bug with no colorful print in `fix-deps.js`; - Fix: Bug with no colorful print in installing step in generator; - Fix: Bug when returns total count of records even with `where` criteria; +- Fix: Change log level info to `info` in production mode; ## Version 0.5.1 diff --git a/generators/app/templates/config/env/production.js b/generators/app/templates/config/env/production.js index 475b13da..65dfd115 100644 --- a/generators/app/templates/config/env/production.js +++ b/generators/app/templates/config/env/production.js @@ -6,6 +6,6 @@ module.exports = { port: 80, log: { - level: "silent" + level: "info" } }; From 3ee013455fdb8f76f58e6961c826b2491b6ad522 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 12:51:02 +0200 Subject: [PATCH 059/118] Change descriptions to options --- generators/app/options/index.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/generators/app/options/index.json b/generators/app/options/index.json index 519573f5..d2849fa3 100644 --- a/generators/app/options/index.json +++ b/generators/app/options/index.json @@ -1,30 +1,30 @@ { "skip-generator-update": { - "desc": "Skip checking for generator updates on running", + "desc": "Do not check for generator updates", "type": "Boolean", "defaults": false, "hide": false }, "skip-generator-welcome": { - "desc": "Skip saying welcome when generator is running", + "desc": "Do not welcome at start", "type": "Boolean", "defaults": false, "hide": false }, "skip-project-install": { - "desc": "Skip installing npm dependencies in project", + "desc": "Do not install npm dependencies", "type": "Boolean", "defaults": false, "hide": false }, "skip-project-diagnostic": { - "desc": "Skip running diagnostic tools in project", + "desc": "Do not run diagnostic tools", "type": "Boolean", "defaults": false, "hide": false }, "skip-all": { - "desc": "Skip everything, just project scaffolding", + "desc": "Do nothing, just project scaffolding", "type": "Boolean", "defaults": false, "hide": false From cfe01ed0a7faaa36ba854cf01d67aa1d1b2eb9ff Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 12:57:29 +0200 Subject: [PATCH 060/118] Add description to generator --- generators/app/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/generators/app/index.js b/generators/app/index.js index 278a6bdf..29c13fa1 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -2,9 +2,11 @@ var yeoman = require('yeoman-generator'); module.exports = yeoman.generators.Base.extend({ constructor: function () { + yeoman.generators.Base.apply(this, arguments); + var options = require('./options/index'); - yeoman.generators.Base.apply(this, arguments); + this.description = "Yeoman generator for scaffolding Sails REST API with predefined features"; Object.keys(options).forEach(function (name) { this.option(name, options[name]); From 645015e7e54ea287bac0dcdc1b142e25babf69c9 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 13:26:08 +0200 Subject: [PATCH 061/118] Update description with more detailed description --- generators/app/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/app/index.js b/generators/app/index.js index 29c13fa1..c70d70d0 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -6,7 +6,7 @@ module.exports = yeoman.generators.Base.extend({ var options = require('./options/index'); - this.description = "Yeoman generator for scaffolding Sails REST API with predefined features"; + this.description = "Yeoman generator that provides already configured and optimized Sails REST API with bundle of predefined features"; Object.keys(options).forEach(function (name) { this.option(name, options[name]); From 012d31f534a5d259254bd923529c5f5c37fd2d58 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 13:38:30 +0200 Subject: [PATCH 062/118] Update roadmap --- ROADMAP.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ROADMAP.md b/ROADMAP.md index f9b90f4c..7af4072d 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -9,12 +9,17 @@ - [ ] Add `Twitter`, `VK`, `Google +` Social; - [ ] Add `Local` Storage; - [ ] Test coverage for all `api` files; +- [ ] Implement search on top of `find` blueprint; +- [ ] Implement pluralized form only for REST models; ## Next minor version +- [ ] Improve stability (too much new features is appears in previous version); +- [ ] Implement converting camelCase attributes to snake_case in HTTP response; +- [ ] Make global error codes for API with description and how fix it; +- [ ] Add aliases to common operation (for instance, `v1/user/recently_registered`; - [x] Freeze architecture (only bug-fixes and adding new features); - [x] Add questions list where you can choose which service need to include; -- [ ] Improve stability (too much new features is appears in previous version); ## Version 0.5.0 (released) From 83e5e0481e00cf40f2b5d31c647193d5c77e8e25 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 14:48:08 +0200 Subject: [PATCH 063/118] Add contributing file --- CONTRIBUTING.md | 176 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..5ca2d4c7 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,176 @@ +# Contributing + +At this page we explain how you can contribute to our project. + +## Branch explanation + +Our repository has two main branches: + +1. [master](https://github.com/ghaiklor/generator-sails-rest-api/tree/master "Master Branch") +2. [dev](https://github.com/ghaiklor/generator-sails-rest-api/tree/dev "Development Branch") + +All stable releases will merge into `master` branch. +So if you want get and use last stable release ready for production - use `master` branch. + +But, of course, you can use edge version and check out our latest features. +They are may be unstable and not tested, so they are not ready for production. +All those changes and features will merge into `dev` branch. + +Other branches it's only helper branches which can close at any time. +In general we have 3 types of branches: + ++ Feature branches; ++ Release branches; ++ Hotfix branches; + +Advanced description you will read below in "Git workflow" section. + +## Get the project + +### Clone repository + +Clone repository to your computer. + +```bash +git clone https://github.com/ghaiklor/generator-sails-rest-api.git # via HTTPS +git clone git@github.com:ghaiklor/generator-sails-rest-api.git # via SSH +``` + +### Install dependencies + +We are using `npm` for manage dependencies. +So all development dependencies is declared into `package.json` and you can install it simply call `npm install`. + +```bash +cd generator-sails-rest-api +npm install +``` + +### Run generator-sails-rest-api locally + +When you clone the repository, you can link this repository as global npm module in your system. +Then check if this linked up by executing `npm -g list --depth=0`. +If everything is correct, you will see path to your cloned repository. +After linking, you can call `yo sails-rest-api` and run generator locally. + +```bash +git clone https://github.com/ghaiklor/generator-sails-rest-api.git +cd generator-sails-rest-api +sudo npm link +yo sails-rest-api +``` + +## Tests + +We are using Mocha for testing. +All test cases located into `test` folder and split like source files split. +For every file in `api/` folder we create appropriate in `test/` folder. + +When you create new feature or fix some bug, you **MUST** write test case for it in `test` folder. +For example, you add new feature to `api/services/cipher/BCryptCipher.js`. +After that you need modify `test/services/cipher/BCryptCipher.js` for corresponds to new feature. + +For run tests just call `npm test`. + +## Git workflow + +We are using git workflow, which are nice described [here in Russian](http://habrahabr.ru/post/106912/ "Thanks to Андрей Хитрин aka zloddey") and [here in English](http://nvie.com/posts/a-successful-git-branching-model/ "Thanks to Vincent Driessen"). + +In general, we are using `master` branch for stable releases (and ONLY stable releases) and `dev` branch for development purposes. + +### Feature/bug branches + +Let's say you want realize new feature or fix something. +You **MUST** checkout to new branch from `dev` branch. +Created branch **MUST** have name that begins with **feature-...** or **bug-...**. +This name conventions simplify work with many branches and we can got what exactly each branch doing. +When you finish with branch, manually merge feature-branch into `dev`. + +```bash +git checkout dev # Checkout to dev branch +git pull # Update dev branch changes + +git checkout -b feature-awesome # Create new feature branch +git commit -am "Commit 1" # Commit changes +git commit -am "Commit 2" # Last commit + +git checkout dev # Switch back to dev branch +git pull # Update last changes in dev + +git merge feature-awesome # Merge your changes into dev branch + +git branch -d feature-awesome # And you can delete old branch +git push -u origin dev # Push changes to origin server +``` + +**_Note_**: If you don't have rights for push\merge into `dev`, create pull request and we accept it ourselves. + +### Release branches + +When we decide that `dev` branch is ready for release, we are create new branch with **release-...** prefix. +In this branch we update metadata and fix **ONLY** bugs. +When release branch will proceed all last checks and tests, we merge release branch into `master` and `dev`. +And add tag in `master` branch with appropriate release version. + +```bash +git checkout dev # Switch to development branch +git pull # Get last changes + +git checkout -b release-1.2.0 # Create new release branch + +git commit -am "Release version v1.2.0" # Commit changes into release branch +git commit -am "Allows make small changes" # Maybe small changes + +git checkout master # Switch to master branch +git merge release-1.2.0 # Merge release branch into master +git tag -a "v1.2.0" master # Add a tag to release commit in master branch + +git checkout dev # Switch to dev branch +git merge release-1.2.0 # Merge release changes to dev branch + +git branch -d release-1.2.0 # Remove unused release branch + +git push -u origin --all # And push all to origin server +git push -u origin --tags # With tags too +``` + +### Hotfix branches + +When some seriously error or bug occurs into stable release (`master`) we make hotfix branch. +Hotfix branch **MUST** begins with **hotfix-...** prefix. +After fixes we merge hotfix branch into `master` and `dev`. +Also increment patch version and publish this hotfix as new version. + +```bash +git checkout master # Switch to master branch +git checkout -b hotfix-1.2.1 # Create new hotfix branch + +git commit -am "Fix for something" # Critical bugs fixes +git commit -am "Bumped version and build" # Last commit + +git checkout master # Switch back to master branch +git merge hotfix-1.2.1 # Merge hotfix branch +git tag -a "v1.2.1" master # Add tag to this commit + +git checkout dev # Switch to dev branch +git merge hotfix-1.2.1 # Apply fixes to dev branch too + +git branch -d hotfix-1.2.1 # Remove hotfix branch +git push -u origin --all # Push all changes to origin server +git push -u origin --tags # And push tags to origin server +``` + +## Versions + +We are using "Semantic Versioning". +You can find rules how to use it [here](http://semver.org/). + +In general, 4 types of version exists: + +1. Pre-release -> `v1.2.3-4`. Pre-release changes only builds number after `-`. I.e `v1.2.3-4` -> `v1.2.3-5`. + +2. Patch -> `v1.2.3`. Patch version changes only patch version at the end and remove builds number. I.e. `v1.2.3-5` -> `v1.2.3` -> `v1.2.4`. + +3. Minor -> `v1.3.0`. Minor version changes second number in version and reset patch version and prerelease version. I.e. `v1.2.4` -> `v1.3.0`. + +4. Major -> `v2.0.0`. Major version changes first number in version and reset all other versions. I.e. `v1.3.0` -> `v2.0.0`. From d51dcf6602f028b5aa6cd1981b5730e4a1b832c3 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 14:52:44 +0200 Subject: [PATCH 064/118] Update readme --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eaa70d42..e747bc5b 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,11 @@ node app.js Congratulations, you just have setup your first Sails REST API :+1: -## ready-2-use services +## How to use project code? + +_TODO:_ Fill with information. But you can read more at our [wiki page](https://github.com/ghaiklor/generator-sails-rest-api/wiki/How-to-use) + +## Bundled Sails services | Service Name | Implemented providers | |:--------------:|:------------------------------------------------:| From f2683fec4e2f381ca0294a6de8873c5c32d5dca2 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 14:55:09 +0200 Subject: [PATCH 065/118] Update package.json --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index db3ddd73..75fa46fd 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,16 @@ { "name": "generator-sails-rest-api", "version": "0.5.1", - "description": "Yeoman generator for scaffolding Sails REST API with bundled ready-2-use services", + "description": "Yeoman generator that provides already configured and optimized Sails REST API with bundle of predefined features.", "keywords": [ "yeoman-generator", - "yeoman", - "generator", + "sails", "boilerplate", "scaffolder", - "sails", "rest", - "api" + "api", + "yeoman", + "generator" ], "homepage": "https://github.com/ghaiklor/generator-sails-rest-api", "bugs": { From a8f4ca9d7b6d9197ed37ca3b8b2141d3618d76d3 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 15:08:50 +0200 Subject: [PATCH 066/118] Update contributing --- CONTRIBUTING.md | 63 ++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5ca2d4c7..8e69bb70 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,28 +2,10 @@ At this page we explain how you can contribute to our project. -## Branch explanation - -Our repository has two main branches: - -1. [master](https://github.com/ghaiklor/generator-sails-rest-api/tree/master "Master Branch") -2. [dev](https://github.com/ghaiklor/generator-sails-rest-api/tree/dev "Development Branch") - -All stable releases will merge into `master` branch. -So if you want get and use last stable release ready for production - use `master` branch. - -But, of course, you can use edge version and check out our latest features. -They are may be unstable and not tested, so they are not ready for production. -All those changes and features will merge into `dev` branch. - -Other branches it's only helper branches which can close at any time. -In general we have 3 types of branches: - -+ Feature branches; -+ Release branches; -+ Hotfix branches; +## Creating issue -Advanced description you will read below in "Git workflow" section. +If you have any proposal or want to report about bug, feel free to create issue. +We don't moderate issues and will answer you as soon as possible. ## Get the project @@ -60,17 +42,28 @@ sudo npm link yo sails-rest-api ``` -## Tests +## Branch explanation -We are using Mocha for testing. -All test cases located into `test` folder and split like source files split. -For every file in `api/` folder we create appropriate in `test/` folder. +Our repository has two main branches: -When you create new feature or fix some bug, you **MUST** write test case for it in `test` folder. -For example, you add new feature to `api/services/cipher/BCryptCipher.js`. -After that you need modify `test/services/cipher/BCryptCipher.js` for corresponds to new feature. +1. [master](https://github.com/ghaiklor/generator-sails-rest-api/tree/master "Master Branch") +2. [dev](https://github.com/ghaiklor/generator-sails-rest-api/tree/dev "Development Branch") -For run tests just call `npm test`. +All stable releases will merge into `master` branch. +So if you want get and use last stable release ready for production - use `master` branch. + +But, of course, you can use edge version and check out our latest features. +They are may be unstable and not tested, so they are not ready for production. +All those changes and features will merge into `dev` branch. + +Other branches it's only helper branches which can close at any time. +In general we have 3 types of branches: + ++ Feature branches; ++ Release branches; ++ Hotfix branches; + +Advanced description you will read below in "Git workflow" section. ## Git workflow @@ -160,6 +153,18 @@ git push -u origin --all # Push all changes to origin server git push -u origin --tags # And push tags to origin server ``` +## Tests + +We are using Mocha for testing. +All test cases located into `test` folder and split like source files split. +For every file in `api/` folder we create appropriate in `test/` folder. + +When you create new feature or fix some bug, you **MUST** write test case for it in `test` folder. +For example, you add new feature to `api/services/cipher/BCryptCipher.js`. +After that you need modify `test/services/cipher/BCryptCipher.js` for corresponds to new feature. + +For run tests just call `npm test`. + ## Versions We are using "Semantic Versioning". From 64e63a0664fc298217a323be6e91bfb4683a6a43 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 15:28:32 +0200 Subject: [PATCH 067/118] Add rizr to thanks section --- AUTHORS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index d74261a2..9ae3f041 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -9,3 +9,7 @@ ## Contributors We don't have contributors yet... + +## Special Thanks + ++ @rizr - for participating in testing and proposals to make it better; From 03f3b6180315de9d5c628f266ac810393007fef4 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 15:44:08 +0200 Subject: [PATCH 068/118] Typo fix --- test/app.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/app.js b/test/app.js index 7bb8e4ce..7e46bf56 100644 --- a/test/app.js +++ b/test/app.js @@ -5,7 +5,8 @@ var path = require('path'), describe('sails-rest-api:app', function () { before(function (done) { - helpers.run(path.join(__dirname, '../generators/app')) + helpers + .run(path.join(__dirname, '../generators/app')) .inDir(path.join(os.tmpdir(), './temp-test')) .withOptions({"skip-all": true}) .on('end', done); From 28e7d62972da7b3d97aed5e4e35cdfc582f76669 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 15:48:34 +0200 Subject: [PATCH 069/118] Fix link to GitHub one of testers --- AUTHORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index 9ae3f041..d953f551 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -12,4 +12,4 @@ We don't have contributors yet... ## Special Thanks -+ @rizr - for participating in testing and proposals to make it better; ++ [@rizr](https://github.com/rizr) - for participating in testing and proposals to make it better; From 98d99d20d8b3a5f3f4af3b89bf8d80364ae41602 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 16:08:00 +0200 Subject: [PATCH 070/118] Implement arguments loading --- generators/app/arguments/index.json | 1 + generators/app/index.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 generators/app/arguments/index.json diff --git a/generators/app/arguments/index.json b/generators/app/arguments/index.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/generators/app/arguments/index.json @@ -0,0 +1 @@ +{} diff --git a/generators/app/index.js b/generators/app/index.js index c70d70d0..0b4a9b15 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -4,7 +4,8 @@ module.exports = yeoman.generators.Base.extend({ constructor: function () { yeoman.generators.Base.apply(this, arguments); - var options = require('./options/index'); + var options = require('./options/index'), + args = require('./arguments/index'); this.description = "Yeoman generator that provides already configured and optimized Sails REST API with bundle of predefined features"; @@ -12,6 +13,10 @@ module.exports = yeoman.generators.Base.extend({ this.option(name, options[name]); }.bind(this)); + Object.keys(args).forEach(function (name) { + this.argument(name, options[name]); + }.bind(this)); + this.config.save(); }, From 5cfd365db74feeb7848da22909fa702fe754f051 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 16:19:35 +0200 Subject: [PATCH 071/118] Move args and options from json to js --- generators/app/arguments/index.js | 16 ++++++++++ generators/app/arguments/index.json | 1 - generators/app/index.js | 4 +-- generators/app/options/index.js | 46 +++++++++++++++++++++++++++++ generators/app/options/index.json | 32 -------------------- 5 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 generators/app/arguments/index.js delete mode 100644 generators/app/arguments/index.json create mode 100644 generators/app/options/index.js delete mode 100644 generators/app/options/index.json diff --git a/generators/app/arguments/index.js b/generators/app/arguments/index.js new file mode 100644 index 00000000..1ee0d95d --- /dev/null +++ b/generators/app/arguments/index.js @@ -0,0 +1,16 @@ +/** + * Exports object contains arguments names and their configuration objects + * + * @example + * module.exports = { + * argName: { + * desc: "Argument description", + * required: false, + * optional: true, + * type: String || Number || Array || Object, + * defaults: "test" + * } + * }; + */ + +module.exports = {}; diff --git a/generators/app/arguments/index.json b/generators/app/arguments/index.json deleted file mode 100644 index 0967ef42..00000000 --- a/generators/app/arguments/index.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/generators/app/index.js b/generators/app/index.js index 0b4a9b15..98f68de8 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -4,8 +4,8 @@ module.exports = yeoman.generators.Base.extend({ constructor: function () { yeoman.generators.Base.apply(this, arguments); - var options = require('./options/index'), - args = require('./arguments/index'); + var options = require('./options'), + args = require('./arguments'); this.description = "Yeoman generator that provides already configured and optimized Sails REST API with bundle of predefined features"; diff --git a/generators/app/options/index.js b/generators/app/options/index.js new file mode 100644 index 00000000..2792eb78 --- /dev/null +++ b/generators/app/options/index.js @@ -0,0 +1,46 @@ +/** + * Exports object contains options names and their configuration objects + * + * @example + * module.exports = { + * "option-name": { + * desc: "Option description", + * type: Boolean || String || Number, + * defaults: false, + * hide: false + * } + * }; + */ + +module.exports = { + "skip-generator-update": { + desc: "Do not check for generator updates", + type: Boolean, + defaults: false, + hide: false + }, + "skip-generator-welcome": { + desc: "Do not welcome at start", + type: Boolean, + defaults: false, + hide: false + }, + "skip-project-install": { + desc: "Do not install npm dependencies", + type: Boolean, + defaults: false, + hide: false + }, + "skip-project-diagnostic": { + desc: "Do not run diagnostic tools", + type: Boolean, + defaults: false, + hide: false + }, + "skip-all": { + desc: "Do nothing, just project scaffolding", + type: Boolean, + defaults: false, + hide: false + } +}; diff --git a/generators/app/options/index.json b/generators/app/options/index.json deleted file mode 100644 index d2849fa3..00000000 --- a/generators/app/options/index.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "skip-generator-update": { - "desc": "Do not check for generator updates", - "type": "Boolean", - "defaults": false, - "hide": false - }, - "skip-generator-welcome": { - "desc": "Do not welcome at start", - "type": "Boolean", - "defaults": false, - "hide": false - }, - "skip-project-install": { - "desc": "Do not install npm dependencies", - "type": "Boolean", - "defaults": false, - "hide": false - }, - "skip-project-diagnostic": { - "desc": "Do not run diagnostic tools", - "type": "Boolean", - "defaults": false, - "hide": false - }, - "skip-all": { - "desc": "Do nothing, just project scaffolding", - "type": "Boolean", - "defaults": false, - "hide": false - } -} From 845922388308a12753bdf13156f0b5b22328d65d Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 16:48:29 +0200 Subject: [PATCH 072/118] Fix wrong loading of arguments --- generators/app/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/app/index.js b/generators/app/index.js index 98f68de8..4a45d416 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -14,7 +14,7 @@ module.exports = yeoman.generators.Base.extend({ }.bind(this)); Object.keys(args).forEach(function (name) { - this.argument(name, options[name]); + this.argument(name, args[name]); }.bind(this)); this.config.save(); From 2f50210407fb3849ac06545bab5d51f9bd2f33d1 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 17:16:29 +0200 Subject: [PATCH 073/118] Add index file to questions folder --- generators/app/questions/index.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 generators/app/questions/index.js diff --git a/generators/app/questions/index.js b/generators/app/questions/index.js new file mode 100644 index 00000000..44ae264c --- /dev/null +++ b/generators/app/questions/index.js @@ -0,0 +1,23 @@ +/** + * Exports object contains questions divided into sections. + * Each section should contain array with questions. + * Array with questions it's Inquirer prompts objects - https://github.com/SBoudrias/Inquirer.js#prompts-type + * + * @example + * module.exports = { + * sectionName: require('./sectionName'), + * anotherSection: [{ + * type: 'input', + * name: 'application-name', + * message: 'Typo your application name', + * default: 'sails-rest-api' + * }] + * }; + */ + +module.exports = { + application: require('./application'), + database: require('./database'), + miscellaneous: require('./miscellaneous'), + services: require('./services') +}; From aa02052e306e8bc3e44ec896c14d13754f391443 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 17:18:59 +0200 Subject: [PATCH 074/118] Remove require-folder util --- generators/app/steps/prompting.js | 3 +-- generators/app/util/require-folder.js | 17 ----------------- 2 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 generators/app/util/require-folder.js diff --git a/generators/app/steps/prompting.js b/generators/app/steps/prompting.js index 582a38f7..f557fced 100644 --- a/generators/app/steps/prompting.js +++ b/generators/app/steps/prompting.js @@ -6,8 +6,7 @@ var path = require('path'), chalk = require('chalk'), assign = require('../util/assign'), - requireFolder = require('../util/require-folder'), - questions = requireFolder(path.resolve(__dirname, '../questions')); + questions = require('../questions'); module.exports = { /** diff --git a/generators/app/util/require-folder.js b/generators/app/util/require-folder.js deleted file mode 100644 index 75daea6d..00000000 --- a/generators/app/util/require-folder.js +++ /dev/null @@ -1,17 +0,0 @@ -var fs = require('fs'); - -/** - * Require all files within folder - * @param {String} dirName Directory name - * @returns {Object} - */ -module.exports = function requireFolder(dirName) { - var files = fs.readdirSync(dirName), - modules = {}; - - for (var i = 0; i < files.length; i++) { - modules[files[i].replace('.js', '')] = require(dirName + '/' + files[i]); - } - - return modules; -}; From f63d043a1a71ca01dba51018e5c19c8e97433d48 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 17:27:14 +0200 Subject: [PATCH 075/118] Add index file to steps in run loop --- generators/app/index.js | 17 +++++++++-------- generators/app/steps/index.js | 13 +++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 generators/app/steps/index.js diff --git a/generators/app/index.js b/generators/app/index.js index 4a45d416..9cf18596 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -1,4 +1,5 @@ -var yeoman = require('yeoman-generator'); +var yeoman = require('yeoman-generator'), + runSteps = require('./steps'); module.exports = yeoman.generators.Base.extend({ constructor: function () { @@ -20,11 +21,11 @@ module.exports = yeoman.generators.Base.extend({ this.config.save(); }, - initializing: require('./steps/initializing'), - prompting: require('./steps/prompting'), - configuring: require('./steps/configuring'), - writing: require('./steps/writing'), - conflicts: require('./steps/conflicts'), - install: require('./steps/install'), - end: require('./steps/end') + initializing: runSteps.initializing, + prompting: runSteps.prompting, + configuring: runSteps.configuring, + writing: runSteps.writing, + conflicts: runSteps.conflicts, + install: runSteps.install, + end: runSteps.end }); diff --git a/generators/app/steps/index.js b/generators/app/steps/index.js new file mode 100644 index 00000000..a3298803 --- /dev/null +++ b/generators/app/steps/index.js @@ -0,0 +1,13 @@ +/** + * Exports object contains each priority step for yeoman run loop + */ + +module.exports = { + configuring: require('./configuring'), + conflicts: require('./conflicts'), + end: require('./end'), + initializing: require('./initializing'), + install: require('./install'), + prompting: require('./prompting'), + writing: require('./writing') +}; From aaae5cd54f07968a6250cb4429e55a3df78c409f Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 17:29:18 +0200 Subject: [PATCH 076/118] Add index file for helper methods --- generators/app/steps/prompting.js | 2 +- generators/app/util/index.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 generators/app/util/index.js diff --git a/generators/app/steps/prompting.js b/generators/app/steps/prompting.js index f557fced..cc5d34b4 100644 --- a/generators/app/steps/prompting.js +++ b/generators/app/steps/prompting.js @@ -5,7 +5,7 @@ var path = require('path'), chalk = require('chalk'), - assign = require('../util/assign'), + assign = require('../util').assign, questions = require('../questions'); module.exports = { diff --git a/generators/app/util/index.js b/generators/app/util/index.js new file mode 100644 index 00000000..3aafaddc --- /dev/null +++ b/generators/app/util/index.js @@ -0,0 +1,7 @@ +/** + * Exports object contains helper methods or objects for generator + */ + +module.exports = { + assign: require('./assign') +}; From 67bc54467167867ed358abae589c81ab78d4dc0a Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 17:37:19 +0200 Subject: [PATCH 077/118] Typo fixes --- generators/app/index.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/generators/app/index.js b/generators/app/index.js index 9cf18596..d5e28d30 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -1,31 +1,30 @@ var yeoman = require('yeoman-generator'), - runSteps = require('./steps'); + steps = require('./steps'); module.exports = yeoman.generators.Base.extend({ constructor: function () { yeoman.generators.Base.apply(this, arguments); - var options = require('./options'), - args = require('./arguments'); + var args = require('./arguments'), + options = require('./options'); - this.description = "Yeoman generator that provides already configured and optimized Sails REST API with bundle of predefined features"; - - Object.keys(options).forEach(function (name) { - this.option(name, options[name]); + Object.keys(args).forEach(function (argName) { + this.argument(argName, args[argName]); }.bind(this)); - Object.keys(args).forEach(function (name) { - this.argument(name, args[name]); + Object.keys(options).forEach(function (optionName) { + this.option(optionName, options[optionName]); }.bind(this)); + this.description = "Yeoman generator that provides already configured and optimized Sails REST API with bundle of predefined features"; this.config.save(); }, - initializing: runSteps.initializing, - prompting: runSteps.prompting, - configuring: runSteps.configuring, - writing: runSteps.writing, - conflicts: runSteps.conflicts, - install: runSteps.install, - end: runSteps.end + initializing: steps.initializing, + prompting: steps.prompting, + configuring: steps.configuring, + writing: steps.writing, + conflicts: steps.conflicts, + install: steps.install, + end: steps.end }); From 2eb858174f59c61088c8d37a6daaa0dc40bb2863 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 18:11:58 +0200 Subject: [PATCH 078/118] Typo fixes --- generators/app/arguments/index.js | 4 +- generators/app/index.js | 2 + generators/app/options/index.js | 24 +++--- generators/app/questions/application.js | 56 +++++++------- generators/app/questions/database.js | 50 ++++++------- generators/app/questions/miscellaneous.js | 18 ++--- generators/app/questions/services.js | 90 +++++++++++------------ generators/app/steps/configuring.js | 2 +- generators/app/steps/end.js | 19 +++-- generators/app/steps/initializing.js | 34 ++++----- generators/app/steps/install.js | 9 ++- generators/app/steps/prompting.js | 13 ++-- 12 files changed, 164 insertions(+), 157 deletions(-) diff --git a/generators/app/arguments/index.js b/generators/app/arguments/index.js index 1ee0d95d..9ec08954 100644 --- a/generators/app/arguments/index.js +++ b/generators/app/arguments/index.js @@ -4,11 +4,11 @@ * @example * module.exports = { * argName: { - * desc: "Argument description", + * desc: 'Argument description', * required: false, * optional: true, * type: String || Number || Array || Object, - * defaults: "test" + * defaults: 'test' * } * }; */ diff --git a/generators/app/index.js b/generators/app/index.js index d5e28d30..abb37caa 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -5,6 +5,8 @@ module.exports = yeoman.generators.Base.extend({ constructor: function () { yeoman.generators.Base.apply(this, arguments); + // TODO: make debug option + var args = require('./arguments'), options = require('./options'); diff --git a/generators/app/options/index.js b/generators/app/options/index.js index 2792eb78..4f6a3de5 100644 --- a/generators/app/options/index.js +++ b/generators/app/options/index.js @@ -3,8 +3,8 @@ * * @example * module.exports = { - * "option-name": { - * desc: "Option description", + * 'option-name': { + * desc: 'Option description', * type: Boolean || String || Number, * defaults: false, * hide: false @@ -13,32 +13,32 @@ */ module.exports = { - "skip-generator-update": { - desc: "Do not check for generator updates", + 'skip-generator-update': { + desc: 'Do not check for generator updates', type: Boolean, defaults: false, hide: false }, - "skip-generator-welcome": { - desc: "Do not welcome at start", + 'skip-generator-welcome': { + desc: 'Do not welcome at start', type: Boolean, defaults: false, hide: false }, - "skip-project-install": { - desc: "Do not install npm dependencies", + 'skip-project-install': { + desc: 'Do not install npm dependencies', type: Boolean, defaults: false, hide: false }, - "skip-project-diagnostic": { - desc: "Do not run diagnostic tools", + 'skip-project-diagnostic': { + desc: 'Do not run diagnostic tools', type: Boolean, defaults: false, hide: false }, - "skip-all": { - desc: "Do nothing, just project scaffolding", + 'skip-all': { + desc: 'Do nothing, just project scaffolding', type: Boolean, defaults: false, hide: false diff --git a/generators/app/questions/application.js b/generators/app/questions/application.js index cb920859..bfee0c9f 100644 --- a/generators/app/questions/application.js +++ b/generators/app/questions/application.js @@ -1,38 +1,38 @@ var crypto = require('crypto'); module.exports = [{ - type: "input", - name: "application:name", - message: "Type your application name", - default: "sails-rest-api" + type: 'input', + name: 'application:name', + message: 'Type your application name', + default: 'sails-rest-api' }, { - type: "input", - name: "application:api-secret-key", - message: "Type your private API key", - default: crypto.randomBytes(32).toString("hex") + type: 'input', + name: 'application:api-secret-key', + message: 'Type your private API key', + default: crypto.randomBytes(32).toString('hex') }, { - type: "input", - name: "application:jwt-secret", - message: "Type your private key for JSON Web Token", - default: crypto.randomBytes(32).toString("hex") + type: 'input', + name: 'application:jwt-secret', + message: 'Type your private key for JSON Web Token', + default: crypto.randomBytes(32).toString('hex') }, { - type: "input", - name: "application:facebook-app-id", - message: "Type your Facebook App ID", - default: "-" + type: 'input', + name: 'application:facebook-app-id', + message: 'Type your Facebook App ID', + default: '-' }, { - type: "input", - name: "application:facebook-app-secret", - message: "Type your Facebook App Secret", - default: "-" + type: 'input', + name: 'application:facebook-app-secret', + message: 'Type your Facebook App Secret', + default: '-' }, { - type: "input", - name: "application:twitter-consumer-key", - message: "Type your Twitter Consumer Key", - default: "-" + type: 'input', + name: 'application:twitter-consumer-key', + message: 'Type your Twitter Consumer Key', + default: '-' }, { - type: "input", - name: "application:twitter-consumer-secret", - message: "Type your Twitter Consumer Secret", - default: "-" + type: 'input', + name: 'application:twitter-consumer-secret', + message: 'Type your Twitter Consumer Secret', + default: '-' }]; diff --git a/generators/app/questions/database.js b/generators/app/questions/database.js index 03854b2b..a23946e2 100644 --- a/generators/app/questions/database.js +++ b/generators/app/questions/database.js @@ -1,32 +1,32 @@ module.exports = [{ - "type": "list", - "name": "database:adapter", - "message": "Choose database adapter", - "default": 1, - "choices": [ - "MySQL", - "Mongo", - "PostgreSQL", - "Redis" + type: 'list', + name: 'database:adapter', + message: 'Choose database adapter', + default: 1, + choices: [ + 'MySQL', + 'Mongo', + 'PostgreSQL', + 'Redis' ] }, { - "type": "input", - "name": "database:host", - "message": "Type your database host", - "default": "localhost" + type: 'input', + name: 'database:host', + message: 'Type your database host', + default: 'localhost' }, { - "type": "input", - "name": "database:name", - "message": "Type your database name", - "default": "sails-rest-api" + type: 'input', + name: 'database:name', + message: 'Type your database name', + default: 'sails-rest-api' }, { - "type": "input", - "name": "database:user", - "message": "Type your database username", - "default": "" + type: 'input', + name: 'database:user', + message: 'Type your database username', + default: '' }, { - "type": "password", - "name": "database:password", - "message": "Type your database password", - "default": "" + type: 'password', + name: 'database:password', + message: 'Type your database password', + default: '' }]; diff --git a/generators/app/questions/miscellaneous.js b/generators/app/questions/miscellaneous.js index eb1b899b..c716c466 100644 --- a/generators/app/questions/miscellaneous.js +++ b/generators/app/questions/miscellaneous.js @@ -1,16 +1,16 @@ module.exports = [{ - type: "confirm", - name: "docs:include", - message: "Is Swagger documentation needed for project?", + type: 'confirm', + name: 'docs:include', + message: 'Is Swagger documentation needed for project?', default: true }, { - type: "confirm", - name: "tests:include", - message: "Is Mocha tests needed for project?", + type: 'confirm', + name: 'tests:include', + message: 'Is Mocha tests needed for project?', default: true }, { - type: "confirm", - name: "tools:include", - message: "Is diagnostic tools needed for project?", + type: 'confirm', + name: 'tools:include', + message: 'Is diagnostic tools needed for project?', default: true }]; diff --git a/generators/app/questions/services.js b/generators/app/questions/services.js index 4447f393..4269dbb8 100644 --- a/generators/app/questions/services.js +++ b/generators/app/questions/services.js @@ -1,89 +1,89 @@ var inquirer = require('yo/node_modules/inquirer'); module.exports = [{ - type: "checkbox", - name: "services:cipher", - message: "Choose which Cipher services you want", + type: 'checkbox', + name: 'services:cipher', + message: 'Choose which Cipher services you want', choices: [{ - name: "bcrypt", + name: 'bcrypt', checked: true }, { - name: "jwt", + name: 'jwt', checked: true }, new inquirer.Separator(), { - name: "More Cipher is coming", - disabled: "Wait for it..." + name: 'More Cipher is coming', + disabled: 'Wait for it...' }] }, { - type: "checkbox", - name: "services:mailer", - message: "Choose which Mailer services you want", + type: 'checkbox', + name: 'services:mailer', + message: 'Choose which Mailer services you want', choices: [{ - name: "Mandrill", + name: 'Mandrill', checked: false }, new inquirer.Separator(), { - name: "More Mailer is coming", - disabled: "Wait for it..." + name: 'More Mailer is coming', + disabled: 'Wait for it...' }] }, { - type: "checkbox", - name: "services:payment", - message: "Choose which Payment services you want", + type: 'checkbox', + name: 'services:payment', + message: 'Choose which Payment services you want', choices: [{ - name: "Stripe", + name: 'Stripe', checked: false }, new inquirer.Separator(), { - name: "More Payment is coming", - disabled: "Wait for it..." + name: 'More Payment is coming', + disabled: 'Wait for it...' }] }, { - type: "checkbox", - name: "services:pusher", - message: "Choose which Pusher services you want", + type: 'checkbox', + name: 'services:pusher', + message: 'Choose which Pusher services you want', choices: [{ - name: "Apple Push Notification", + name: 'Apple Push Notification', checked: false }, { - name: "Google Cloud Messaging", + name: 'Google Cloud Messaging', checked: false }, new inquirer.Separator(), { - name: "More Pusher is coming", - disabled: "Wait for it..." + name: 'More Pusher is coming', + disabled: 'Wait for it...' }] }, { - type: "checkbox", - name: "services:sms", - message: "Choose which SMS services you want", + type: 'checkbox', + name: 'services:sms', + message: 'Choose which SMS services you want', choices: [{ - name: "Twilio", + name: 'Twilio', checked: false }, new inquirer.Separator(), { - name: "More SMS is coming", - disabled: "Wait for it..." + name: 'More SMS is coming', + disabled: 'Wait for it...' }] }, { - type: "checkbox", - name: "services:social", - message: "Choose which Social services you want", + type: 'checkbox', + name: 'services:social', + message: 'Choose which Social services you want', choices: [{ - name: "Facebook", + name: 'Facebook', checked: false }, new inquirer.Separator(), { - name: "More Social is coming", - disabled: "Wait for it..." + name: 'More Social is coming', + disabled: 'Wait for it...' }] }, { - type: "checkbox", - name: "services:storage", - message: "Choose which Storage services you want", + type: 'checkbox', + name: 'services:storage', + message: 'Choose which Storage services you want', choices: [{ - name: "Amazon S3", + name: 'Amazon S3', checked: false }, { - name: "Google Cloud Storage", + name: 'Google Cloud Storage', checked: false }, new inquirer.Separator(), { - name: "More Storage is coming", - disabled: "Wait for it..." + name: 'More Storage is coming', + disabled: 'Wait for it...' }] }]; diff --git a/generators/app/steps/configuring.js b/generators/app/steps/configuring.js index 675b1cbf..83ccabd6 100644 --- a/generators/app/steps/configuring.js +++ b/generators/app/steps/configuring.js @@ -1,6 +1,6 @@ /** * Step 3 - * Saving configurations and configure the project (creating .editorconfig files and other metadata files) + * Saving configurations and configure the project (creating .sails-rc files and other metadata files) */ module.exports = {}; diff --git a/generators/app/steps/end.js b/generators/app/steps/end.js index 17a3d6ba..5069374e 100644 --- a/generators/app/steps/end.js +++ b/generators/app/steps/end.js @@ -11,12 +11,13 @@ module.exports = { * Run diagnostic tools */ runDiagnostic: function () { - if (!(this.options["skip-project-diagnostic"] || this.options["skip-all"])) { + if (!(this.options['skip-project-diagnostic'] || this.options['skip-all'])) { var done = this.async(); - this.log(chalk.yellow("Starting diagnostic, please wait...")); + this.log(chalk.yellow('Starting diagnostic, please wait...')); this.spawnCommand('npm', ['run-script', 'fix-deps']).on('close', function () { + // TODO: parse code and if !== 0 then process.exit() this.spawnCommand('npm', ['run-script', 'check-updates']).on('close', done); }.bind(this)); } @@ -26,11 +27,12 @@ module.exports = { * Say warning that this generator is under development */ sayUnderDevelopmentWarning: function () { + // TODO: remove when will be stable version printMessage([ - "This generator under heavy development", - "If you found any bugs or have proposals, feel free to create issue", + 'This generator under heavy development', + 'If you found any bugs or have proposals, feel free to create issue', chalk.red(this.pkg.bugs.url), - "Or you can write me the letter", + 'Or you can write me the letter', chalk.red(this.pkg.bugs.email) ], { marginTop: 0, @@ -43,10 +45,11 @@ module.exports = { * Warn user if he skip installing dependencies */ sayNotInstalledNpmDepsWarning: function () { - if (this.options['skip-project-install'] || this.options["skip-all"]) { + // TODO: remove this message when installing step will be more stable + if (this.options['skip-project-install'] || this.options['skip-all']) { printMessage([ - "You have skipped installing npm modules", - "Install them manually via " + chalk.blue("npm install") + 'You have skipped installing npm modules', + 'Install them manually via ' + chalk.blue('npm install') ], { marginTop: 0, marginBottom: 0, diff --git a/generators/app/steps/initializing.js b/generators/app/steps/initializing.js index a3043c89..2c143848 100644 --- a/generators/app/steps/initializing.js +++ b/generators/app/steps/initializing.js @@ -3,8 +3,7 @@ * Your initialization methods (checking current project state, getting configs, etc) */ -var path = require('path'), - chalk = require('chalk'), +var chalk = require('chalk'), updateNotifier = require('update-notifier'), printMessage = require('print-message'), yosay = require('yosay'); @@ -14,7 +13,16 @@ module.exports = { * Load package.json */ loadPackageInfo: function () { - this.pkg = require(path.resolve(__dirname, '../../../package.json')); + this.pkg = require('../../../package.json'); + }, + + /** + * Say yeoman hello + */ + sayHello: function () { + if (!(this.options['skip-generator-welcome'] || this.options['skip-all'])) { + this.log(yosay('Welcome to the laudable ' + chalk.red('Sails REST API') + ' generator!')); + } }, /** @@ -24,15 +32,16 @@ module.exports = { if (!(this.options['skip-generator-update'] || this.options['skip-all'])) { var done = this.async(); - this.log(chalk.yellow("Checking for updates...")); + this.log(chalk.yellow('Checking for updates...')); updateNotifier({ pkg: this.pkg, callback: function (error, update) { - if (update && update.type && update.type !== 'latest') { + // TODO: print out error and process.exit() + if (update && update.type !== 'latest') { printMessage([ - "Update available: " + chalk.green.bold(update.latest) + chalk.dim(" (current: " + update.current + ")"), - "Run " + chalk.blue("npm update -g " + update.name) + " to update." + 'Update available: ' + chalk.green.bold(update.latest) + chalk.dim(' (current: ' + update.current + ')'), + 'Run ' + chalk.blue('npm update -g ' + update.name) + ' to update.' ], { marginTop: 0, marginBottom: 0, @@ -41,20 +50,11 @@ module.exports = { process.exit(0); } else { - this.log(chalk.yellow("OK... You're using the latest version " + chalk.green.bold(update.current))); + this.log(chalk.yellow('OK... You are using the latest version ' + chalk.green.bold(update.current))); done(); } }.bind(this) }); } - }, - - /** - * Say yeoman hello - */ - sayHello: function () { - if (!(this.options["skip-generator-welcome"] || this.options["skip-all"])) { - this.log(yosay('Welcome to the laudable ' + chalk.red('Sails REST API') + ' generator!')); - } } }; diff --git a/generators/app/steps/install.js b/generators/app/steps/install.js index 25ffa27c..9876963d 100644 --- a/generators/app/steps/install.js +++ b/generators/app/steps/install.js @@ -10,10 +10,13 @@ module.exports = { * Install npm dependencies */ installNpmDependencies: function () { - if (!(this.options['skip-project-install'] || this.options["skip-all"])) { - this.log(chalk.yellow("Start installing npm dependencies, please wait...")); + if (!(this.options['skip-project-install'] || this.options['skip-all'])) { + this.log(chalk.yellow('Start installing npm dependencies, please wait...')); + // TODO: pipe verbose log to console this.npmInstall([], { - color: "always" + color: 'always', + // TODO: make global DEBUG variable + verbose: true }); } } diff --git a/generators/app/steps/prompting.js b/generators/app/steps/prompting.js index cc5d34b4..ae96d1b4 100644 --- a/generators/app/steps/prompting.js +++ b/generators/app/steps/prompting.js @@ -3,8 +3,7 @@ * Where you prompt users for options (where you'd call this.prompt()) */ -var path = require('path'), - chalk = require('chalk'), +var chalk = require('chalk'), assign = require('../util').assign, questions = require('../questions'); @@ -15,7 +14,7 @@ module.exports = { askDatabaseQuestions: function () { var done = this.async(); - this.log(chalk.yellow("\nDatabase questions:")); + this.log(chalk.yellow('\nDatabase questions:')); this.prompt(questions.database, function (answers) { this.answers = assign(this.answers, answers); @@ -29,7 +28,7 @@ module.exports = { askApplicationQuestions: function () { var done = this.async(); - this.log(chalk.yellow("\nApplication questions:")); + this.log(chalk.yellow('\nApplication questions:')); this.prompt(questions.application, function (answers) { this.answers = assign(this.answers, answers); @@ -43,7 +42,7 @@ module.exports = { askServiceQuestions: function () { var done = this.async(); - this.log(chalk.yellow("\nService questions:")); + this.log(chalk.yellow('\nService questions:')); this.prompt(questions.services, function (answers) { this.answers = assign(this.answers, answers); @@ -54,10 +53,10 @@ module.exports = { /** * Ask miscellaneous questions */ - askMiscellaneousSections: function () { + askMiscellaneousQuestions: function () { var done = this.async(); - this.log(chalk.yellow("\nMiscellaneous questions:")); + this.log(chalk.yellow('\nMiscellaneous questions:')); this.prompt(questions.miscellaneous, function (answers) { this.answers = assign(this.answers, answers); From c082cb54c1d74d2c5131717314a7ce4d1543fa8e Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 18:15:22 +0200 Subject: [PATCH 079/118] Add verbose flag --- generators/app/options/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/generators/app/options/index.js b/generators/app/options/index.js index 4f6a3de5..00ddd0c2 100644 --- a/generators/app/options/index.js +++ b/generators/app/options/index.js @@ -13,6 +13,12 @@ */ module.exports = { + 'verbose': { + desc: 'Print all information to console', + type: Boolean, + defaults: false, + hide: false + }, 'skip-generator-update': { desc: 'Do not check for generator updates', type: Boolean, From 86b0648130ddd41689709081ce81af99bae09737 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 18:24:27 +0200 Subject: [PATCH 080/118] Add comment how prompting is working --- generators/app/steps/prompting.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/generators/app/steps/prompting.js b/generators/app/steps/prompting.js index ae96d1b4..79a0d43a 100644 --- a/generators/app/steps/prompting.js +++ b/generators/app/steps/prompting.js @@ -1,6 +1,9 @@ /** * Step 2 - * Where you prompt users for options (where you'd call this.prompt()) + * Where you prompt users for options (where you'd call this.prompt()). + * + * Questions is required from ../questions folder. + * Each of answers is mixin to this.answers attribute and available in templates as answers variable. */ var chalk = require('chalk'), From 8cdd87a7319a49b6f7fa57375f6309bc4d4353c8 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 18:33:48 +0200 Subject: [PATCH 081/118] Assign verbose flag to npm install --- generators/app/index.js | 2 -- generators/app/steps/end.js | 1 + generators/app/steps/initializing.js | 1 + generators/app/steps/install.js | 4 +--- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/generators/app/index.js b/generators/app/index.js index abb37caa..d5e28d30 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -5,8 +5,6 @@ module.exports = yeoman.generators.Base.extend({ constructor: function () { yeoman.generators.Base.apply(this, arguments); - // TODO: make debug option - var args = require('./arguments'), options = require('./options'); diff --git a/generators/app/steps/end.js b/generators/app/steps/end.js index 5069374e..a0135e6a 100644 --- a/generators/app/steps/end.js +++ b/generators/app/steps/end.js @@ -18,6 +18,7 @@ module.exports = { this.spawnCommand('npm', ['run-script', 'fix-deps']).on('close', function () { // TODO: parse code and if !== 0 then process.exit() + // TODO: implement verbose flag for both scripts this.spawnCommand('npm', ['run-script', 'check-updates']).on('close', done); }.bind(this)); } diff --git a/generators/app/steps/initializing.js b/generators/app/steps/initializing.js index 2c143848..e48b77fc 100644 --- a/generators/app/steps/initializing.js +++ b/generators/app/steps/initializing.js @@ -38,6 +38,7 @@ module.exports = { pkg: this.pkg, callback: function (error, update) { // TODO: print out error and process.exit() + // TODO: enable verbose mode if exists if (update && update.type !== 'latest') { printMessage([ 'Update available: ' + chalk.green.bold(update.latest) + chalk.dim(' (current: ' + update.current + ')'), diff --git a/generators/app/steps/install.js b/generators/app/steps/install.js index 9876963d..778f213f 100644 --- a/generators/app/steps/install.js +++ b/generators/app/steps/install.js @@ -12,11 +12,9 @@ module.exports = { installNpmDependencies: function () { if (!(this.options['skip-project-install'] || this.options['skip-all'])) { this.log(chalk.yellow('Start installing npm dependencies, please wait...')); - // TODO: pipe verbose log to console this.npmInstall([], { color: 'always', - // TODO: make global DEBUG variable - verbose: true + verbose: this.options.verbose }); } } From ac9f18e9151f6fe6f4b1f3968c71ad3b7cc7ff2a Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 18:38:40 +0200 Subject: [PATCH 082/118] Implement printing out answers object in verbose mode --- generators/app/steps/prompting.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/generators/app/steps/prompting.js b/generators/app/steps/prompting.js index 79a0d43a..5cc5a430 100644 --- a/generators/app/steps/prompting.js +++ b/generators/app/steps/prompting.js @@ -65,5 +65,15 @@ module.exports = { this.answers = assign(this.answers, answers); done(); }.bind(this)); + }, + + /** + * Print generated answers object if in verbose mode + */ + printAnswersObject: function () { + if (this.options.verbose) { + this.log(chalk.yellow('\nAnswers to your questions:')); + this.log(this.answers); + } } }; From 93c77553bf5158728f55d46f3320ea734ba2f6de Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 28 Feb 2015 18:43:58 +0200 Subject: [PATCH 083/118] Update changelog --- CHANGELOG.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83e6c56b..1f49fd10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,16 @@ ## Edge version - Improvement: Frozen structure of generator and project. Any serious changes in project structure; -- Improvement: Split CLI options, questions and steps to separate modules, so generator is more maintainable; -- Improvement: Cleaning up in questions and split out them to sections; +- Improvement: Split generator arguments declaration to separate folder; +- Improvement: Split generator options declaration to separate folder; +- Improvement: Split generator questions declaration to separate folder; +- Improvement: Answers to questions is dynamically assign to existing `this.answers` object in `RunContext`; +- Improvement: Split each generator step to separate folder and modules; +- Improvement: Implement util `assign()` method which is using in `prompting` step for extend answers object; +- Improvement: Redesign of generator structure; - Improvement: Add options to `check-updates.js` tool; -- Improvement: Add tools to npm scripts, so you can call `npm run-script check-updates` now; +- Improvement: Add tools to npm scripts, so you can call `npm run-script ` now; +- Improvement: Add `verbose` flag, so you can see everything what going on in `RunContext`; - Fix: Bug with no colorful print in `fix-deps.js`; - Fix: Bug with no colorful print in installing step in generator; - Fix: Bug when returns total count of records even with `where` criteria; From fba76f2b51d561f159f84392146282679d18ae9a Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sun, 1 Mar 2015 13:45:30 +0200 Subject: [PATCH 084/118] Implement process.exit if some error occured on diagnostic --- generators/app/steps/end.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/generators/app/steps/end.js b/generators/app/steps/end.js index a0135e6a..333e3ea2 100644 --- a/generators/app/steps/end.js +++ b/generators/app/steps/end.js @@ -16,10 +16,28 @@ module.exports = { this.log(chalk.yellow('Starting diagnostic, please wait...')); - this.spawnCommand('npm', ['run-script', 'fix-deps']).on('close', function () { - // TODO: parse code and if !== 0 then process.exit() - // TODO: implement verbose flag for both scripts - this.spawnCommand('npm', ['run-script', 'check-updates']).on('close', done); + this.spawnCommand('npm', ['run-script', 'fix-deps', this.options.verbose ? '--verbose' : '']).on('close', function (code) { + if (code !== 0) { + printMessage(['Some error was occurred'], { + borderColor: 'red', + printFn: this.log + }); + + return process.exit(code); + } + + this.spawnCommand('npm', ['run-script', 'check-updates', this.options.verbose ? '--verbose' : '']).on('close', function (code) { + if (code !== 0) { + printMessage(['Some error was occurred'], { + borderColor: 'red', + printFn: this.log + }); + + return process.exit(code); + } + + done(); + }.bind(this)); }.bind(this)); } }, From eba9d406c52f60f36916619d581c4ef6de95d483 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sun, 1 Mar 2015 13:47:51 +0200 Subject: [PATCH 085/118] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f49fd10..657a1d0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Edge version +- Improvement: Implemented parsing CommonJS modules from AST (Abstract Syntax Tree), so now generator is knows which modules you are really using; - Improvement: Frozen structure of generator and project. Any serious changes in project structure; - Improvement: Split generator arguments declaration to separate folder; - Improvement: Split generator options declaration to separate folder; From a6c89dba461ac40265102db17a3e2dc74c8e83fe Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sun, 1 Mar 2015 13:52:20 +0200 Subject: [PATCH 086/118] Add console error on updates checking --- generators/app/steps/initializing.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/generators/app/steps/initializing.js b/generators/app/steps/initializing.js index e48b77fc..e5db8975 100644 --- a/generators/app/steps/initializing.js +++ b/generators/app/steps/initializing.js @@ -37,8 +37,11 @@ module.exports = { updateNotifier({ pkg: this.pkg, callback: function (error, update) { - // TODO: print out error and process.exit() - // TODO: enable verbose mode if exists + if (error) { + console.error(error.stack || error); + return process.exit(1); + } + if (update && update.type !== 'latest') { printMessage([ 'Update available: ' + chalk.green.bold(update.latest) + chalk.dim(' (current: ' + update.current + ')'), From 4127c6e511ca5d816d8a507d563a1a519a9a5800 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sun, 1 Mar 2015 13:57:40 +0200 Subject: [PATCH 087/118] Add error logging in installing step --- generators/app/steps/install.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/generators/app/steps/install.js b/generators/app/steps/install.js index 778f213f..3bba9aed 100644 --- a/generators/app/steps/install.js +++ b/generators/app/steps/install.js @@ -15,6 +15,11 @@ module.exports = { this.npmInstall([], { color: 'always', verbose: this.options.verbose + }, function (error) { + if (error) { + console.error(error.stack || error); + return process.exit(1); + } }); } } From b6582e88d5b89e511de712abb94f758dc1f72390 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sun, 1 Mar 2015 14:11:41 +0200 Subject: [PATCH 088/118] Split mixin answers to one function --- generators/app/steps/prompting.js | 43 +++++++++++-------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/generators/app/steps/prompting.js b/generators/app/steps/prompting.js index 5cc5a430..f207f566 100644 --- a/generators/app/steps/prompting.js +++ b/generators/app/steps/prompting.js @@ -10,61 +10,48 @@ var chalk = require('chalk'), assign = require('../util').assign, questions = require('../questions'); +/** + * Triggers when user finishes answering to questions from section + * @param {Function} done + * @param {Object} answers + * @private + */ +function _onDone(done, answers) { + this.answers = assign(this.answers, answers); + done(); +} + module.exports = { /** * Ask database questions */ askDatabaseQuestions: function () { - var done = this.async(); - this.log(chalk.yellow('\nDatabase questions:')); - - this.prompt(questions.database, function (answers) { - this.answers = assign(this.answers, answers); - done(); - }.bind(this)); + this.prompt(questions.database, _onDone.bind(this, this.async())); }, /** * Ask application questions */ askApplicationQuestions: function () { - var done = this.async(); - this.log(chalk.yellow('\nApplication questions:')); - - this.prompt(questions.application, function (answers) { - this.answers = assign(this.answers, answers); - done(); - }.bind(this)); + this.prompt(questions.application, _onDone.bind(this, this.async())); }, /** * Ask services questions */ askServiceQuestions: function () { - var done = this.async(); - this.log(chalk.yellow('\nService questions:')); - - this.prompt(questions.services, function (answers) { - this.answers = assign(this.answers, answers); - done(); - }.bind(this)); + this.prompt(questions.services, _onDone.bind(this, this.async())); }, /** * Ask miscellaneous questions */ askMiscellaneousQuestions: function () { - var done = this.async(); - this.log(chalk.yellow('\nMiscellaneous questions:')); - - this.prompt(questions.miscellaneous, function (answers) { - this.answers = assign(this.answers, answers); - done(); - }.bind(this)); + this.prompt(questions.miscellaneous, _onDone.bind(this, this.async())); }, /** From 5a8fccbb6d1c5caefe791b8080dd0f06a9d1e3cf Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sun, 1 Mar 2015 14:35:01 +0200 Subject: [PATCH 089/118] Remove callback hell from end step --- generators/app/steps/end.js | 73 ++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/generators/app/steps/end.js b/generators/app/steps/end.js index 333e3ea2..62979c57 100644 --- a/generators/app/steps/end.js +++ b/generators/app/steps/end.js @@ -6,39 +6,60 @@ var chalk = require('chalk'), printMessage = require('print-message'); +/** + * Triggers when check-updates is finished + * @param {Function} done + * @param {Number} code + * @private + */ +function _onCheckUpdatesClose(done, code) { + if (code !== 0) { + printMessage(['Some error was occurred'], { + borderColor: 'red', + printFn: this.log + }); + + return process.exit(code); + } + + done(); +} + +/** + * Triggers when fix-deps tools is finished + * @param {Function} done + * @param {Number} code + * @private + */ +function _onFixDepsClose(done, code) { + if (code !== 0) { + printMessage(['Some error was occurred'], { + borderColor: 'red', + printFn: this.log + }); + + return process.exit(code); + } + + this.spawnCommand('npm', [ + 'run-script', + 'check-updates', + this.options.verbose ? '--verbose' : '' + ]).on('close', _onCheckUpdatesClose.bind(this, done)); +} + module.exports = { /** * Run diagnostic tools */ runDiagnostic: function () { if (!(this.options['skip-project-diagnostic'] || this.options['skip-all'])) { - var done = this.async(); - this.log(chalk.yellow('Starting diagnostic, please wait...')); - - this.spawnCommand('npm', ['run-script', 'fix-deps', this.options.verbose ? '--verbose' : '']).on('close', function (code) { - if (code !== 0) { - printMessage(['Some error was occurred'], { - borderColor: 'red', - printFn: this.log - }); - - return process.exit(code); - } - - this.spawnCommand('npm', ['run-script', 'check-updates', this.options.verbose ? '--verbose' : '']).on('close', function (code) { - if (code !== 0) { - printMessage(['Some error was occurred'], { - borderColor: 'red', - printFn: this.log - }); - - return process.exit(code); - } - - done(); - }.bind(this)); - }.bind(this)); + this.spawnCommand('npm', [ + 'run-script', + 'fix-deps', + this.options.verbose ? '--verbose' : '' + ]).on('close', _onFixDepsClose.bind(this, this.async())); } }, From 85a73391c6e208e9a58d80a51c9192db004579db Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 2 Mar 2015 14:14:10 +0200 Subject: [PATCH 090/118] Move update notifier callback --- generators/app/steps/initializing.js | 53 ++++++++++++++++------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/generators/app/steps/initializing.js b/generators/app/steps/initializing.js index e5db8975..5e51d35f 100644 --- a/generators/app/steps/initializing.js +++ b/generators/app/steps/initializing.js @@ -8,6 +8,36 @@ var chalk = require('chalk'), printMessage = require('print-message'), yosay = require('yosay'); +/** + * Triggers when updateNotifier done checking updates + * @param {Function} done + * @param {Object} error + * @param {Object} update + * @private + */ +function _onUpdateNotifier(done, error, update) { + if (error) { + console.error(error.stack || error); + return process.exit(1); + } + + if (update && update.type !== 'latest') { + printMessage([ + 'Update available: ' + chalk.green.bold(update.latest) + chalk.dim(' (current: ' + update.current + ')'), + 'Run ' + chalk.blue('npm update -g ' + update.name) + ' to update.' + ], { + marginTop: 0, + marginBottom: 0, + printFn: this.log + }); + + process.exit(0); + } else { + this.log(chalk.yellow('OK... You are using the latest version ' + chalk.green.bold(update.current))); + done(); + } +} + module.exports = { /** * Load package.json @@ -36,28 +66,7 @@ module.exports = { updateNotifier({ pkg: this.pkg, - callback: function (error, update) { - if (error) { - console.error(error.stack || error); - return process.exit(1); - } - - if (update && update.type !== 'latest') { - printMessage([ - 'Update available: ' + chalk.green.bold(update.latest) + chalk.dim(' (current: ' + update.current + ')'), - 'Run ' + chalk.blue('npm update -g ' + update.name) + ' to update.' - ], { - marginTop: 0, - marginBottom: 0, - printFn: this.log - }); - - process.exit(0); - } else { - this.log(chalk.yellow('OK... You are using the latest version ' + chalk.green.bold(update.current))); - done(); - } - }.bind(this) + callback: _onUpdateNotifier.bind(this, done) }); } } From f63c234f5f0fa43619ee96866121665e9d279775 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 2 Mar 2015 14:15:25 +0200 Subject: [PATCH 091/118] Move done() to arguments --- generators/app/steps/initializing.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/generators/app/steps/initializing.js b/generators/app/steps/initializing.js index 5e51d35f..68ec5309 100644 --- a/generators/app/steps/initializing.js +++ b/generators/app/steps/initializing.js @@ -60,13 +60,10 @@ module.exports = { */ notifyAboutGeneratorUpdate: function () { if (!(this.options['skip-generator-update'] || this.options['skip-all'])) { - var done = this.async(); - this.log(chalk.yellow('Checking for updates...')); - updateNotifier({ pkg: this.pkg, - callback: _onUpdateNotifier.bind(this, done) + callback: _onUpdateNotifier.bind(this, this.async()) }); } } From 3a0bef9eb190e97dad975e251a72783d2d1c5a36 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 2 Mar 2015 14:26:06 +0200 Subject: [PATCH 092/118] Move on npm install done callback --- generators/app/steps/install.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/generators/app/steps/install.js b/generators/app/steps/install.js index 3bba9aed..88f91c4d 100644 --- a/generators/app/steps/install.js +++ b/generators/app/steps/install.js @@ -5,6 +5,18 @@ var chalk = require('chalk'); +/** + * Triggers when npm install is done + * @param {Object} error + * @private + */ +function _onNpmInstallClose(error) { + if (error) { + console.error(error.stack || error); + return process.exit(1); + } +} + module.exports = { /** * Install npm dependencies @@ -15,12 +27,7 @@ module.exports = { this.npmInstall([], { color: 'always', verbose: this.options.verbose - }, function (error) { - if (error) { - console.error(error.stack || error); - return process.exit(1); - } - }); + }, _onNpmInstallClose.bind(this)); } } }; From 823ae1274a47f2b24e3a46cef23e92c6d179f9f7 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 2 Mar 2015 20:35:51 +0200 Subject: [PATCH 093/118] Update print-message version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 75fa46fd..20ae4313 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ }, "dependencies": { "chalk": "^1.0.0", - "print-message": "^1.1.0", + "print-message": "^1.2.0", "update-notifier": "^0.3.0", "yeoman-generator": "^0.18.9", "yosay": "^1.0.2" From 85b6f122d606d19dd2649f720d9b7f868b017f4e Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 2 Mar 2015 20:38:30 +0200 Subject: [PATCH 094/118] Cleaning up in print-message --- generators/app/steps/end.js | 24 ++++-------------------- generators/app/steps/initializing.js | 6 +----- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/generators/app/steps/end.js b/generators/app/steps/end.js index 62979c57..26b0351b 100644 --- a/generators/app/steps/end.js +++ b/generators/app/steps/end.js @@ -14,11 +14,7 @@ var chalk = require('chalk'), */ function _onCheckUpdatesClose(done, code) { if (code !== 0) { - printMessage(['Some error was occurred'], { - borderColor: 'red', - printFn: this.log - }); - + printMessage('Some error was occurred', {borderColor: 'red'}); return process.exit(code); } @@ -33,11 +29,7 @@ function _onCheckUpdatesClose(done, code) { */ function _onFixDepsClose(done, code) { if (code !== 0) { - printMessage(['Some error was occurred'], { - borderColor: 'red', - printFn: this.log - }); - + printMessage('Some error was occurred', {borderColor: 'red'}); return process.exit(code); } @@ -74,11 +66,7 @@ module.exports = { chalk.red(this.pkg.bugs.url), 'Or you can write me the letter', chalk.red(this.pkg.bugs.email) - ], { - marginTop: 0, - marginBottom: 0, - printFn: this.log - }); + ]); }, /** @@ -90,11 +78,7 @@ module.exports = { printMessage([ 'You have skipped installing npm modules', 'Install them manually via ' + chalk.blue('npm install') - ], { - marginTop: 0, - marginBottom: 0, - printFn: this.log - }); + ]); } } }; diff --git a/generators/app/steps/initializing.js b/generators/app/steps/initializing.js index 68ec5309..2cfa27ac 100644 --- a/generators/app/steps/initializing.js +++ b/generators/app/steps/initializing.js @@ -25,11 +25,7 @@ function _onUpdateNotifier(done, error, update) { printMessage([ 'Update available: ' + chalk.green.bold(update.latest) + chalk.dim(' (current: ' + update.current + ')'), 'Run ' + chalk.blue('npm update -g ' + update.name) + ' to update.' - ], { - marginTop: 0, - marginBottom: 0, - printFn: this.log - }); + ]); process.exit(0); } else { From 73847142252250fcbd1a031a26f0948ae1cdaef1 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 2 Mar 2015 20:40:14 +0200 Subject: [PATCH 095/118] Update print-message version in template --- generators/app/templates/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/app/templates/package.json b/generators/app/templates/package.json index 3823d4dd..c8bfd520 100644 --- a/generators/app/templates/package.json +++ b/generators/app/templates/package.json @@ -9,7 +9,7 @@ "dependency-check": "^2.2.2", "mocha": "^2.1.0", "npm-check": "^3.2.7", - "print-message": "^1.1.0", + "print-message": "^1.2.0", "recursive-readdir": "^1.2.1" }, "scripts": { From 301feaaca8ec63a8a2cdb1b82268608e6ad408b4 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 2 Mar 2015 20:57:47 +0200 Subject: [PATCH 096/118] Update print-message version --- generators/app/templates/package.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/generators/app/templates/package.json b/generators/app/templates/package.json index c8bfd520..56a3d1f5 100644 --- a/generators/app/templates/package.json +++ b/generators/app/templates/package.json @@ -9,7 +9,7 @@ "dependency-check": "^2.2.2", "mocha": "^2.1.0", "npm-check": "^3.2.7", - "print-message": "^1.2.0", + "print-message": "^1.2.1", "recursive-readdir": "^1.2.1" }, "scripts": { diff --git a/package.json b/package.json index 20ae4313..5b829f03 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ }, "dependencies": { "chalk": "^1.0.0", - "print-message": "^1.2.0", + "print-message": "^1.2.1", "update-notifier": "^0.3.0", "yeoman-generator": "^0.18.9", "yosay": "^1.0.2" From 83e1a666c2cfeaac03d97d63e10267fe125515c5 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Mon, 2 Mar 2015 22:45:55 +0200 Subject: [PATCH 097/118] Update Roadmap --- ROADMAP.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ROADMAP.md b/ROADMAP.md index 7af4072d..83478628 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -11,6 +11,8 @@ - [ ] Test coverage for all `api` files; - [ ] Implement search on top of `find` blueprint; - [ ] Implement pluralized form only for REST models; +- [ ] Think about questions "Which hook you want to leave enable?" and disable\enable hooks based on those answers; +- [ ] Think about generating not only backend REST API, so user can still have clean Sails application (maybe call spawn `sails new `; ## Next minor version From 205033e71ad5b2fe419f9f771c673abff117a059 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 12:18:48 +0200 Subject: [PATCH 098/118] Fix bug with bodyParser --- generators/app/templates/config/http.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generators/app/templates/config/http.js b/generators/app/templates/config/http.js index d9c80021..9fcf7fbf 100644 --- a/generators/app/templates/config/http.js +++ b/generators/app/templates/config/http.js @@ -11,7 +11,7 @@ module.exports.http = { * * @type {Object|Boolean} */ - serverOptions: false, + serverOptions: undefined, /** * You can define own custom middleware here @@ -30,7 +30,7 @@ module.exports.http = { * * @type {Function|Boolean} */ - bodyParser: false, + bodyParser: undefined, /** * Express middleware to use for every Sails request From 7b1a4ea4d97ca9183874be78001ceeeb5f3ea8b4 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 12:58:40 +0200 Subject: [PATCH 099/118] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 657a1d0c..63c8ff54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Improvement: Add options to `check-updates.js` tool; - Improvement: Add tools to npm scripts, so you can call `npm run-script ` now; - Improvement: Add `verbose` flag, so you can see everything what going on in `RunContext`; +- Fix: Bug with `bodyParser` is not parsing POST body; - Fix: Bug with no colorful print in `fix-deps.js`; - Fix: Bug with no colorful print in installing step in generator; - Fix: Bug when returns total count of records even with `where` criteria; From 243d1d76cc17e3358ab0e565a4373699825ae005 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 13:02:56 +0200 Subject: [PATCH 100/118] Add Yahoo auth system --- CHANGELOG.md | 1 + generators/app/questions/application.js | 10 +++++ .../api/controllers/AuthController.js | 23 +++++++++++ generators/app/templates/api/models/User.js | 4 ++ generators/app/templates/config/passport.js | 40 ++++++++++++++++++- 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63c8ff54..974b7df8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Improvement: Implemented parsing CommonJS modules from AST (Abstract Syntax Tree), so now generator is knows which modules you are really using; - Improvement: Frozen structure of generator and project. Any serious changes in project structure; +- Improvement: Add Yahoo authorization; - Improvement: Split generator arguments declaration to separate folder; - Improvement: Split generator options declaration to separate folder; - Improvement: Split generator questions declaration to separate folder; diff --git a/generators/app/questions/application.js b/generators/app/questions/application.js index bfee0c9f..98e363b8 100644 --- a/generators/app/questions/application.js +++ b/generators/app/questions/application.js @@ -35,4 +35,14 @@ module.exports = [{ name: 'application:twitter-consumer-secret', message: 'Type your Twitter Consumer Secret', default: '-' +}, { + type: 'input', + name: 'application:yahoo-app-id', + message: 'Type your Yahoo App ID', + default: '-' +}, { + type: 'input', + name: 'application:yahoo-app-secret', + message: 'Type your Yahoo App Secret', + default: '-' }]; diff --git a/generators/app/templates/api/controllers/AuthController.js b/generators/app/templates/api/controllers/AuthController.js index b77d0f6f..28f87b88 100644 --- a/generators/app/templates/api/controllers/AuthController.js +++ b/generators/app/templates/api/controllers/AuthController.js @@ -90,5 +90,28 @@ module.exports = { } })(req, res); })(req, res); + }, + + /** + * Yahoo authorization\linking + */ + yahoo: function (req, res) { + passport.authenticate('jwt', function (error, user) { + req.user = user; + + passport.authenticate('yahoo-token', function (error, user, info) { + if (error) { + sails.log.error(error); + res.serverError(error); + } else if (info) { + res.unauthorized(null, info.code, info.message); + } else { + res.ok({ + token: CipherService.create('jwt', {id: user.id}).hashSync(), + user: user + }); + } + })(req, res); + })(req, res); } }; diff --git a/generators/app/templates/api/models/User.js b/generators/app/templates/api/models/User.js index 0489636b..c2085436 100644 --- a/generators/app/templates/api/models/User.js +++ b/generators/app/templates/api/models/User.js @@ -58,6 +58,10 @@ module.exports = { type: 'object' }, + yahoo: { + type: 'object' + }, + toJSON: function () { var obj = this.toObject(); diff --git a/generators/app/templates/config/passport.js b/generators/app/templates/config/passport.js index d9a3f80e..e9851575 100644 --- a/generators/app/templates/config/passport.js +++ b/generators/app/templates/config/passport.js @@ -7,7 +7,8 @@ var passport = require('passport'), LocalStrategy = require('passport-local').Strategy, JwtStrategy = require('passport-jwt').Strategy, FacebookTokenStrategy = require('passport-facebook-token').Strategy, - TwitterTokenStrategy = require('passport-twitter-token').Strategy; + TwitterTokenStrategy = require('passport-twitter-token').Strategy, + YahooTokenStrategy = require('passport-yahoo-token').Strategy; passport.use(new LocalStrategy({ usernameField: 'username', @@ -141,3 +142,40 @@ passport.use(new TwitterTokenStrategy({ req.user.save(next); } })); + +passport.use(new YahooTokenStrategy({ + clientID: "<%= answers['application:yahoo-app-id'] %>", + clientSecret: "<%= answers['application:yahoo-app-secret'] %>", + passReqToCallback: true +}, function (req, accessToken, refreshToken, profile, next) { + if (!req.user) { + User + .findOrCreate({ + 'yahoo.id': profile.id + }, { + username: req.param('username') || profile.username || profile.displayName, + email: req.param('email') || (profile.emails && profile.emails[0].value), + firstName: req.param('firstName') || (profile.displayName && profile.displayName.split(' ')[0]), + lastName: req.param('lastName') || (profile.displayName && profile.displayName.split(' ')[1]), + photo: req.param('photo') || ['https://graph.facebook.com/', profile.id, '/picture?type=large'].join(''), + facebook: profile._json + }) + .exec(function (error, user) { + if (error) { + return next(error); + } + + if (!user) { + return next(null, false, { + code: "E_AUTH_FAILED", + message: "Yahoo auth failed" + }); + } + + return next(null, user); + }); + } else { + req.user.yahoo = profile._json; + req.user.save(next); + } +})); From 3147603bc970d1fe34ef677e656f1533a7adc7f0 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 16:01:58 +0200 Subject: [PATCH 101/118] Fix bug with passport-jwt strategy --- CHANGELOG.md | 1 + generators/app/templates/config/passport.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 974b7df8..4b402fb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Improvement: Add options to `check-updates.js` tool; - Improvement: Add tools to npm scripts, so you can call `npm run-script ` now; - Improvement: Add `verbose` flag, so you can see everything what going on in `RunContext`; +- Fix: Bug with passport-jwt upgrade; - Fix: Bug with `bodyParser` is not parsing POST body; - Fix: Bug with no colorful print in `fix-deps.js`; - Fix: Bug with no colorful print in installing step in generator; diff --git a/generators/app/templates/config/passport.js b/generators/app/templates/config/passport.js index e9851575..b2470bf3 100644 --- a/generators/app/templates/config/passport.js +++ b/generators/app/templates/config/passport.js @@ -45,7 +45,8 @@ passport.use(new LocalStrategy({ }); })); -passport.use(new JwtStrategy("<%= answers['application:jwt-secret'] %>", { +passport.use(new JwtStrategy({ + secretOrKey: "<%= answers['application:jwt-secret'] %>", tokenBodyField: 'jwt-token', tokenHeader: 'JWT' }, function (payload, next) { From a233fa009958e029505708453cce119772150e8e Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 16:27:26 +0200 Subject: [PATCH 102/118] Fix bug when empty POST to auth issued JWT --- CHANGELOG.md | 1 + .../api/controllers/AuthController.js | 72 ++++++++++--------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b402fb5..37dc939d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Improvement: Add options to `check-updates.js` tool; - Improvement: Add tools to npm scripts, so you can call `npm run-script ` now; - Improvement: Add `verbose` flag, so you can see everything what going on in `RunContext`; +- Fix: Bug when JWT issued to user `false`; - Fix: Bug with passport-jwt upgrade; - Fix: Bug with `bodyParser` is not parsing POST body; - Fix: Bug with no colorful print in `fix-deps.js`; diff --git a/generators/app/templates/api/controllers/AuthController.js b/generators/app/templates/api/controllers/AuthController.js index 28f87b88..2a1f0e35 100644 --- a/generators/app/templates/api/controllers/AuthController.js +++ b/generators/app/templates/api/controllers/AuthController.js @@ -13,15 +13,17 @@ module.exports = { passport.authenticate('local', function (error, user, info) { if (error) { sails.log.error(error); - res.serverError(error); - } else if (info) { - res.unauthorized(null, info.code, info.message); - } else { - res.ok({ - token: CipherService.create('jwt', {id: user.id}).hashSync(), - user: user - }); + return res.serverError(error); + } + + if (info || !user) { + return res.unauthorized(null, info.code, info.message); } + + res.ok({ + token: CipherService.create('jwt', {id: user.id}).hashSync(), + user: user + }); })(req, res); }, @@ -56,15 +58,17 @@ module.exports = { passport.authenticate('facebook-token', function (error, user, info) { if (error) { sails.log.error(error); - res.serverError(error); - } else if (info) { - res.unauthorized(null, info.code, info.message); - } else { - res.ok({ - token: CipherService.create('jwt', {id: user.id}).hashSync(), - user: user - }); + return res.serverError(error); + } + + if (info || !user) { + return res.unauthorized(null, info.code, info.message); } + + res.ok({ + token: CipherService.create('jwt', {id: user.id}).hashSync(), + user: user + }); })(req, res); })(req, res); }, @@ -79,15 +83,17 @@ module.exports = { passport.authenticate('twitter-token', function (error, user, info) { if (error) { sails.log.error(error); - res.serverError(error); - } else if (info) { - res.unauthorized(null, info.code, info.message); - } else { - res.ok({ - token: CipherService.create('jwt', {id: user.id}).hashSync(), - user: user - }); + return res.serverError(error); } + + if (info) { + return res.unauthorized(null, info.code, info.message); + } + + res.ok({ + token: CipherService.create('jwt', {id: user.id}).hashSync(), + user: user + }); })(req, res); })(req, res); }, @@ -102,15 +108,17 @@ module.exports = { passport.authenticate('yahoo-token', function (error, user, info) { if (error) { sails.log.error(error); - res.serverError(error); - } else if (info) { - res.unauthorized(null, info.code, info.message); - } else { - res.ok({ - token: CipherService.create('jwt', {id: user.id}).hashSync(), - user: user - }); + return res.serverError(error); + } + + if (info) { + return res.unauthorized(null, info.code, info.message); } + + res.ok({ + token: CipherService.create('jwt', {id: user.id}).hashSync(), + user: user + }); })(req, res); })(req, res); } From 14f261ef246679e3edc9c67ebfc2b2cf38a8ab1d Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 16:44:21 +0200 Subject: [PATCH 103/118] Optimize auth controller --- .../api/controllers/AuthController.js | 92 ++++++------------- 1 file changed, 29 insertions(+), 63 deletions(-) diff --git a/generators/app/templates/api/controllers/AuthController.js b/generators/app/templates/api/controllers/AuthController.js index 2a1f0e35..8db2a69a 100644 --- a/generators/app/templates/api/controllers/AuthController.js +++ b/generators/app/templates/api/controllers/AuthController.js @@ -5,26 +5,37 @@ var passport = require('passport'); +/** + * Triggers when user authenticates via passport + * @param {Object} req + * @param {Object} res + * @param {Object} error + * @param {Object} user + * @param {Object} info + * @private + */ +function _onPassportAuth(req, res, error, user, info) { + if (error) { + sails.log.error(error); + return res.serverError(error); + } + + if (info || !user) { + return res.unauthorized(null, info.code, info.message); + } + + res.ok({ + token: CipherService.create('jwt', {id: user.id}).hashSync(), + user: user + }); +} + module.exports = { /** * Sign in by local strategy in passport */ signin: function (req, res) { - passport.authenticate('local', function (error, user, info) { - if (error) { - sails.log.error(error); - return res.serverError(error); - } - - if (info || !user) { - return res.unauthorized(null, info.code, info.message); - } - - res.ok({ - token: CipherService.create('jwt', {id: user.id}).hashSync(), - user: user - }); - })(req, res); + passport.authenticate('local', _onPassportAuth.bind(this, req, res))(req, res); }, /** @@ -54,22 +65,7 @@ module.exports = { facebook: function (req, res) { passport.authenticate('jwt', function (error, user) { req.user = user; - - passport.authenticate('facebook-token', function (error, user, info) { - if (error) { - sails.log.error(error); - return res.serverError(error); - } - - if (info || !user) { - return res.unauthorized(null, info.code, info.message); - } - - res.ok({ - token: CipherService.create('jwt', {id: user.id}).hashSync(), - user: user - }); - })(req, res); + passport.authenticate('facebook-token', _onPassportAuth.bind(this, req, res))(req, res); })(req, res); }, @@ -79,22 +75,7 @@ module.exports = { twitter: function (req, res) { passport.authenticate('jwt', function (error, user) { req.user = user; - - passport.authenticate('twitter-token', function (error, user, info) { - if (error) { - sails.log.error(error); - return res.serverError(error); - } - - if (info) { - return res.unauthorized(null, info.code, info.message); - } - - res.ok({ - token: CipherService.create('jwt', {id: user.id}).hashSync(), - user: user - }); - })(req, res); + passport.authenticate('twitter-token', _onPassportAuth.bind(this, req, res))(req, res); })(req, res); }, @@ -104,22 +85,7 @@ module.exports = { yahoo: function (req, res) { passport.authenticate('jwt', function (error, user) { req.user = user; - - passport.authenticate('yahoo-token', function (error, user, info) { - if (error) { - sails.log.error(error); - return res.serverError(error); - } - - if (info) { - return res.unauthorized(null, info.code, info.message); - } - - res.ok({ - token: CipherService.create('jwt', {id: user.id}).hashSync(), - user: user - }); - })(req, res); + passport.authenticate('yahoo-token', _onPassportAuth.bind(this, req, res))(req, res); })(req, res); } }; From ed22d43a54d8eb98a9f33b86a09f993f214d4a3f Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 17:21:39 +0200 Subject: [PATCH 104/118] Optimizing auth controller --- CHANGELOG.md | 1 + .../api/controllers/AuthController.js | 27 +++++++------------ .../templates/api/responses/serverError.js | 1 + 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37dc939d..847da01e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Improvement: Add options to `check-updates.js` tool; - Improvement: Add tools to npm scripts, so you can call `npm run-script ` now; - Improvement: Add `verbose` flag, so you can see everything what going on in `RunContext`; +- Improvement: Add logging all `serverError` responses to log by default (you don't need call `sails.log.error()`); - Fix: Bug when JWT issued to user `false`; - Fix: Bug with passport-jwt upgrade; - Fix: Bug with `bodyParser` is not parsing POST body; diff --git a/generators/app/templates/api/controllers/AuthController.js b/generators/app/templates/api/controllers/AuthController.js index 8db2a69a..0829bb20 100644 --- a/generators/app/templates/api/controllers/AuthController.js +++ b/generators/app/templates/api/controllers/AuthController.js @@ -15,16 +15,10 @@ var passport = require('passport'); * @private */ function _onPassportAuth(req, res, error, user, info) { - if (error) { - sails.log.error(error); - return res.serverError(error); - } - - if (info || !user) { - return res.unauthorized(null, info.code, info.message); - } + if (error) return res.serverError(error); + if (!user) return res.unauthorized(null, info.code, info.message); - res.ok({ + return res.ok({ token: CipherService.create('jwt', {id: user.id}).hashSync(), user: user }); @@ -47,15 +41,12 @@ module.exports = { User .create(req.allParams()) .exec(function (error, user) { - if (error) { - sails.log.error(error); - res.serverError(error); - } else { - res.created({ - token: CipherService.create('jwt', {id: user.id}).hashSync(), - user: user - }); - } + if (error) return res.serverError(error); + + return res.created({ + token: CipherService.create('jwt', {id: user.id}).hashSync(), + user: user + }); }); }, diff --git a/generators/app/templates/api/responses/serverError.js b/generators/app/templates/api/responses/serverError.js index 4958c140..e7715420 100644 --- a/generators/app/templates/api/responses/serverError.js +++ b/generators/app/templates/api/responses/serverError.js @@ -6,6 +6,7 @@ */ module.exports = function (data, code, message, root) { + this.req._sails.log.error(data); this.res.status(500); this.res.jsonx(_.assign({ code: code || "E_INTERNAL_SERVER_ERROR", From 02f45a1876a03ced3325b25d48cec18bce441d41 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 17:24:32 +0200 Subject: [PATCH 105/118] Optimizing blueprints --- .../app/templates/api/blueprints/create.js | 4 +-- .../app/templates/api/blueprints/destroy.js | 13 +++------- .../app/templates/api/blueprints/find.js | 12 +++------ .../app/templates/api/blueprints/findOne.js | 9 ++----- .../app/templates/api/blueprints/update.js | 26 +++++-------------- 5 files changed, 15 insertions(+), 49 deletions(-) diff --git a/generators/app/templates/api/blueprints/create.js b/generators/app/templates/api/blueprints/create.js index 60a6f757..c25f8402 100644 --- a/generators/app/templates/api/blueprints/create.js +++ b/generators/app/templates/api/blueprints/create.js @@ -13,9 +13,7 @@ module.exports = function (req, res) { Model .create(data) .exec(function (error, record) { - if (error) { - return res.serverError(error); - } + if (error) return res.serverError(error); return res.created(record); }); diff --git a/generators/app/templates/api/blueprints/destroy.js b/generators/app/templates/api/blueprints/destroy.js index bd9624c3..90d7938b 100644 --- a/generators/app/templates/api/blueprints/destroy.js +++ b/generators/app/templates/api/blueprints/destroy.js @@ -13,20 +13,13 @@ module.exports = function (req, res) { query = actionUtil.populateEach(query, req); query.exec(function (error, record) { - if (error) { - return res.serverError(error); - } - - if (!record) { - return res.notFound(); - } + if (error) return res.serverError(error); + if (!record) return res.notFound(); Model .destroy(pk) .exec(function (error) { - if (error) { - return res.serverError(error); - } + if (error) return res.serverError(error); return res.ok(record); }); diff --git a/generators/app/templates/api/blueprints/find.js b/generators/app/templates/api/blueprints/find.js index 355992a2..9442849a 100644 --- a/generators/app/templates/api/blueprints/find.js +++ b/generators/app/templates/api/blueprints/find.js @@ -9,9 +9,7 @@ var actionUtil = require('sails/lib/hooks/blueprints/actionUtil'); * If an id was specified, just the instance with that unique id will be returned. */ module.exports = function (req, res) { - if (actionUtil.parsePk(req)) { - return require('./findOne')(req, res); - } + if (actionUtil.parsePk(req)) return require('./findOne')(req, res); var Model = actionUtil.parseModel(req), where = actionUtil.parseCriteria(req), @@ -22,16 +20,12 @@ module.exports = function (req, res) { query = actionUtil.populateEach(query, req); query.exec(function (error, records) { - if (error) { - return res.serverError(error); - } + if (error) return res.serverError(error); Model .count(where) .exec(function (error, count) { - if (error) { - return res.serverError(error); - } + if (error) return res.serverError(error); var metaInfo = { start: skip, diff --git a/generators/app/templates/api/blueprints/findOne.js b/generators/app/templates/api/blueprints/findOne.js index b57b9deb..20e36b7b 100644 --- a/generators/app/templates/api/blueprints/findOne.js +++ b/generators/app/templates/api/blueprints/findOne.js @@ -14,13 +14,8 @@ module.exports = function (req, res) { query = actionUtil.populateEach(query, req); query.exec(function (error, record) { - if (error) { - return res.serverError(error); - } - - if (!record) { - return res.notFound(); - } + if (error) return res.serverError(error); + if (!record) return res.notFound(); return res.ok(record); }); diff --git a/generators/app/templates/api/blueprints/update.js b/generators/app/templates/api/blueprints/update.js index ba498020..11709171 100644 --- a/generators/app/templates/api/blueprints/update.js +++ b/generators/app/templates/api/blueprints/update.js @@ -11,40 +11,26 @@ module.exports = function (req, res) { pk = actionUtil.requirePk(req), values = actionUtil.parseValues(req); - if (!((req.body && req.body.id) || req.query.id)) { - delete values.id; - } + if (!((req.body && req.body.id) || req.query.id)) delete values.id; Model .findOne(pk) .exec(function (error, record) { - if (error) { - return res.serverError(error); - } - - if (!record) { - return res.notFound(); - } + if (error) return res.serverError(error); + if (!record) return res.notFound(); Model .update(pk, values) .exec(function (error, records) { - if (error) { - return res.serverError(error); - } + if (error) return res.serverError(error); var updatedRecord = records[0]; var query = Model.findOne(updatedRecord[Model.primaryKey]); query = actionUtil.populateEach(query, req); query.exec(function (error, populatedRecord) { - if (error) { - return res.serverError(error); - } - - if (!populatedRecord) { - return res.serverError(null, null, "Could not find record after updating"); - } + if (error) return res.serverError(error); + if (!populatedRecord) return res.serverError(null, null, "Could not find record after updating"); return res.ok(populatedRecord); }); From 325bbbf8813255d0ec55870c81da07d95261a027 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 18:08:31 +0200 Subject: [PATCH 106/118] Typo update in comments --- .../app/templates/api/controllers/AuthController.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/generators/app/templates/api/controllers/AuthController.js b/generators/app/templates/api/controllers/AuthController.js index 0829bb20..83934c55 100644 --- a/generators/app/templates/api/controllers/AuthController.js +++ b/generators/app/templates/api/controllers/AuthController.js @@ -7,11 +7,11 @@ var passport = require('passport'); /** * Triggers when user authenticates via passport - * @param {Object} req - * @param {Object} res - * @param {Object} error - * @param {Object} user - * @param {Object} info + * @param {Object} req Request stream + * @param {Object} res Response stream + * @param {Object} error Error object + * @param {Object} user User profile + * @param {Object} info Info if some error occurs * @private */ function _onPassportAuth(req, res, error, user, info) { From 33f10083e23fe7f793663e608974ce7ba320b9ce Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 18:15:15 +0200 Subject: [PATCH 107/118] Fix bug with empty info --- generators/app/templates/api/controllers/AuthController.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/generators/app/templates/api/controllers/AuthController.js b/generators/app/templates/api/controllers/AuthController.js index 83934c55..45c7be60 100644 --- a/generators/app/templates/api/controllers/AuthController.js +++ b/generators/app/templates/api/controllers/AuthController.js @@ -11,10 +11,13 @@ var passport = require('passport'); * @param {Object} res Response stream * @param {Object} error Error object * @param {Object} user User profile - * @param {Object} info Info if some error occurs + * @param {Object} _info Info if some error occurs * @private */ -function _onPassportAuth(req, res, error, user, info) { +function _onPassportAuth(req, res, error, user, _info) { + // TODO: cleans up info + var info = _info || {}; + if (error) return res.serverError(error); if (!user) return res.unauthorized(null, info.code, info.message); From 49ad1bd1e1df31a93b7df90e56f94a818fcb05b6 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 18:19:44 +0200 Subject: [PATCH 108/118] Optimize policies --- .../app/templates/api/policies/isAllowed.js | 2 +- .../templates/api/policies/isAuthenticated.js | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/generators/app/templates/api/policies/isAllowed.js b/generators/app/templates/api/policies/isAllowed.js index 103f2b55..6beada68 100644 --- a/generators/app/templates/api/policies/isAllowed.js +++ b/generators/app/templates/api/policies/isAllowed.js @@ -4,7 +4,7 @@ */ module.exports = function (req, res, next) { - var token = req.headers["application-token"]; + var token = req.headers['application-token']; if (token && token === "<%= answers['application:api-secret-key'] %>") { next(); diff --git a/generators/app/templates/api/policies/isAuthenticated.js b/generators/app/templates/api/policies/isAuthenticated.js index a3844ebc..92bd71f3 100644 --- a/generators/app/templates/api/policies/isAuthenticated.js +++ b/generators/app/templates/api/policies/isAuthenticated.js @@ -6,15 +6,14 @@ var passport = require('passport'); module.exports = function (req, res, next) { - passport.authenticate('jwt', function (error, user, info) { - if (error) { - sails.log.error(error); - res.serverError(error); - } else if (info) { - res.unauthorized(null, info.code, info.message); - } else { - req.user = user; - next(); - } + passport.authenticate('jwt', function (error, user, _info) { + // TODO: cleans up info + var info = _info || {}; + + if (error) return res.serverError(error); + if (!user) return res.unauthorized(null, info.code, info.message); + + req.user = user; + next(); })(req, res); }; From cf9a91cf67e9a2dc455a704a379021791be0368f Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 18:33:56 +0200 Subject: [PATCH 109/118] Implement logging all responses in silly mode --- CHANGELOG.md | 1 + generators/app/templates/api/responses/badRequest.js | 10 +++++++--- generators/app/templates/api/responses/created.js | 10 +++++++--- generators/app/templates/api/responses/forbidden.js | 10 +++++++--- generators/app/templates/api/responses/notFound.js | 10 +++++++--- generators/app/templates/api/responses/ok.js | 10 +++++++--- generators/app/templates/api/responses/serverError.js | 11 +++++++---- .../app/templates/api/responses/unauthorized.js | 10 +++++++--- 8 files changed, 50 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 847da01e..cc6e019d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Improvement: Add tools to npm scripts, so you can call `npm run-script ` now; - Improvement: Add `verbose` flag, so you can see everything what going on in `RunContext`; - Improvement: Add logging all `serverError` responses to log by default (you don't need call `sails.log.error()`); +- Improvement: Implement logging all responses in `silly` mode; - Fix: Bug when JWT issued to user `false`; - Fix: Bug with passport-jwt upgrade; - Fix: Bug with `bodyParser` is not parsing POST body; diff --git a/generators/app/templates/api/responses/badRequest.js b/generators/app/templates/api/responses/badRequest.js index e3bc1d70..ee404a19 100644 --- a/generators/app/templates/api/responses/badRequest.js +++ b/generators/app/templates/api/responses/badRequest.js @@ -7,10 +7,14 @@ */ module.exports = function (data, code, message, root) { - this.res.status(400); - this.res.jsonx(_.assign({ + var response = _.assign({ code: code || "E_BAD_REQUEST", message: message || "The request cannot be fulfilled due to bad syntax", response: data || {} - }, root)); + }, root); + + this.req._sails.log.silly('Sent (400 BAD REQUEST)\n', response); + + this.res.status(400); + this.res.jsonx(response); }; diff --git a/generators/app/templates/api/responses/created.js b/generators/app/templates/api/responses/created.js index e2b83a58..7c7c49f4 100644 --- a/generators/app/templates/api/responses/created.js +++ b/generators/app/templates/api/responses/created.js @@ -8,10 +8,14 @@ */ module.exports = function (data, code, message, root) { - this.res.status(201); - this.res.jsonx(_.assign({ + var response = _.assign({ code: code || "CREATED", message: message || "The request has been fulfilled and resulted in a new resource being created", response: data || {} - }, root)); + }, root); + + this.req._sails.log.silly('Sent (201 CREATED)\n', response); + + this.res.status(201); + this.res.jsonx(response); }; diff --git a/generators/app/templates/api/responses/forbidden.js b/generators/app/templates/api/responses/forbidden.js index 428d5fd1..999b04be 100644 --- a/generators/app/templates/api/responses/forbidden.js +++ b/generators/app/templates/api/responses/forbidden.js @@ -7,10 +7,14 @@ */ module.exports = function (data, code, message, root) { - this.res.status(403); - this.res.jsonx(_.assign({ + var response = _.assign({ code: code || "E_FORBIDDEN", message: message || "User not authorized to perform the operation", response: data || {} - }, root)); + }, root); + + this.req._sails.log.silly('Sent (403 FORBIDDEN)\n', response); + + this.res.status(403); + this.res.jsonx(response); }; diff --git a/generators/app/templates/api/responses/notFound.js b/generators/app/templates/api/responses/notFound.js index 974e91e9..966202d1 100644 --- a/generators/app/templates/api/responses/notFound.js +++ b/generators/app/templates/api/responses/notFound.js @@ -7,10 +7,14 @@ */ module.exports = function (data, code, message, root) { - this.res.status(404); - this.res.jsonx(_.assign({ + var response = _.assign({ code: code || "E_NOT_FOUND", message: message || "The requested resource could not be found but may be available again in the future", response: data || {} - }, root)); + }, root); + + this.req._sails.log.silly('Sent (404 NOT FOUND)\n', response); + + this.res.status(404); + this.res.jsonx(response); }; diff --git a/generators/app/templates/api/responses/ok.js b/generators/app/templates/api/responses/ok.js index 0a65960b..fd077d87 100644 --- a/generators/app/templates/api/responses/ok.js +++ b/generators/app/templates/api/responses/ok.js @@ -8,10 +8,14 @@ */ module.exports = function (data, code, message, root) { - this.res.status(200); - this.res.jsonx(_.assign({ + var response = _.assign({ code: code || "OK", message: message || "Operation is successfully executed", response: data || {} - }, root)); + }, root); + + this.req._sails.log.silly('Sent (200 OK)\n', response); + + this.res.status(200); + this.res.jsonx(response); }; diff --git a/generators/app/templates/api/responses/serverError.js b/generators/app/templates/api/responses/serverError.js index e7715420..54a2e046 100644 --- a/generators/app/templates/api/responses/serverError.js +++ b/generators/app/templates/api/responses/serverError.js @@ -6,11 +6,14 @@ */ module.exports = function (data, code, message, root) { - this.req._sails.log.error(data); - this.res.status(500); - this.res.jsonx(_.assign({ + var response = _.assign({ code: code || "E_INTERNAL_SERVER_ERROR", message: message || "Something bad happened on the server", response: data || {} - }, root)); + }, root); + + this.req._sails.log.error('Sent (500 INTERNAL SERVER ERROR)\n', response); + + this.res.status(500); + this.res.jsonx(response); }; diff --git a/generators/app/templates/api/responses/unauthorized.js b/generators/app/templates/api/responses/unauthorized.js index eb2e3e59..5cafc5de 100644 --- a/generators/app/templates/api/responses/unauthorized.js +++ b/generators/app/templates/api/responses/unauthorized.js @@ -7,10 +7,14 @@ */ module.exports = function (data, code, message, root) { - this.res.status(401); - this.res.jsonx(_.assign({ + var response = _.assign({ code: code || "E_UNAUTHORIZED", message: message || "Missing or invalid authentication token", response: data || {} - }, root)); + }, root); + + this.req._sails.log.silly('Sent (401 UNAUTHORIZED)\n', response); + + this.res.status(401); + this.res.jsonx(response); }; From f6d9158d1bd761e202c6eb3b6cb4b80e95fb8524 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 18:44:42 +0200 Subject: [PATCH 110/118] Typo fixes --- generators/app/templates/config/passport.js | 94 ++++++++------------- 1 file changed, 34 insertions(+), 60 deletions(-) diff --git a/generators/app/templates/config/passport.js b/generators/app/templates/config/passport.js index b2470bf3..aee32955 100644 --- a/generators/app/templates/config/passport.js +++ b/generators/app/templates/config/passport.js @@ -23,25 +23,19 @@ passport.use(new LocalStrategy({ }] }) .exec(function (error, user) { - if (error) { - return next(error); - } + if (error) return next(error, false, {}); - if (!user) { - return next(null, false, { - code: "E_USER_NOT_FOUND", - message: username + " is not found" - }); - } + if (!user) return next(null, false, { + code: "E_USER_NOT_FOUND", + message: username + " is not found" + }); - if (!CipherService.create('bcrypt', user.password).compareSync(password)) { - return next(null, false, { - code: "E_WRONG_PASSWORD", - message: "Password is wrong" - }); - } + if (!CipherService.create('bcrypt', user.password).compareSync(password)) return next(null, false, { + code: "E_WRONG_PASSWORD", + message: "Password is wrong" + }); - return next(null, user); + return next(null, user, {}); }); })); @@ -55,18 +49,13 @@ passport.use(new JwtStrategy({ id: payload.id }) .exec(function (error, user) { - if (error) { - return next(error); - } - - if (!user) { - return next(null, false, { - code: "E_USER_NOT_FOUND", - message: "User with that JWT not found" - }); - } + if (error) return next(error, false, {}); + if (!user) return next(null, false, { + code: "E_USER_NOT_FOUND", + message: "User with that JWT not found" + }); - return next(null, user); + return next(null, user, {}); }); })); @@ -88,18 +77,13 @@ passport.use(new FacebookTokenStrategy({ facebook: profile._json }) .exec(function (error, user) { - if (error) { - return next(error); - } - - if (!user) { - return next(null, false, { - code: "E_AUTH_FAILED", - message: "Facebook auth failed" - }); - } + if (error) return next(error, false, {}); + if (!user) return next(null, false, { + code: "E_AUTH_FAILED", + message: "Facebook auth failed" + }); - return next(null, user); + return next(null, user, {}); }); } else { req.user.facebook = profile._json; @@ -125,18 +109,13 @@ passport.use(new TwitterTokenStrategy({ twitter: profile._json }) .exec(function (error, user) { - if (error) { - return next(error); - } - - if (!user) { - return next(null, false, { - code: "E_AUTH_FAILED", - message: "Twitter auth failed" - }); - } + if (error) return next(error, false, {}); + if (!user) return next(null, false, { + code: "E_AUTH_FAILED", + message: "Twitter auth failed" + }); - return next(null, user); + return next(null, user, {}); }); } else { req.user.twitter = profile._json; @@ -162,18 +141,13 @@ passport.use(new YahooTokenStrategy({ facebook: profile._json }) .exec(function (error, user) { - if (error) { - return next(error); - } - - if (!user) { - return next(null, false, { - code: "E_AUTH_FAILED", - message: "Yahoo auth failed" - }); - } + if (error) return next(error, false, {}); + if (!user) return next(null, false, { + code: "E_AUTH_FAILED", + message: "Yahoo auth failed" + }); - return next(null, user); + return next(null, user, {}); }); } else { req.user.yahoo = profile._json; From f635d70f8b7cb6bc1deea7d6e5e4353997fed4d5 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 18:46:18 +0200 Subject: [PATCH 111/118] Cleans up info --- generators/app/templates/api/controllers/AuthController.js | 7 ++----- generators/app/templates/api/policies/isAuthenticated.js | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/generators/app/templates/api/controllers/AuthController.js b/generators/app/templates/api/controllers/AuthController.js index 45c7be60..83934c55 100644 --- a/generators/app/templates/api/controllers/AuthController.js +++ b/generators/app/templates/api/controllers/AuthController.js @@ -11,13 +11,10 @@ var passport = require('passport'); * @param {Object} res Response stream * @param {Object} error Error object * @param {Object} user User profile - * @param {Object} _info Info if some error occurs + * @param {Object} info Info if some error occurs * @private */ -function _onPassportAuth(req, res, error, user, _info) { - // TODO: cleans up info - var info = _info || {}; - +function _onPassportAuth(req, res, error, user, info) { if (error) return res.serverError(error); if (!user) return res.unauthorized(null, info.code, info.message); diff --git a/generators/app/templates/api/policies/isAuthenticated.js b/generators/app/templates/api/policies/isAuthenticated.js index 92bd71f3..b5808035 100644 --- a/generators/app/templates/api/policies/isAuthenticated.js +++ b/generators/app/templates/api/policies/isAuthenticated.js @@ -6,10 +6,7 @@ var passport = require('passport'); module.exports = function (req, res, next) { - passport.authenticate('jwt', function (error, user, _info) { - // TODO: cleans up info - var info = _info || {}; - + passport.authenticate('jwt', function (error, user, info) { if (error) return res.serverError(error); if (!user) return res.unauthorized(null, info.code, info.message); From 4df8b8e41f9d106ff8e79dff3e28df65226bc206 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Wed, 4 Mar 2015 19:41:49 +0200 Subject: [PATCH 112/118] Comment non-working questions --- generators/app/steps/prompting.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/generators/app/steps/prompting.js b/generators/app/steps/prompting.js index f207f566..8d2fdb6c 100644 --- a/generators/app/steps/prompting.js +++ b/generators/app/steps/prompting.js @@ -38,21 +38,22 @@ module.exports = { this.prompt(questions.application, _onDone.bind(this, this.async())); }, - /** - * Ask services questions - */ - askServiceQuestions: function () { - this.log(chalk.yellow('\nService questions:')); - this.prompt(questions.services, _onDone.bind(this, this.async())); - }, - - /** - * Ask miscellaneous questions - */ - askMiscellaneousQuestions: function () { - this.log(chalk.yellow('\nMiscellaneous questions:')); - this.prompt(questions.miscellaneous, _onDone.bind(this, this.async())); - }, + // TODO: uncomment this when will be done this feature + ///** + // * Ask services questions + // */ + //askServiceQuestions: function () { + // this.log(chalk.yellow('\nService questions:')); + // this.prompt(questions.services, _onDone.bind(this, this.async())); + //}, + // + ///** + // * Ask miscellaneous questions + // */ + //askMiscellaneousQuestions: function () { + // this.log(chalk.yellow('\nMiscellaneous questions:')); + // this.prompt(questions.miscellaneous, _onDone.bind(this, this.async())); + //}, /** * Print generated answers object if in verbose mode From e5a483594d924f409563a1149928f4114ac28a3c Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 5 Mar 2015 14:27:54 +0200 Subject: [PATCH 113/118] Add ping route --- CHANGELOG.md | 1 + .../app/templates/api/controllers/AuthController.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc6e019d..1ef069fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Improvement: Add `verbose` flag, so you can see everything what going on in `RunContext`; - Improvement: Add logging all `serverError` responses to log by default (you don't need call `sails.log.error()`); - Improvement: Implement logging all responses in `silly` mode; +- Improvement: Add `ping` route to `AuthController` which just respond with OK; - Fix: Bug when JWT issued to user `false`; - Fix: Bug with passport-jwt upgrade; - Fix: Bug with `bodyParser` is not parsing POST body; diff --git a/generators/app/templates/api/controllers/AuthController.js b/generators/app/templates/api/controllers/AuthController.js index 83934c55..e6e0fa35 100644 --- a/generators/app/templates/api/controllers/AuthController.js +++ b/generators/app/templates/api/controllers/AuthController.js @@ -78,5 +78,13 @@ module.exports = { req.user = user; passport.authenticate('yahoo-token', _onPassportAuth.bind(this, req, res))(req, res); })(req, res); + }, + + /** + * Server ping + * Useful when need to check if it's server is down or some logic is break + */ + ping: function (req, res) { + res.ok(null, null, 'Pong'); } }; From 117a583c7be63fb1202f80fc8c7a52d285a78c13 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 5 Mar 2015 14:38:35 +0200 Subject: [PATCH 114/118] Typo fixes --- generators/app/templates/api/policies/isAllowed.js | 2 +- generators/app/templates/api/responses/badRequest.js | 4 ++-- generators/app/templates/api/responses/created.js | 4 ++-- generators/app/templates/api/responses/forbidden.js | 4 ++-- generators/app/templates/api/responses/notFound.js | 4 ++-- generators/app/templates/api/responses/ok.js | 4 ++-- generators/app/templates/api/responses/serverError.js | 4 ++-- generators/app/templates/api/responses/unauthorized.js | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/generators/app/templates/api/policies/isAllowed.js b/generators/app/templates/api/policies/isAllowed.js index 6beada68..8449e334 100644 --- a/generators/app/templates/api/policies/isAllowed.js +++ b/generators/app/templates/api/policies/isAllowed.js @@ -9,6 +9,6 @@ module.exports = function (req, res, next) { if (token && token === "<%= answers['application:api-secret-key'] %>") { next(); } else { - res.unauthorized(null, null, "You must provide application token"); + res.unauthorized(null, null, 'You must provide application token'); } }; diff --git a/generators/app/templates/api/responses/badRequest.js b/generators/app/templates/api/responses/badRequest.js index ee404a19..c41d038e 100644 --- a/generators/app/templates/api/responses/badRequest.js +++ b/generators/app/templates/api/responses/badRequest.js @@ -8,8 +8,8 @@ module.exports = function (data, code, message, root) { var response = _.assign({ - code: code || "E_BAD_REQUEST", - message: message || "The request cannot be fulfilled due to bad syntax", + code: code || 'E_BAD_REQUEST', + message: message || 'The request cannot be fulfilled due to bad syntax', response: data || {} }, root); diff --git a/generators/app/templates/api/responses/created.js b/generators/app/templates/api/responses/created.js index 7c7c49f4..f6eaffa5 100644 --- a/generators/app/templates/api/responses/created.js +++ b/generators/app/templates/api/responses/created.js @@ -9,8 +9,8 @@ module.exports = function (data, code, message, root) { var response = _.assign({ - code: code || "CREATED", - message: message || "The request has been fulfilled and resulted in a new resource being created", + code: code || 'CREATED', + message: message || 'The request has been fulfilled and resulted in a new resource being created', response: data || {} }, root); diff --git a/generators/app/templates/api/responses/forbidden.js b/generators/app/templates/api/responses/forbidden.js index 999b04be..2b243ff2 100644 --- a/generators/app/templates/api/responses/forbidden.js +++ b/generators/app/templates/api/responses/forbidden.js @@ -8,8 +8,8 @@ module.exports = function (data, code, message, root) { var response = _.assign({ - code: code || "E_FORBIDDEN", - message: message || "User not authorized to perform the operation", + code: code || 'E_FORBIDDEN', + message: message || 'User not authorized to perform the operation', response: data || {} }, root); diff --git a/generators/app/templates/api/responses/notFound.js b/generators/app/templates/api/responses/notFound.js index 966202d1..985925f5 100644 --- a/generators/app/templates/api/responses/notFound.js +++ b/generators/app/templates/api/responses/notFound.js @@ -8,8 +8,8 @@ module.exports = function (data, code, message, root) { var response = _.assign({ - code: code || "E_NOT_FOUND", - message: message || "The requested resource could not be found but may be available again in the future", + code: code || 'E_NOT_FOUND', + message: message || 'The requested resource could not be found but may be available again in the future', response: data || {} }, root); diff --git a/generators/app/templates/api/responses/ok.js b/generators/app/templates/api/responses/ok.js index fd077d87..326aeb5a 100644 --- a/generators/app/templates/api/responses/ok.js +++ b/generators/app/templates/api/responses/ok.js @@ -9,8 +9,8 @@ module.exports = function (data, code, message, root) { var response = _.assign({ - code: code || "OK", - message: message || "Operation is successfully executed", + code: code || 'OK', + message: message || 'Operation is successfully executed', response: data || {} }, root); diff --git a/generators/app/templates/api/responses/serverError.js b/generators/app/templates/api/responses/serverError.js index 54a2e046..9853d77c 100644 --- a/generators/app/templates/api/responses/serverError.js +++ b/generators/app/templates/api/responses/serverError.js @@ -7,8 +7,8 @@ module.exports = function (data, code, message, root) { var response = _.assign({ - code: code || "E_INTERNAL_SERVER_ERROR", - message: message || "Something bad happened on the server", + code: code || 'E_INTERNAL_SERVER_ERROR', + message: message || 'Something bad happened on the server', response: data || {} }, root); diff --git a/generators/app/templates/api/responses/unauthorized.js b/generators/app/templates/api/responses/unauthorized.js index 5cafc5de..9e08c7e5 100644 --- a/generators/app/templates/api/responses/unauthorized.js +++ b/generators/app/templates/api/responses/unauthorized.js @@ -8,8 +8,8 @@ module.exports = function (data, code, message, root) { var response = _.assign({ - code: code || "E_UNAUTHORIZED", - message: message || "Missing or invalid authentication token", + code: code || 'E_UNAUTHORIZED', + message: message || 'Missing or invalid authentication token', response: data || {} }, root); From 770e488210a8cf59c5052ea3486ed28441a4e0ab Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 5 Mar 2015 14:51:48 +0200 Subject: [PATCH 115/118] Typo fixes --- .../app/templates/config/env/production.js | 2 +- generators/app/templates/config/http.js | 2 +- generators/app/templates/config/passport.js | 28 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/generators/app/templates/config/env/production.js b/generators/app/templates/config/env/production.js index 65dfd115..643f547b 100644 --- a/generators/app/templates/config/env/production.js +++ b/generators/app/templates/config/env/production.js @@ -6,6 +6,6 @@ module.exports = { port: 80, log: { - level: "info" + level: 'info' } }; diff --git a/generators/app/templates/config/http.js b/generators/app/templates/config/http.js index 9fcf7fbf..1e32280f 100644 --- a/generators/app/templates/config/http.js +++ b/generators/app/templates/config/http.js @@ -28,7 +28,7 @@ module.exports.http = { * To enable streaming file uploads (to disk or somewhere else) * you'll want to set this option to `false` to disable the body parser * - * @type {Function|Boolean} + * @type {Function|Boolean|Object} */ bodyParser: undefined, diff --git a/generators/app/templates/config/passport.js b/generators/app/templates/config/passport.js index aee32955..b4b9b065 100644 --- a/generators/app/templates/config/passport.js +++ b/generators/app/templates/config/passport.js @@ -26,13 +26,13 @@ passport.use(new LocalStrategy({ if (error) return next(error, false, {}); if (!user) return next(null, false, { - code: "E_USER_NOT_FOUND", - message: username + " is not found" + code: 'E_USER_NOT_FOUND', + message: username + ' is not found' }); if (!CipherService.create('bcrypt', user.password).compareSync(password)) return next(null, false, { - code: "E_WRONG_PASSWORD", - message: "Password is wrong" + code: 'E_WRONG_PASSWORD', + message: 'Password is wrong' }); return next(null, user, {}); @@ -51,8 +51,8 @@ passport.use(new JwtStrategy({ .exec(function (error, user) { if (error) return next(error, false, {}); if (!user) return next(null, false, { - code: "E_USER_NOT_FOUND", - message: "User with that JWT not found" + code: 'E_USER_NOT_FOUND', + message: 'User with that JWT not found' }); return next(null, user, {}); @@ -79,8 +79,8 @@ passport.use(new FacebookTokenStrategy({ .exec(function (error, user) { if (error) return next(error, false, {}); if (!user) return next(null, false, { - code: "E_AUTH_FAILED", - message: "Facebook auth failed" + code: 'E_AUTH_FAILED', + message: 'Facebook auth failed' }); return next(null, user, {}); @@ -111,8 +111,8 @@ passport.use(new TwitterTokenStrategy({ .exec(function (error, user) { if (error) return next(error, false, {}); if (!user) return next(null, false, { - code: "E_AUTH_FAILED", - message: "Twitter auth failed" + code: 'E_AUTH_FAILED', + message: 'Twitter auth failed' }); return next(null, user, {}); @@ -137,14 +137,14 @@ passport.use(new YahooTokenStrategy({ email: req.param('email') || (profile.emails && profile.emails[0].value), firstName: req.param('firstName') || (profile.displayName && profile.displayName.split(' ')[0]), lastName: req.param('lastName') || (profile.displayName && profile.displayName.split(' ')[1]), - photo: req.param('photo') || ['https://graph.facebook.com/', profile.id, '/picture?type=large'].join(''), - facebook: profile._json + photo: req.param('photo') || (profile.photos && profile.photos[0].value), + yahoo: profile._json }) .exec(function (error, user) { if (error) return next(error, false, {}); if (!user) return next(null, false, { - code: "E_AUTH_FAILED", - message: "Yahoo auth failed" + code: 'E_AUTH_FAILED', + message: 'Yahoo auth failed' }); return next(null, user, {}); From d484efbd9f8626fe6eb2633b87a7f4502f5fa814 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 5 Mar 2015 16:29:09 +0200 Subject: [PATCH 116/118] Update roadmap --- ROADMAP.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ROADMAP.md b/ROADMAP.md index 83478628..7362f8c8 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -16,10 +16,13 @@ ## Next minor version -- [ ] Improve stability (too much new features is appears in previous version); - [ ] Implement converting camelCase attributes to snake_case in HTTP response; - [ ] Make global error codes for API with description and how fix it; - [ ] Add aliases to common operation (for instance, `v1/user/recently_registered`; + +## Version 0.6.0 (released) + +- [x] Improve stability (too much new features is appears in previous version); - [x] Freeze architecture (only bug-fixes and adding new features); - [x] Add questions list where you can choose which service need to include; From 9f5cb8b7eb4cc7ae55a0c4526bc846996540b7c4 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 5 Mar 2015 16:29:52 +0200 Subject: [PATCH 117/118] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5b829f03..a942128f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "generator-sails-rest-api", - "version": "0.5.1", + "version": "0.6.0", "description": "Yeoman generator that provides already configured and optimized Sails REST API with bundle of predefined features.", "keywords": [ "yeoman-generator", From 10ed4d57d019297e238be5d901e9748a4f862aa0 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 5 Mar 2015 16:30:50 +0200 Subject: [PATCH 118/118] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ef069fe..54bb2653 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Edge version +## Version 0.6.0 + - Improvement: Implemented parsing CommonJS modules from AST (Abstract Syntax Tree), so now generator is knows which modules you are really using; - Improvement: Frozen structure of generator and project. Any serious changes in project structure; - Improvement: Add Yahoo authorization;