-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mjs
73 lines (62 loc) · 1.86 KB
/
build.mjs
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
import * as esbuild from 'esbuild';
import { fileURLToPath } from 'url';
import { dirname, join, relative } from 'path';
import { readdirSync } from 'fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Function to get all TypeScript files recursively
function getTypeScriptFiles(dir) {
const files = [];
const entries = readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = join(dir, entry.name);
if (entry.isDirectory()) {
files.push(...getTypeScriptFiles(fullPath));
} else if (entry.isFile() && /\.tsx?$/.test(entry.name) && !entry.name.includes('.d.ts')) {
files.push(fullPath);
}
}
return files;
}
// Get all TypeScript files from both typescript-sdk and utils directories at root level
const srcFiles = [
...getTypeScriptFiles('typescript-sdk'),
...getTypeScriptFiles('utils')
];
// Create entry points object for esbuild
const entryPoints = {};
srcFiles.forEach(file => {
// Get the path relative to the root of the project
const relativePath = file.startsWith('typescript-sdk/') ? file : file;
const outPath = relativePath.replace(/\.tsx?$/, '');
entryPoints[outPath] = file;
});
console.log('Building files:', Object.keys(entryPoints));
const commonConfig = {
entryPoints,
bundle: true,
platform: 'node',
target: 'esnext',
external: ['dotenv', 'ethers', 'siwe'],
sourcemap: true,
minify: false,
outbase: '.', // Changed to root directory
logLevel: 'info',
preserveSymlinks: true,
packages: 'external'
};
// Build ESM version
console.log('\nBuilding ESM version...');
await esbuild.build({
...commonConfig,
outdir: 'dist/esm',
format: 'esm',
});
// Build CJS version
console.log('\nBuilding CJS version...');
await esbuild.build({
...commonConfig,
outdir: 'dist/cjs',
format: 'cjs',
});
console.log('\nBuild complete');