@@ -7,89 +7,88 @@ const chalk = require("chalk");
7
7
let distPath = path . normalize ( __dirname + "/../dist/" ) ;
8
8
let srcPath = path . normalize ( __dirname + "/../assets/" ) ;
9
9
let headerPath = path . normalize (
10
- __dirname + "/../../src/modules/http/favicon.h"
10
+ __dirname + "/../../src/modules/http/favicon.h"
11
11
) ;
12
12
13
-
14
-
15
13
const convertToC = ( filepath ) => {
16
- console . log ( chalk . yellow ( "Converting bin to text file" ) ) ;
17
- //Cleaning files
18
- if ( fs . existsSync ( distPath + "out.tmp" ) ) fs . rmSync ( distPath + "out.tmp" ) ;
19
- if ( fs . existsSync ( distPath + "favicon.h" ) ) fs . rmSync ( distPath + "favicon.h" ) ;
14
+ console . log ( chalk . yellow ( "Converting bin to text file" ) ) ;
15
+ //Cleaning files
16
+ if ( fs . existsSync ( distPath + "out.tmp" ) ) fs . rmSync ( distPath + "out.tmp" ) ;
17
+ if ( fs . existsSync ( distPath + "favicon.h" ) )
18
+ fs . rmSync ( distPath + "favicon.h" ) ;
20
19
21
- const data = new Uint8Array (
22
- fs . readFileSync ( filepath , { flag : "r" } )
23
- ) ;
24
- console . log ( "data size is " , data . length ) ;
25
- let out = "#define favicon_size " + data . length + "\n" ;
26
- out += "const unsigned char favicon[" + data . length + "] PROGMEM = {\n " ;
27
- let nb = 0 ;
28
- data . forEach ( ( byte , index ) => {
29
- out += " 0x" + ( byte . toString ( 16 ) . length == 1 ? "0" : "" ) + byte . toString ( 16 ) ;
30
- if ( index < data . length - 1 ) out += "," ;
31
- if ( nb == 15 ) {
32
- out += "\n " ;
33
- nb = 0 ;
34
- } else {
35
- nb ++ ;
36
- }
37
- } ) ;
20
+ const data = new Uint8Array ( fs . readFileSync ( filepath , { flag : "r" } ) ) ;
21
+ console . log ( "data size is " , data . length ) ;
22
+ let out = "#define favicon_size " + data . length + "\n" ;
23
+ out += "const unsigned char favicon[" + data . length + "] PROGMEM = {\n " ;
24
+ let nb = 0 ;
25
+ data . forEach ( ( byte , index ) => {
26
+ out +=
27
+ " 0x" +
28
+ ( byte . toString ( 16 ) . length == 1 ? "0" : "" ) +
29
+ byte . toString ( 16 ) ;
30
+ if ( index < data . length - 1 ) out += "," ;
31
+ if ( nb == 15 ) {
32
+ out += "\n " ;
33
+ nb = 0 ;
34
+ } else {
35
+ nb ++ ;
36
+ }
37
+ } ) ;
38
38
39
- out += "\n};\n" ;
40
- fs . writeFileSync ( distPath + "out.tmp" , out ) ;
39
+ out += "\n};\n" ;
40
+ fs . writeFileSync ( distPath + "out.tmp" , out ) ;
41
41
42
- //Check conversion
43
- if ( fs . existsSync ( distPath + "out.tmp" ) ) {
44
- console . log ( chalk . green ( "[ok]" ) ) ;
45
- } else {
46
- console . log ( chalk . red ( "[error]Conversion failed" ) ) ;
47
- return ;
48
- }
49
-
50
- //Format header file
51
- console . log ( chalk . yellow ( "Building header" ) ) ;
52
- fs . writeFileSync (
53
- distPath + "favicon.h" ,
54
- fs . readFileSync ( srcPath + "header.txt" )
55
- ) ;
56
- let bin2cfile = fs . readFileSync ( distPath + "out.tmp" ) . toString ( ) ;
57
- fs . appendFileSync ( distPath + "favicon.h" , bin2cfile ) ;
58
- fs . appendFileSync (
59
- distPath + "favicon.h" ,
60
- fs . readFileSync ( srcPath + "footer.txt" )
61
- ) ;
42
+ //Check conversion
43
+ if ( fs . existsSync ( distPath + "out.tmp" ) ) {
44
+ console . log ( chalk . green ( "[ok]" ) ) ;
45
+ } else {
46
+ console . log ( chalk . red ( "[error]Conversion failed" ) ) ;
47
+ return ;
48
+ }
62
49
63
- //Check format result
64
- if ( fs . existsSync ( distPath + "favicon.h" ) ) {
65
- console . log ( chalk . green ( "[ok]" ) ) ;
66
- } else {
67
- console . log ( chalk . red ( "[error]Conversion failed" ) ) ;
68
- return ;
69
- }
50
+ //Format header file
51
+ console . log ( chalk . yellow ( "Building header" ) ) ;
52
+ fs . writeFileSync (
53
+ distPath + "favicon.h" ,
54
+ fs . readFileSync ( srcPath + "header.txt" )
55
+ ) ;
56
+ let bin2cfile = fs . readFileSync ( distPath + "out.tmp" ) . toString ( ) ;
57
+ fs . appendFileSync ( distPath + "favicon.h" , bin2cfile ) ;
58
+ fs . appendFileSync (
59
+ distPath + "favicon.h" ,
60
+ fs . readFileSync ( srcPath + "footer.txt" )
61
+ ) ;
70
62
71
- //Move file to src
72
- console . log ( chalk . yellow ( "Overwriting header in sources" ) ) ;
73
- fs . writeFileSync ( headerPath , fs . readFileSync ( distPath + "favicon.h" ) ) ;
74
- if ( fs . existsSync ( headerPath ) ) {
75
- console . log ( chalk . green ( "[ok]" ) ) ;
76
- } else {
77
- console . log ( chalk . red ( "[error]Overwriting failed" ) ) ;
78
- return ;
79
- }
63
+ //Check format result
64
+ if ( fs . existsSync ( distPath + "favicon.h" ) ) {
65
+ console . log ( chalk . green ( "[ok]" ) ) ;
66
+ } else {
67
+ console . log ( chalk . red ( "[error]Conversion failed" ) ) ;
68
+ return ;
69
+ }
80
70
81
- }
71
+ //Move file to src
72
+ console . log ( chalk . yellow ( "Overwriting header in sources" ) ) ;
73
+ fs . writeFileSync ( headerPath , fs . readFileSync ( distPath + "favicon.h" ) ) ;
74
+ if ( fs . existsSync ( headerPath ) ) {
75
+ console . log ( chalk . green ( "[ok]" ) ) ;
76
+ } else {
77
+ console . log ( chalk . red ( "[error]Overwriting failed" ) ) ;
78
+ return ;
79
+ }
80
+ } ;
82
81
83
-
84
82
// Create a gzip function for reusable purpose
85
83
const compressFile = ( filePath , targetPath ) => {
86
- const stream = createReadStream ( filePath ) ;
87
- stream
88
- . pipe ( createGzip ( targetPath ) )
89
- . pipe ( createWriteStream ( targetPath ) )
90
- . on ( "finish" , ( ) => { console . log ( `Successfully compressed at ${ targetPath } ` ) ;
91
- convertToC ( targetPath ) }
92
- ) ;
84
+ const stream = createReadStream ( filePath ) ;
85
+ stream
86
+ . pipe ( createGzip ( targetPath ) )
87
+ . pipe ( createWriteStream ( targetPath ) )
88
+ . on ( "finish" , ( ) => {
89
+ console . log ( `Successfully compressed at ${ targetPath } ` ) ;
90
+ convertToC ( targetPath ) ;
91
+ } ) ;
93
92
} ;
94
93
95
- compressFile ( srcPath + "favicon.ico" , distPath + "favicon.ico.gz" ) ;
94
+ compressFile ( srcPath + "favicon.ico" , distPath + "favicon.ico.gz" ) ;
0 commit comments