Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
106 lines (93 loc) · 2.74 KB
/
Copy pathindex.js
File metadata and controls
106 lines (93 loc) · 2.74 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const { JSDOM } = require('jsdom');
const dom = new JSDOM('<!doctype html><html><body></body></html>', {
pretendToBeVisual: true,
});
const { window } = dom;
global.window = window;
global.document = window.document;
global.navigator = window.navigator;
global.HTMLElement = window.HTMLElement;
global.Element = window.Element;
global.Node = window.Node;
global.HTMLCanvasElement = window.HTMLCanvasElement;
global.CanvasRenderingContext2D = window.CanvasRenderingContext2D;
global.addEventListener = window.addEventListener.bind(window);
global.removeEventListener = window.removeEventListener.bind(window);
const fallbackRaf = (cb) => setTimeout(cb, 0);
const fallbackCancel = (id) => clearTimeout(id);
global.requestAnimationFrame = window.requestAnimationFrame || fallbackRaf;
global.cancelAnimationFrame = window.cancelAnimationFrame || fallbackCancel;
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = global.requestAnimationFrame;
window.cancelAnimationFrame = global.cancelAnimationFrame;
}
if (!window.matchMedia) {
window.matchMedia = () => ({
matches: false,
addListener: () => {},
removeListener: () => {},
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => false,
});
}
if (typeof global.ResizeObserver === 'undefined') {
global.ResizeObserver = class {
observe() {}
unobserve() {}
disconnect() {}
};
}
if (global.HTMLCanvasElement) {
const noop = () => {};
global.HTMLCanvasElement.prototype.getContext = () => ({
fillRect: noop,
clearRect: noop,
getImageData: () => ({ data: [] }),
putImageData: noop,
createImageData: () => [],
setTransform: noop,
drawImage: noop,
save: noop,
fillText: noop,
restore: noop,
beginPath: noop,
closePath: noop,
moveTo: noop,
lineTo: noop,
clip: noop,
stroke: noop,
translate: noop,
scale: noop,
rotate: noop,
arc: noop,
fill: noop,
measureText: () => ({ width: 0 }),
transform: noop,
rect: noop,
globalAlpha: 1,
fillStyle: '',
strokeStyle: '',
shadowBlur: 0,
shadowColor: '',
shadowOffsetX: 0,
shadowOffsetY: 0,
});
global.HTMLCanvasElement.prototype.toDataURL = () => '';
}
const fs = require('fs');
const path = require('path');
const _carbonLibraries = require('./dist');
const pathname = './dist';
const filename = 'index.json';
const content = JSON.stringify(_carbonLibraries);
(async () => {
if (!fs.existsSync(pathname)) {
console.log('Creating directory:', pathname);
fs.mkdirSync(pathname, { recursive: true });
}
const jsonFilePath = path.resolve(pathname, filename);
console.log('Writing library content to:', jsonFilePath);
fs.writeFileSync(jsonFilePath, content);
process.exit();
})();