Created
May 23, 2015 20:35
-
-
Save claycarpenter/57596765f78cbb47347d to your computer and use it in GitHub Desktop.
Test of wrapped metalsmith-browser-sync plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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(); | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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