From 95a5483eb399908beafa5727a42da9b4af3f29e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20B=C3=A4lter?= Date: Mon, 18 Nov 2013 15:05:03 +0100 Subject: [PATCH] added files --- .gitignore | 5 +++ .jshintrc | 13 ++++++++ Gruntfile.js | 78 +++++++++++++++++++++++++++++++++++++++++++ LICENSE-MIT | 22 ++++++++++++ package.json | 45 +++++++++++++++++++++++++ tasks/rsimulatorjs.js | 50 +++++++++++++++++++++++++++ 6 files changed, 213 insertions(+) create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 Gruntfile.js create mode 100644 LICENSE-MIT create mode 100644 package.json create mode 100644 tasks/rsimulatorjs.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f11ae92 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules +npm-debug.log +tmp +*.idea +*.iml \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..f57a8ff --- /dev/null +++ b/.jshintrc @@ -0,0 +1,13 @@ +{ + "curly": true, + "eqeqeq": true, + "immed": true, + "latedef": true, + "newcap": true, + "noarg": true, + "sub": true, + "undef": true, + "boss": true, + "eqnull": true, + "node": true +} diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..5b6c941 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,78 @@ +/* + * grunt-rsimulatorjs + * https://github.com/baelter/grunt-rsimulatorjs + * + * Copyright (c) 2013 Anders Bälter + * Licensed under the MIT license. + */ + +'use strict'; + +module.exports = function(grunt) { + + // Project configuration. + grunt.initConfig({ + jshint: { + all: [ + 'Gruntfile.js', + 'tasks/*.js', + '<%= nodeunit.tests %>' + ], + options: { + jshintrc: '.jshintrc' + } + }, + + // Before generating any new files, remove any previously-created files. + clean: { + tests: ['tmp'] + }, + + // Configuration to be run (and then tested). + rsimulatorjs: { + default_options: { + options: { + } + }, + custom_options: { + options: { + simulator: { + port: 6001, + rootPath: './mockmock', + useRootRelativePath: false + }, + proxy: { + port : 8001, + pathnameOnly : false, + router : { + '/hoo' : '127.0.0.1:' + 6001, + '' : '127.0.0.1:' + 9001 + } + } + } + } + }, + + // Unit tests. + nodeunit: { + tests: ['test/*_test.js'] + } + + }); + + // Actually load this plugin's task(s). + grunt.loadTasks('tasks'); + + // These plugins provide necessary tasks. + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-contrib-nodeunit'); + + // Whenever the "test" task is run, first clean the "tmp" dir, then run this + // plugin's task(s), then test the result. + grunt.registerTask('test', ['clean', 'rsimulatorjs', 'nodeunit']); + + // By default, lint and run all tests. + grunt.registerTask('default', ['jshint', 'test']); + +}; diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..fbedb8c --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,22 @@ +Copyright (c) 2013 Anders Bälter + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json new file mode 100644 index 0000000..0685970 --- /dev/null +++ b/package.json @@ -0,0 +1,45 @@ +{ + "name": "grunt-rsimulatorjs", + "description": "Grunt plugin for rsimulatorjs-server", + "version": "0.1.0", + "homepage": "https://github.com/baelter/grunt-rsimulatorjs", + "author": { + "name": "Anders Bälter", + "email": "abaelter@gmail.com" + }, + "repository": { + "type": "git", + "url": "https://github.com/baelter/grunt-rsimulatorjs.git" + }, + "bugs": { + "url": "https://github.com/baelter/grunt-rsimulatorjs/issues" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://github.com/baelter/grunt-rsimulatorjs/blob/master/LICENSE-MIT" + } + ], + "main": "Gruntfile.js", + "engines": { + "node": ">= 0.8.0" + }, + "scripts": { + "test": "grunt test" + }, + "devDependencies": { + "grunt-contrib-jshint": "~0.6.0", + "grunt-contrib-clean": "~0.4.0", + "grunt-contrib-nodeunit": "~0.2.0", + "grunt": "~0.4.1" + }, + "peerDependencies": { + "grunt": "~0.4.1" + }, + "keywords": [ + "gruntplugin" + ], + "dependencies": { + "rsimulatorjs-server": "~0.3.9" + } +} diff --git a/tasks/rsimulatorjs.js b/tasks/rsimulatorjs.js new file mode 100644 index 0000000..dc22df4 --- /dev/null +++ b/tasks/rsimulatorjs.js @@ -0,0 +1,50 @@ +/* + * grunt-rsimulatorjs + * https://github.com/baelter/grunt-rsimulatorjs + * + * Copyright (c) 2013 Anders Bälter + * Licensed under the MIT license. + */ + +'use strict'; + +module.exports = function(grunt) { + + // Please see the Grunt documentation for more information regarding task + // creation: http://gruntjs.com/creating-tasks + grunt.registerMultiTask('rsimulatorjs', 'Start rsimulatorjs', function () { + var rsimulatorjsServer = require('rsimulatorjs-server'), + route, + options = this.options({ + simulator: { + port: 9005, + rootPath: './mocked-rest-api', + useRootRelativePath: true + }, + proxy: { + port : 9004, + pathnameOnly : true, + router : { + '/service' : '127.0.0.1:' + 9005, + '' : '127.0.0.1:' + 9001 + } + } + }), + serverOptions = { + simulatorConfig: options.simulator, + proxyConfig: { + port: options.proxy.port, + options: { + pathnameOnly: options.proxy.pathnameOnly, + router: options.proxy.router + } + } + }; + rsimulatorjsServer(serverOptions); + grunt.log.writeln('Started rsimulator on ' + options.simulator.port + ' with proxy on ' + options.proxy.port + ' with the following routes:'); + for(route in options.proxy.router) { + grunt.log.writeln(route + ' : ' + options.proxy.router[route]); + } + }); + +};