///
import _ = require('lodash');
import fs = require('fs');
import grunt = require('grunt');
import utils = require('./utils');
/////////////////////////////////////////////////////////////////////
// Reference file logic
////////////////////////////////////////////////////////////////////
// Updates the reference file
export function updateReferenceFile(files: string[], generatedFiles: string[], referenceFile: string, referencePath: string, eol: string): boolean {
var referenceIntro = '/// ';
var referenceMatch = /\/\/\/ referenceIntro + utils.makeRelativePath(referencePath, file) + referenceEnd);
var contents = utils.insertArrayAt([ourSignatureStart], 1, generatedFiles);
// Put in the new / observed missing files:
files.forEach((filename: string) => {
// The file we are about to add
var filepath = utils.makeRelativePath(referencePath, filename);
// If there are orig references
if (origFileReferences.length) {
if (_.includes(origFileReferences, filepath)) {
return;
}
}
// Finally add the filepath
contents.push(referenceIntro + filepath + referenceEnd);
});
contents.push(ourSignatureEnd);
var updatedFileLines = utils.insertArrayAt(origFileLines, signatureSectionPosition, contents);
var updatedFileContents = updatedFileLines.join(eol);
// Modify the orig contents to put in our contents only if changed
// Also Return whether the file was changed
if (updatedFileContents !== referenceContents) {
grunt.file.write(referenceFile, updatedFileContents);
return true;
}
else {
return false;
}
}