@@ -10,12 +10,27 @@ use toml_edit::{Array, Document, InlineTable, Item, Value};
1010use std:: {
1111 fs:: File ,
1212 io:: { Read , Write } ,
13+ path:: Path ,
1314} ;
1415
1516pub struct Manifest {
1617 pub features : Vec < String > ,
1718}
1819
20+ fn read_manifest ( manifest_path : & Path ) -> crate :: Result < Document > {
21+ let mut manifest_str = String :: new ( ) ;
22+
23+ let mut manifest_file = File :: open ( manifest_path)
24+ . with_context ( || format ! ( "failed to open `{:?}` file" , manifest_path) ) ?;
25+ manifest_file. read_to_string ( & mut manifest_str) ?;
26+
27+ let manifest: Document = manifest_str
28+ . parse :: < Document > ( )
29+ . with_context ( || "failed to parse Cargo.toml" ) ?;
30+
31+ Ok ( manifest)
32+ }
33+
1934fn features_to_vec ( features : & Array ) -> Vec < String > {
2035 let mut string_features = Vec :: new ( ) ;
2136 for feat in features. iter ( ) {
@@ -28,13 +43,7 @@ fn features_to_vec(features: &Array) -> Vec<String> {
2843
2944pub fn rewrite_manifest ( config : ConfigHandle ) -> crate :: Result < Manifest > {
3045 let manifest_path = tauri_dir ( ) . join ( "Cargo.toml" ) ;
31- let mut manifest_str = String :: new ( ) ;
32- let mut manifest_file = File :: open ( & manifest_path)
33- . with_context ( || format ! ( "failed to open `{:?}` file" , manifest_path) ) ?;
34- manifest_file. read_to_string ( & mut manifest_str) ?;
35- let mut manifest: Document = manifest_str
36- . parse :: < Document > ( )
37- . with_context ( || "failed to parse Cargo.toml" ) ?;
46+ let mut manifest = read_manifest ( & manifest_path) ?;
3847 let dependencies = manifest
3948 . as_table_mut ( )
4049 . entry ( "dependencies" )
@@ -127,3 +136,24 @@ pub fn rewrite_manifest(config: ConfigHandle) -> crate::Result<Manifest> {
127136 features : features_to_vec ( & features) ,
128137 } )
129138}
139+
140+ pub fn get_workspace_members ( ) -> crate :: Result < Vec < String > > {
141+ let mut manifest = read_manifest ( & tauri_dir ( ) . join ( "Cargo.toml" ) ) ?;
142+ let workspace = manifest. as_table_mut ( ) . entry ( "workspace" ) . as_table_mut ( ) ;
143+
144+ match workspace {
145+ Some ( workspace) => {
146+ let members = workspace
147+ . entry ( "members" )
148+ . as_array ( )
149+ . expect ( "workspace members aren't an array" ) ;
150+ Ok (
151+ members
152+ . iter ( )
153+ . map ( |v| v. as_str ( ) . unwrap ( ) . to_string ( ) )
154+ . collect ( ) ,
155+ )
156+ }
157+ None => Ok ( vec ! [ ] ) ,
158+ }
159+ }
0 commit comments