@@ -11,9 +11,11 @@ const main = async () => {
11
11
'--require-version' : String ,
12
12
'--artifact' : String ,
13
13
'--boc' : String ,
14
+ '--boc-hex' : String ,
14
15
'--boc-base64' : String ,
15
16
'--fift' : String ,
16
17
'--cwd' : String ,
18
+ '--verbose' : Boolean ,
17
19
18
20
'-v' : '--version' ,
19
21
'-h' : '--help' ,
@@ -22,37 +24,47 @@ const main = async () => {
22
24
23
25
if ( args [ '--help' ] ) {
24
26
console . log ( `Usage: func-js [OPTIONS] targets
27
+
28
+ targets: One or more FunC source files to compile
29
+
25
30
Options:
26
- -h, --help - print this and exit
27
- -v, --version - print func version and exit
28
- --cwd <path>, -C <path> - run func-js as if it was launched from the given path (useful in npm scripts)
29
- --require-version <version> - set the required func version, exit if it is different
30
- --artifact <path> - path where JSON artifact, containing BOC and FIFT output, will be written
31
- --boc <path> - path where compiled code will be written as binary bag of cells
32
- --boc-base64 <path> - path where compiled code will be written as bag of cells using base64 encoding
33
- --fift <path> - path where compiled fift code will be written
31
+ -h, --help Show this help message and exit
32
+ -v, --version Show compiler version and exit
33
+ -C, --cwd <path> Use <path> as the working directory (useful in npm scripts)
34
+ --require-version <version> Enforce a specific FunC compiler version
35
+ --verbose Enable verbose output
36
+
37
+ Output options:
38
+ --artifact <path> Write full JSON artifact (BoC, Fift, etc.) to the specified file
39
+ --boc <path> Write BoC binary to the specified file
40
+ --boc-hex <path> Write BoC as hex to the specified file. Use "" to output to the console
41
+ --boc-base64 <path> Write BoC as base64 to the specified file. Use "" to output to the console
42
+ --fift <path> Write Fift code to the specified file. Use "" to output to the console
34
43
` ) ;
35
44
process . exit ( 0 ) ;
36
45
}
37
46
47
+ const verbose = args [ '--verbose' ] ?? false ;
48
+ const verboseLog = ( message : string ) => verbose && console . log ( message ) ;
49
+
38
50
const v = await compilerVersion ( ) ;
39
51
40
52
if ( args [ '--require-version' ] !== undefined && v . funcVersion !== args [ '--require-version' ] ) {
41
- console . error ( `Failed to run func-js: the required func version is ${ args [ '--require-version' ] } , but the func version is ${ v . funcVersion } ` ) ;
53
+ console . error ( `Error: Required FunC version " ${ args [ '--require-version' ] } " , but found " ${ v . funcVersion } " ` ) ;
42
54
process . exit ( 1 ) ;
43
55
}
44
56
45
57
if ( args [ '--version' ] ) {
46
- console . log ( `func v${ v . funcVersion } ` ) ;
58
+ console . log ( `FunC v${ v . funcVersion } ` ) ;
47
59
process . exit ( 0 ) ;
48
60
}
49
61
50
62
if ( args . _ . length === 0 ) {
51
- console . error ( 'No targets were specified. Run with -h to see help .' ) ;
63
+ console . error ( 'Error: No target files specified. Use --help to see available options .' ) ;
52
64
process . exit ( 1 ) ;
53
65
}
54
66
55
- console . log ( `Compiling using func v${ v . funcVersion } `) ;
67
+ verboseLog ( `Using FunC compiler v${ v . funcVersion } `) ;
56
68
57
69
const basePath = args [ '--cwd' ] ;
58
70
const pathResolver = basePath === undefined
@@ -69,34 +81,68 @@ Options:
69
81
process . exit ( 1 ) ;
70
82
}
71
83
72
- if ( args [ '--artifact' ] !== undefined ) {
73
- writeFileSync ( args [ '--artifact' ] , JSON . stringify ( {
84
+ let hasOutput = false ;
85
+ verboseLog ( 'Compilation successful.' ) ;
86
+
87
+ const jsonArtifactOutputFilePath = args [ '--artifact' ] ;
88
+ if ( jsonArtifactOutputFilePath !== undefined ) {
89
+ writeFileSync ( jsonArtifactOutputFilePath , JSON . stringify ( {
74
90
artifactVersion : 1 ,
75
91
version : v . funcVersion ,
76
92
sources : cr . snapshot ,
77
93
codeBoc : cr . codeBoc ,
78
94
fiftCode : cr . fiftCode ,
79
95
} ) ) ;
96
+ verboseLog ( `Compilation artifact written to "${ jsonArtifactOutputFilePath } "` ) ;
97
+ hasOutput = true ;
80
98
}
81
99
82
- if ( args [ '--boc-base64' ] !== undefined ) {
83
- writeFileSync ( args [ '--boc-base64' ] , cr . codeBoc ) ;
100
+ const bocBinaryOutputFilePath = args [ '--boc' ] ;
101
+ if ( bocBinaryOutputFilePath !== undefined ) {
102
+ writeFileSync ( bocBinaryOutputFilePath , Buffer . from ( cr . codeBoc , 'base64' ) ) ;
103
+ verboseLog ( `BoC binary written to "${ bocBinaryOutputFilePath } "` ) ;
104
+ hasOutput = true ;
84
105
}
85
106
86
- if ( args [ '--boc' ] !== undefined ) {
87
- writeFileSync ( args [ '--boc' ] , Buffer . from ( cr . codeBoc , 'base64' ) ) ;
107
+ const bocBase64 = cr . codeBoc ;
108
+
109
+ const bocHexOutputFilePath = args [ '--boc-hex' ] ?. trim ( ) ;
110
+ if ( bocHexOutputFilePath != undefined ) {
111
+ const bocHex = Buffer . from ( bocBase64 , 'base64' ) . toString ( 'hex' ) ;
112
+ if ( bocHexOutputFilePath ) {
113
+ writeFileSync ( bocHexOutputFilePath , bocHex ) ;
114
+ verboseLog ( `BoC (hex) written to "${ bocHexOutputFilePath } "` ) ;
115
+ } else {
116
+ console . log ( bocHex ) ;
117
+ }
118
+ hasOutput = true ;
88
119
}
89
120
90
- if ( args [ '--fift' ] !== undefined ) {
91
- writeFileSync ( args [ '--fift' ] , cr . fiftCode ) ;
121
+ const bocBase64OutputFilePath = args [ '--boc-base64' ] ?. trim ( ) ;
122
+ if ( bocBase64OutputFilePath != undefined ) {
123
+ if ( bocBase64OutputFilePath ) {
124
+ writeFileSync ( bocBase64OutputFilePath , bocBase64 ) ;
125
+ verboseLog ( `BoC (base64) written to "${ bocBase64OutputFilePath } "` ) ;
126
+ } else {
127
+ console . log ( bocBase64 ) ;
128
+ }
129
+ hasOutput = true ;
92
130
}
93
131
94
- console . log ( 'Compiled successfully!' ) ;
132
+ const fiftCodeOutputFilePath = args [ '--fift' ] ?. trim ( ) ;
133
+ if ( fiftCodeOutputFilePath != undefined ) {
134
+ const fiftCode = cr . fiftCode ;
135
+ if ( fiftCodeOutputFilePath ) {
136
+ writeFileSync ( fiftCodeOutputFilePath , fiftCode ) ;
137
+ verboseLog ( `Fift code written to "${ fiftCodeOutputFilePath } "` ) ;
138
+ } else {
139
+ console . log ( fiftCode ) ;
140
+ }
141
+ hasOutput = true ;
142
+ }
95
143
96
- if ( ! args [ '--artifact' ] && ! args [ '--boc' ] && ! args [ '--boc-base64' ] && ! args [ '--fift' ] ) {
97
- console . warn ( 'Warning: No output options were specified. Run with -h to see help.' ) ;
98
- } else {
99
- console . log ( 'Written output files.' ) ;
144
+ if ( ! hasOutput ) {
145
+ console . warn ( 'Warning: No output options specified. Use --help to see available options.' ) ;
100
146
}
101
147
} ;
102
148
0 commit comments