This repository has been archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
6,611 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules/ | ||
# If eslint goes into this dir it will read package.json as a config file | ||
# We either rename the package.json template, or we don't lint this dir | ||
generators/app/templates/ | ||
generators/core/templates/ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
env: | ||
node: true | ||
es6: true | ||
mocha: true | ||
|
||
rules: | ||
strict: 2 | ||
no-var: 2 | ||
no-console: 0 | ||
indent: [2, 2, { "SwitchCase": 1}] | ||
|
||
extends: eslint:recommended | ||
|
||
plugins: [ejs] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules/ | ||
coverage/ | ||
.nyc_output/ | ||
.vscode/ | ||
.idea | ||
*.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- '8' | ||
|
||
script: npm test && npm run coveralls && ./npm_patch.sh | ||
|
||
branches: | ||
only: | ||
- development | ||
- master | ||
|
||
notifications: | ||
slack: | ||
rooms: | ||
- $SLACK_ARF_DEVOPS | ||
|
||
deploy: | ||
provider: npm | ||
email: $NPM_EMAIL | ||
api_key: $NPM_TOKEN | ||
on: | ||
branch: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,89 @@ | ||
# generator-nodeserver | ||
# NodeServer Generator | ||
|
||
[![Bluemix powered][img-bluemix-powered]][url-bluemix] | ||
[![Travis][img-travis-master]][url-travis-master] | ||
[![Coveralls][img-coveralls-master]][url-coveralls-master] | ||
[![Codacy][img-codacy]][url-codacy] | ||
[![Version][img-version]][url-npm] | ||
[![DownloadsMonthly][img-npm-downloads-monthly]][url-npm] | ||
[![DownloadsTotal][img-npm-downloads-total]][url-npm] | ||
[![License][img-license]][url-npm] | ||
|
||
[img-bluemix-powered]: https://img.shields.io/badge/bluemix-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 | ||
[img-version]: https://img.shields.io/npm/v/generator-nodeserver.svg | ||
[img-npm-downloads-monthly]: https://img.shields.io/npm/dm/generator-nodeserver.svg | ||
[img-npm-downloads-total]: https://img.shields.io/npm/dt/generator-nodeserver.svg | ||
|
||
[img-travis-master]: https://travis-ci.org/ibm-developer/generator-nodeserver.svg?branch=development | ||
[url-travis-master]: https://travis-ci.org/ibm-developer/generator-nodeserver/branches | ||
|
||
[img-coveralls-master]: https://coveralls.io/repos/github/ibm-developer/generator-nodeserver/badge.svg | ||
[url-coveralls-master]: https://coveralls.io/github/ibm-developer/generator-nodeserver | ||
|
||
[img-codacy]: https://api.codacy.com/project/badge/Grade/a5893a4622094dc8920c8a372a8d3588?branch=master | ||
[url-codacy]: https://www.codacy.com/app/ibm-developer/generator-nodeserver | ||
|
||
|
||
## Current State | ||
|
||
This is an early version of the nodeserver generator. It produces a simple Expressed-based node.js server that serves up a trivial page and exposes a health endpoint (/health). Additionally, configuration files are generated for the following tools and deployment environments: | ||
|
||
1. Docker | ||
2. Kubernetes/Helm | ||
3. Cloud Foundry | ||
4. [IBM Cloud Developer Tools](https://github.com/IBM-Bluemix/ibm-cloud-developer-tools) | ||
|
||
#### Prompting | ||
|
||
The generator presently prompts for project name and optional swagger json input to direct code generation. | ||
|
||
Additional prompting is planned for adding IBM Cloud services, including Cloudant, ObjectStore,AppID, and more. | ||
|
||
## Pre-requisites | ||
|
||
Install [Yeoman](http://yeoman.io) | ||
|
||
```bash | ||
npm install -g yo | ||
``` | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install -g generator-nodeserver | ||
``` | ||
## Usage | ||
|
||
```bash | ||
yo nodeserver | ||
``` | ||
|
||
## Development | ||
|
||
Clone this repository and link it via npm | ||
|
||
```bash | ||
git clone https://github.com/ibm-developer/generator-nodeserver | ||
cd generator-nodeserver | ||
npm link | ||
``` | ||
|
||
In a separate directory invoke the generator via | ||
|
||
```bash | ||
yo nodeserver | ||
``` | ||
|
||
## Publishing Changes | ||
|
||
In order to publish changes, you will need to fork the repository or ask to join the `ibm-developer` org and branch off the development branch. | ||
|
||
Once you are finished with your changes, run `npm test` to make sure all tests pass. | ||
|
||
Do a pull request against `development`, make sure the build passes. A team member will review and merge your pull request. | ||
Once merged to development, the version will be auto-incremented. | ||
Do a pull request against master, once that PR is reviewed and merged, a new version will be published to npm. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
Copyright 2017 IBM Corp. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const Generator = require('yeoman-generator'); | ||
const Bundle = require("../../package.json"); | ||
const Log4js = require('log4js'); | ||
const logger = Log4js.getLogger("generator-nodeserver"); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const OPTION_BLUEMIX = 'bluemix'; | ||
const OPTION_STARTER = 'starter'; | ||
|
||
module.exports = class extends Generator { | ||
constructor(args, opts) { | ||
super(args, opts); | ||
|
||
logger.level= "info"; | ||
logger.info("Package info ::", Bundle.name, Bundle.version); | ||
|
||
if ( typeof this.options.bluemix == "undefined" ) { | ||
// generate only for Node.js apps | ||
this.opts = {bluemix: {backendPlatform: 'NODE'}, spec: {applicationType: 'WEB'}}; | ||
} | ||
else { | ||
|
||
this._sanitizeOption(this.options, OPTION_BLUEMIX); | ||
this._sanitizeOption(this.options, OPTION_STARTER); | ||
|
||
this.opts = opts; | ||
|
||
} | ||
} | ||
|
||
initializing() { | ||
} | ||
|
||
prompting() { | ||
|
||
let swaggerFileValidator= function(str) { | ||
if ( str == "None" ) { | ||
return true; | ||
} | ||
else { | ||
if ( fs.existsSync(str.trim()) ) { | ||
return true; | ||
} | ||
else { | ||
console.log("\n"+str+" not found."); | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
let prompts = []; | ||
prompts.push({ | ||
type: 'input', | ||
name: 'name', | ||
message: 'Project name', | ||
default: path.basename(process.cwd()) | ||
}); | ||
prompts.push({ | ||
type: 'input', | ||
name: 'swaggerFileName', | ||
message: 'OpenAPI Document', | ||
default: "None", | ||
validate: swaggerFileValidator | ||
}); | ||
return this.prompt(prompts).then(this._processAnswers.bind(this)); | ||
|
||
} | ||
|
||
configuring() {} | ||
|
||
_processAnswers(answers) { | ||
|
||
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) }]; | ||
} | ||
|
||
this._composeSubGenerators(); | ||
} | ||
|
||
_composeSubGenerators() { | ||
|
||
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-cloud-enablement', this.opts); | ||
} | ||
else { | ||
const modDirName = __dirname + '/../../node_modules'; | ||
this.composeWith( | ||
path.join( | ||
modDirName, | ||
'generator-ibm-core-node-express', | ||
'app' | ||
), | ||
this.opts | ||
); | ||
this.composeWith( | ||
path.join( | ||
modDirName, | ||
'generator-ibm-cloud-enablement', | ||
'generators', | ||
'app' | ||
), | ||
this.opts | ||
); | ||
} | ||
} | ||
|
||
_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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ev | ||
|
||
if [[ "${TRAVIS_PULL_REQUEST}" = "false" ]]; then | ||
echo "Not a Pull Request build. Proceeding." | ||
|
||
# On development branch, we want to auto increment package patch version number | ||
# and push commit back to repo | ||
if [[ "${TRAVIS_BRANCH}" = "development" ]]; then | ||
echo "On development branch" | ||
echo "Commit message: ${TRAVIS_COMMIT_MESSAGE}" | ||
|
||
if [[ "${TRAVIS_COMMIT_MESSAGE}" == "[Travis - npm version patch]"* ]]; then | ||
echo "This is a version increment commit. Doing nothing." | ||
else | ||
echo "Incrementing patch version and pushing back to repo." | ||
|
||
echo "commit: ${TRAVIS_COMMIT}" | ||
USER_EMAIL=$(git --no-pager show -s --format='%ae' "${TRAVIS_COMMIT}") | ||
USER_NAME=$(git --no-pager show -s --format='%an' "${TRAVIS_COMMIT}") | ||
echo "user email: ${USER_EMAIL}" | ||
echo "user name: ${USER_NAME}" | ||
git config user.email "${USER_EMAIL}" | ||
git config user.name "${USER_NAME}" | ||
|
||
git checkout -- . | ||
git checkout -b increment-patch-version | ||
npm version patch -m "[Travis - npm version patch] Increment package version to %s" | ||
|
||
git branch --set-upstream-to origin/development | ||
git push $GITHUB_URL_SECURED HEAD:development | ||
git push $GITHUB_URL_SECURED HEAD:development --tags | ||
fi | ||
fi | ||
else | ||
echo "This is a Pull Request build. Doing nothing." | ||
fi |
Oops, something went wrong.