Skip to content

Commit 915c517

Browse files
authored
chore(NODE-5277): add definition clean up script (#576)
1 parent c74d177 commit 915c517

File tree

4 files changed

+116
-347
lines changed

4 files changed

+116
-347
lines changed

etc/clean_definition_files.cjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#! /usr/bin/env node
2+
/* eslint-disable @typescript-eslint/no-var-requires */
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
function* walk(root) {
7+
const directoryContents = fs.readdirSync(root);
8+
for (const filepath of directoryContents) {
9+
const fullPath = path.join(root, filepath);
10+
const stat = fs.statSync(fullPath);
11+
if (stat.isDirectory()) {
12+
yield fullPath;
13+
yield* walk(fullPath);
14+
} else if (stat.isFile()) {
15+
yield fullPath;
16+
}
17+
}
18+
}
19+
20+
const libPath = path.resolve(__dirname, '..', 'lib');
21+
if (fs.existsSync(libPath)) {
22+
const definitionFiles = Array.from(walk(libPath))
23+
.filter(filePath => filePath.endsWith('.d.ts') || filePath.endsWith('.d.ts.map'));
24+
25+
for (const definitionFile of definitionFiles) {
26+
fs.unlinkSync(definitionFile);
27+
}
28+
29+
const emptyDirectories = Array.from(walk(libPath))
30+
.filter(filePath => fs.statSync(filePath).isDirectory() && fs.readdirSync(filePath).length === 0);
31+
32+
for (const emptyDirectory of emptyDirectories) {
33+
fs.rmdirSync(emptyDirectory);
34+
}
35+
}

0 commit comments

Comments
 (0)