1
1
import babelCompile , { getOutputPath } from '@tsbb/babel' ;
2
- import tsCompile , { findConfigFile , Log , getRootsFolderName , CopyFilesOptions } from '@tsbb/typescript' ;
2
+ import tsCompile , { findConfigFile , Log , getExt , getRootsFolderName , CopyFilesOptions } from '@tsbb/typescript' ;
3
3
import path from 'node:path' ;
4
4
import ts from 'typescript' ;
5
5
import fs from 'fs-extra' ;
@@ -11,26 +11,42 @@ export function babelTransform(options: CompileOptions = {}) {
11
11
const rootDirsRelative = [ ...new Set ( getRootsFolderName ( options . entry ) ) ] ;
12
12
const entry = rootDirsRelative . map ( ( item ) => path . resolve ( item ) ) ;
13
13
const onFilesChange : CopyFilesOptions [ 'onFilesChange' ] = ( eventName , filepath , stats ) => {
14
- if ( / \. ( m ? j s | j s x ? | m ? t s | t s x ? | c ? j s ) $ / i. test ( filepath ) && ! / \. d \. t s $ / i. test ( filepath ) ) {
15
- const log = new Log ( ) ;
16
- if ( / ^ ( a d d | c h a n g e ) $ / . test ( eventName ) ) {
14
+ if ( / \. ( m ? j s | j s x ? | m ? t s | t s x ? | c ? j s ) $ / i. test ( filepath ) ) {
15
+ const log = new Log ( ) . name ( ) ;
16
+ const dt = getOutputPath ( filepath , options ) ;
17
+ if ( / ^ ( a d d | c h a n g e ) $ / . test ( eventName ) && ! / \. d \. t s $ / i. test ( filepath ) ) {
17
18
babelCompile ( filepath , { ...options } ) ;
19
+ } else if ( / \. d \. t s $ / i. test ( filepath ) ) {
20
+ if ( typeof cjs !== 'boolean' ) {
21
+ fs . ensureDirSync ( path . dirname ( dt . cjs . path ) ) ;
22
+ fs . copyFile ( filepath , dt . cjs . path ) ;
23
+ log
24
+ . icon ( '🐶' )
25
+ . success (
26
+ `${ getExt ( filepath ) } ┈┈▶ \x1b[32;1m${ dt . folderFilePath } \x1b[0m => \x1b[34;1m${ dt . cjs . tsFileName } \x1b[0m` ,
27
+ ) ;
28
+ }
29
+ if ( typeof esm !== 'boolean' ) {
30
+ fs . ensureDirSync ( path . dirname ( dt . esm . path ) ) ;
31
+ fs . copyFile ( filepath , dt . esm . path ) ;
32
+ log
33
+ . icon ( '🐶' )
34
+ . success (
35
+ `${ getExt ( filepath ) } ┈┈▶ \x1b[32;1m${ dt . folderFilePath } \x1b[0m => \x1b[34;1m${ dt . esm . tsFileName } \x1b[0m` ,
36
+ ) ;
37
+ }
18
38
}
19
39
if ( / ^ ( u n l i n k | u n l i n k D i r ) $ / . test ( eventName ) ) {
20
- const dt = getOutputPath ( filepath , options ) ;
21
40
fs . remove ( dt . cjs . path ) ;
22
41
fs . remove ( dt . esm . path ) ;
23
- log
24
- . name ( )
25
- . icon ( '🗑️' )
26
- . success ( `┈┈▶ \x1b[32;1m${ path . relative ( process . cwd ( ) , filepath ) } \x1b[0m` ) ;
42
+ log . icon ( '🗑️' ) . success ( `┈┈▶ \x1b[32;1m${ path . relative ( process . cwd ( ) , filepath ) } \x1b[0m` ) ;
27
43
}
28
44
}
29
45
} ;
30
46
const onReady = ( ) => {
31
47
const log = new Log ( ) ;
32
48
if ( ! options . watch ) {
33
- log . name ( ) . icon ( '\n🎉' ) . error ( '\x1b[32;1mCompilation successful!\x1b[0m\n' ) ;
49
+ // log.name().icon('\n🎉').error('\x1b[32;1mCompilation successful!\x1b[0m\n');
34
50
} else {
35
51
log . name ( ) . icon ( '\n🎉' ) . error ( '\x1b[32;1mWatching for file changes.\x1b[0m\n' ) ;
36
52
}
@@ -69,5 +85,5 @@ const writeFile = (to: string, target: string, fileName: string, content: string
69
85
const log = new Log ( ) ;
70
86
log . name ( ) ;
71
87
ts . sys . writeFile ( to , content , writeByteOrderMark ) ;
72
- log . icon ( '🐳' ) . success ( `┈┈▶ [ts] \x1b[32;1m${ fileName } \x1b[0m => \x1b[34;1m${ target } \x1b[0m` ) ;
88
+ log . icon ( '🐳' ) . success ( `${ getExt ( fileName ) } ┈┈▶ \x1b[32;1m${ fileName } \x1b[0m => \x1b[34;1m${ target } \x1b[0m` ) ;
73
89
} ;
0 commit comments