Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #13 from ibm-developer/development
Browse files Browse the repository at this point in the history
copy dev to master
  • Loading branch information
cvignola committed Sep 28, 2017
2 parents a9d940b + f340f52 commit 441b74c
Show file tree
Hide file tree
Showing 14 changed files with 469 additions and 11 deletions.
77 changes: 68 additions & 9 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Log4js = require('log4js');
const logger = Log4js.getLogger("generator-nodeserver");
const path = require('path');
const fs = require('fs');
const services= require('./services/services');

const OPTION_BLUEMIX = 'bluemix';
const OPTION_STARTER = 'starter';
Expand All @@ -35,13 +36,16 @@ module.exports = class extends Generator {
this.opts = {bluemix: {backendPlatform: 'NODE'}, spec: {applicationType: 'WEB'}};
}
else {

this._sanitizeOption(this.options, OPTION_BLUEMIX);
this._sanitizeOption(this.options, OPTION_STARTER);

this.opts = opts;

this.opts = opts;
}

/* Do this so there are no overwrite messages when
subgenerators run. The overwrites are expected
by design.
*/
this.conflicter.force = true;
}

initializing() {
Expand All @@ -64,6 +68,10 @@ module.exports = class extends Generator {
}
}

let choseCloudServices= function(answers) {
return answers.addCloudServices;
}

let prompts = [];
prompts.push({
type: 'input',
Expand All @@ -76,10 +84,22 @@ module.exports = class extends Generator {
name: 'swaggerFileName',
message: 'OpenAPI Document',
default: "None",
validate: swaggerFileValidator
validate: swaggerFileValidator,
});
prompts.push({
type: 'confirm',
name: 'addCloudServices',
message: 'Add IBM Cloud Service Enablement?',
default: false
});
prompts.push({
type: 'checkbox',
name: 'services',
message: 'Choose IBM Cloud Services',
when: choseCloudServices,
choices: services.SERVICE_CHOICES
});
return this.prompt(prompts).then(this._processAnswers.bind(this));

}

configuring() {}
Expand All @@ -89,15 +109,35 @@ module.exports = class extends Generator {
this.opts.bluemix.backendPlatform = 'NODE';
this.opts.bluemix.name = answers.name || this.opts.bluemix.name;
answers.swaggerFileName = answers.swaggerFileName.trim();

if ( answers.swaggerFileName.length > 0 && answers.swaggerFileName !== "None" ) {
let rawdata = fs.readFileSync(answers.swaggerFileName);
let swaggerJson = JSON.parse(rawdata)
this.opts.bluemix.openApiServers= [{"spec": JSON.stringify(swaggerJson) }];
let swagger = fs.readFileSync(answers.swaggerFileName,"utf8");
this.opts.bluemix.openApiServers= [{"spec": swagger }];
}

this._processServices(answers);
this._composeSubGenerators();
}

// store specified option in bluemix object to drive generator-ibm-service-enablement
_storeServiceName(service) {
let service_name= services.SERVICES[services.SERVICE_LABELS.indexOf(service)];
let service_data= require("./services/"+service_name);
this.opts.bluemix[service_name]= service_data[service_name];
}

// process each service selected by user
_processServices(answers) {

if ( answers.services ) {
this.hasServices= true;
answers.services.forEach(this._storeServiceName.bind(this));
}
else {
this.hasServices= false;
}
}

