Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generator js #6

Merged
merged 54 commits into from
Jul 5, 2016
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
1b51f4f
OHM-239: Remove bower template
Jun 20, 2016
f910855
OHM-239: Allow command line options to populate prompts
Jun 20, 2016
15237d3
OHM-239: Add Andrew as a contributer
Jun 20, 2016
1ad8a76
OHM-239: Add start script for npm
Jun 20, 2016
a75ee95
OHM-239: Change mediator folder scaffolding
Jun 21, 2016
087513f
OHM-239: Remove yeoman gruntfile template
Jun 23, 2016
d9f8e42
OHM-239: Remove yeoman register template
Jun 23, 2016
9292031
OHM-239: Add yeoman templates for OpenHIM specific methods and utils
Jun 23, 2016
879c851
OHM-239: Remove .jshintrc, using standardjs
Jun 23, 2016
eef7f2c
OHM-239: Add all configurable parameters to the mediator config
Jun 24, 2016
d15dab0
OHM-239: Add all configurable params to api config
Jun 24, 2016
466189e
OHM:239: Remove layout config
Jun 24, 2016
f6fdfbe
OHM-239: Rearrange the template file structure
Jun 24, 2016
60d1e11
OHM-239: Add dput conf config options
Jun 24, 2016
87421c3
OHM-239: Add config to shell script
Jun 24, 2016
f13d61f
OHM-239: Add config to create deb script
Jun 24, 2016
df641fe
OHM-239: Inject all config into templates
Jun 24, 2016
47c0c8f
OHM-239: Add a config file with the default injectable configs
Jun 24, 2016
bc8888c
OHM-239: Update the prompts with relevant fields
Jun 24, 2016
3dc802a
OHM-239: Remove unnecessary deps
Jun 24, 2016
05b0fa4
OHM-239: Update the generator tests
Jun 24, 2016
0176fb7
OHM-239: Add meaningul config properties and update to work with late…
Jun 24, 2016
9387e86
OHM-239: Prompt based on options
Jun 24, 2016
6d66bee
OHM-239: Update readme
Jun 24, 2016
0ca01a7
OHM-239: Add tests and edit formatting to pass standardjs tests
Jun 27, 2016
23d7f83
OHM-239: Add gitignore to mediator
Jun 28, 2016
ee14c2a
OHM-239: Fix config typo
Jun 28, 2016
422b41c
OHM-239: Add readme to generated mediator
Jun 28, 2016
248ae72
OHM-239: Accept all requests
Jun 28, 2016
2316a86
OHM-239: Remove repetition of enable prompts and simplify
Jun 28, 2016
d90b2b5
OHM-239: Ensure user provides mediator name and description
Jun 28, 2016
ebb69c2
OHM-239: Refactor the prompting for better usability
Jun 28, 2016
832871f
OHM-239: Remove unecessary socket settings
Jun 28, 2016
590357c
OHM-239: Restructure and remove unecessary dependencies
Jun 28, 2016
5167bf0
OHM-239: Update packaging controls for mediator
Jun 28, 2016
2a5bd50
OHM-239: Add comments to indicate where to add functionality to mediator
Jun 28, 2016
dcc9d10
OHM-239: Remove functionality not common to all mediators
Jun 28, 2016
9758328
OHM-239: Change config from struct to string for simplicity
Jun 28, 2016
22ccfd7
OHM-239: Structural changes
Jun 28, 2016
e64fb18
OHM-239: Remove repeated code
Jun 28, 2016
cd42d5b
OHM-239: Assert compulsory name option to pass tests
Jun 28, 2016
c560bd7
OHM-239: Fix logic and validate entered ip address
Jun 29, 2016
89049fe
OHM-239: Include headers in orchestration request
Jun 29, 2016
2581acf
OHM-239: Add prompt for mediator maintainer
Jun 29, 2016
5bab2b7
OHM-239: Add basic test to help mediator authors
Jun 29, 2016
c3792df
OHM-239: Standardjs formatting to pass tests
Jun 29, 2016
f71e05c
OHM-239: Add .nyc_output to .gitignore
Jul 4, 2016
3ac2234
OHM-239: Change path config of mediator to listen on channel path
Jul 4, 2016
cd500c6
OHM-239: Update test config
Jul 4, 2016
d3c4e55
OHM-239: Only create the packaging folders if this option is selected
Jul 4, 2016
94de1e8
OHM-239: Update readme to include option flags
Jul 4, 2016
df66084
OHM-239: Update README.md
Jul 4, 2016
70e0a17
OHM-239: Change console.log to winston
Jul 4, 2016
c7389a7
OHM-239: Correct url path
Jul 4, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions generator-mediator-js/.jshintrc

