-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare.js
43 lines (33 loc) · 1 KB
/
prepare.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
const fs = require('fs');
const distPackage = require('./package.json');
// remove dev dependencies
delete distPackage.devDependencies;
distPackage.scripts = {
postversion: 'cd .. && node bump.js',
};
// include all 'dist/*' files
distPackage.files = ['*'];
// updates source flags removing 'dist' path
['main', 'module'].forEach((prop) => {
distPackage[prop] = distPackage[prop].replace('dist/', '');
});
// update paths for exports
const updateDistPaths = (obj) => {
for (const key in obj) {
if (typeof obj[key] === 'string' && obj[key].startsWith('./dist/')) {
obj[key] = obj[key].replace('dist/', '');
} else if (typeof obj[key] === 'object') {
updateDistPaths(obj[key]);
}
}
};
if (distPackage.exports) {
updateDistPaths(distPackage.exports);
}
fs.mkdirSync('./dist', { recursive: true });
fs.copyFileSync('./README.md', './dist/README.md');
fs.copyFileSync('./LICENSE', './dist/LICENSE');
fs.writeFileSync(
'./dist/package.json',
JSON.stringify(distPackage, undefined, 2)
);