@@ -8,6 +8,7 @@ import { ClassNode } from '../explorer/models/classesNode';
8
8
import { RoutineNode } from '../explorer/models/routineNode' ;
9
9
import { config } from '../extension' ;
10
10
import Bottleneck from 'bottleneck' ;
11
+ import { RootNode } from '../explorer/models/rootNode' ;
11
12
12
13
const filesFilter = ( file : any ) => {
13
14
if ( file . cat === 'CSP' || file . name . startsWith ( '%' ) || file . name . startsWith ( 'INFORMATION.' ) ) {
@@ -33,9 +34,9 @@ const getFileName = (folder: string, name: string, split: boolean, addCategory:
33
34
return [ folder , cat , name ] . filter ( notNull ) . join ( path . sep ) ;
34
35
} ;
35
36
36
- export async function exportFile ( workspaceFolder : string , name : string , fileName : string ) : Promise < any > {
37
+ export async function exportFile ( workspaceFolder : string , name : string , fileName : string ) : Promise < void > {
37
38
if ( ! config ( 'conn' , workspaceFolder ) . active ) {
38
- return ;
39
+ return Promise . reject ( 'Connection not active' ) ;
39
40
}
40
41
const api = new AtelierAPI ( ) ;
41
42
api . setConnection ( workspaceFolder ) ;
@@ -77,7 +78,7 @@ export async function exportFile(workspaceFolder: string, name: string, fileName
77
78
}
78
79
} ) ;
79
80
80
- promise
81
+ return promise
81
82
. then ( ( res : any ) => {
82
83
let joinedContent = ( content || [ ] ) . join ( '\n' ) . toString ( 'utf8' ) ;
83
84
let isSkipped = '' ;
@@ -107,6 +108,7 @@ export async function exportFile(workspaceFolder: string, name: string, fileName
107
108
} )
108
109
. catch ( error => {
109
110
log ( 'ERROR: ' + error ) ;
111
+ throw error ;
110
112
} ) ;
111
113
}
112
114
@@ -131,10 +133,26 @@ export async function exportList(files: string[], workspaceFolder: string): Prom
131
133
return results ;
132
134
}
133
135
return Promise . all (
134
- files . map ( file => {
135
- exportFile ( workspaceFolder , file , getFileName ( root , file , atelier , addCategory ) ) ;
136
- } )
137
- ) ;
136
+ files . map ( file =>
137
+ exportFile ( workspaceFolder , file , getFileName ( root , file , atelier , addCategory ) )
138
+ . then ( ( ) => ( {
139
+ file,
140
+ result : true ,
141
+ error : ''
142
+ } ) )
143
+ . catch ( error => ( {
144
+ file,
145
+ result : false ,
146
+ error
147
+ } ) )
148
+ )
149
+ ) . then ( files => {
150
+ outputChannel . appendLine ( `Exported items: ${ files . filter ( el => el . result ) . length } ` ) ;
151
+ const failed = files . filter ( el => ! el . result ) . map ( el => `${ el . file } - ${ el . error } ` ) ;
152
+ if ( files . find ( el => ! el . result ) ) {
153
+ outputChannel . appendLine ( `Items failed to export: \n${ failed . join ( '\n' ) } ` ) ;
154
+ }
155
+ } ) ;
138
156
}
139
157
140
158
export async function exportAll ( workspaceFolder ?: string ) : Promise < any > {
@@ -161,10 +179,20 @@ export async function exportAll(workspaceFolder?: string): Promise<any> {
161
179
} ) ;
162
180
}
163
181
164
- export async function exportExplorerItem ( node : PackageNode | ClassNode | RoutineNode ) : Promise < any > {
182
+ export async function exportExplorerItem ( node : RootNode | PackageNode | ClassNode | RoutineNode ) : Promise < any > {
165
183
if ( ! config ( 'conn' , node . workspaceFolder ) . active ) {
166
184
return ;
167
185
}
168
- const items = node instanceof PackageNode ? node . getClasses ( ) : [ node . fullName ] ;
169
- return exportList ( items , node . workspaceFolder ) ;
186
+ const workspaceFolder = node . workspaceFolder ;
187
+ const nodes = node instanceof RootNode ? node . getChildren ( node ) : Promise . resolve ( [ node ] ) ;
188
+ return nodes
189
+ . then ( nodes =>
190
+ nodes . reduce (
191
+ ( list , subNode ) => list . concat ( subNode instanceof PackageNode ? subNode . getClasses ( ) : [ subNode . fullName ] ) ,
192
+ [ ]
193
+ )
194
+ )
195
+ . then ( items => {
196
+ return exportList ( items , workspaceFolder ) ;
197
+ } ) ;
170
198
}
0 commit comments