-
-
Notifications
You must be signed in to change notification settings - Fork 818
/
Copy pathbuild.ts
109 lines (102 loc) · 1.89 KB
/
build.ts
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
103
104
105
106
107
108
109
import * as esbuild from 'esbuild';
import { readFileSync, writeFileSync } from 'node:fs';
import * as tsup from 'tsup';
import pkg from './package.json';
const driversPackages = [
// postgres drivers
'pg',
'postgres',
'@vercel/postgres',
'@neondatabase/serverless',
'@electric-sql/pglite',
// mysql drivers
'mysql2',
'@planetscale/database',
// sqlite drivers
'@libsql/client',
'better-sqlite3',
];
esbuild.buildSync({
entryPoints: ['./src/utils.ts'],
bundle: true,
outfile: 'dist/utils.js',
format: 'cjs',
target: 'node16',
platform: 'node',
external: [
'commander',
'json-diff',
'glob',
'esbuild',
'drizzle-orm',
...driversPackages,
],
banner: {
js: `#!/usr/bin/env node`,
},
});
esbuild.buildSync({
entryPoints: ['./src/utils.ts'],
bundle: true,
outfile: 'dist/utils.mjs',
format: 'esm',
target: 'node16',
platform: 'node',
external: [
'commander',
'json-diff',
'glob',
'esbuild',
'drizzle-orm',
...driversPackages,
],
banner: {
js: `#!/usr/bin/env node`,
},
});
esbuild.buildSync({
entryPoints: ['./src/cli/index.ts'],
bundle: true,
outfile: 'dist/bin.cjs',
format: 'cjs',
target: 'node16',
platform: 'node',
define: {
'process.env.DRIZZLE_KIT_VERSION': `"${pkg.version}"`,
},
external: [
'esbuild',
'drizzle-orm',
...driversPackages,
],
banner: {
js: `#!/usr/bin/env node`,
},
});
const main = async () => {
await tsup.build({
entryPoints: ['./src/index.ts', './src/api.ts'],
outDir: './dist',
splitting: false,
dts: true,
format: ['cjs', 'esm'],
outExtension: (ctx) => {
if (ctx.format === 'cjs') {
return {
dts: '.d.ts',
js: '.js',
};
}
return {
dts: '.d.mts',
js: '.mjs',
};
},
});
const apiCjs = readFileSync('./dist/api.js', 'utf8').replace(/await import\(/g, 'require(');
writeFileSync('./dist/api.js', apiCjs);
};
main().catch((e) => {
console.error(e);
process.exit(1);
});