-
Notifications
You must be signed in to change notification settings - Fork 4
/
options.js
53 lines (43 loc) · 1.61 KB
/
options.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
import loadJsonFile from 'load-json-file';
import meteorProjectPath from 'meteor-project-path';
import path from 'path';
import sha1 from './sha1';
global.nathantreidStaticAssets = global.nathantreidStaticAssets || { lastNotifiedHash: null, };
const optionsFilePath = path.join(meteorProjectPath || '', 'package.json');
const defaultOptions = {
extensions: [
'gif',
'jpg',
'png',
'svg',
],
pathPrefix: 'static/',
exportAbsolutePaths: true,
};
let initialExtensions;
let options;
loadOptions();
initialExtensions = JSON.stringify(options.extensions);
function loadOptions() {
const previousHash = options ? options.hash : null;
const userOptions = loadOptionsFromFile();
options = { ...defaultOptions, ...userOptions };
options.hash = sha1(JSON.stringify(options));
if (previousHash && previousHash !== options.hash && global.nathantreidStaticAssets.lastNotifiedHash !== options.hash) {
global.nathantreidStaticAssets.lastNotifiedHash = options.hash;
console.info('nathantreid:static-assets plugin options updated, recompiling all static assets.');
if (JSON.stringify(options.extensions) !== initialExtensions) {
console.warn(`The list of extensions handled by the nathantreid:static-assets plugin has changed to: ${options.extensions}.\nThis change requires a manual Meteor restart to take effect.\n`)
}
}
}
function loadOptionsFromFile() {
/* The Meteor project path is only null when publishing */
return meteorProjectPath
? loadJsonFile.sync(optionsFilePath).staticAssets || {}
: {};
}
export default function getOptions() {
loadOptions();
return options;
}