-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtsup.leetcode.config.js
More file actions
102 lines (83 loc) · 3.32 KB
/
tsup.leetcode.config.js
File metadata and controls
102 lines (83 loc) · 3.32 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
import { defineConfig } from 'tsup';
import { readdir, readFile, writeFile } from 'fs/promises';
import { join } from 'path';
const commonConfig = {
format: ['esm'],
outDir: 'dist/leetcode',
splitting: false,
sourcemap: false,
keepNames: true,
treeshake: false,
clean: true,
target: 'es2022',
minify: false,
dts: false,
outExtension() {
return { js: '.mjs' };
},
esbuildOptions(options) {
options.drop = ['debugger']
},
// The true ultimate solution: automatic cleaning up of comments after the build is complete
onSuccess: async () => {
const distDir = 'dist/leetcode';
try {
const files = await readdir(distDir);
let cleanedCount = 0;
for (const file of files) {
// Only .mjs and .js files are processed
if (!file.endsWith('.mjs') && !file.endsWith('.js')) continue;
const filePath = join(distDir, file);
let content = await readFile(filePath, 'utf-8');
// Step 1: Remove all block comments (including JSDoc)
content = content.replace(/\/\*[\s\S]*?\*\//g, '');
// Step 2: Remove all line comments
content = content.replace(/^\s*\/\/.*$/gm, '');
// Step 3: Remove extra blank lines (optional, delete this line if you want to keep it)
content = content.replace(/\n\s*\n/g, '\n');
await writeFile(filePath, content);
cleanedCount++;
}
} catch (err) {
process.exit(1);
}
}
};
const entries = {
// ============ Heap ============
heap: 'src/data-structures/heap/heap.ts',
'max-heap': 'src/data-structures/heap/max-heap.ts',
'min-heap': 'src/data-structures/heap/min-heap.ts',
// ============ Binary Trees ============
'binary-tree': 'src/data-structures/binary-tree/binary-tree.ts',
bst: 'src/data-structures/binary-tree/bst.ts',
'red-black-tree': 'src/data-structures/binary-tree/red-black-tree.ts',
'avl-tree': 'src/data-structures/binary-tree/avl-tree.ts',
'avl-tree-counter': 'src/data-structures/binary-tree/avl-tree-counter.ts',
'avl-tree-multi-map': 'src/data-structures/binary-tree/avl-tree-multi-map.ts',
'tree-counter': 'src/data-structures/binary-tree/tree-counter.ts',
'tree-multi-map': 'src/data-structures/binary-tree/tree-multi-map.ts',
// ============ Graph ============
'directed-graph': 'src/data-structures/graph/directed-graph.ts',
'undirected-graph': 'src/data-structures/graph/undirected-graph.ts',
// ============ Hash ============
'hash-map': 'src/data-structures/hash/hash-map.ts',
// ============ LinkedList ============
'doubly-linked-list': 'src/data-structures/linked-list/doubly-linked-list.ts',
'singly-linked-list': 'src/data-structures/linked-list/singly-linked-list.ts',
// ============ PriorityQueue ============
'priority-queue': 'src/data-structures/priority-queue/priority-queue.ts',
'max-priority-queue': 'src/data-structures/priority-queue/max-priority-queue.ts',
'min-priority-queue': 'src/data-structures/priority-queue/min-priority-queue.ts',
// ============ Queue ============
deque: 'src/data-structures/queue/deque.ts',
queue: 'src/data-structures/queue/queue.ts',
// ============ Stack ============
stack: 'src/data-structures/stack/stack.ts',
// ============ Trie ============
trie: 'src/data-structures/trie/trie.ts'
};
export default defineConfig({
...commonConfig,
entry: entries
});