Repository navigation
Expand file tree
/
Copy pathcleanup.js
More file actions
67 lines (56 loc) · 1.58 KB
/
Copy pathcleanup.js
File metadata and controls
67 lines (56 loc) · 1.58 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
/**
* Pre-publish cleanup script for docusaurus-plugin-llms
* This script removes unnecessary files from the lib directory that were generated
* from deleted source files but are still compiled by TypeScript.
*/
const fs = require('fs');
const path = require('path');
// Files and directories to remove from lib
const toRemove = [
// 'types.js',
// 'types.d.ts',
'constants.js',
'constants.d.ts',
'helpers',
'remark-plugins'
];
// Helper to remove a directory recursively
function removeDir(dirPath) {
if (fs.existsSync(dirPath)) {
fs.readdirSync(dirPath).forEach(file => {
const curPath = path.join(dirPath, file);
if (fs.lstatSync(curPath).isDirectory()) {
removeDir(curPath);
} else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(dirPath);
console.log(`✓ Removed directory: ${dirPath}`);
}
}
// Main cleanup function
function cleanup() {
const libDir = path.join(__dirname, 'lib');
if (!fs.existsSync(libDir)) {
console.warn('⚠️ lib directory not found, nothing to clean up.');
return;
}
console.log('Cleaning up lib directory before publishing...');
// Process each item to remove
toRemove.forEach(item => {
const itemPath = path.join(libDir, item);
if (fs.existsSync(itemPath)) {
const stats = fs.statSync(itemPath);
if (stats.isDirectory()) {
removeDir(itemPath);
} else {
fs.unlinkSync(itemPath);
console.log(`✓ Removed file: ${itemPath}`);
}
}
});
console.log('✓ Cleanup complete!');
}
// Run the cleanup
cleanup();