@@ -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 } from '../utils' ;
5
+ import { outputChannel , mkdirSyncRecursive , currentWorkspaceFolder } 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' ;
@@ -19,7 +19,7 @@ const filesFilter = (file: any) => {
19
19
const getFileName = ( folder : string , name : string , split : boolean ) : string => {
20
20
let fileNameArray : string [ ] = name . split ( '.' ) ;
21
21
let fileExt = fileNameArray . pop ( ) . toLowerCase ( ) ;
22
- const root = vscode . workspace . rootPath ;
22
+ const root = [ vscode . workspace . rootPath , currentWorkspaceFolder ( ) ] . join ( path . sep ) ;
23
23
const cat = fileExt === 'cls' ? 'CLS' : [ 'int' , 'mac' , 'inc' ] . includes ( fileExt ) ? 'RTN' : 'OTH' ;
24
24
if ( split ) {
25
25
let fileName = [ root , folder , cat , ...fileNameArray ] . join ( path . sep ) ;
@@ -45,53 +45,58 @@ export async function exportFile(name: string, fileName: string): Promise<any> {
45
45
const { noStorage, dontExportIfNoChanges } = config ( ) . get ( 'export' ) ;
46
46
47
47
const promise = new Promise ( ( resolve , reject ) => {
48
- if ( noStorage ) {
48
+ if ( noStorage ) {
49
49
// get only the storage xml for the doc.
50
50
api . getDoc ( name + '?storageOnly=1' ) . then ( storageData => {
51
51
if ( ! storageData || ! storageData . result ) {
52
52
reject ( new Error ( 'Something wrong happened fetching the storage data' ) ) ;
53
53
}
54
54
const storageContent = storageData . result . content ;
55
-
55
+
56
56
if ( storageContent . length > 1 && storageContent [ 0 ] && storageContent . length < content . length ) {
57
- const storageContentString = storageContent . join ( "\n" ) ;
58
- const contentString = content . join ( "\n" ) ;
59
-
57
+ const storageContentString = storageContent . join ( '\n' ) ;
58
+ const contentString = content . join ( '\n' ) ;
59
+
60
60
// find and replace the docs storage section with ''
61
- resolve ( { 'found' : contentString . indexOf ( storageContentString ) >= 0 , 'content' : contentString . replace ( storageContentString , '' ) } ) ;
61
+ resolve ( {
62
+ found : contentString . indexOf ( storageContentString ) >= 0 ,
63
+ content : contentString . replace ( storageContentString , '' )
64
+ } ) ;
62
65
} else {
63
- resolve ( { ' found' : false } ) ;
66
+ resolve ( { found : false } ) ;
64
67
}
65
68
} ) ;
66
- } else {
67
- resolve ( { ' found' : false } ) ;
69
+ } else {
70
+ resolve ( { found : false } ) ;
68
71
}
69
72
} ) ;
70
73
71
- promise . then ( ( res :any ) => {
72
- let joinedContent = ( content || [ ] ) . join ( "\n" ) . toString ( 'utf8' ) ;
73
- let isSkipped = '' ;
74
-
75
- if ( res . found ) {
76
- joinedContent = res . content . toString ( 'utf8' ) ;
77
- }
78
-
79
- if ( dontExportIfNoChanges && fs . existsSync ( fileName ) ) {
80
- const existingContent = fs . readFileSync ( fileName , "utf8" ) ;
81
- // stringify to harmonise the text encoding.
82
- if ( JSON . stringify ( joinedContent ) != JSON . stringify ( existingContent ) ) {
83
- fs . writeFileSync ( fileName , joinedContent ) ;
74
+ promise
75
+ . then ( ( res : any ) => {
76
+ let joinedContent = ( content || [ ] ) . join ( '\n' ) . toString ( 'utf8' ) ;
77
+ let isSkipped = '' ;
78
+
79
+ if ( res . found ) {
80
+ joinedContent = res . content . toString ( 'utf8' ) ;
81
+ }
82
+
83
+ if ( dontExportIfNoChanges && fs . existsSync ( fileName ) ) {
84
+ const existingContent = fs . readFileSync ( fileName , 'utf8' ) ;
85
+ // stringify to harmonise the text encoding.
86
+ if ( JSON . stringify ( joinedContent ) != JSON . stringify ( existingContent ) ) {
87
+ fs . writeFileSync ( fileName , joinedContent ) ;
88
+ } else {
89
+ isSkipped = ' => skipped - no changes.' ;
90
+ }
84
91
} else {
85
- isSkipped = ' => skipped - no changes.' ;
92
+ fs . writeFileSync ( fileName , joinedContent ) ;
86
93
}
87
- } else {
88
- fs . writeFileSync ( fileName , joinedContent ) ;
89
- }
90
-
91
- log ( `Success ${ isSkipped } ` ) ;
92
- } ) . catch ( error => {
93
- throw error ;
94
- } ) ;
94
+
95
+ log ( `Success ${ isSkipped } ` ) ;
96
+ } )
97
+ . catch ( error => {
98
+ throw error ;
99
+ } ) ;
95
100
} ) ;
96
101
} )
97
102
. catch ( error => {
@@ -110,7 +115,7 @@ export async function exportList(files: string[]): Promise<any> {
110
115
maxConcurrent : maxConcurrentConnections
111
116
} ) ;
112
117
const results = [ ] ;
113
- for ( let i = 0 ; i < files . length ; i ++ ) {
118
+ for ( let i = 0 ; i < files . length ; i ++ ) {
114
119
const result = await limiter . schedule ( ( ) => exportFile ( files [ i ] , getFileName ( folder , files [ i ] , atelier ) ) ) ;
115
120
results . push ( result ) ;
116
121
}
0 commit comments