-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrunch-config.js
231 lines (210 loc) · 8.84 KB
/
brunch-config.js
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// See http://brunch.io for documentation.
// For a different structure than /app/ see:
// https://github.com/brunch/brunch/issues/1676
const fs = require('fs');
const settings = require('./app/js/settings.js');
// Add your theme in app/themes and select it in app/js/settings.js theme property
//
// Currently we have serveral themes:
// - clean
// - material
// - flatly (based in clean + custom bootstrap)
//
const theme = settings.theme;
const cleanBased = theme == 'flatly' || theme == 'superhero' || theme == 'yeti' || theme == 'cosmo' || theme == 'darkly' || theme == 'paper' || theme == 'sandstone' || theme == 'simplex' || theme == 'slate';
const themeAssets = cleanBased || theme == 'clean' ? 'clean' : theme;
const toReplace = [
/index\.html$/, // index can be used as your main LA page
/pagesLayout\.html$/, // Layout, usable by markdown pages
/errorPage\.html/, // An error page that can be used in your infrastructure
/testPage\.html$/, // testPate is just for text some headings, buttons, etc
/testSmall\.html$/]; // testSmall is for test the footer with small contents
const toReplaceOthers = [
/banner\.html$/,
/footer\.html$/,
/index\.html$/, // index can be used as your main LA page
/pagesLayout\.html$/, // Layout, usable by markdown pages
/errorPage\.html/, // An error page that can be used in your infrastructure
/testPage\.html$/, // testPate is just for text some headings, buttons, etc
/testSmall\.html$/, // testSmall is for test the footer with small contents
];
// Don't add head.html above because this replacement is done by ala-boostrap
exports.files = {
javascripts: {
joinTo: {
'js/vendor.js': [ // Files that are not in `app/js` dir.
/^(?!app)/
],
'js/app.js': [
'app/js/*js',
...(cleanBased ? ['app/themes/clean/js/*.js'] : []),
`app/themes/${theme}/js/*.js`
]
}
},
stylesheets: {
joinTo: {
'css/app.css': [
'app/css/*css',
...(cleanBased ? ['app/themes/clean/css/*.css'] : []),
`app/themes/${theme}/css/*.css`
]
}
}
};
exports.plugins = {
// TODO add eslint
// This do some var substition in js code:
// jscc: {
// values: {
// _LOCALES_URL: process.env.NODE_ENV === 'development' ? 'http://localhost:3333' : settings.baseFooterUrl
// }
// },
babel: { presets: ['latest'] },
copycat: {
// just copy ALA default builded files to our build
// These are loaded by ala-bootstrap3 library, so we need to load manually in our development testPage
'js': ['commonui-bs3-2019/build/js/'],
...(theme == 'material' ? { 'material-lite': ['app/themes/material/material-lite'] } : {}),
...(theme == 'material' ? { 'custom-bootstrap': ['app/themes/material/custom-bootstrap'] } : {}),
'css': ['commonui-bs3-2019/build/css/'],
'fonts': 'commonui-bs3-2019/build/fonts/',
verbose: false, // shows each file that is copied to the destination directory
onlyChanged: true // only copy a file if it's modified time has changed (only effective when using brunch watch)
},
// Maybe replace this plugin by: https://github.com/bmatcuk/html-brunch-static
replacement: {
replacements: [
// Right now this file replacements are only done with `brunch build` and not via the watcher
// So if you edit them, exec `brunch build` later
{
files: toReplace, match: {
find: 'INDEX_BODY', replace: () => {
return fs.readFileSync(`app/themes/${themeAssets}/assets/indexBody.html`, 'utf8');
}
}
},
{
files: toReplace, match: {
find: 'TEST_BODY', replace: () => {
return fs.readFileSync(`app/themes/${themeAssets}/assets/testBody.html`, 'utf8');
}
}
},
{
files: toReplace, match: {
find: 'HEADLOCAL_HERE', replace: () => {
return fs.readFileSync(`app/themes/${themeAssets}/assets/headLocal.html`, 'utf8');
}
}
},
{
files: toReplace, match: {
find: 'HEAD_HERE', replace: () => {
return fs.readFileSync(`app/themes/${themeAssets}/assets/head.html`, 'utf8');
}
}
},
{
files: toReplace, match: {
find: 'BANNER_HERE', replace: () => {
return fs.readFileSync(`app/themes/${themeAssets}/assets/banner.html`, 'utf8');
}
}
},
{
files: toReplace, match: {
find: 'FOOTER_HERE', replace: () => {
return fs.readFileSync(`app/themes/${themeAssets}/assets/footer.html`, 'utf8');
}
}
},
// These replacements are done by
// https://github.com/AtlasOfLivingAustralia/ala-bootstrap3/blob/grails2/grails-app/taglib/au/org/ala/bootstrap3/HeaderFooterTagLib.groovy#L208
// in the ALA modules that uses it (most of them)
{ files: toReplace, match: { find: '::containerClass::', replace: 'container' } },
{
files: toReplace, match: {
find: '::headerFooterServer::', replace:
process.env.NODE_ENV === 'development' ?
'http://localhost:3333' :
settings.baseFooterUrl
}
},
{ files: toReplace, match: { find: '::loginURL::', replace: settings.loginUrl } },
{ files: toReplace, match: { find: '::logoutURL::', replace: settings.logoutUrl } },
{ files: toReplace, match: { find: '::searchServer::', replace: settings.services.bie.url } },
{ files: toReplace, match: { find: '::searchPath::', replace: '/search' } },
{ files: toReplace, match: { find: '::centralServer::', replace: settings.mainLAUrl } },
{ files: toReplace, match: { find: '::bugSVG::', replace: fs.readFileSync(`app/assets/images/bug.svg`, 'utf8') } },
// These other replacements are only done during build time (and are specific for this skin), so see toReplaceOthers var.
// Also edit app/js/settings.js before build
{ files: toReplaceOthers, match: { find: '::spatialURL::', replace: settings.services.spatial.url }},
{ files: toReplaceOthers, match: { find: '::collectoryURL::', replace: settings.services.collectory.url } },
{
files: toReplaceOthers, match: {
find: '::datasetsURL::', replace: `${settings.services.collectory.url}/datasets`
}
},
{ files: toReplaceOthers, match: { find: '::biocacheURL::', replace: settings.services.biocache.url } },
{ files: toReplaceOthers, match: { find: '::bieURL::', replace: settings.services.bie.url } },
{ files: toReplaceOthers, match: { find: '::regionsURL::', replace: settings.services.regions.url } },
{ files: toReplaceOthers, match: { find: '::listsURL::', replace: settings.services.lists.url } },
{ files: toReplaceOthers, match: { find: '::spatialURL::', replace: settings.services.spatial.url } },
{ files: toReplaceOthers, match: { find: '::casURL::', replace: settings.services.cas.url } },
{ files: toReplaceOthers, match: { find: '::imagesURL::', replace: settings.services.images.url } },
{ files: toReplaceOthers, match: { find: '::bugSVG::', replace: fs.readFileSync(`app/assets/images/bug.svg`, 'utf8') } },
// And just for testing:
{ files: toReplace, match: { find: '::loginStatus::', replace: process.env.NODE_ENV === 'development' ? 'signedIn' : '::loginStatus::' } }
]
},
static: {
processors: [
require('html-brunch-static')({
processors: [
require('marked-brunch-static') ({
fileMatch: 'app/pages/**/*.md',
fileTransform: (filename) => filename.replace(/\.md$/, '.html').replace(/^app\/pages\//, 'pages/'),
})
]
})
]
},
// Using:
// https://github.com/ocombe/browser-sync-brunch
// instead of auto-reload-brunch and just `brunch watch`
// We can return to auto-reload in the future
browserSync: {
port: 3333,
// logLevel: "debug"
// Don't open a browser tab on each modification (this was working in another browser-sync plugin)
// open: false
}
// Also:
// https://github.com/mikefarah/git-digest-brunch
};
exports.conventions = {
// file won't be compiled and will be just moved to public directory instead
ignored: [
...(theme == 'material' ? [/^app\/material-lite/] : []),
...(theme == 'material' ? [/^app\/custom-bootstrap/] : [])
]
};
exports.server = {
noPushState: true // returns 404 when file not found
// If you want to test other html page during development
// indexPath: 'testPage.html'
};
// FIXME, document this
exports.paths = {
watched: ['app/js', 'app/css', 'app/assets', `app/themes/${theme}/assets`, `app/themes/${theme}/css`,
`app/themes/${themeAssets}/assets`, `app/themes/${themeAssets}/css`,
'app/pages'
]
};
// https://brunch.io/docs/troubleshooting
exports.watcher = {
awaitWriteFinish: true,
usePolling: true
}
// exports.optimize = true; // same like brunch build --production