Shorter way to set livereload port

This commit is contained in:
Kyle Robinson Young 2013-04-30 13:44:21 -07:00
parent cbb0e8e0e4
commit 08a62f813b
3 changed files with 10 additions and 5 deletions

View File

@ -17,8 +17,13 @@ module.exports = function(grunt) {
};
function LR(options) {
if (options === true) { options = defaults; }
else { options = grunt.util._.defaults(options, defaults); }
if (options === true) {
options = defaults;
} else if (typeof options === 'number') {
options = {port: options};
} else {
options = grunt.util._.defaults(options, defaults);
}
this.server = tinylr();
this.server.listen(options.port, function(err) {
if (err) { return grunt.fatal(err); }

View File

@ -24,7 +24,7 @@ module.exports = function(grunt) {
tasks: ['before'],
options: {
nospawn: true,
livereload: true,
livereload: 1337,
},
},
},

View File

@ -88,14 +88,14 @@ exports.livereload = {
var cwd = path.resolve(fixtures, 'livereload');
var assertWatch = helper.assertTask(['watch:nospawn', '-v'], {cwd: cwd});
assertWatch([function() {
request(35729, function(data) {
request(1337, function(data) {
resultData += data;
grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var one = true;');
});
}], function(result) {
helper.verboseLog(result);
test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.');
test.ok(result.indexOf('Live reload server started on port: 35729') !== -1, 'live reload server should have been started on port 35729.');
test.ok(result.indexOf('Live reload server started on port: 1337') !== -1, 'live reload server should have been started on port 35729.');
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
resultData = JSON.parse(resultData);
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');