Skip to content

Instantly share code, notes, and snippets.

@claycarpenter
Created May 23, 2015 20:35
Show Gist options
  • Save claycarpenter/57596765f78cbb47347d to your computer and use it in GitHub Desktop.
Save claycarpenter/57596765f78cbb47347d to your computer and use it in GitHub Desktop.
Test of wrapped metalsmith-browser-sync plugin.
#!/usr/bin/env node
var Metalsmith = require('metalsmith'),
browserSync = require('metalsmith-browser-sync');
// Hard-coded value. In more complex scripts, this value is read from
// CLI args.
var isWatchEnabled = true;
var browserSyncOptions = {
server: 'output',
files: [
'src/index.html' // Only watch for index file changes.
],
port: process.env.PORT || 3000
};
// Define the Metalsmith file processing pipeline.
Metalsmith(__dirname)
.source('./src/')
.destination('./output/')
.clean(false)
// Conditionally watch and serve with BrowserSync.
.use(conditionalWatchMode(browserSync(browserSyncOptions)))
.build(function (err, files) {
if (err) throw err;
console.log('Build successful.');
});
function conditionalWatchMode (plugin) {
return function (files, metalsmith, done) {
if (isWatchEnabled) {
plugin(files, metalsmith, done);
} else {
done();
}
};
}
{
"name": "metalsmith-browsersync-plugin-test",
"version": "1.0.0",
"description": "Test of metalsmith-browser-sync plugin.",
"private": true,
"main": "build.js",
"author": "Clay Carpenter",
"license": "ISC",
"dependencies": {
"metalsmith": "^1.6.0",
"metalsmith-browser-sync": "git://github.com/mdvorscak/metalsmith-browser-sync.git",
"yargs": "^3.8.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment