@@ -151,24 +151,52 @@ impl PackageJson {
151
151
}
152
152
}
153
153
154
- pub fn list ( & self , dependency_group : DependencyGroup , node_modules_path : & PathBuf , depth : u32 ) -> Result < ( ) , PackageJsonError > {
155
-
156
- let scope : & str ;
154
+ pub fn list ( & self , dependency_group : DependencyGroup , node_modules_path : & PathBuf , depth : u32 ) -> Result < String , PackageJsonError > {
155
+ let mut scope : String = String :: new ( ) ;
156
+ let default = Value :: default ( ) ;
157
157
match dependency_group {
158
- DependencyGroup :: Dev => scope = "devDependencies" ,
159
- DependencyGroup :: Default => scope = "dependencies" ,
160
- _ => scope = "dependencies"
158
+ DependencyGroup :: Dev => {
159
+ let mut dependencies = self
160
+ . value
161
+ . get ( "devDependencies" )
162
+ . unwrap_or ( & default)
163
+ . as_object ( )
164
+ . into_iter ( ) ;
165
+
166
+ let dep = dependencies. next ( ) ;
167
+ while !dep. is_none ( ) {
168
+ let tree: String = dep. unwrap ( )
169
+ . into_iter ( )
170
+ . map ( |( name, version) | {
171
+ let mut res = format ! ( "{}@{}" , name, version) ;
172
+
173
+ if depth > 1 {
174
+ let nested = PackageJson :: from_path ( & node_modules_path. join ( name) )
175
+ . unwrap ( ) ;
176
+ let unwraped = nested. list ( DependencyGroup :: Dev , node_modules_path, depth) ;
177
+ res = format ! ( "\n \t {}" , unwraped. unwrap( ) )
178
+ }
179
+
180
+ res
181
+ } ) . collect ( ) ;
182
+ scope = format ! ( "{:?}\n " , tree) ;
183
+ }
184
+
185
+ } ,
186
+ DependencyGroup :: Default => scope = "dependencies" . to_string ( ) ,
187
+ _ => scope = "all" . to_string ( )
161
188
}
162
189
163
- let binding = Value :: default ( ) ;
164
- let mut dependencies = self . value . get ( scope) . unwrap_or ( & binding) . as_object ( ) . into_iter ( ) ;
190
+ // let binding = Value::default();
191
+ // let mut dependencies = self.value.get(scope).unwrap_or(&binding).as_object().into_iter();
165
192
166
- let dep = dependencies. next ( ) ;
193
+ // let mut dep = dependencies.next();
167
194
// while !dep.is_none() {
168
-
195
+ // println!("{:?}", dep);
196
+ // dep = dependencies.next();
169
197
// }
170
198
171
- Ok ( ( ) )
199
+ Ok ( scope . clone ( ) )
172
200
}
173
201
174
202
}
0 commit comments