@@ -52,6 +52,8 @@ const AUTHOR_BLOCK_GRAMMAR: &str = "\n * @author ";
5252const AUTHOR_NAME_PLACEHOLDER_GRAMMAR : & str = "PARSER_AUTHOR_NAME" ;
5353const AUTHOR_EMAIL_PLACEHOLDER_GRAMMAR : & str = " PARSER_AUTHOR_EMAIL" ;
5454
55+ const FUNDING_URL_PLACEHOLDER : & str = "FUNDING_URL" ;
56+
5557const GRAMMAR_JS_TEMPLATE : & str = include_str ! ( "./templates/grammar.js" ) ;
5658const PACKAGE_JSON_TEMPLATE : & str = include_str ! ( "./templates/package.json" ) ;
5759const GITIGNORE_TEMPLATE : & str = include_str ! ( "./templates/gitignore" ) ;
@@ -118,6 +120,8 @@ pub struct JsonConfigOpts {
118120 pub description : String ,
119121 #[ serde( skip_serializing_if = "Option::is_none" ) ]
120122 pub repository : Option < Url > ,
123+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
124+ pub funding : Option < Url > ,
121125 pub scope : String ,
122126 pub file_types : Vec < String > ,
123127 pub version : Version ,
@@ -166,6 +170,7 @@ impl JsonConfigOpts {
166170 ) )
167171 . expect ( "Failed to parse default repository URL" )
168172 } ) ,
173+ funding : self . funding ,
169174 homepage : None ,
170175 } ) ,
171176 namespace : None ,
@@ -182,6 +187,7 @@ impl Default for JsonConfigOpts {
182187 camelcase : String :: new ( ) ,
183188 description : String :: new ( ) ,
184189 repository : None ,
190+ funding : None ,
185191 scope : String :: new ( ) ,
186192 file_types : vec ! [ ] ,
187193 version : Version :: from_str ( "0.1.0" ) . unwrap ( ) ,
@@ -200,6 +206,7 @@ struct GenerateOpts<'a> {
200206 license : Option < & ' a str > ,
201207 description : Option < & ' a str > ,
202208 repository : Option < & ' a str > ,
209+ funding : Option < & ' a str > ,
203210 version : & ' a Version ,
204211 camel_parser_name : & ' a str ,
205212}
@@ -261,6 +268,11 @@ pub fn generate_grammar_files(
261268 . links
262269 . as_ref ( )
263270 . map ( |l| l. repository . as_str ( ) ) ,
271+ funding : tree_sitter_config
272+ . metadata
273+ . links
274+ . as_ref ( )
275+ . and_then ( |l| l. funding . as_ref ( ) . map ( |f| f. as_str ( ) ) ) ,
264276 version : & tree_sitter_config. metadata . version ,
265277 camel_parser_name : & camel_name,
266278 } ;
@@ -848,6 +860,25 @@ fn generate_file(
848860 }
849861 }
850862
863+ if let Some ( funding_url) = generate_opts. funding {
864+ match filename {
865+ "pyproject.toml" | "package.json" => {
866+ replacement = replacement. replace ( FUNDING_URL_PLACEHOLDER , funding_url) ;
867+ }
868+ _ => { }
869+ }
870+ } else {
871+ match filename {
872+ "package.json" => {
873+ replacement = replacement. replace ( " \" funding\" : \" FUNDING_URL\" ,\n " , "" ) ;
874+ }
875+ "pyproject.toml" => {
876+ replacement = replacement. replace ( "Funding = \" FUNDING_URL\" \n " , "" ) ;
877+ }
878+ _ => { }
879+ }
880+ }
881+
851882 write_file ( path, replacement) ?;
852883 Ok ( ( ) )
853884}
0 commit comments