_composeSubGenerators() {

this.opts.bluemix.quiet= true; // suppress version messages
Expand All @@ -106,6 +146,14 @@ module.exports = class extends Generator {
// for develop-mode testing
this.composeWith('ibm-core-node-express', this.opts);
this.composeWith('ibm-cloud-enablement', this.opts);

if ( this.hasServices ) {
this.composeWith('ibm-service-enablement', {
bluemix: JSON.stringify(this.opts.bluemix),
spec: JSON.stringify(this.opts.spec),
starter: "{}",
quiet: true});
}
}
else {
const modDirName = __dirname + '/../../node_modules';
Expand All @@ -126,6 +174,17 @@ module.exports = class extends Generator {
),
this.opts
);

if ( this.hasServices ) {
this.composeWith(
path.join(modDirName,'generator-ibm-service-enablement','generators','app'),
{
bluemix: JSON.stringify(this.opts.bluemix),
spec: JSON.stringify(this.opts.spec),
starter: "{}",
quiet: true
});
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions generators/app/services/alertnotification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
let alertnotification = {}
exports.alertnotification = alertnotification;
15 changes: 15 additions & 0 deletions generators/app/services/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
let auth = {
"clientId": "auth-client-id",
"oauthServerUrl": "https://appid-oauth.ng.bluemix.net/oauth/v3/auth-client-id",
"profilesUrl": "https://appid-profiles.ng.bluemix.net",
"secret": "auth-secret",
"tenantId": "auth-tenantId",
"version": "3",
"serviceInfo": {
"label": "auth-label",
"name": "auth-name",
"plan": "auth-plan"
}
}
exports.auth = auth;
14 changes: 14 additions & 0 deletions generators/app/services/cloudant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
let cloudant = [
{
"url": "https://account.cloudant.com",
"username": "cloudant-username",
"password": "cloudant-password",
"serviceInfo": {
"label": "cloudant-label",
"name": "cloudant-name",
"plan": "cloudant-plan"
}
}
]
exports.cloudant = cloudant;
12 changes: 12 additions & 0 deletions generators/app/services/conversation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';
let conversation = {
"url": "https://gateway.watsonplatform.net/conversation/api",
"username": "conversation-username",
"password": "conversation-password",
"serviceInfo": {
"label": "conversation-label",
"name": "conversation-name",
"plan": "conversation-plan"
}
}
exports.conversation = conversation;
16 changes: 16 additions & 0 deletions generators/app/services/mongodb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
let mongodb = {
"ca_certificate_base64": "BASE64-CERT",
"db_type": "mongodb",
"maps": [],
"name": "bmix-dal-yp-11111111-1111-1111-1111-87d2894a1111",
"uri": "mongodb://admin:PASSCODE@hostname1.dblayer.com:11111,hostname2.dblayer.com:22222/compose?ssl=true&authSource=admin",
"uri_cli": "mongo --ssl --sslAllowInvalidCertificates hostname1.7.dblayer.com:11111/compose --authenticationDatabase admin -u admin -p PASSCODE",
"deployment_id": "1234123412346f001800558a",
"serviceInfo": {
"label": "compose-for-mongodb",
"name": "my-mongodb",
"plan": "Standard"
}
}
exports.mongodb = mongodb;
21 changes: 21 additions & 0 deletions generators/app/services/objectStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
let objectStorage = [
{
"auth_url": "https://identity.open.softlayer.com",
"domainId": "object-storage-domainid",
"domainName": "object-storage-domain-name",
"password": "object-storage-password",
"project": "object-storage-project",
"projectId": "object-storage-projectid",
"region": "dallas",
"role": "admin",
"userId": "object-storage-userid",
"username": "object-storage-username",
"serviceInfo": {
"label": "object-storage-label",
"name": "object-storage-name",
"plan": "object-storage-plan"
}
}
]
exports.objectStorage = objectStorage;
18 changes: 18 additions & 0 deletions generators/app/services/postgresql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
let postgresql = {
"db_type": "postgresql",
"uri_cli": "psql \"sslmode=require hostname1.dblayer.com port=11111 dbname=compose user=admin\"",
"uri_cli_1": "psql \"sslmode=require host=hostname2.dblayer.com port=22222 dbname=compose user=admin\"",
"uri_direct_1": "postgres://admin:PASSCODE@hostname.dblayer.com:11111/compose",
"maps": [],
"name": "bmix-dal-yp-11111111-1111-1111-1111-87d2894a1111",
"ca_certificate_base64": "BASE64-CERT",
"uri": "postgres://admin:PASSCODE@sl-us-south-1-portal.7.dblayer.com:22107/compose",
"deployment_id": "1234123412346f001800558a",
"serviceInfo": {
"label": "compose-for-postgresql",
"name": "my-postgresql",
"plan": "Standard"
}
}
exports.postgresql = postgresql;
13 changes: 13 additions & 0 deletions generators/app/services/push.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
let push = {
"appGuid": "push-app-guid",
"appSecret": "push-app-secret",
"clientSecret": "push-client-secret",
"url":"http://imfpush.BLUEMIX_REGION.bluemix.net/imfpush/v1/apps/APP_GUID",
"serviceInfo": {
"label": "push-label",
"name": "push-name",
"plan": "push-plan"
}
}
exports.push = push;
15 changes: 15 additions & 0 deletions generators/app/services/redis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
let redis= {
"db_type": "redis",
"maps": [],
"name": "bmix-dal-yp-11111111-1111-1111-1111-87d2894a1111",
"uri": "redis://admin:PASSCODE@hostname.dblayer.com:11111",
"uri_cli": "redis-cli -h hostname.dblayer.com -p 11111 -a PASSCODE",
"deployment_id": "1234123412346f001800558a",
"serviceInfo": {
"label": "compose-for-redis",
"name": "my-redis",
"plan": "Standard"
}
}
exports.redis = redis;
62 changes: 62 additions & 0 deletions generators/app/services/services.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';

// labels for prompt checkbox
const CHECKBOX_ALERT = "alert";
const CHECKBOX_APPID = "appid";
const CHECKBOX_CLOUDANT = "cloudant";
const CHECKBOX_MONGO = "mongo";
const CHECKBOX_OBJECT_STORAGE = "object storage";
const CHECKBOX_POSTGRE = "postgre";
const CHECKBOX_PUSH = "push";
const CHECKBOX_REDIS = "redis";
const CHECKBOX_WATSON_CONVERSATION = "watson conversation";

// array of labels for easy index lookup
const SERVICE_LABELS= [
CHECKBOX_ALERT,
CHECKBOX_APPID,
CHECKBOX_CLOUDANT,
CHECKBOX_MONGO,
CHECKBOX_OBJECT_STORAGE,
CHECKBOX_POSTGRE,
CHECKBOX_PUSH,
CHECKBOX_REDIS,
CHECKBOX_WATSON_CONVERSATION
];

// checkbox array for prompt
const SERVICE_CHOICES= [
{"name":CHECKBOX_ALERT},
{"name":CHECKBOX_APPID},
{"name":CHECKBOX_CLOUDANT},
{"name":CHECKBOX_MONGO},
{"name":CHECKBOX_OBJECT_STORAGE},
{"name":CHECKBOX_POSTGRE},
{"name":CHECKBOX_PUSH},
{"name":CHECKBOX_REDIS},
{"name":CHECKBOX_WATSON_CONVERSATION}
];

/*
keys to select services via generator-ibm-service-enablement.
must match SCAFFOLDER_PROJECT_PROPERTY_NAME value in corresponding
service sub-generator (e.g. service-alert-notification)
*/

const SERVICES= [
"alertnotification",
"auth",
"cloudant",
"mongodb",
"objectStorage",
"postgresql",
"push",
"redis",
"conversation"
];

module.exports = {
SERVICE_LABELS,
SERVICE_CHOICES,
SERVICES
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-nodeserver",
"version": "0.0.11",
"version": "0.0.12",
"description": "Generates a nodeserver project.",
"main": "generators/app/index.js",
"license": "Apache-2.0",
Expand All @@ -14,6 +14,7 @@
"fs-extra": "^2.0.0",
"generator-ibm-core-node-express": "^0.0.57",
"generator-ibm-cloud-enablement": "^0.0.77",
"generator-ibm-service-enablement": "^0.0.81",
"handlebars": "^4.0.10",
"js-yaml": "^3.9.0",
"lodash": "^4.17.4",
Expand Down
Loading

0 comments on commit 441b74c

Please sign in to comment.