grunt-reloadlet
Advanced tools
Comparing version 0.1.1 to 0.1.2
javascript: (function() { | ||
function getScript(url, success) { | ||
var script = document.createElement('script'); | ||
script.src = url; | ||
var head = document.getElementsByTagName('head')[0], | ||
done = false; | ||
script.onload = script.onreadystatechange = function() { | ||
if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { | ||
done = true; | ||
success(); | ||
script.onload = script.onreadystatechange = null; | ||
head.removeChild(script); | ||
} | ||
}; | ||
head.appendChild(script); | ||
} | ||
function loadjQuery() { | ||
var otherjQuery = false; | ||
if (typeof jQuery != 'undefined') { | ||
console.log('This page already using jQuery v' + jQuery.fn.jquery); | ||
} else { | ||
if (typeof $ == 'function') { | ||
otherjQuery = true; | ||
} | ||
getScript('//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.js', function() { | ||
if (typeof jQuery == 'undefined') { | ||
console.log('Sorry, but jQuery wasn\'t able to load') | ||
} else { | ||
console.log('This page is now jQuerified with v' + jQuery.fn.jquery + otherjQuery ? ' and noConflict(). Use $jq(), not $().' : ''); | ||
} | ||
}); | ||
} | ||
} | ||
function reload(asset) { | ||
@@ -8,3 +42,4 @@ $("link[href='" + asset + "']").remove(); | ||
var mtimes = {}; | ||
var mtimes = {}, | ||
errors = 0; | ||
@@ -21,17 +56,28 @@ function checkmtime(asset, mtime) { | ||
function tick() { | ||
$.ajax({ | ||
var request = $.ajax({ | ||
url: "http://localhost:8005/", | ||
cache: false | ||
}) | ||
.done(function(response) { | ||
for (asset in response) { | ||
var mtime = response[asset]; | ||
if (checkmtime(asset, mtime)) { | ||
console.log("reloading " + asset); | ||
reload(asset); | ||
} | ||
}); | ||
request.done(function(response) { | ||
errors = 0; | ||
for (asset in response) { | ||
var mtime = response[asset]; | ||
if (checkmtime(asset, mtime)) { | ||
console.log("reloading " + asset); | ||
reload(asset); | ||
} | ||
}); | ||
} | ||
}); | ||
request.fail(function(jqXHR, textStatus) { | ||
if (++errors >= 3) { | ||
console.log("stopping live reload..."); | ||
window.clearInterval(window.reloadlet); | ||
} | ||
}); | ||
} | ||
loadjQuery(); | ||
if (window.reloadlet) { | ||
@@ -38,0 +84,0 @@ window.clearInterval(window.reloadlet); |
{ | ||
"name": "grunt-reloadlet", | ||
"description": "simple live reloader", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"homepage": "https://github.com/mosborn/grunt-reloadlet", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -6,3 +6,3 @@ # grunt-reloadlet | ||
## Getting Started | ||
This plugin requires Grunt `~0.4.5` | ||
This plugin requires Grunt `~0.4.0` | ||
@@ -29,9 +29,22 @@ If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: | ||
reloadlet: { | ||
options: { | ||
// Task-specific options go here. | ||
}, | ||
your_target: { | ||
// Target-specific file lists and/or options go here. | ||
}, | ||
}, | ||
options: { | ||
port: 8005 | ||
}, | ||
main: { | ||
sass: { | ||
src: 'common/app/assets/stylesheets/', | ||
dest: 'static/target/stylesheets' | ||
}, | ||
assets: [ | ||
{ | ||
local: 'static/target/stylesheets/head.default.css', | ||
remote: '/assets/stylesheets/head.default.css' | ||
}, | ||
{ | ||
local: 'static/target/stylesheets/global.css', | ||
remote: '/assets/stylesheets/global.css' | ||
} | ||
] | ||
} | ||
} | ||
}); | ||
@@ -42,51 +55,16 @@ ``` | ||
#### options.separator | ||
Type: `String` | ||
Default value: `', '` | ||
#### options.port | ||
Type: `Integer` | ||
Default value: `8005` | ||
A string value that is used to do something with whatever. | ||
Port to host the webserver on. | ||
#### options.punctuation | ||
Type: `String` | ||
Default value: `'.'` | ||
#### sass | ||
A string value that is used to do something else with whatever else. | ||
sass watch command is created using this: | ||
'sass --watch ' + options.sass.src + ':' + options.sass.dest | ||
### Usage Examples | ||
#### Default Options | ||
In this example, the default options are used to do something with whatever. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result would be `Testing, 1 2 3.` | ||
#### assets | ||
```js | ||
grunt.initConfig({ | ||
reloadlet: { | ||
options: {}, | ||
files: { | ||
'dest/default_options': ['src/testing', 'src/123'], | ||
}, | ||
}, | ||
}); | ||
``` | ||
#### Custom Options | ||
In this example, custom options are used to do something else with whatever else. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result in this case would be `Testing: 1 2 3 !!!` | ||
```js | ||
grunt.initConfig({ | ||
reloadlet: { | ||
options: { | ||
separator: ': ', | ||
punctuation: ' !!!', | ||
}, | ||
files: { | ||
'dest/default_options': ['src/testing', 'src/123'], | ||
}, | ||
}, | ||
}); | ||
``` | ||
## Contributing | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
## Release History | ||
_(Nothing yet)_ | ||
local path to watch and remote css asset url to refresh on change |
@@ -12,7 +12,3 @@ /* | ||
module.exports = function(grunt) { | ||
// Please see the Grunt documentation for more information regarding task | ||
// creation: http://gruntjs.com/creating-tasks | ||
var http = require('http'), | ||
//_ = require('lodash'), | ||
fs = require('fs'), | ||
@@ -23,4 +19,3 @@ spawn = require('win-spawn'); | ||
this.async(); | ||
//console.log(this.data.assets); | ||
// Merge task-specific and/or target-specific options with these defaults. | ||
var assets = this.data.assets, | ||
@@ -65,30 +60,4 @@ sassOpts = this.data.sass, | ||
}); | ||
// Iterate over all specified file groups. | ||
// this.files.forEach(function(f) { | ||
// // Concat specified files. | ||
// var src = f.src.filter(function(filepath) { | ||
// // Warn on and remove invalid source files (if nonull was set). | ||
// if (!grunt.file.exists(filepath)) { | ||
// grunt.log.warn('Source file "' + filepath + '" not found.'); | ||
// return false; | ||
// } else { | ||
// return true; | ||
// } | ||
// }).map(function(filepath) { | ||
// // Read file source. | ||
// return grunt.file.read(filepath); | ||
// }).join(grunt.util.normalizelf(options.separator)); | ||
// // Handle options. | ||
// src += options.punctuation; | ||
// // Write the destination file. | ||
// grunt.file.write(f.dest, src); | ||
// // Print a success message. | ||
// grunt.log.writeln('File "' + f.dest + '" created.'); | ||
// }); | ||
}); | ||
}; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
222
1
1
11388
13
67