Skip to content

Commit

Permalink
Merge pull request #6 from jembi/update-generator-js
Browse files Browse the repository at this point in the history
Update generator js
  • Loading branch information
hnnesv committed Jul 5, 2016
2 parents 95b4250 + c7389a7 commit 2483cfc
Show file tree
Hide file tree
Showing 39 changed files with 916 additions and 413 deletions.
17 changes: 0 additions & 17 deletions generator-mediator-js/.jshintrc

This file was deleted.

35 changes: 11 additions & 24 deletions generator-mediator-js/README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,34 @@
# 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

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.

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).
Finally, from a clean directory into which you would like to install the mediator:

```bash
yo mediator-js
```

## License
You will be prompted to enter the config needed to create the mediator, to use default config:

MIT
```bash
yo mediator-js --useDefaults --name="Mediator Name" --description="This is what my mediator does"
```
19 changes: 19 additions & 0 deletions generator-mediator-js/app/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"mediatorAuthor":"Jembi Health Systems NPC",
"mediatorMaintainer":"Name Surname <email@exchange.com> (https://github.com/githubusername)",
"configPort":7000,
"nonLocalMediator":false,

"mediatorHost":"localhost",
"defaultChannelPath":"channelPath",

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

"enablePPA":false,
"ppaUsername":"openhie"
}
180 changes: 107 additions & 73 deletions generator-mediator-js/app/index.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,128 @@
'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 = require('./prompts')
var config = require('./config')

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 mediatorJsGenerator = generator.Base.extend({
constructor: function () {
generator.Base.apply(this, arguments)

this.prompt(prompts, function (props) {
this.configPort = props.configPort;
this.mediatorName = props.mediatorName;
this.mediatorDesc = props.mediatorDesc;
this.mediatorRoutePath = props.mediatorRoutePath;

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

scaffoldFolders: function(){
this.mkdir("app/config");
this.mkdir("build");
this.option('name')
this.nameProvided = (this.options.name ? true : false)

this.option('description')
this.descriptionProvided = (this.options.description ? true : false)
},

prompting: function () {
return this.prompt(prompts.promptsList(this.enablePrompts, this.nameProvided, this.descriptionProvided)).then(function (props) {
// Mediator settings
this.mediatorName = this.options.name || props.mediatorName
this.mediatorDesc = this.options.description || props.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.mediatorHost = props.mediatorHost || config.mediatorHost
this.appName = this.mediatorName.replace(/ /g,"-")

// 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(),
appName: this.mediatorName.replace(/ /g,"-"),
mediatorUUID: "urn:uuid:" + uuid.v1(),
appName: this.appName,
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,
mediatorHost: this.mediatorHost
}

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.appName,
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/_.gitignore'), this.destinationPath('.gitignore'))
this.fs.copyTpl(this.templatePath('mediatorTemplate/_README.md'), this.destinationPath('README.md'), 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/config/_test.json'), this.destinationPath('config/test.json'), apiContext)
this.fs.copyTpl(this.templatePath('mediatorTemplate/lib/_index.js'), this.destinationPath('lib/index.js'))
this.fs.copyTpl(this.templatePath('mediatorTemplate/lib/_utils.js'), this.destinationPath('lib/utils.js'))
this.fs.copyTpl(this.templatePath('mediatorTemplate/test/_basic.js'), this.destinationPath('test/basic.js'))
this.fs.copyTpl(this.templatePath('mediatorTemplate/test/_openhim-mock.js'), this.destinationPath('test/openhim-mock.js'))
this.fs.copyTpl(this.templatePath('mediatorTemplate/test/tls-certs/_key.pem'), this.destinationPath('test/tls-certs/key.pem'))
this.fs.copyTpl(this.templatePath('mediatorTemplate/test/tls-certs/_cert.pem'), this.destinationPath('test/tls-certs/cert.pem'))

// Add the PPA files
if(this.enablePPA) {
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 + '.conf'), 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

0 comments on commit 2483cfc

Please sign in to comment.