forked from opensearch-project/oui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preinstall.js
134 lines (122 loc) · 3.2 KB
/
preinstall.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
const { rmSync, readdirSync, existsSync } = require('fs');
const { join } = require('path');
const { INIT_CWD, PWD = process.cwd() } = process.env;
// Only run when installed as a dep
if (!INIT_CWD?.startsWith?.(PWD)) {
/* These are deps and types which get installed when a production package is installed.
* When this library is linked as a dep to another project, having all the deps could
* confuse or conflict the project's compilers.
*
* When being installed as dep of another project in production, `node_modules` would
* be empty.
*/
const depsToKeep = [
'@opensearch',
'@types',
'csstype',
'detect-node',
'is-buffer',
'is-plain-obj',
'mdast-util-definitions',
'mdast-util-to-hast',
'mdurl',
'react-focus-lock',
'react-focus-on',
'react-is',
'react-remove-scroll',
'react-remove-scroll-bar',
'react-style-singleton',
'rehype-react',
'remark-parse',
'remark-rehype',
'unified',
'unist-builder',
'unist-util-generated',
'unist-util-is',
'unist-util-position',
'unist-util-remove-position',
'unist-util-stringify-position',
'unist-util-visit',
'unist-util-visit-parents',
'use-callback-ref',
'use-sidecar',
'uuid',
'vfile-message',
];
if (existsSync('node_modules')) {
for (const name of readdirSync('node_modules')) {
if (!depsToKeep.includes(name))
rmSync(join('node_modules', name), { recursive: true, force: true });
}
}
const typesToKeep = [
'chroma-js',
'lodash',
'mdast',
'numeral',
'prismjs',
'prop-types',
'react-beautiful-dnd',
'react-dom',
'react-input-autosize',
'react-virtualized-auto-sizer',
'react-window',
'refractor',
'resize-observer-browser',
'scheduler',
'unist',
'vfile-message',
];
if (existsSync('node_modules/@types')) {
for (const name of readdirSync('node_modules/@types')) {
if (!typesToKeep.includes(name))
rmSync(join('node_modules/@types', name), {
recursive: true,
force: true,
});
}
}
const toDeleteFromRoot = [
'.DS_Store',
'.cache-loader',
'.eslintcache',
'.git',
'.idea',
'.nvmrc',
'.vscode',
'docs',
'generator-oui',
'packages/eslint-plugin',
'packages/react-datepicker',
'reports',
'src-docs',
'test',
'tmp',
'tsconfig-builttypes.json',
'tsconfig.json',
'types',
'wiki',
'yarn-error.log',
'yarn.lock',
];
for (const name of toDeleteFromRoot) {
rmSync(name, { recursive: true, force: true });
}
const scriptsToKeep = ['postinstall.js', 'preinstall.js'];
for (const name of readdirSync('scripts')) {
if (!scriptsToKeep.includes(name))
rmSync(join('scripts', name), { recursive: true, force: true });
}
const deleteNonSCSS = (loc) => {
for (const entry of readdirSync(loc, { withFileTypes: true })) {
if (entry.isDirectory()) deleteNonSCSS(join(loc, entry.name));
else if (entry.isFile() && !entry.name.endsWith('.scss'))
rmSync(join(loc, entry.name), { force: true });
}
};
deleteNonSCSS('src');
}