grunt-devserver
Advanced tools
Comparing version 0.2.0 to 0.2.1
var path = require('path'); | ||
module.exports = function(grunt) { | ||
var config = { devserver : { port : 4321 | ||
, base : '.' | ||
} | ||
, mochaTest : { files : ['./test/**/*Test.js'] } | ||
, mochaTestConfig : { options : { ui : 'bdd' | ||
, reporter : 'spec' | ||
, require : 'test/common' | ||
} | ||
} | ||
var config = { devserver: getDevServerConfig() | ||
, mochaTest: getMochaTestConfig() | ||
, mochaTestConfig: getMochaTestConfigConfig() | ||
, jshint: getJshintConfig() | ||
} | ||
loadTasks() | ||
grunt.registerTask('test', ['mochaTest']) | ||
grunt.initConfig(config) | ||
function getDevServerConfig() { | ||
return { port : 4321 | ||
, base : '.' | ||
, cache : 'no-store' | ||
} | ||
} | ||
function getMochaTestConfig() { | ||
return { unit: ['./test/unit/**/*Test.js'] } | ||
} | ||
function getMochaTestConfigConfig() { | ||
return { unit: { options: { ui: 'bdd' | ||
, reporter: 'spec' | ||
, require: 'test/unit/common' | ||
} | ||
} | ||
} | ||
} | ||
function getJshintConfig() { | ||
return { options: { jshintrc: '.jshintrc' } | ||
, all: { src: ['Gruntfile.js', 'lib/**/*.js', 'test/unit/**/*.js'] } | ||
} | ||
} | ||
function loadTasks() { | ||
grunt.loadTasks(path.resolve('tasks')) | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-mocha-test') | ||
grunt.registerTask('default', ['jshint', 'test']) | ||
} | ||
loadTasks() | ||
grunt.registerTask('test', ['mochaTest']) | ||
grunt.initConfig(config) | ||
} |
@@ -5,10 +5,20 @@ var optimist = require('optimist') | ||
function buildConfigFromCliArgsCmd(args) { | ||
var config = new Config() | ||
args = getCLIArguments(args) | ||
config.port = args.port || config.port | ||
config.folder = args.folder || config.folder | ||
config.cacheControl = args.cache || config.cacheControl | ||
return config | ||
} | ||
function getCLIArguments(args) { | ||
var o = args ? optimist(args) : optimist | ||
return o.default('port', Config.DEFAULT_PORT) | ||
.default('folder', Config.DEFAULT_FOLDER) | ||
.alias('p', 'port') | ||
.alias('f', 'folder') | ||
.argv | ||
return o.describe('port', 'listens on this port. Default: ' + Config.DEFAULT_PORT) | ||
.describe('folder', 'serves content from this folder. Default: ' + Config.DEFAULT_FOLDER) | ||
.describe('cache', 'caching method used. Default: ' + Config.DEFAULT_CACHE_CONTROL) | ||
.alias('p', 'port') | ||
.alias('f', 'folder') | ||
.argv | ||
} | ||
module.exports = buildConfigFromCliArgsCmd |
@@ -7,2 +7,3 @@ function Config() { | ||
this.folder = Config.DEFAULT_FOLDER | ||
this.cacheControl = Config.DEFAULT_CACHE_CONTROL | ||
} | ||
@@ -12,3 +13,4 @@ | ||
Config.DEFAULT_FOLDER = process.cwd() | ||
Config.DEFAULT_CACHE_CONTROL = 'no-cache' | ||
module.exports = Config |
@@ -1,2 +0,2 @@ | ||
exports['Server'] = require('./Server.js') | ||
exports['commands'] = { startFromConsole : require('./cli/startFromConsoleCmd.js') } | ||
exports.Server = require('./Server.js') | ||
exports.commands = { startFromConsole : require('./cli/startFromConsoleCmd.js') } |
module.exports = corsSupport | ||
function corsSupport(req, res, next) { | ||
res.setHeader('Access-Control-Allow-Origin', '*') | ||
next() | ||
} | ||
function corsSupport() { | ||
return function corsSupport(req, res, next) { | ||
res.setHeader('Access-Control-Allow-Origin', '*') | ||
next() | ||
} | ||
} |
module.exports = noCacheHeaders | ||
function noCacheHeaders(req, res, next) { | ||
res.setHeader('Cache-Control', 'no-cache') | ||
next() | ||
} | ||
function noCacheHeaders(cacheMethod) { | ||
if(!cacheMethod) | ||
throw new Error('invalid cache method') | ||
return function noCacheHeaders(req, res, next) { | ||
res.setHeader('Cache-Control', cacheMethod) | ||
next() | ||
} | ||
} |
@@ -26,4 +26,4 @@ var path = require('path') | ||
app.use(express.logger()) | ||
app.use(corsSupport) | ||
app.use(noCacheHeaders) | ||
app.use(corsSupport()) | ||
app.use(noCacheHeaders(config.cacheControl)) | ||
registerStaticContent(app, config) | ||
@@ -30,0 +30,0 @@ } |
{ | ||
"name": "grunt-devserver", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "a simple web server without caching for development", | ||
@@ -31,3 +31,4 @@ "homepage": "https://github.com/devpaul/grunt-devserver", | ||
"sandboxed-module": "*", | ||
"grunt-mocha-test": "~0.2.0" | ||
"grunt-mocha-test": "~0.2.0", | ||
"grunt-contrib-jshint": "~0.3.0" | ||
}, | ||
@@ -34,0 +35,0 @@ "peerDependencies": { |
@@ -14,9 +14,9 @@ # Developer Web Server | ||
``` | ||
npm install grunt-devserver | ||
npm install grunt-devserver --save-dev | ||
``` | ||
Or add it to your package.json devDependicies | ||
``` | ||
"devDependencies": { | ||
"grunt-devserver": "*" | ||
} | ||
"devDependencies": { | ||
"grunt-devserver": "*" | ||
} | ||
``` | ||
@@ -29,2 +29,3 @@ | ||
-f, --folder (full path to a folder) serves this folder | ||
--cache (method) the method to return in the Cache-Control HTTP header. Default is no-cache. | ||
``` | ||
@@ -37,2 +38,3 @@ | ||
, 'base' : <directory> (defaults to .) | ||
, 'cache' : <string> (defaults to 'no-cache') | ||
} | ||
@@ -66,2 +68,2 @@ ``` | ||
<br> [Grunt](http://www.gruntjs.com) | ||
<br> [Yeoman](http://www.yeoman.io) | ||
<br> [Yeoman](http://www.yeoman.io) |
@@ -21,2 +21,3 @@ var Server = require('../lib/Server.js') | ||
config.folder = grunt.config('devserver.base') || config.folder | ||
config.cacheControl = grunt.config('devserver.cache') || config.cacheControl | ||
return config | ||
@@ -23,0 +24,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46810
26
484
66
9
2