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

Commit

Permalink
fix: update node and web generator versions
Browse files Browse the repository at this point in the history
generator-ibm-web was made public and generator-ibm-core-node-express had a major version change.
  • Loading branch information
Jennifer Oliver committed Apr 12, 2018
1 parent 9e8c41e commit 618cf1a
Show file tree
Hide file tree
Showing 6 changed files with 1,490 additions and 1,034 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NodeServer Generator

[![Bluemix powered][img-bluemix-powered]][url-bluemix]
[![IBM Cloud powered][img-ibmcloud-powered]][url-bluemix]
[![Travis][img-travis-master]][url-travis-master]
[![Coveralls][img-coveralls-master]][url-coveralls-master]
[![Codacy][img-codacy]][url-codacy]
Expand All @@ -9,7 +9,7 @@
[![DownloadsTotal][img-npm-downloads-total]][url-npm]
[![License][img-license]][url-npm]

[img-bluemix-powered]: https://img.shields.io/badge/bluemix-powered-blue.svg
[img-ibmcloud-powered]: https://img.shields.io/badge/IBM%20Cloud-powered-blue.svg
[url-bluemix]: http://bluemix.net
[url-npm]: https://www.npmjs.com/package/generator-nodeserver
[img-license]: https://img.shields.io/npm/l/generator-nodeserver.svg
Expand Down Expand Up @@ -124,13 +124,13 @@ yo nodeserver --headless='{"name":"your-app-name"}'

To specify which services to add use:
```bash
yo nodeserver --headless='{"service":["service1", "service2"]}'
yo nodeserver --headless='{"services":["service1", "service2"]}'
```
For valid services see below.

Full usage:
```bash
yo nodeserver --headless='{"name":"your-app-name","swaggerFileName":"your-swagger-file-name","service":["service1", "service2"]}'
yo nodeserver --headless='{"name":"your-app-name","swaggerFileName":"your-swagger-file-name","services":["service1", "service2"]}'
```

#### Valid Services
Expand Down
84 changes: 48 additions & 36 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +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 services = require('./services/services');

const OPTION_BLUEMIX = 'bluemix';
const OPTION_STARTER = 'starter';
Expand All @@ -28,12 +28,16 @@ module.exports = class extends Generator {
constructor(args, opts) {
super(args, opts);

logger.level= "info";
logger.level = "info";
logger.info("Package info ::", Bundle.name, Bundle.version);

if ( typeof this.options.bluemix == "undefined" ) {
if (typeof this.options.bluemix == "undefined") {
// generate only for Node.js apps
this.opts = {bluemix: {backendPlatform: 'NODE'}, spec: {applicationType: 'WEB'}};
this.opts = {
bluemix: { backendPlatform: 'NODE' },
spec: { applicationType: 'WEB' },
framework: 'None'
};
}
else {
this._sanitizeOption(this.options, OPTION_BLUEMIX);
Expand All @@ -42,7 +46,7 @@ module.exports = class extends Generator {
}

const headlessDesc = 'Run in headless mode (no prompts). Format --headless=\'{"name": "myproject"}\'"';
this.option('headless', {desc: headlessDesc, type: String});
this.option('headless', { desc: headlessDesc, type: String });

/* Do this so there are no overwrite messages when
subgenerators run. The overwrites are expected
Expand All @@ -55,22 +59,22 @@ module.exports = class extends Generator {
}

prompting() {
let swaggerFileValidator= function(str) {
if ( str == "None" ) {
let swaggerFileValidator = function (str) {
if (str == "None") {
return true;
}
else {
if ( fs.existsSync(str.trim()) ) {
if (fs.existsSync(str.trim())) {
return true;
}
else {
console.log("\n"+str+" not found.");
console.log("\n" + str + " not found.");
return false;
}
}
}

let choseCloudServices= function(answers) {
let choseCloudServices = function (answers) {
return answers.addCloudServices;
}
// If headless mode don't prompt
Expand Down Expand Up @@ -120,37 +124,36 @@ module.exports = class extends Generator {
}
}

configuring() {}
configuring() { }

_processAnswers(answers) {
this.opts.bluemix.fromYo = true;
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 swagger = fs.readFileSync(answers.swaggerFileName,"utf8");
this.opts.bluemix.openApiServers= [{"spec": swagger }];
if (answers.swaggerFileName.length > 0 && answers.swaggerFileName !== "None") {
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];
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];
this.opts.bluemix.server.services.push(service_name.toUpperCase() + "_INSTANCE_REPLACE_ME");
}

// process each service selected by user
_processServices(answers) {
if ( answers.services ) {
this.hasServices= true;
if ( !("server" in this.opts.bluemix) ) {
if (answers.services) {
this.hasServices = true;

if (!("server" in this.opts.bluemix)) {
this.opts.bluemix["server"] = []
}
let services = []
Expand All @@ -159,29 +162,33 @@ module.exports = class extends Generator {
answers.services.forEach(this._storeServiceName.bind(this));
}
else {
this.hasServices= false;
this.hasServices = false;
}
}

_composeSubGenerators() {

this.opts.bluemix.quiet= true; // suppress version messages

this.opts.bluemix.quiet = true; // suppress version messages
if (process.env.YO_SUB_GEN_MODE === 'global') {
// for develop-mode testing
this.composeWith('ibm-core-node-express', this.opts);

this.composeWith('ibm-web', this.opts);

this.composeWith('ibm-cloud-enablement', this.opts);

if ( this.hasServices ) {
if (this.hasServices) {
this.composeWith('ibm-service-enablement', {
bluemix: JSON.stringify(this.opts.bluemix),
spec: JSON.stringify(this.opts.spec),
starter: "{}",
quiet: true});
quiet: true
});
}
}
else {
const modDirName = __dirname + '/../../node_modules';

this.composeWith(
path.join(
modDirName,
Expand All @@ -191,6 +198,16 @@ module.exports = class extends Generator {
this.opts
);

this.composeWith(
path.join(
modDirName,
'generator-ibm-web',
'generators',
'app'
),
this.opts
);

this.composeWith(
path.join(
modDirName,
Expand All @@ -201,9 +218,9 @@ module.exports = class extends Generator {
this.opts
);

if ( this.hasServices ) {
if (this.hasServices) {
this.composeWith(
path.join(modDirName,'generator-ibm-service-enablement','generators','app'),
path.join(modDirName, 'generator-ibm-service-enablement', 'generators', 'app'),
{
bluemix: JSON.stringify(this.opts.bluemix),
spec: JSON.stringify(this.opts.spec),
Expand All @@ -215,13 +232,8 @@ module.exports = class extends Generator {
}

_sanitizeOption(options, name) {

try {
this.options[name] = typeof (this.options[name]) === 'string' ?
JSON.parse(this.options[name]) : this.options[name];
} catch (e) {
throw Error(`${name} parameter is expected to be a valid stringified JSON object`);
}
this.options[name] = typeof (this.options[name]) === 'string' ?
JSON.parse(this.options[name]) : this.options[name];
}

};
Loading

0 comments on commit 618cf1a

Please sign in to comment.