forked from shoptet/shoptet-bender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·47 lines (39 loc) · 1.25 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
#!/usr/bin/env node
import browserSync from 'browser-sync';
import command from './cli.js';
import { config } from './config.js'
command.parse(process.argv);
const options = command.opts();
const blankModeStyle = {
match: /<link rel="stylesheet" media="all" href="https:\/\/cdn\.myshoptet\.com.*>/i,
fn: function () { return ('');},
}
const blankModeScript = {
match: /<script src="https:\/\/cdn.myshoptet.com.*>/i,
fn: function () { return ('');},
};
const scriptStyle = {
match: /<\/body>(?![\s\S]*<\/body>[\s\S]*$)/i,
fn: function (req, res, match) {
return (
'<script src="/script.js"></script><link rel="stylesheet" href="/style.css">' +
match
);
},
}
const rewriteRules = [
{...scriptStyle},
{...(options.blankMode && blankModeStyle)},
{...(options.blankMode && blankModeScript)}
];
const bs = browserSync.create();
bs.init({
proxy: { target: options.remote ?? config.defaultUrl },
watch: options.watch,
files: [options.folder ? './' + options.folder + '/*' : config.defaultFolder + '/*'],
serveStatic: [options.folder ?? config.defaultFolder],
rewriteRules: rewriteRules.filter(
(value) => Object.keys(value).length !== 0
),
notify: options.notify
});