forked from mdn/interactive-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (43 loc) · 1.59 KB
/
index.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
'use strict';
const fse = require('fs-extra');
const glob = require('glob');
const bundler = require('./lib/bundler');
const config = require('./lib/config');
const pageBuilder = require('./lib/pageBuilder');
const utils = require('./lib/utils');
/**
* Initialization of the module. This loads `site.json` at the root of the
* project and calls the follow on functions to generate the pages.
*/
function init() {
fse
.readJson('./site.json')
.then(function(site) {
// if the destination dir exists
if (fse.pathExistsSync(config.baseDir)) {
// clean it out before writing files
fse.emptyDirSync(config.baseDir);
} else {
// ensure the destination dir exists
fse.ensureDirSync(config.baseDir);
}
// copy assets in `/media`
utils.copyDirectory(config.mediaRoot, config.baseDir);
// builds the CSS and JS bundles
bundler.buildBundles(site.bundles);
// generated pages using glob.
const metaJSONArray = glob.sync('live-examples/**/meta.json', {});
for (const metaJson of metaJSONArray) {
const file = fse.readJsonSync(metaJson);
pageBuilder.buildPages(file.pages);
}
// clean up
utils.removeJSBundles();
// done
console.log('Pages built successfully'); // eslint-disable-line no-console
})
.catch(function(err) {
console.error('Error thrown while loading JSON', err);
});
}
init();