Skip to content

Commit ad2c140

Browse files
committed
Split deploy and preview builds
1 parent 2f9145e commit ad2c140

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

build.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ var watch = require('metalsmith-watch');
88
var collections = require('metalsmith-collections');
99
var excerpts = require('metalsmith-excerpts');
1010
var browserify = require('metalsmith-browserify-alt');
11+
var msif = require('metalsmith-if');
1112

1213
var preprocess = require('metalsmith-preprocess');
1314

15+
// look for build flag
16+
var preview = false;
17+
var args = process.argv.slice(2);
18+
if (args.length) {
19+
preview = true;
20+
}
21+
1422
var siteBuild = Metalsmith(__dirname)
1523
.metadata({
1624
site: {
@@ -51,14 +59,21 @@ var siteBuild = Metalsmith(__dirname)
5159
moment: moment,
5260
partials: "partials"
5361
}))
54-
.use(serve({
55-
port: 8080,
56-
verbose: true
57-
}))
58-
.use(watch({
59-
pattern: '**/*',
60-
livereload: true
61-
}))
62+
// livereload and preview server only run if command line argument present
63+
.use(msif(
64+
preview,
65+
serve({
66+
port: 8080,
67+
verbose: true
68+
})
69+
))
70+
.use(msif(
71+
preview,
72+
watch({
73+
pattern: '**/*',
74+
livereload: preview
75+
})
76+
))
6277
.build(function (err, files) {
6378
if (err) {
6479
throw err;

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
"metalsmith-browserify-alt": "^1.0.1",
1313
"metalsmith-collections": "^0.7.0",
1414
"metalsmith-excerpts": "^1.1.0",
15+
"metalsmith-if": "^0.1.1",
1516
"metalsmith-layouts": "^1.4.1",
1617
"metalsmith-markdown": "^0.2.1",
1718
"metalsmith-permalinks": "^0.1.0",
1819
"metalsmith-watch": "^1.0.3",
1920
"pug": "^2.0.0-beta6"
2021
},
2122
"scripts": {
22-
"preview": "node build.js",
23-
"deploy": "node build.js; echo \"done yeah!\""
23+
"preview": "node build.js --preview",
24+
"deploy": "node build.js"
2425
}
2526
}

0 commit comments

Comments
 (0)