Skip to content

Commit

Permalink
Added exclude storage xml from source options and also added an optio…
Browse files Browse the repository at this point in the history
…n to only modify the local files if the local and server data differs.
  • Loading branch information
Kenneth Shepherd committed Feb 12, 2019
1 parent cd0013a commit 7648ea9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
52 changes: 50 additions & 2 deletions commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,56 @@ export async function exportFile(name: string, fileName: string): Promise<any> {
throw new Error('Something wrong happened');
}
const content = data.result.content;
fs.writeFileSync(fileName, (content || []).join('\n'));
log('Success');
const { noStorage, dontExportIfNoChanges } = config().get('export');

const promise = new Promise((resolve, reject) => {
if(noStorage) {
// get only the storage xml for the doc.
api.getDoc(name + '?storageOnly=1').then(storageData => {
if (!storageData || !storageData.result) {
reject(new Error('Something wrong happened fetching the storage data'));
}
const storageContent = storageData.result.content;

if (storageContent.length>1 && storageContent[0]) {
const storageContentString = storageContent.join("\n");
const contentString = content.join("\n");

// find and replace the docs storage section with ''
resolve({'found': contentString.indexOf(storageContentString) >= 0, 'content': contentString.replace(storageContentString, '')});
} else {
resolve({'found': false});
}
});
}else{
resolve({'found': false});
}
});

promise.then((res:any) => {
let joinedContent = (content || []).join("\n").toString('utf8');
let isSkipped = '';

if(res.found) {
joinedContent = res.content.toString('utf8');
}

if (dontExportIfNoChanges && fs.existsSync(fileName)) {
const existingContent = fs.readFileSync(fileName, "utf8");
// stringify to harmonise the text encoding.
if (JSON.stringify(joinedContent) != JSON.stringify(existingContent)) {
fs.writeFileSync(fileName, joinedContent);
} else {
isSkipped = ' => skipped - no changes.';
}
} else {
fs.writeFileSync(fileName, joinedContent);
}

log(`Success ${isSkipped}`);
}).catch(error => {
throw error;
});
});
})
.catch(error => {
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,16 @@
"type": "boolean",
"default": false,
"description": "Automatically Preview XML Export files as UDL"
},
"objectscript.export.noStorage": {
"description": "Strip the storage xml on export. (Useful for multiple systems)",
"type": "boolean",
"default": false
},
"objectscript.export.dontExportIfNoChanges": {
"description": "Don't update the local file on export if the content is identical to the server code",
"type": "boolean",
"default": false
}
}
},
Expand Down

0 comments on commit 7648ea9

Please sign in to comment.