forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle-html.js
More file actions
83 lines (76 loc) · 3.02 KB
/
Copy pathbundle-html.js
File metadata and controls
83 lines (76 loc) · 3.02 KB
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
const fs = require('fs-extra');
const {getDestDir} = require('./paths');
const enLocale = fs.readFileSync('src/_locales/en.config', {encoding: 'utf8'}).replace(/^#.*?$/gm, '');
global.chrome = global.chrome || {};
global.chrome.i18n = global.chrome.i18n || {};
global.chrome.i18n.getMessage = global.chrome.i18n.getMessage || ((name) => {
const index = enLocale.indexOf(`@${name}`);
if (index < 0) {
throw new Error(`Message @${name} not found`);
}
const start = index + name.length + 1;
let end = enLocale.indexOf('@', start);
if (end < 0) {
end = enLocale.length;
}
const message = enLocale.substring(start, end).trim();
return message;
});
global.chrome.i18n.getUILanguage = global.chrome.i18n.getUILanguage || (() => 'en-US');
const tsConfig = require('../src/tsconfig.json');
require('ts-node').register({
...tsConfig,
compilerOptions: {
...tsConfig.compilerOptions,
module: 'commonjs',
},
ignore: [
'/node_modules\/(?!malevic).*/',
]
});
require('tsconfig-paths').register({
baseUrl: './',
paths: {
'malevic/*': ['node_modules/malevic/umd/*'],
'malevic': ['node_modules/malevic/umd/index'],
}
});
const Malevic = require('malevic/umd/index');
const MalevicString = require('malevic/umd/string');
const DevToolsBody = require('../src/ui/devtools/components/body').default;
const PopupBody = require('../src/ui/popup/components/body').default;
const CSSEditorBody = require('../src/ui/stylesheet-editor/components/body').default;
const {getMockData, getMockActiveTabInfo} = require('../src/ui/connect/mock');
async function bundlePopupHTML({dir}) {
let html = await fs.readFile('src/ui/popup/index.html', 'utf8');
const data = getMockData({isReady: false});
const tab = getMockActiveTabInfo();
const actions = null;
const bodyText = MalevicString.stringify(Malevic.m(PopupBody, {data, tab, actions}));
html = html.replace('$BODY', bodyText);
await fs.outputFile(`${dir}/ui/popup/index.html`, html);
}
async function bundleDevToolsHTML({dir}) {
let html = await fs.readFile('src/ui/devtools/index.html', 'utf8');
const data = getMockData();
const actions = null;
const bodyText = MalevicString.stringify(Malevic.m(DevToolsBody, {data, actions}));
html = html.replace('$BODY', bodyText);
await fs.outputFile(`${dir}/ui/devtools/index.html`, html);
}
async function bundleCSSEditorHTML({dir}) {
let html = await fs.readFile('src/ui/stylesheet-editor/index.html', 'utf8');
const data = getMockData();
const tab = getMockActiveTabInfo();
const actions = null;
const bodyText = MalevicString.stringify(Malevic.m(CSSEditorBody, {data, tab, actions}));
html = html.replace('$BODY', bodyText);
await fs.outputFile(`${dir}/ui/stylesheet-editor/index.html`, html);
}
async function bundleHTML({production}) {
const dir = getDestDir({production});
await bundlePopupHTML({dir});
await bundleDevToolsHTML({dir});
await bundleCSSEditorHTML({dir});
}
module.exports = bundleHTML;