-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreateEncryptingHTMLFile.ts
More file actions
46 lines (34 loc) · 1.79 KB
/
CreateEncryptingHTMLFile.ts
File metadata and controls
46 lines (34 loc) · 1.79 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
import { readFile, writeFile } from 'fs/promises';
import { stringToBase64 } from './CreateEncryptingLib.js';
async function main() {
const selfDecryptingLibSourceBuffer = await readFile('SelfDecryptingLib.js');
const selfDecryptingLibSource = selfDecryptingLibSourceBuffer.toString();
const base64selfDecryptingLibSource = stringToBase64(selfDecryptingLibSource);
// Create the output file
const selfDecryptingTemplateBuffer = await readFile('SelfDecryptingTemplate.html');
const selfDecryptingTemplate = selfDecryptingTemplateBuffer.toString()
const base64selfDecryptingTemplate = stringToBase64(selfDecryptingTemplate);
const encryptingLibSourceBuffer = await readFile('EncryptingLib.js');
let encryptingLibSource = encryptingLibSourceBuffer.toString();
const encryptingTemplateBuffer = await readFile('EncryptingTemplate.html');
let encryptingTemplate = encryptingTemplateBuffer.toString();
// Remove export declations from encryption library
encryptingLibSource = encryptingLibSource.replace(/export function/g, 'function');
// Write library and encrypted file into the template
const htmlFile = encryptingTemplate
.replace(/<!--DECRYPT_LIB_BASE64-->/g, base64selfDecryptingLibSource)
.replace(/<!--DECRYPT_TEMPLATE_BASE64-->/g, base64selfDecryptingTemplate)
.replace(/\/\/<!--ENCRYPTION_LIB-->/g, encryptingLibSource);
// Write the output file
const outputFilename = 'EasyEncryptionEverywhere.html';
await writeFile(outputFilename, htmlFile);
console.log(`Wrote ${outputFilename}`);
}
// Rest of the functions used in main()...
if (process.argv.length != 2) {
console.log("Usage: node CreateEncryptingHTMLFile.js");
process.exit(1);
}
else {
/*await*/ main().catch(console.error);
}