@@ -10,12 +10,27 @@ use toml_edit::{Array, Document, InlineTable, Item, Value};
10
10
use std:: {
11
11
fs:: File ,
12
12
io:: { Read , Write } ,
13
+ path:: Path ,
13
14
} ;
14
15
15
16
pub struct Manifest {
16
17
pub features : Vec < String > ,
17
18
}
18
19
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
+
19
34
fn features_to_vec ( features : & Array ) -> Vec < String > {
20
35
let mut string_features = Vec :: new ( ) ;
21
36
for feat in features. iter ( ) {
@@ -28,13 +43,7 @@ fn features_to_vec(features: &Array) -> Vec<String> {
28
43
29
44
pub fn rewrite_manifest ( config : ConfigHandle ) -> crate :: Result < Manifest > {
30
45
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) ?;
38
47
let dependencies = manifest
39
48
. as_table_mut ( )
40
49
. entry ( "dependencies" )
@@ -127,3 +136,24 @@ pub fn rewrite_manifest(config: ConfigHandle) -> crate::Result<Manifest> {
127
136
features : features_to_vec ( & features) ,
128
137
} )
129
138
}
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