Skip to content

Commit e034bc4

Browse files
Kenneth Shepherddaimor
authored andcommitted
Added exclude storage xml from source options and also added an option to only modify the local files if the local and server data differs.
1 parent 002b757 commit e034bc4

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

commands/export.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,56 @@ export async function exportFile(name: string, fileName: string): Promise<any> {
4141
throw new Error('Something wrong happened');
4242
}
4343
const content = data.result.content;
44-
fs.writeFileSync(fileName, (content || []).join('\n'));
45-
log('Success');
44+
const { noStorage, dontExportIfNoChanges } = config().get('export');
45+
46+
const promise = new Promise((resolve, reject) => {
47+
if(noStorage) {
48+
// get only the storage xml for the doc.
49+
api.getDoc(name + '?storageOnly=1').then(storageData => {
50+
if (!storageData || !storageData.result) {
51+
reject(new Error('Something wrong happened fetching the storage data'));
52+
}
53+
const storageContent = storageData.result.content;
54+
55+
if (storageContent.length>1 && storageContent[0]) {
56+
const storageContentString = storageContent.join("\n");
57+
const contentString = content.join("\n");
58+
59+
// find and replace the docs storage section with ''
60+
resolve({'found': contentString.indexOf(storageContentString) >= 0, 'content': contentString.replace(storageContentString, '')});
61+
} else {
62+
resolve({'found': false});
63+
}
64+
});
65+
}else{
66+
resolve({'found': false});
67+
}
68+
});
69+
70+
promise.then((res:any) => {
71+
let joinedContent = (content || []).join("\n").toString('utf8');
72+
let isSkipped = '';
73+
74+
if(res.found) {
75+
joinedContent = res.content.toString('utf8');
76+
}
77+
78+
if (dontExportIfNoChanges && fs.existsSync(fileName)) {
79+
const existingContent = fs.readFileSync(fileName, "utf8");
80+
// stringify to harmonise the text encoding.
81+
if (JSON.stringify(joinedContent) != JSON.stringify(existingContent)) {
82+
fs.writeFileSync(fileName, joinedContent);
83+
} else {
84+
isSkipped = ' => skipped - no changes.';
85+
}
86+
} else {
87+
fs.writeFileSync(fileName, joinedContent);
88+
}
89+
90+
log(`Success ${isSkipped}`);
91+
}).catch(error => {
92+
throw error;
93+
});
4694
});
4795
})
4896
.catch(error => {

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,16 @@
417417
"type": "boolean",
418418
"default": false,
419419
"description": "Automatically Preview XML Export files as UDL"
420+
},
421+
"objectscript.export.noStorage": {
422+
"description": "Strip the storage xml on export. (Useful for multiple systems)",
423+
"type": "boolean",
424+
"default": false
425+
},
426+
"objectscript.export.dontExportIfNoChanges": {
427+
"description": "Don't update the local file on export if the content is identical to the server code",
428+
"type": "boolean",
429+
"default": false
420430
}
421431
}
422432
},

0 commit comments

Comments
 (0)