Project builder can now ignore files.

This patch adds the ignoreFiles option to the package builder, which
permits us to build a list of paths that should be ignored by our
tools. For example, this can be used to build a .gitignore or an
.eslintignore list.

Change-Id: I5ba67a9dbac1b90b72fb0a7ab1994fd2229e39d0
This commit is contained in:
Michael Krotscheck
2016-05-23 10:21:40 -07:00
parent 00c98191e4
commit aaccbb2d0e
2 changed files with 34 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
var includedFiles = []; var includedFiles = [];
var excludedFiles = []; var excludedFiles = [];
var ignoredFiles = [];
/** /**
* Ensure that a file is removed, or not present, in the project. * Ensure that a file is removed, or not present, in the project.
@@ -14,6 +15,20 @@
excludedFiles.push(destinationPath); excludedFiles.push(destinationPath);
} }
/**
* Flag a file path as 'ignored'.
*
* This does not have a real impact on which files are created/removed from the bootstrapped
* project, however it does permit other modules to retrieve this list and modify their
* behavior accordingly. For example, eslint could use this to generate .eslintignore
*
* @param {String} destinationPath Path to the file, relative to output root.
* @returns {void}
*/
function ignoreFile (destinationPath) {
ignoredFiles.push(destinationPath);
}
/** /**
* Add a file to the project. * Add a file to the project.
* *
@@ -54,6 +69,15 @@
return excludedFiles; return excludedFiles;
} }
/**
* Get a list of all file paths that should be ignored.
*
* @returns {Array} A list of file paths.
*/
function getIgnoredFiles () {
return ignoredFiles;
}
/** /**
* Clear the current configuration. * Clear the current configuration.
* *
@@ -62,13 +86,16 @@
function clearAll () { function clearAll () {
includedFiles = []; includedFiles = [];
excludedFiles = []; excludedFiles = [];
ignoredFiles = [];
} }
module.exports = { module.exports = {
addFile: addFile, addFile: addFile,
writeFile: writeFile, writeFile: writeFile,
removeFile: removeFile, removeFile: removeFile,
ignoreFile: ignoreFile,
getIncludedFiles: getIncludedFiles, getIncludedFiles: getIncludedFiles,
getIgnoredFiles: getIgnoredFiles,
getExcludedFiles: getExcludedFiles, getExcludedFiles: getExcludedFiles,
clear: clearAll clear: clearAll
}; };

View File

@@ -47,5 +47,12 @@
builder.removeFile(testFilePath); builder.removeFile(testFilePath);
expect(builder.getExcludedFiles()[0]).toBe(testFilePath); expect(builder.getExcludedFiles()[0]).toBe(testFilePath);
}); });
it('should permit adding a file to the ignore list',
function () {
var testFilePath = 'test_path.json';
builder.ignoreFile(testFilePath);
expect(builder.getIgnoredFiles()[0]).toBe(testFilePath);
});
}); });
})(); })();