44
55var fs = require ( "fs" ) ,
66 path = require ( "path" ) ,
7- ugly = require ( "terser" ) ,
7+ terser = require ( "terser" ) ,
88 year = ( new Date ( ) ) . getFullYear ( ) ,
99
1010 ROOT_DIR = path . join ( __dirname , ".." ) ,
@@ -24,69 +24,71 @@ var fs = require("fs"),
2424
2525console . log ( "*** Building ESLint Plugin 'proper-arrows' ***" ) ;
2626
27- // read version number from package.json
28- var packageJSON = JSON . parse (
29- fs . readFileSync (
30- path . join ( ROOT_DIR , "package.json" ) ,
27+ ( async function main ( ) {
28+ // try to make the dist directory, if needed
29+ try {
30+ fs . mkdirSync ( DIST_DIR , 0o755 ) ;
31+ }
32+ catch ( err ) { }
33+
34+ // read version number from package.json
35+ var packageJSON = JSON . parse (
36+ fs . readFileSync (
37+ path . join ( ROOT_DIR , "package.json" ) ,
38+ { encoding : "utf8" , }
39+ )
40+ ) ;
41+ var version = packageJSON . version ;
42+
43+ // read copyright-header text, render with version and year
44+ var copyrightHeader = fs . readFileSync (
45+ path . join ( SRC_DIR , "copyright-header.txt" ) ,
3146 { encoding : "utf8" , }
32- )
33- ) ;
34- var version = packageJSON . version ;
47+ ) . replace ( / ` / g, "" ) ;
48+ copyrightHeader = Function ( "version" , "year" , `return \`${ copyrightHeader } \`;` ) ( version , year ) ;
3549
36- // read copyright-header text, render with version and year
37- var copyrightHeader = fs . readFileSync (
38- path . join ( SRC_DIR , "copyright-header.txt" ) ,
39- { encoding : "utf8" , }
40- ) . replace ( / ` / g, "" ) ;
41- copyrightHeader = Function ( "version" , "year" , `return \`${ copyrightHeader } \`;` ) ( version , year ) ;
4250
51+ // ***************************
4352
44- // ***************************
53+ for ( let [ idx , SRC , ] of LIB_SRC . entries ( ) ) {
54+ let DIST = LIB_DIST [ idx ] ;
4555
46- // try to make the dist directory, if needed
47- try {
48- fs . mkdirSync ( DIST_DIR , 0o755 ) ;
49- }
50- catch ( err ) { }
56+ console . log ( `Building: ${ DIST } ` ) ;
5157
52- for ( let [ idx , SRC , ] of LIB_SRC . entries ( ) ) {
53- let DIST = LIB_DIST [ idx ] ;
58+ try {
59+ let result = "" ;
5460
55- console . log ( `Building: ${ DIST } ` ) ;
61+ result += fs . readFileSync ( SRC , { encoding : "utf8" , } ) ;
5662
57- try {
58- let result = "" ;
59-
60- result += fs . readFileSync ( SRC , { encoding : "utf8" , } ) ;
61-
62- result = ugly . minify ( result , {
63- mangle : {
64- keep_fnames : true ,
65- } ,
66- compress : {
67- keep_fnames : true ,
68- } ,
69- output : {
70- comments : / ^ ! / ,
71- } ,
72- } ) ;
73-
74- // was compression successful?
75- if ( ! ( result && result . code ) ) {
76- if ( result . error ) throw result . error ;
77- else throw result ;
78- }
63+ result = await terser . minify ( result , {
64+ mangle : {
65+ keep_fnames : true ,
66+ } ,
67+ compress : {
68+ keep_fnames : true ,
69+ } ,
70+ output : {
71+ comments : / ^ ! / ,
72+ } ,
73+ } ) ;
7974
80- // append copyright-header text
81- result = `${ copyrightHeader } ${ result . code } ` ;
75+ // was compression successful?
76+ if ( ! ( result && result . code ) ) {
77+ if ( result . error ) throw result . error ;
78+ else throw result ;
79+ }
8280
83- // write dist
84- fs . writeFileSync ( DIST , result , { encoding : "utf8" , } ) ;
85- }
86- catch ( err ) {
87- console . error ( err ) ;
88- process . exit ( 1 ) ;
81+ // append copyright-header text
82+ result = `${ copyrightHeader } ${ result . code } ` ;
83+
84+ // write dist
85+ fs . writeFileSync ( DIST , result , { encoding : "utf8" , } ) ;
86+ }
87+ catch ( err ) {
88+ console . error ( err ) ;
89+ process . exit ( 1 ) ;
90+ }
8991 }
90- }
9192
92- console . log ( "Complete." ) ;
93+ console . log ( "Complete." ) ;
94+ } ) ( ) ;
0 commit comments