@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
2
2
import fs = require( 'fs' ) ;
3
3
import path = require( 'path' ) ;
4
4
import { AtelierAPI } from '../api' ;
5
- import { outputChannel , mkdirSyncRecursive , currentWorkspaceFolder } from '../utils' ;
5
+ import { outputChannel , mkdirSyncRecursive , currentWorkspaceFolder , notNull } from '../utils' ;
6
6
import { PackageNode } from '../explorer/models/packageNode' ;
7
7
import { ClassNode } from '../explorer/models/classesNode' ;
8
8
import { RoutineNode } from '../explorer/models/routineNode' ;
@@ -16,16 +16,22 @@ const filesFilter = (file: any) => {
16
16
return true ;
17
17
} ;
18
18
19
- const getFileName = ( folder : string , name : string , split : boolean ) : string => {
19
+ const getFileName = ( folder : string , name : string , split : boolean , addCategory : boolean ) : string => {
20
20
let fileNameArray : string [ ] = name . split ( '.' ) ;
21
21
let fileExt = fileNameArray . pop ( ) . toLowerCase ( ) ;
22
22
const root = [ vscode . workspace . rootPath , currentWorkspaceFolder ( ) ] . join ( path . sep ) ;
23
- const cat = fileExt === 'cls' ? 'CLS' : [ 'int' , 'mac' , 'inc' ] . includes ( fileExt ) ? 'RTN' : 'OTH' ;
23
+ const cat = addCategory
24
+ ? fileExt === 'cls'
25
+ ? 'CLS'
26
+ : [ 'int' , 'mac' , 'inc' ] . includes ( fileExt )
27
+ ? 'RTN'
28
+ : 'OTH'
29
+ : null ;
24
30
if ( split ) {
25
- let fileName = [ root , folder , cat , ...fileNameArray ] . join ( path . sep ) ;
31
+ let fileName = [ root , folder , cat , ...fileNameArray ] . filter ( notNull ) . join ( path . sep ) ;
26
32
return [ fileName , fileExt ] . join ( '.' ) ;
27
33
}
28
- return [ root , folder , cat , name ] . join ( path . sep ) ;
34
+ return [ root , folder , cat , name ] . filter ( notNull ) . join ( path . sep ) ;
29
35
} ;
30
36
31
37
export async function exportFile ( name : string , fileName : string ) : Promise < any > {
@@ -42,7 +48,7 @@ export async function exportFile(name: string, fileName: string): Promise<any> {
42
48
throw new Error ( 'Something wrong happened' ) ;
43
49
}
44
50
const content = data . result . content ;
45
- const { noStorage, dontExportIfNoChanges } = config ( ) . get ( 'export' ) ;
51
+ const { noStorage, dontExportIfNoChanges } = config ( 'export' ) ;
46
52
47
53
const promise = new Promise ( ( resolve , reject ) => {
48
54
if ( noStorage ) {
@@ -108,22 +114,24 @@ export async function exportList(files: string[]): Promise<any> {
108
114
if ( ! files || ! files . length ) {
109
115
vscode . window . showWarningMessage ( 'Nothing to export' ) ;
110
116
}
111
- const { atelier, folder, maxConcurrentConnections } = config ( ) . get ( 'export' ) ;
117
+ const { atelier, folder, maxConcurrentConnections, addCategory } = config ( 'export' ) ;
112
118
113
119
if ( maxConcurrentConnections > 0 ) {
114
120
const limiter = new Bottleneck ( {
115
121
maxConcurrent : maxConcurrentConnections
116
122
} ) ;
117
123
const results = [ ] ;
118
124
for ( let i = 0 ; i < files . length ; i ++ ) {
119
- const result = await limiter . schedule ( ( ) => exportFile ( files [ i ] , getFileName ( folder , files [ i ] , atelier ) ) ) ;
125
+ const result = await limiter . schedule ( ( ) =>
126
+ exportFile ( files [ i ] , getFileName ( folder , files [ i ] , atelier , addCategory ) )
127
+ ) ;
120
128
results . push ( result ) ;
121
129
}
122
130
return results ;
123
131
}
124
132
return Promise . all (
125
133
files . map ( file => {
126
- exportFile ( file , getFileName ( folder , file , atelier ) ) ;
134
+ exportFile ( file , getFileName ( folder , file , atelier , addCategory ) ) ;
127
135
} )
128
136
) ;
129
137
}
@@ -134,7 +142,7 @@ export async function exportAll(): Promise<any> {
134
142
}
135
143
const api = new AtelierAPI ( ) ;
136
144
outputChannel . show ( true ) ;
137
- const { category, generated, filter } = config ( ) . get ( 'export' ) ;
145
+ const { category, generated, filter } = config ( 'export' ) ;
138
146
const files = data => data . result . content . filter ( filesFilter ) . map ( file => file . name ) ;
139
147
return api . getDocNames ( { category, generated, filter } ) . then ( data => {
140
148
return exportList ( files ( data ) ) ;
0 commit comments