1- const shell = require ( " shelljs" ) ;
2- const ts = require ( " typescript" ) ;
3- const path = require ( " path" ) ;
1+ const shell = require ( ' shelljs' ) ;
2+ const ts = require ( ' typescript' ) ;
3+ const path = require ( ' path' ) ;
44
55// Make sure shelljs will exit with nonzero exit code if anything fails
66shell . config . fatal = true ;
77
88// Make sure working directory is the root of the repository
9- shell . cd ( path . join ( __dirname , ".." ) ) ;
9+ shell . cd ( path . join ( __dirname , '..' ) ) ;
1010
1111// 1. Copy all the JavaScript source code (.js / .mjs) and
1212// all the manually written type definition files (.d.ts / .d.mts)
1313console . log ( "Copying all JavaScript source code to ./dist..." ) ;
14- shell
15- . find ( "./src/" )
16- . filter ( ( file ) => {
14+ shell . find ( './src/' )
15+ . filter ( file => {
1716 const ext = path . extname ( file ) ;
18- return (
19- [ ".js" , ".mjs" , ".mts" , ".ts" ] . includes ( ext ) && ! file . includes ( ".test." )
20- ) ;
17+ return [ '.js' , '.mjs' , '.mts' , '.ts' ] . includes ( ext ) && ! file . includes ( '.test.' ) ;
2118 } )
22- . forEach ( ( file ) => {
23- const distFile = path . join ( " ./dist" , file ) ;
24- shell . mkdir ( "-p" , path . dirname ( distFile ) ) ;
19+ . forEach ( file => {
20+ const distFile = path . join ( ' ./dist' , file ) ;
21+ shell . mkdir ( '-p' , path . dirname ( distFile ) ) ;
2522 shell . cp ( file , distFile ) ;
2623 } ) ;
2724
2825// 2. Compile all TypeScript source code (.ts / .mts) in the project
2926console . log ( "Compiling all TypeScript source code to ./dist..." ) ;
3027
3128// Read the TypeScript configuration file
32- const configPath = path . join ( process . cwd ( ) , " tsconfig.build.json" ) ;
29+ const configPath = path . join ( process . cwd ( ) , ' tsconfig.build.json' ) ;
3330const config = ts . readConfigFile ( configPath , ts . sys . readFile ) . config ;
3431
3532// Parse the configuration file
36- const parsed = ts . parseJsonConfigFileContent (
37- config ,
38- ts . sys ,
39- path . dirname ( configPath )
40- ) ;
33+ const parsed = ts . parseJsonConfigFileContent ( config , ts . sys , path . dirname ( configPath ) ) ;
4134
4235// Create a program based on the configuration
4336const program = ts . createProgram ( parsed . fileNames , parsed . options ) ;
@@ -46,25 +39,16 @@ const program = ts.createProgram(parsed.fileNames, parsed.options);
4639const emitResult = program . emit ( ) ;
4740
4841// Get all diagnostics
49- const allDiagnostics = ts
50- . getPreEmitDiagnostics ( program )
51- . concat ( emitResult . diagnostics ) ;
42+ const allDiagnostics = ts . getPreEmitDiagnostics ( program ) . concat ( emitResult . diagnostics ) ;
5243
5344// Print all diagnostics
54- allDiagnostics . forEach ( ( diagnostic ) => {
45+ allDiagnostics . forEach ( diagnostic => {
5546 if ( diagnostic . file ) {
56- const { line, character } = diagnostic . file . getLineAndCharacterOfPosition (
57- diagnostic . start
58- ) ;
59- const message = ts . flattenDiagnosticMessageText (
60- diagnostic . messageText ,
61- "\n"
62- ) ;
63- console . log (
64- `${ diagnostic . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } `
65- ) ;
47+ const { line, character } = diagnostic . file . getLineAndCharacterOfPosition ( diagnostic . start ) ;
48+ const message = ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' ) ;
49+ console . log ( `${ diagnostic . file . fileName } (${ line + 1 } ,${ character + 1 } ): ${ message } ` ) ;
6650 } else {
67- console . log ( ts . flattenDiagnosticMessageText ( diagnostic . messageText , "\n" ) ) ;
51+ console . log ( ts . flattenDiagnosticMessageText ( diagnostic . messageText , '\n' ) ) ;
6852 }
6953} ) ;
7054
@@ -73,4 +57,4 @@ if (emitResult.emitSkipped) {
7357 process . exit ( 1 ) ;
7458}
7559
76- console . log ( "Done!" ) ;
60+ console . log ( "Done!" ) ;
0 commit comments