@@ -9,7 +9,6 @@ use anyhow::{Context, Result};
99use semver:: VersionReq ;
1010use serde:: { Deserialize , Serialize } ;
1111use tokio:: io:: AsyncWriteExt ;
12- use wasm_metadata:: { Link , LinkType , RegistryMetadata } ;
1312
1413/// The default name of the configuration file.
1514pub const CONFIG_FILE_NAME : & str = "wkg.toml" ;
@@ -75,55 +74,45 @@ pub struct Override {
7574pub struct Metadata {
7675 /// The authors of the package.
7776 #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
78- pub authors : Option < Vec < String > > ,
79- /// The categories of the package.
80- #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
81- pub categories : Option < Vec < String > > ,
77+ pub author : Option < String > ,
8278 /// The package description.
8379 #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
8480 pub description : Option < String > ,
8581 /// The package license.
8682 #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
87- pub license : Option < String > ,
88- /// The package documentation URL.
83+ pub licenses : Option < String > ,
84+ /// The package source code URL.
8985 #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
90- pub documentation : Option < String > ,
86+ pub source : Option < String > ,
9187 /// The package homepage URL.
9288 #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
9389 pub homepage : Option < String > ,
94- /// The package repository URL .
90+ /// The package source control revision .
9591 #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
96- pub repository : Option < String > ,
92+ pub revision : Option < String > ,
9793}
9894
99- impl From < Metadata > for wasm_metadata :: RegistryMetadata {
100- fn from ( value : Metadata ) -> Self {
101- let mut meta = RegistryMetadata :: default ( ) ;
102- meta . set_authors ( value . authors ) ;
103- meta . set_categories ( value . categories ) ;
104- meta . set_description ( value . description ) ;
105- meta . set_license ( value . license ) ;
106- let mut links = Vec :: new ( ) ;
107- if let Some ( documentation ) = value . documentation {
108- links . push ( Link {
109- ty : LinkType :: Documentation ,
110- value : documentation ,
111- } ) ;
95+ impl Metadata {
96+ pub fn update_wasm_metadata ( self , wasm_metadata : & mut wasm_metadata :: Metadata ) -> Result < ( ) > {
97+ if let Some ( author ) = self . author {
98+ wasm_metadata . author = Some ( author . parse ( ) ? ) ;
99+ }
100+ if let Some ( description) = self . description {
101+ wasm_metadata . description = Some ( description . parse ( ) ? ) ;
102+ }
103+ if let Some ( licenses ) = self . licenses {
104+ wasm_metadata . licenses = Some ( licenses . parse ( ) ? ) ;
105+ }
106+ if let Some ( source ) = self . source {
107+ wasm_metadata . source = Some ( source . parse ( ) ? ) ;
112108 }
113- if let Some ( homepage) = value. homepage {
114- links. push ( Link {
115- ty : LinkType :: Homepage ,
116- value : homepage,
117- } ) ;
109+ if let Some ( homepage) = self . homepage {
110+ wasm_metadata. homepage = Some ( homepage. parse ( ) ?) ;
118111 }
119- if let Some ( repository) = value. repository {
120- links. push ( Link {
121- ty : LinkType :: Repository ,
122- value : repository,
123- } ) ;
112+ if let Some ( revision) = self . revision {
113+ wasm_metadata. revision = Some ( revision. parse ( ) ?) ;
124114 }
125- meta. set_links ( ( !links. is_empty ( ) ) . then_some ( links) ) ;
126- meta
115+ Ok ( ( ) )
127116 }
128117}
129118
@@ -144,13 +133,12 @@ mod tests {
144133 } ,
145134 ) ] ) ) ,
146135 metadata : Some ( Metadata {
147- authors : Some ( vec ! [ "foo" . to_string( ) , "bar" . to_string( ) ] ) ,
148- categories : Some ( vec ! [ "foo" . to_string( ) , "bar" . to_string( ) ] ) ,
149- description : Some ( "foo" . to_string ( ) ) ,
150- license : Some ( "foo" . to_string ( ) ) ,
151- documentation : Some ( "foo" . to_string ( ) ) ,
152- homepage : Some ( "foo" . to_string ( ) ) ,
153- repository : Some ( "foo" . to_string ( ) ) ,
136+ author : Some ( "Foo Bar" . to_string ( ) ) ,
137+ description : Some ( "Foobar baz" . to_string ( ) ) ,
138+ licenses : Some ( "FBB" . to_string ( ) ) ,
139+ source : Some ( "https://gitfoo/bar" . to_string ( ) ) ,
140+ homepage : Some ( "https://foo.bar" . to_string ( ) ) ,
141+ revision : Some ( "f00ba4" . to_string ( ) ) ,
154142 } ) ,
155143 } ;
156144
0 commit comments