forked from decentdao/decent-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
91 lines (77 loc) · 2.43 KB
/
build.ts
File metadata and controls
91 lines (77 loc) · 2.43 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
import { execSync } from 'child_process';
import { join } from 'path';
import { readdir, stat } from 'fs/promises';
console.log('🔨 Building decent-sdk...');
const external = ['react', 'react-dom', '@tanstack/react-query'];
// Clean dist directory
console.log('Cleaning dist directory...');
execSync('rm -rf dist', { stdio: 'inherit' });
// Build ESM
console.log('Building ESM modules with optimizations...');
await Bun.build({
entrypoints: ['./src/core/index.ts', './src/react/index.ts'],
outdir: './dist/esm',
target: 'node',
external,
naming: {
entry: '[dir]/index.[ext]',
},
minify: false,
sourcemap: 'external',
});
// Build CJS
console.log('Building CommonJS modules with optimizations...');
await Bun.build({
entrypoints: ['./src/core/index.ts', './src/react/index.ts'],
outdir: './dist/cjs',
target: 'node',
format: 'cjs',
external,
naming: {
entry: '[dir]/index.[ext]',
},
minify: false,
sourcemap: 'external',
});
// Generate TypeScript declarations for ESM
console.log('Generating TypeScript declarations for ESM...');
execSync('tsc --project tsconfig.json', { stdio: 'inherit' });
// Generate TypeScript declarations for CJS
console.log('Generating TypeScript declarations for CJS...');
execSync('tsc --project tsconfig.cjs.json', { stdio: 'inherit' });
// Verify exports
console.log('Verifying exports are correctly built...');
try {
console.log('📊 Build statistics:');
const countFilesInDir = async (dir: string): Promise<number> => {
let count = 0;
const items = await readdir(dir);
for (const item of items) {
const fullPath = join(dir, item);
const stats = await stat(fullPath);
if (stats.isDirectory()) {
count += await countFilesInDir(fullPath);
} else {
count++;
}
}
return count;
};
const totalFiles = await countFilesInDir('./dist');
console.log(`Total files generated: ${totalFiles}`);
// Verify key directories exist
const dirs = ['dist/esm/core', 'dist/esm/react', 'dist/cjs/core', 'dist/cjs/react'];
for (const dir of dirs) {
const files = await readdir(dir);
if (files.length > 0) {
console.log(`✅ ${dir}: ${files.length} files`);
} else {
throw new Error(`Directory ${dir} is empty or doesn't exist`);
}
}
} catch (error) {
console.error('Failed to verify exports. Build may be incomplete.');
console.error(error);
process.exit(1);
}
console.log('✅ Build completed successfully.');