-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgenerateExports.cjs
46 lines (40 loc) · 1.46 KB
/
generateExports.cjs
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
/*
* @Author: liwb lwbhtml@163.com
* @Date: 2025-04-09 11:06:16
* @LastEditors: liwb lwbhtml@163.com
* @LastEditTime: 2025-04-18 13:56:05
* @FilePath: /cloud-utils/generateExports.cjs
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
const fs = require('fs');
const path = require('path');
const SRC_DIR = path.join(__dirname, 'src');
const OUTPUT_FILE = path.join(__dirname, 'src', 'index.ts');
function getTypeScriptFiles(dir) {
// 忽略 src/core
if (dir.includes('.internal')) {
return [];
}
const files = fs.readdirSync(dir);
return files
.filter(file => file.endsWith('.ts') && !file.endsWith('.d.ts') && !file.endsWith('index.ts'))
.map(file => path.join(dir, file));
}
function generateExportStatements(files) {
return files
.map(file => {
const fileName = path.basename(file, '.ts');
if (fileName === 'is' || fileName === 'cookie'|| fileName === 'math') {
return `export * from './${fileName}';`;
}
return `export { ${fileName} } from './${fileName}';`;
})
.join('\n');
}
function main() {
const tsFiles = getTypeScriptFiles(SRC_DIR);
const exportStatements = '// 此文件是自动生成,请勿手动修改此文件。\r\n' + generateExportStatements(tsFiles);
fs.writeFileSync(OUTPUT_FILE, exportStatements);
console.log(`Generated exports in ${OUTPUT_FILE}`);
}
main();