update document contents even if postprocess command returns error

needed for standardjs which changes file on disk and return error if there are unfixed issues
pull/125/merge
nightwing 2017-04-30 21:39:59 +04:00
rodzic 91a5badde9
commit 2795ef0379
1 zmienionych plików z 23 dodań i 33 usunięć

Wyświetl plik

@ -1941,6 +1941,9 @@ function syncDocument(docId, doc, client, forceSync, callback) {
function doSyncDocument() { function doSyncDocument() {
Fs.readFile(file, "utf8", function (err, contents) { Fs.readFile(file, "utf8", function (err, contents) {
if (typeof doc.contents != "string" && doc.contents)
doc.contents = doc.contents.toString(); // because it can be a buffer
if (err) if (err)
return callback(err); return callback(err);
@ -2201,7 +2204,7 @@ function handleSaveFile(userIds, client, data) {
type: "POST_PROCESSOR_ERROR", type: "POST_PROCESSOR_ERROR",
data: { data: {
code: err.code, code: err.code,
stderr: result && result.stderr, stderr: err.stderr,
docId: docId, docId: docId,
} }
}); });
@ -2223,40 +2226,27 @@ function handleSaveFile(userIds, client, data) {
function execPostProcessor(absPath, docId, doc, fileContents, client, postProcessor, callback) { function execPostProcessor(absPath, docId, doc, fileContents, client, postProcessor, callback) {
localfsAPI.writeToWatchedFile(absPath, function(afterWrite) { localfsAPI.writeToWatchedFile(absPath, function(afterWrite) {
localfsAPI.execFile( localfsAPI.execFile(postProcessor.command, {
postProcessor.command, args: postProcessor.args.map(function(a) { return a.replace(/\$file/g, absPath); }),
{ args: postProcessor.args.map(function(a) { return a.replace(/\$file/g, absPath); }) }, cwd: Path.dirname(absPath),
},
function(err, result) { function(err, result) {
if (err) return done(err);
afterWrite(function() {
Fs.readFile(absPath, "utf8", done);
});
}
);
});
function done(err, result) {
var newFileContents = result && result.toString().replace(/\n/g, doc.newLineChar || DEFAULT_NL_CHAR_FILE);
if (!newFileContents || newFileContents === fileContents) {
if (err) { if (err) {
client.send({ client.send({
type: "POST_PROCESSOR_ERROR", type: "POST_PROCESSOR_ERROR",
data: { data: {
code: err.code, code: err.code,
stderr: result && result.stderr, stderr: err.stderr,
docId: docId, docId: docId,
} }
}); });
return callback();
}
return callback();
} }
doc.contents = fileContents; syncDocument(docId, doc, null, true, function() {
afterWrite(callback)
syncDocument(docId, doc, null, false, callback); });
} });
});
} }
/** /**