This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (85 loc) · 2.23 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
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
const docredux = require('docredux');
const buildDocs = () => {
return docredux.build.json({
destination: `${__dirname}/docs/`,
source: `${__dirname}/docs/bundle.js`,
});
};
const rollup = require('rollup').rollup;
const { terser: minify } = require('rollup-plugin-terser');
const tinyLR = require('tiny-lr')();
const liveReload = require('connect-livereload');
const fs = require('fs');
const watch = require('node-watch');
const express = require('express');
const path = require('path');
const app = express();
const expressRoot = '/';
const expressPort = 8890;
const liveReloadPort = 35729;
const liveReloadStart = () => {
app.use(liveReload());
app.use(express.static(`${__dirname}/docs`));
app.listen(expressPort);
tinyLR.listen(liveReloadPort);
};
const notifyLiveReload = (evt, filename) => {
const fileName = path.relative(expressRoot, filename);
tinyLR.changed({
body: {
files: [fileName],
},
});
};
const copyFile = (start, end) => {
fs.writeFileSync(end, fs.readFileSync(path.join(__dirname, start)).toString(), 'utf8');
};
const build = async () => {
console.log('Build Start');
const bundle = await rollup({
input: './source/index.js',
});
console.log('Bundle Rolled');
await bundle.write({
file: './build/bundle.js',
format: 'umd',
name: '$',
sourcemap: true
});
console.log('Bundle Written');
const production = await rollup({
input: './source/index.js',
plugins: [
minify()
]
});
console.log('Rolled Production');
await production.write({
file: './build/index.js',
format: 'umd',
name: '$',
sourcemap: false,
});
console.log('Production Written');
copyFile('./build/bundle.js', './docs/bundle.js');
copyFile('./build/index.js', './docs/bundle.min.js');
console.log('Build Complete');
console.log('Docs Started');
await buildDocs();
console.log('Docs Complete');
console.log('NPM Started');
copyFile('./build/index.js', './npm/index.js');
copyFile('./LICENSE', './npm/LICENSE');
copyFile('./README.md', './npm/README.md');
copyFile('./build/index.js', './node_modules/Lucy/index.js');
console.log('NPM Complete');
console.log('Build Complete');
};
build();
liveReloadStart();
watch('./source/', {
recursive: true
}, async (evt, filename) => {
await build();
notifyLiveReload(evt, filename);
});