-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from cybertk/generate_hooks
Generate hooks
- Loading branch information
Showing
15 changed files
with
420 additions
and
211 deletions.
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
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
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
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
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
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
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,30 @@ | ||
fs = require 'fs' | ||
Mustache = require 'mustache' | ||
|
||
generateHooks = (names, ramlFile, templateFile, callback) -> | ||
if !names | ||
callback new Error 'no names found for which to generate hooks' | ||
|
||
if !templateFile | ||
callback new Error 'missing template file' | ||
|
||
try | ||
template = fs.readFileSync templateFile, 'utf8' | ||
datetime = new Date().toISOString().replace('T', ' ').substr(0, 19) | ||
view = | ||
ramlFile: ramlFile | ||
timestamp: datetime | ||
hooks: | ||
{ 'name': name } for name in names | ||
view.hooks[0].comment = true | ||
|
||
content = Mustache.render template, view | ||
console.log content | ||
catch error | ||
console.error 'failed to generate skeleton hooks' | ||
callback error | ||
|
||
callback | ||
|
||
module.exports = generateHooks | ||
|
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,6 +1,7 @@ | ||
async = require 'async' | ||
_ = require 'underscore' | ||
|
||
|
||
class Hooks | ||
constructor: () -> | ||
@beforeHooks = {} | ||
|
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
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,5 +1,6 @@ | ||
express = require 'express' | ||
|
||
|
||
PORT = '3333' | ||
|
||
app = express() | ||
|
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
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
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
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,47 @@ | ||
// | ||
// ABAO hooks file {{! Mustache template }} | ||
// Generated from RAML specification | ||
// RAML: {{ramlFile}} | ||
// Date: {{timestamp}} | ||
// <https://github.com/cybertk/abao> | ||
// | ||
|
||
var | ||
hooks = require('hooks'), | ||
assert = require('chai').assert; | ||
|
||
// | ||
// Setup/Teardown | ||
// | ||
|
||
hooks.beforeAll(function (done) { | ||
done(); | ||
}); | ||
|
||
hooks.afterAll(function (done) { | ||
done(); | ||
}); | ||
|
||
|
||
// | ||
// Hooks | ||
// | ||
|
||
{{#hooks}} | ||
//----------------------------------------------------------------------------- | ||
hooks.before('{{{name}}}', function (test, done) { | ||
{{#comment}} | ||
// Modify 'test.request' properties here to modify the inbound request | ||
{{/comment}} | ||
done(); | ||
}); | ||
|
||
hooks.after('{{{name}}}', function (test, done) { | ||
{{#comment}} | ||
// Assert against 'test.response' properties here to verify expected results | ||
{{/comment}} | ||
done(); | ||
}); | ||
|
||
{{/hooks}} | ||
|
Oops, something went wrong.