-
Notifications
You must be signed in to change notification settings - Fork 15
/
patch-crypto.js
38 lines (34 loc) · 1.19 KB
/
patch-crypto.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
var fs = require('fs')
function isComment(line) {
var eval = line.replace(/\s/g, '').replace('\t', '');
return eval.startsWith('*') || eval.startsWith('/*') || eval.startsWith('//');
}
function removeComments(path) {
var array = fs.readFileSync(path).toString().split('\n');
output = '';
comments = 0;
array.forEach(line => {
if (!isComment(line)) output += line + '\n'; else comments++;
});
if (comments > 0) {
console.info('Removed comments', comments, path);
fs.writeFile(path, output, 'utf8', function (err) {
if (err) return console.info(err);
});
}
}
function replaceBrowserPath() {
var browserConfigPath = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js';
fs.readFile(browserConfigPath, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
const result = data.replace(/node: false/g, 'node: {crypto: true, stream: true}');
fs.writeFile(browserConfigPath, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
}
removeComments('./node_modules/crypto-js/cipher-core.js');
removeComments('./node_modules/crypto-js/core.js');
replaceBrowserPath();