This file was deleted.

32 changes: 12 additions & 20 deletions generator-mediator-js/README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
# generator-mediator-js

> [Yeoman](http://yeoman.io) generator


## Getting Started

### What is Yeoman?

Trick question. It's not a thing. It's this guy:

![](http://i.imgur.com/JHaAlBJ.png)

Basically, he wears a top hat, lives in your computer, and waits for you to tell him what kind of application you wish to create.

Not every new computer comes with a Yeoman pre-installed. He lives in the [npm](https://npmjs.org) package repository. You only have to ask for him once, then he packs up and moves into your hard drive. *Make sure you clean up, he likes new and shiny things.*
### How to use our friend Yeoman to generate a new mediator

```bash
npm install -g yo
```

### Yeoman Generators

Yeoman travels light. He didn't pack any generators when he moved in. You can think of a generator like a plug-in. You get to choose what type of application you wish to create, such as a Backbone application or even a Chrome extension.

To install generator-mediator-js from npm, run:

```bash
npm install -g generator-mediator-js
```

Finally, initiate the generator:
Or for dev purposes, from the generator-mediator-js directory, run:

```bash
yo mediator-js
sudo npm link
```

### Getting To Know Yeoman
Finally, from a clean directory into which you would like to install the mediator:

Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced.
```bash
yo mediator-js
```

If you'd like to get to know Yeoman better and meet some of his friends, [Grunt](http://gruntjs.com) and [Bower](http://bower.io), check out the complete [Getting Started Guide](https://github.com/yeoman/yeoman/wiki/Getting-Started).
You will be prompted to enter the config needed to create the mediator, to use default config:

```bash
yo mediator-js --useDefaults
```


## License
Copy link
Contributor

@hnnesv hnnesv Jul 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was here already, but I think let's remove the license field. Tbh I'm not too sure about how licensing works for something like this, but if anything it should be MPL 2.0 (but let's leave it out for now)

Expand Down
21 changes: 21 additions & 0 deletions generator-mediator-js/app/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"enablePrompts":true,
"mediatorName":"Yeoman Generated Mediator",
"mediatorDesc":"Brief Description",
"mediatorAuthor":"Jembi Health Systems NPC",
"mediatorMaintainer":"Name Surname <email@exchange.com> (https://github.com/githubusername)",
"configPort":7000,
"defaultChannelPath":"channelPath",
"mediatorRouteHost":"localhost",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should just be mediatorHost

"mediatorRoutePath":"routePath",
Copy link
Member

@rcrichton rcrichton Jun 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that instead of setting a routePath the mediator should rather accept all requests. Like the following:

  app.all(mediatorConfig.endpoints[0].path, (req, res) => {
    console.log(`Processing ${req.method} request on ${mediatorConfig.endpoints[0].path}`)


"configureApi": false,
"mediatorApiUsername":"root@openhim.org",
"mediatorApiPassword":"password",
"mediatorApiUrl":"https://localhost:8080",
"mediatorApiSsl":true,
"mediatorRegister":true,

"enablePPA":false,
"ppaUsername":"rg-crichton"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this default to openhie

}
167 changes: 95 additions & 72 deletions generator-mediator-js/app/index.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,117 @@
'use strict';
'use strict'

var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
var uuid = require('node-uuid');
var generator = require('yeoman-generator')
var chalk = require('chalk')
var yosay = require('yosay')
var uuid = require('node-uuid')

var mediatorJsGenerator = yeoman.generators.Base.extend({

prompting: function () {
var done = this.async();

// Have Yeoman greet the user.
this.log(yosay(
'Welcome to the marvelous ' + chalk.red('MediatorJs') + ' generator!'
));

var prompts = [{
type: 'input',
name: 'mediatorName',
message: 'What is your Mediator\'s name?',
default: 'Yeoman Generated Mediator',
validate: function(mediatorName){
if(mediatorName !== ''){ return true; }else{ return 'Please supply a Mediator Name'; }
}
}, {
type: 'input',
name: 'mediatorDesc',
message: 'What does your Mediator do?',
default: 'Brief Description'
}, {
type: 'input',
name: 'configPort',
message: 'Under what port number should the mediator run?',
default: 3000
}, {
type: 'input',
name: 'mediatorRoutePath',
message: 'What is your primary route path?'
}];
var prompts = require('./prompts')
var config = require('./config')

this.prompt(prompts, function (props) {
this.configPort = props.configPort;
this.mediatorName = props.mediatorName;
this.mediatorDesc = props.mediatorDesc;
this.mediatorRoutePath = props.mediatorRoutePath;
var mediatorJsGenerator = generator.Base.extend({
constructor: function () {
generator.Base.apply(this, arguments)

done();
}.bind(this));
this.option('useDefaults')
this.enablePrompts = (this.options.useDefaults ? false : true)
},

scaffoldFolders: function(){
this.mkdir("app/config");
this.mkdir("build");

prompting: function () {
return this.prompt(prompts.promptsList(this.enablePrompts)).then(function (props) {
// Mediator settings
this.mediatorName = props.mediatorName || config.mediatorName
this.mediatorDesc = props.mediatorDesc || config.mediatorDesc
this.mediatorAuthor = props.mediatorAuthor || config.mediatorAuthor
this.mediatorMaintainer = props.mediatorMaintainer || config.mediatorMaintainer
this.configPort = props.configPort || config.configPort
this.defaultChannelPath = props.defaultChannelPath || config.defaultChannelPath
this.mediatorRoutePath = props.mediatorRoutePath || config.mediatorRoutePath
this.mediatorRouteHost = props.mediatorRouteHost || config.mediatorRouteHost

// API settings
this.configureApi = props.configureApi || config.configureApi
this.mediatorApiUsername = props.mediatorApiUsername || config.mediatorApiUsername
this.mediatorApiPassword = props.mediatorApiPassword || config.mediatorApiPassword
this.mediatorApiUrl = props.mediatorApiUrl || config.mediatorApiUrl
this.mediatorApiSsl = props.mediatorApiSsl || config.mediatorApiSsl
this.mediatorRegister = props.mediatorRegister || config.mediatorRegister

// PPA settings
this.enablePPA = props.enablePPA || config.enablePPA
this.ppaUsername = props.ppaUsername || config.ppaUsername
}.bind(this))
},

copyMainFiles: function(){

var context = {
writing: function() {
// Set up context objects to populate templates
var mediatorContext = {
configPort: this.configPort,
mediatorUUID: "urn:uuid:"+uuid.v1(),
mediatorUUID: "urn:uuid:" + uuid.v1(),
appName: this.mediatorName.replace(/ /g,"-"),
mediatorName: this.mediatorName,
mediatorDesc: this.mediatorDesc,
mediatorRoutePath: this.mediatorRoutePath,
};

this.template("_gruntfile.js", "Gruntfile.js", context);
this.template("_package.json", "package.json", context);
this.template("_mediator.json", "app/config/mediator.json", context);

this.copy("_config.json", "app/config/config.json");
this.copy("_index.js", "app/index.js");
this.copy("_register.js", "app/register.js");
mediatorAuthor: this.mediatorAuthor,
mediatorMaintainer: this.mediatorMaintainer,
defaultChannelPath: this.defaultChannelPath,
mediatorRouteHost: this.mediatorRouteHost,
mediatorRoutePath: this.mediatorRoutePath
}

var apiContext = {
mediatorApiUsername: this.mediatorApiUsername,
mediatorApiPassword: this.mediatorApiPassword,
mediatorApiUrl: this.mediatorApiUrl,
mediatorApiSsl: this.mediatorApiSsl,
mediatorRegister: this.mediatorRegister
}

var ppaContext = {
ppaUsername: this.ppaUsername,
mediatorName: this.mediatorName,
appName: this.mediatorName.replace(/ /g,"-"),
mediatorMaintainer: this.mediatorMaintainer,
mediatorDesc: this.mediatorDesc
}

// Add the mediator files
this.fs.copyTpl(this.templatePath('mediatorTemplate/_package.json'), this.destinationPath('package.json'), mediatorContext)
this.fs.copyTpl(this.templatePath('mediatorTemplate/config/_mediator.json'), this.destinationPath('config/mediator.json'), mediatorContext)
this.fs.copyTpl(this.templatePath('mediatorTemplate/config/_config.json'), this.destinationPath('config/config.json'), apiContext)
this.fs.copyTpl(this.templatePath('mediatorTemplate/lib/_index.js'), this.destinationPath('lib/index.js'))
this.fs.copyTpl(this.templatePath('mediatorTemplate/lib/_openhim.js'), this.destinationPath('lib/openhim.js'))
this.fs.copyTpl(this.templatePath('mediatorTemplate/lib/_utils.js'), this.destinationPath('lib/utils.js'))
this.fs.copyTpl(this.templatePath('mediatorTemplate/test/_openhim.js'), this.destinationPath('test/openhim.js'))
this.fs.copyTpl(this.templatePath('mediatorTemplate/test/_test-openhim-server.js'), this.destinationPath('test/test-openhim-server.js'))

// Add the PPA files
this.fs.copyTpl(this.templatePath('packagingTemplate/_.dput.cf'), this.destinationPath('packaging/.dput.cf'), ppaContext)
this.fs.copyTpl(this.templatePath('packagingTemplate/_cp-mediators-into-pkg.sh'), this.destinationPath('packaging/cp-mediators-into-pkg.sh'), ppaContext)
this.fs.copyTpl(this.templatePath('packagingTemplate/_create-deb.sh'), this.destinationPath('packaging/create-deb.sh'), ppaContext)
this.fs.copyTpl(this.templatePath('packagingTemplate/targets/trusty/debian/_changelog'), this.destinationPath('packaging/targets/trusty/debian/changelog'), ppaContext)
this.fs.copyTpl(this.templatePath('packagingTemplate/targets/trusty/debian/_control'), this.destinationPath('packaging/targets/trusty/debian/control'), ppaContext)
this.fs.copyTpl(this.templatePath('packagingTemplate/targets/trusty/debian/_postinst'), this.destinationPath('packaging/targets/trusty/debian/postinst'), ppaContext)
this.fs.copyTpl(this.templatePath('packagingTemplate/targets/trusty/etc/init/_mediator.conf'), this.destinationPath('packaging/targets/trusty/etc/init/' + ppaContext.appName), ppaContext)
this.fs.copyTpl(this.templatePath('packagingTemplate/targets/trusty/debian/_config'), this.destinationPath('packaging/targets/trusty/debian/config'))
this.fs.copyTpl(this.templatePath('packagingTemplate/targets/trusty/debian/_install'), this.destinationPath('packaging/targets/trusty/debian/install'))
this.fs.copyTpl(this.templatePath('packagingTemplate/targets/trusty/debian/_rules'), this.destinationPath('packaging/targets/trusty/debian/rules'))
this.fs.copyTpl(this.templatePath('packagingTemplate/targets/trusty/debian/_templates'), this.destinationPath('packaging/targets/trusty/debian/templates'))
this.fs.copyTpl(this.templatePath('packagingTemplate/targets/trusty/etc/openhim/_install-node-4.sh'), this.destinationPath('packaging/targets/trusty/etc/openhim/install-node-4.sh'))
},

install: function () {
this.installDependencies({
skipInstall: this.options['skip-install'],
npm: true,
bower: false,
callback: function () {
// Have Yeoman greet the user.
// On successful install, have Yeoman greet the user.
console.log(yosay(
'Scaffolding Complete!\r' +
chalk.green('Remember "npm install"\r') +
chalk.green('Simply run: "npm start"\r') +
'Goodbye!'
));
))
}
});
})
}
});
})

module.exports = mediatorJsGenerator;
module.exports = mediatorJsGenerator
Loading