1
1
import fs from "node:fs" ;
2
2
import path from "node:path" ;
3
+ import { execSync } from "node:child_process" ;
4
+
3
5
import * as esbuild from "esbuild" ;
4
6
import { rimraf } from "rimraf" ;
7
+ import { bundle } from "dts-bundle" ;
5
8
6
- /** @type {(str: string) => string } */
7
- const blue = str => `\x1b[34m${ str } \x1b[0m` ;
8
-
9
- /** @type {(str: string) => string } */
10
- const green = str => `\x1b[32m${ str } \x1b[0m` ;
11
-
12
- /** @type {(dir: string) => void } */
13
- const finishedBuild = dir => console . log ( `${ green ( "✔︎" ) } build: ${ blue ( dir ) } ` ) ;
9
+ const blue = ( str : string ) => `\x1b[34m${ str } \x1b[0m` ;
10
+ const green = ( str : string ) => `\x1b[32m${ str } \x1b[0m` ;
11
+ const finishedBuild = ( dir : string ) => console . log ( `${ green ( "✔︎" ) } build: ${ blue ( dir ) } ` ) ;
14
12
15
13
const CLI_OUT_DIR = `packages/tools/bin` ;
16
14
17
- /**
18
- * @type {() => PromiseLike<void> }
19
- */
20
15
export const buildCli = async ( ) => {
21
- /**
22
- * @type {import('esbuild').BuildOptions }
23
- */
24
16
await esbuild . build ( {
25
17
entryPoints : [ path . resolve ( "packages/tools/src/bin" ) ] ,
26
18
bundle : true ,
@@ -44,48 +36,52 @@ export const buildCli = async () => {
44
36
finishedBuild ( `${ CLI_OUT_DIR } /jTegaki.zip)` ) ;
45
37
} ;
46
38
47
- /**
48
- * @type {() => void }
49
- */
50
39
export const clearCliSync = ( ) => {
51
40
rimraf . sync ( CLI_OUT_DIR ) ;
52
41
} ;
53
42
54
43
const PACKAGES = [ "tecack" , "frontend" , "backend" , "dataset" , "shared" ] ;
55
44
56
- /**
57
- * @type {() => PromiseLike<import('esbuild').BuildResult<{ entryPoints: string, outdir: string }>>[] }
58
- */
59
45
export const buildTecack = ( ) =>
60
46
PACKAGES . map ( pkg => {
61
- /**
62
- * @type {import('esbuild').BuildOptions }
63
- */
64
47
const res = esbuild . build ( {
65
48
entryPoints : [ path . resolve ( `packages/${ pkg } /src/index` ) ] ,
66
49
bundle : true ,
67
50
minify : true ,
68
51
target : "es2018" ,
69
52
outdir : `packages/${ pkg } /dist` ,
70
53
format : "esm" ,
54
+ plugins : [
55
+ {
56
+ name : "TypeScriptDeclarationsPlugin" ,
57
+ setup ( build ) {
58
+ build . onEnd ( ( ) => {
59
+ bundle ( {
60
+ name : pkg ,
61
+ main : `temp/packages/${ pkg } /src/index.d.ts` ,
62
+ out : path . resolve ( `packages/${ pkg } /dist/index.d.ts` ) ,
63
+ } ) ;
64
+ } ) ;
65
+ } ,
66
+ } ,
67
+ ] ,
71
68
} ) ;
72
69
res . then ( ( ) => finishedBuild ( `packages/${ pkg } /dist` ) ) ;
73
70
return res ;
74
71
} ) ;
75
72
76
- /**
77
- * @type {function(): void }
78
- */
79
73
export const clearTecackSync = ( ) => {
80
74
PACKAGES . map ( pkg => `packages/${ pkg } /dist` ) . forEach ( dir => rimraf . sync ( dir ) ) ;
81
75
} ;
82
76
83
- ( async function main ( ) {
77
+ await ( async function main ( ) {
84
78
console . log ( "clear dist..." ) ;
85
79
await Promise . allSettled ( [ clearCliSync ( ) , clearTecackSync ( ) ] ) ;
86
80
console . log ( `${ green ( "✔︎" ) } finished clearing dist` ) ;
87
81
console . log ( "building tecack..." ) ;
82
+ execSync ( "tsc -p tsconfig.build.json" ) ;
88
83
const buildingTecack = buildTecack ( ) ;
89
84
const buildingCli = buildCli ( ) ;
90
85
await Promise . all ( [ ...buildingTecack , buildingCli ] ) ;
86
+ execSync ( "rm -rf temp" ) ;
91
87
} ) ( ) ;
0 commit comments