This repository was archived by the owner on Jun 10, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathbuild.js
More file actions
140 lines (135 loc) · 4.55 KB
/
Copy pathbuild.js
File metadata and controls
140 lines (135 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
"use strict";
const metalsmith = require('metalsmith');
const branch = require('metalsmith-branch');
const debug = require('metalsmith-debug');
const define = require('metalsmith-define');
const filenames = require('metalsmith-filenames');
const fingerprint = require('metalsmith-fingerprint-ignore');
const ignore = require('metalsmith-ignore');
const inplace = require('metalsmith-in-place');
const layouts = require('metalsmith-layouts');
const permalinks = require('metalsmith-permalinks');
const serve = require('metalsmith-serve');
const stylus = require('metalsmith-stylus');
const uglify = require('metalsmith-uglify');
const watch = require('metalsmith-watch');
// This is a plugin.
// Lets 'node build' run lean, while 'node build dev' loads add'l plugins.
// TODO: make it a real plugin.
const devonly = function(plugin, options) {
if (process.argv.length > 2 && process.argv.indexOf('dev') > 0) {
return plugin(options);
}
else {
return function(files, metalsmith, done) {
done();
};
}
};
// This is a plugin.
// Dumps some variables to the screen.
// TODO: make it a real plugin.
const dump = function(options) {
return function(files, metalsmith, done) {
console.log(metalsmith);
done();
};
};
metalsmith(__dirname)
// Input files from source directory.
.source('source')
// Define some global values that will be accessible in metadata anywhere.
.use(define({
date_format: 'j F, Y',
version_date: new Date().toISOString(),
}))
// Add debug messages to terminal. Dev-only.
.use(devonly(debug, {}))
// Give each file processed a name during conversion, which is required for
// template inheritance in swig. Conflicts with branch so run it out here.
// https://github.com/MoOx/metalsmith-filenames/issues/1
.use(filenames())
// Restrict the files we transform to a pattern; don't transform 2015.
.use(branch('!2015/**/*')
.use(branch('!berlin-2016/**/*')
.use(branch('!london-2017/**/*')
.use(branch('!assets/**/*')
// Ignore files that we don't want to copy to build dir.
// Must follow json_to_files
.use(ignore([
'**/_*',
'**/*swp',
// At launch we may not have a seattle event. This prevents building its pages.
// '**/seattle-2016/*',
]))
// Make pretty urls by moving foo.html to /foo/index.html.
// Also, add a 'path' to global metadata for each file.
.use(permalinks({
relative: false,
}))
// Minimize and concatenate js files. Must be above fingerprint.
.use(uglify({
filter: 'js/*.js',
sourceMap: true,
concat: 'js/main.js',
}))
// Convert stylus files to css. Must be above fingerprint.
.use(stylus({
compress: true
}))
// Change asset filenames to unique strings per build for cachebusting.
// Must be above inplace.
.use(fingerprint({
pattern: ['stylesheets/style.css', 'js/*.js'],
}))
// Process template files in the source dir using specified engine.
.use(inplace({
engine: 'swig',
pattern: ['**/*.html', 'worker.js'],
autoescape: false,
}))
// Apply layouts to (certain) source files using specified engine.
// We only use this to support json_to_files.
.use(layouts({
engine: 'swig',
pattern: '**/*.html',
autoescape: false,
}))
// Log global metadata, etc., to terminal.
.use(devonly(dump))
))))
// Output files to build dir.
.destination('build')
// Automatically rebuild things in the source directory when they change.
.use(devonly(watch, {
paths: {
'source/assets/**/*': true,
'source/js/**/*': true,
'source/stylesheets/**/*': true,
'source/*': true,
'source/data/**/*': '**/*',
'layouts/**/*': '**/*',
},
livereload: true,
}))
// Start a server on localhost.
.use(devonly(serve, {
host: '0.0.0.0',
port: 8080,
verbose: true,
http_error_files: {
404: "/404.html",
},
}))
.use(devonly(define, {
livereload: '<script src="http://localhost:35729/livereload.js"></script>',
}))
// Do it!
.build(function(err) {
if (err) {
console.log(err);
}
else {
console.info('✫ Built it. ✫');
}
});