-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
39 lines (32 loc) · 1.13 KB
/
index.ts
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
import * as fs from 'fs';
import readdirSync from 'recursive-readdir-sync';
const newContent = `
var colors = require('./colors');
module['exports'] = colors;
// Remark: By default, colors will add style properties to String.prototype.
//
// If you don't wish to extend String.prototype, you can do this instead and
// native String will not be touched:
//
// var colors = require('colors/safe);
// colors.red("foo")
//
//
require('./extendStringPrototype')();
`;
function fixFolder(folderPath) {
const files = readdirSync(folderPath).filter(item => item.indexOf('/colors/lib/index.js') !== -1);
for (let i = 0, len = files.length; i < len; i++) {
fixFile(files[i]);
}
}
function fixFile(filePath) {
if (fs.existsSync(filePath)) {
const oldContent = fs.readFileSync(filePath, 'utf-8');
if (oldContent.indexOf(`am = require('../lib/custom/american')`) !== -1 || oldContent.indexOf('i < Infinity; i++') !== -1) {
fs.writeFileSync(filePath, newContent);
console.log('[fix-colors-out-of-memory] fix colors oom: ', filePath);
}
}
}
export { fixFolder, fixFile };