From 477048f886dbe0e7eb06ebddc104311322990ac1 Mon Sep 17 00:00:00 2001 From: Ulises Layera Date: Sat, 20 Jan 2018 00:53:56 -0300 Subject: [PATCH 1/2] - prompt default values isolation - added env overriding --- app/defaults.json | 16 ++++++++++++++++ app/index.js | 31 ++++++++++++++++--------------- 2 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 app/defaults.json diff --git a/app/defaults.json b/app/defaults.json new file mode 100644 index 0000000..7513faf --- /dev/null +++ b/app/defaults.json @@ -0,0 +1,16 @@ +{ + "_projectName" : process.env.PROJECT_NAME || "Keystone Starter", + "adminLogin" : process.env.ADMIN_MAIL || "user@keystonejs.com", + "adminPassword" : process.env.ADMIN_PASS || "admin", + "viewEngine" : process.env.VIEW_ENGINE || "pug", + "preprocessor" : process.env.PRE_PROCESSOR || "sass", + "userModel" : process.env.USERMODEL_NAME || "User", + "includeEmail" : process.env.INCLUDE_EMAIL || true, + "includeBlog" : process.env.INCLUDE_BLOG || true, + "includeGallery" : process.env.INCLUDE_GALLERY || true, + "usingDemoCloudinaryAccount" : process.env.USING_DEMO_CLOUDINARY_ACCOUNT || true, + "cloudinaryURL" : process.env.CLOUDINARY_URL || "cloudinary://333779167276662:_8jbSi9FB3sWYrfimcl8VKh34rI@keystone-demo", + "includeGuideComments" : process.env.INCLUDE_GUIDE_COMMENTS || true, + "includeEnquiries" : process.env.INCLUDE_ENQUIRIES || true, + "newDirectory" : process.env.NEW_DIRECTORY || true +} diff --git a/app/index.js b/app/index.js index 0fb15e9..fd1d908 100644 --- a/app/index.js +++ b/app/index.js @@ -6,6 +6,7 @@ var utils = require('keystone-utils'); var crypto = require('crypto'); var yeoman = require('yeoman-generator'); require('./includesPolyfill'); +var defaults = require('defaults.json'); var KeystoneGenerator = module.exports = function KeystoneGenerator (args, options, config) { @@ -81,23 +82,23 @@ KeystoneGenerator.prototype.prompts = function prompts () { var cb = this.async(); if (this.auto) { - this._projectName = 'Keystone Starter'; - this.projectName = 'keystone-starter'; - this.adminLogin = 'user@keystonejs.com'; - this.adminPassword = 'admin'; - this.viewEngine = 'pug'; - this.preprocessor = 'sass'; - this.userModel = 'User'; + this._projectName = defaults._projectName; + this.projectName = utils.escapeString(this.projectName); + this.adminLogin = defaults.adminLogin; + this.adminPassword = defaults.adminPassword; + this.viewEngine = defaults.viewEngine; + this.preprocessor = defaults.preprocessor; + this.userModel = defaults.userModel; this.userModelPath = utils.keyToPath(this.userModel, true); this.destinationRoot(utils.slug(this.projectName)); - this.includeEmail = true; - this.includeBlog = true; - this.includeGallery = true; - this.usingDemoCloudinaryAccount = true; - this.cloudinaryURL = 'cloudinary://333779167276662:_8jbSi9FB3sWYrfimcl8VKh34rI@keystone-demo'; - this.includeGuideComments = true; - this.includeEnquiries = true; - this.newDirectory = true; + this.includeEmail = defaults.includeEmail; + this.includeBlog = defaults.includeBlog; + this.includeGallery = defaults.includeGallery; + this.usingDemoCloudinaryAccount = defaults.usingDemoCloudinaryAccount; + this.cloudinaryURL = defaults.cloudinaryURL; + this.includeGuideComments = defaults.includeGuideComments; + this.includeEnquiries = defaults.includeEnquiries; + this.newDirectory = defaults.newDirectory; return cb(); } From 906f3a18b8a056bde222ce70de25ea276579afa7 Mon Sep 17 00:00:00 2001 From: Ulises Layera Date: Sat, 20 Jan 2018 01:32:13 -0300 Subject: [PATCH 2/2] - prompt default values isolation - added env overriding (working version) --- app/defaults.json | 28 ++++++++++++++-------------- app/index.js | 32 ++++++++++++++++---------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/app/defaults.json b/app/defaults.json index 7513faf..8cd3be2 100644 --- a/app/defaults.json +++ b/app/defaults.json @@ -1,16 +1,16 @@ { - "_projectName" : process.env.PROJECT_NAME || "Keystone Starter", - "adminLogin" : process.env.ADMIN_MAIL || "user@keystonejs.com", - "adminPassword" : process.env.ADMIN_PASS || "admin", - "viewEngine" : process.env.VIEW_ENGINE || "pug", - "preprocessor" : process.env.PRE_PROCESSOR || "sass", - "userModel" : process.env.USERMODEL_NAME || "User", - "includeEmail" : process.env.INCLUDE_EMAIL || true, - "includeBlog" : process.env.INCLUDE_BLOG || true, - "includeGallery" : process.env.INCLUDE_GALLERY || true, - "usingDemoCloudinaryAccount" : process.env.USING_DEMO_CLOUDINARY_ACCOUNT || true, - "cloudinaryURL" : process.env.CLOUDINARY_URL || "cloudinary://333779167276662:_8jbSi9FB3sWYrfimcl8VKh34rI@keystone-demo", - "includeGuideComments" : process.env.INCLUDE_GUIDE_COMMENTS || true, - "includeEnquiries" : process.env.INCLUDE_ENQUIRIES || true, - "newDirectory" : process.env.NEW_DIRECTORY || true + "_projectName": "Keystone Starter", + "adminLogin": "user@keystonejs.com", + "adminPassword": "admin", + "viewEngine": "pug", + "preprocessor": "sass", + "userModel": "User", + "includeEmail": true, + "includeBlog": true, + "includeGallery": true, + "usingDemoCloudinaryAccount": true, + "cloudinaryURL": "cloudinary://333779167276662:_8jbSi9FB3sWYrfimcl8VKh34rI@keystone-demo", + "includeGuideComments": true, + "includeEnquiries": true, + "newDirectory": true } diff --git a/app/index.js b/app/index.js index fd1d908..43092f0 100644 --- a/app/index.js +++ b/app/index.js @@ -6,7 +6,7 @@ var utils = require('keystone-utils'); var crypto = require('crypto'); var yeoman = require('yeoman-generator'); require('./includesPolyfill'); -var defaults = require('defaults.json'); +var defaults = require('./defaults.json'); var KeystoneGenerator = module.exports = function KeystoneGenerator (args, options, config) { @@ -82,23 +82,23 @@ KeystoneGenerator.prototype.prompts = function prompts () { var cb = this.async(); if (this.auto) { - this._projectName = defaults._projectName; - this.projectName = utils.escapeString(this.projectName); - this.adminLogin = defaults.adminLogin; - this.adminPassword = defaults.adminPassword; - this.viewEngine = defaults.viewEngine; - this.preprocessor = defaults.preprocessor; - this.userModel = defaults.userModel; + this._projectName = process.env.PROJECT_NAME || defaults._projectName; + this.projectName = utils.escapeString(this._projectName); + this.adminLogin = process.env.ADMIN_MAIL || defaults.adminLogin; + this.adminPassword = process.env.ADMIN_PASS || defaults.adminPassword; + this.viewEngine = process.env.VIEW_ENGINE || defaults.viewEngine; + this.preprocessor = process.env.PRE_PROCESSOR || defaults.preprocessor; + this.userModel = process.env.USERMODEL_NAME || defaults.userModel; this.userModelPath = utils.keyToPath(this.userModel, true); this.destinationRoot(utils.slug(this.projectName)); - this.includeEmail = defaults.includeEmail; - this.includeBlog = defaults.includeBlog; - this.includeGallery = defaults.includeGallery; - this.usingDemoCloudinaryAccount = defaults.usingDemoCloudinaryAccount; - this.cloudinaryURL = defaults.cloudinaryURL; - this.includeGuideComments = defaults.includeGuideComments; - this.includeEnquiries = defaults.includeEnquiries; - this.newDirectory = defaults.newDirectory; + this.includeEmail = process.env.INCLUDE_EMAIL || defaults.includeEmail; + this.includeBlog = process.env.INCLUDE_BLOG || defaults.includeBlog; + this.includeGallery = process.env.INCLUDE_GALLERY || defaults.includeGallery; + this.usingDemoCloudinaryAccount = process.env.USING_DEMO_CLOUDINARY_ACCOUNT || defaults.usingDemoCloudinaryAccount; + this.cloudinaryURL = process.env.CLOUDINARY_URL || defaults.cloudinaryURL; + this.includeGuideComments = process.env.INCLUDE_GUIDE_COMMENTS || defaults.includeGuideComments; + this.includeEnquiries = process.env.INCLUDE_ENQUIRIES || defaults.includeEnquiries; + this.newDirectory = process.env.NEW_DIRECTORY || defaults.newDirectory; return cb(); }