@@ -6,42 +6,42 @@ use std::{
6
6
} ;
7
7
8
8
fn main ( ) -> Result < ( ) , Box < dyn Error > > {
9
- // Skip building from docs.rs.
9
+ // Skip building online from docs.rs
10
10
if std:: env:: var_os ( "DOCS_RS" ) . is_some ( ) {
11
- return Ok ( ( ) ) ;
12
- }
13
- // Retrieve a live version of the reports.proto file
14
- let proto_url = "https://usage-reporting.api.apollographql.com/proto/reports.proto" ;
15
- let response = reqwest:: blocking:: get ( proto_url) ?;
16
- let mut content = response. text ( ) ?;
11
+ } else {
12
+ // Retrieve a live version of the reports.proto file
13
+ let proto_url = "https://usage-reporting.api.apollographql.com/proto/reports.proto" ;
14
+ let response = reqwest:: blocking:: get ( proto_url) ?;
15
+ let mut content = response. text ( ) ?;
17
16
18
- // Process the retrieved content to:
19
- // - Insert a package Report; line after the import lines (currently only one) and before the first message definition
20
- // - Remove the Apollo TS extensions [(js_use_toArray)=true] and [(js_preEncoded)=true] from the file
21
- // Note: Only two in use at the moment. This may fail in future if new extensions are
22
- // added to the source, so be aware future self. It will manifest as a protobuf compile
23
- // error.
24
- let message = "\n message" ;
25
- let msg_index = content. find ( message) . ok_or ( "cannot find message string" ) ?;
26
- content. insert_str ( msg_index, "\n package Report;\n " ) ;
17
+ // Process the retrieved content to:
18
+ // - Insert a package Report; line after the import lines (currently only one) and before the first message definition
19
+ // - Remove the Apollo TS extensions [(js_use_toArray)=true] and [(js_preEncoded)=true] from the file
20
+ // Note: Only two in use at the moment. This may fail in future if new extensions are
21
+ // added to the source, so be aware future self. It will manifest as a protobuf compile
22
+ // error.
23
+ let message = "\n message" ;
24
+ let msg_index = content. find ( message) . ok_or ( "cannot find message string" ) ?;
25
+ content. insert_str ( msg_index, "\n package Report;\n " ) ;
27
26
28
- content = content. replace ( "[(js_use_toArray) = true]" , "" ) ;
29
- content = content. replace ( "[(js_preEncoded) = true]" , "" ) ;
27
+ content = content. replace ( "[(js_use_toArray) = true]" , "" ) ;
28
+ content = content. replace ( "[(js_preEncoded) = true]" , "" ) ;
30
29
31
- // Try to avoid writing out the same content since it will trigger unnecessary re-builds, which wastes time
32
- let write_content = match File :: open ( "proto/reports.proto" ) {
33
- Ok ( mut existing) => {
34
- let mut existing_content = String :: new ( ) ;
35
- existing. read_to_string ( & mut existing_content) ?;
36
- content != existing_content
37
- }
38
- Err ( _) => true ,
39
- } ;
30
+ // Try to avoid writing out the same content since it will trigger unnecessary re-builds, which wastes time
31
+ let write_content = match File :: open ( "proto/reports.proto" ) {
32
+ Ok ( mut existing) => {
33
+ let mut existing_content = String :: new ( ) ;
34
+ existing. read_to_string ( & mut existing_content) ?;
35
+ content != existing_content
36
+ }
37
+ Err ( _) => true ,
38
+ } ;
40
39
41
- // Write the content out if they differ or an error occured trying to open proto file
42
- if write_content {
43
- let mut dest = File :: create ( "proto/reports.proto" ) ?;
44
- copy ( & mut content. as_bytes ( ) , & mut dest) ?;
40
+ // Write the content out if they differ or an error occured trying to open proto file
41
+ if write_content {
42
+ let mut dest = File :: create ( "proto/reports.proto" ) ?;
43
+ copy ( & mut content. as_bytes ( ) , & mut dest) ?;
44
+ }
45
45
}
46
46
47
47
// Process the proto files
0 commit comments