Skip to content

Commit c70430a

Browse files
committed
fix export issue in #18
1 parent f536703 commit c70430a

File tree

2 files changed

+43
-36
lines changed

2 files changed

+43
-36
lines changed

Diff for: commands/export.ts

+39-34
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
22
import fs = require('fs');
33
import path = require('path');
44
import { AtelierAPI } from '../api';
5-
import { outputChannel, mkdirSyncRecursive } from '../utils';
5+
import { outputChannel, mkdirSyncRecursive, currentWorkspaceFolder } from '../utils';
66
import { PackageNode } from '../explorer/models/packageNode';
77
import { ClassNode } from '../explorer/models/classesNode';
88
import { RoutineNode } from '../explorer/models/routineNode';
@@ -19,7 +19,7 @@ const filesFilter = (file: any) => {
1919
const getFileName = (folder: string, name: string, split: boolean): string => {
2020
let fileNameArray: string[] = name.split('.');
2121
let fileExt = fileNameArray.pop().toLowerCase();
22-
const root = vscode.workspace.rootPath;
22+
const root = [vscode.workspace.rootPath, currentWorkspaceFolder()].join(path.sep);
2323
const cat = fileExt === 'cls' ? 'CLS' : ['int', 'mac', 'inc'].includes(fileExt) ? 'RTN' : 'OTH';
2424
if (split) {
2525
let fileName = [root, folder, cat, ...fileNameArray].join(path.sep);
@@ -45,53 +45,58 @@ export async function exportFile(name: string, fileName: string): Promise<any> {
4545
const { noStorage, dontExportIfNoChanges } = config().get('export');
4646

4747
const promise = new Promise((resolve, reject) => {
48-
if(noStorage) {
48+
if (noStorage) {
4949
// get only the storage xml for the doc.
5050
api.getDoc(name + '?storageOnly=1').then(storageData => {
5151
if (!storageData || !storageData.result) {
5252
reject(new Error('Something wrong happened fetching the storage data'));
5353
}
5454
const storageContent = storageData.result.content;
55-
55+
5656
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+
6060
// 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+
});
6265
} else {
63-
resolve({'found': false});
66+
resolve({ found: false });
6467
}
6568
});
66-
}else{
67-
resolve({'found': false});
69+
} else {
70+
resolve({ found: false });
6871
}
6972
});
7073

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+
}
8491
} else {
85-
isSkipped = ' => skipped - no changes.';
92+
fs.writeFileSync(fileName, joinedContent);
8693
}
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+
});
95100
});
96101
})
97102
.catch(error => {
@@ -110,7 +115,7 @@ export async function exportList(files: string[]): Promise<any> {
110115
maxConcurrent: maxConcurrentConnections
111116
});
112117
const results = [];
113-
for (let i=0;i<files.length;i++) {
118+
for (let i = 0; i < files.length; i++) {
114119
const result = await limiter.schedule(() => exportFile(files[i], getFileName(folder, files[i], atelier)));
115120
results.push(result);
116121
}

Diff for: package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@
378378
},
379379
"objectscript.export": {
380380
"type": "object",
381-
"description": "Export only the necessary stuff "
381+
"description": "Export only the necessary stuff ",
382+
"scope": "resource"
382383
},
383384
"objectscript.export.folder": {
384385
"description": "folder for source code",
@@ -408,7 +409,8 @@
408409
"objectscript.autoCompile": {
409410
"description": "Autocompile on save file",
410411
"type": "boolean",
411-
"default": false
412+
"default": false,
413+
"scope": "resource"
412414
},
413415
"objectscript.showExplorer": {
414416
"type": "boolean",

0 commit comments

Comments
 (0)