Skip to content

Commit

Permalink
Only live reload after async write is done
Browse files Browse the repository at this point in the history
  • Loading branch information
drawveloper committed Jan 31, 2016
1 parent c21e765 commit ae394b2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
19 changes: 7 additions & 12 deletions bin/cleaver
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ var Cleaver = require('../');
* presentation
*/
function createAndSave(files, options, done) {
if (!done) {
done = function(){};
}

files.forEach(function (file) {
fs.readFile(file, 'utf-8', function (err, contents) {
if (err) {
Expand All @@ -28,8 +24,7 @@ function createAndSave(files, options, done) {
presentation.run()
.then(function (product) {
var outputFile = presentation.options.output || path.basename(file, '.md') + '-cleaver.html';
fs.writeFile(outputFile, product);
done();
fs.writeFile(outputFile, product, done);
})
.fail(function (err) {
process.stderr.write('!! ' + err.message + '\n');
Expand Down Expand Up @@ -84,19 +79,19 @@ program
console.log('Watching for changes on ' + file + '. Ctrl-C to abort.');
fs.watchFile(file, { persistent: true, interval: 100 }, function () {
console.log('Rebuilding: ' + new Date());
createAndSave([file], options);
console.log('Notifying live reload.');
tinylr.changed(file);
createAndSave([file], options, function() {
tinylr.changed(file);
});
});

// Also watch on stylesheet if included via command prompt
if (options.style) {
console.log('Also watching for changes on ' + options.style);
fs.watchFile(options.style, { persistent: true, interval: 100 }, function () {
console.log('Rebuilding: ' + new Date());
createAndSave([file], options);
console.log('Notifying live reload.');
tinylr.changed(file);
createAndSave([file], options, function() {
tinylr.changed(file);
});
});
}

Expand Down
3 changes: 1 addition & 2 deletions resources/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ function navigate(n) {
function updateURL() {
try {
window.history.replaceState({} , null, '#' + currentPosition());
}
catch (e) {
} catch (e) {
window.location.hash = currentPosition();
}
}
Expand Down
2 changes: 1 addition & 1 deletion templates/layout.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{{style}}}
</style>
{{#options.watch}}
<script async src="http://localhost:35729/livereload.js"></script>
<script async src="http://localhost:35729/livereload.js"></script>
{{/options.watch}}
</head>
<body>
Expand Down

0 comments on commit ae394b2

Please sign in to comment.