Skip to content

Commit

Permalink
added subgenerator 'service' for bootstrapping 'microservice-base'
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Hecher committed Feb 4, 2015
1 parent 24d8a87 commit 9387b35
Show file tree
Hide file tree
Showing 17 changed files with 293 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
17 changes: 17 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"undef": true,
"unused": true,
"strict": true
}
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- '0.10'
before_install:
- currentfolder=${PWD##*/}
- if [ "$currentfolder" != 'generator-duraark' ]; then cd .. && eval "mv $currentfolder generator-duraark" && cd generator-duraark; fi
3 changes: 3 additions & 0 deletions .yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"generator-generator": {}
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generator-duraark

CLI to bootstrap (micro)services and UIs for the DURAARK platform. It can also be used outside the DURAARK project, as it provides very generic blueprints for services and UIs.

The generator is based on [Yeoman](http://yeoman.io).
62 changes: 62 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');

module.exports = yeoman.generators.Base.extend({
initializing: function () {
this.pkg = require('../package.json');
},

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

// Have Yeoman greet the user.
this.log(yosay(
'Welcome to the super-excellent' + chalk.red('Duraark') + ' generator!'
));

var prompts = [{
type: 'confirm',
name: 'someOption',
message: 'Would you like to enable this option?',
default: true
}];

this.prompt(prompts, function (props) {
this.someOption = props.someOption;

done();
}.bind(this));
},

writing: {
app: function () {
this.fs.copy(
this.templatePath('_package.json'),
this.destinationPath('package.json')
);
this.fs.copy(
this.templatePath('_bower.json'),
this.destinationPath('bower.json')
);
},

projectfiles: function () {
this.fs.copy(
this.templatePath('editorconfig'),
this.destinationPath('.editorconfig')
);
this.fs.copy(
this.templatePath('jshintrc'),
this.destinationPath('.jshintrc')
);
}
},

install: function () {
this.installDependencies({
skipInstall: this.options['skip-install']
});
}
});
6 changes: 6 additions & 0 deletions app/templates/_bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "package",
"version": "0.0.0",
"dependencies": {}
}

5 changes: 5 additions & 0 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "package",
"version": "0.0.0",
"dependencies": {}
}
12 changes: 12 additions & 0 deletions app/templates/editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
17 changes: 17 additions & 0 deletions app/templates/jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"undef": true,
"unused": true,
"strict": true
}
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "generator-duraark",
"version": "0.1.0",
"description": "CLI for developing duraark services and UIs",
"license": "MIT",
"main": "app/index.js",
"repository": "duraark/generator-duraark",
"author": {
"name": "Martin Hecher",
"email": "[email protected]",
"url": "https://github.com/duraark"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
},
"files": [
"app",
"service"
],
"keywords": [
"yeoman-generator"
],
"dependencies": {
"yeoman-generator": "^0.18.0",
"chalk": "^0.5.0",
"yosay": "^0.3.0",
"duraark-microservice-base": "^0.2.0"
},
"devDependencies": {
"mocha": "*"
},
"peerDependencies": {
"yo": ">=1.0.0"
}
}
60 changes: 60 additions & 0 deletions service/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';
var yeoman = require('yeoman-generator'),
path = require('path');

module.exports = yeoman.generators.NamedBase.extend({
initializing: function() {
this.log('You called the Duraark subgenerator with the argument ' + this.name + '.');

// this.argument('name', {
// required: true,
// type: String,
// desc: 'The subgenerator name'
// });

this.bootstrapRoot = this.destinationRoot();
},

writing: function() {
var templateRoot = path.join(__dirname, '..', 'node_modules', 'duraark-microservice-base', 'src') + '/**',
deploymentScriptsRoot = path.join(__dirname, '..', 'node_modules', 'duraark-microservice-base', 'deployment') + '/**',
developmentScriptsRoot = path.join(__dirname, '..', 'node_modules', 'duraark-microservice-base', 'src', 'scripts') + '/**';

console.log('Copying template files from "' + templateRoot + '" to "' + this.bootstrapRoot + '"');

this.fs.copy(
templateRoot,
this.bootstrapRoot
);

var deploymentTarget = this.bootstrapRoot + '/deployment';

console.log('Copying deployment scripts from "' + deploymentScriptsRoot + '" to "' + deploymentTarget + '"');

this.fs.copy(
deploymentScriptsRoot,
deploymentTarget
);

var serviceInfoPath = path.join(deploymentTarget, 'service-info.txt');

console.log('Configuring deployment scripts ...');

this.write(serviceInfoPath, this.name);

var developmentTarget = this.bootstrapRoot + '/scripts';

console.log('Copying development scripts from "' + developmentScriptsRoot + '" to "' + developmentTarget + '"');

this.fs.copy(
developmentScriptsRoot,
developmentTarget
);

console.log('Configuring development scripts ...');

serviceInfoPath = path.join(developmentTarget, 'service-info.txt');

this.write(serviceInfoPath, this.name);
}
});
1 change: 1 addition & 0 deletions service/templates/somefile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This is a file copied by your subgenerator
27 changes: 27 additions & 0 deletions test/test-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

var path = require('path');
var assert = require('yeoman-generator').assert;
var helpers = require('yeoman-generator').test;
var os = require('os');

describe('duraark:app', function () {
before(function (done) {
helpers.run(path.join(__dirname, '../app'))
.inDir(path.join(os.tmpdir(), './temp-test'))
.withOptions({ 'skip-install': true })
.withPrompt({
someOption: true
})
.on('end', done);
});

it('creates files', function () {
assert.file([
'bower.json',
'package.json',
'.editorconfig',
'.jshintrc'
]);
});
});
20 changes: 20 additions & 0 deletions test/test-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

var path = require('path');
var assert = require('yeoman-generator').assert;
var helpers = require('yeoman-generator').test;

describe('Duraark:service', function () {
before(function (done) {
helpers.run(path.join(__dirname, '../service'))
.withArguments('name', '--force')
.withOptions({ 'skip-install': true })
.on('end', done);
});

it('creates files', function () {
assert.file([
'somefile.js'
]);
});
});

0 comments on commit 9387b35

Please sign in to comment.