diff --git a/__tests__/buildFile.test.js b/__tests__/buildFile.test.js index 55cdd71f6..449e11a46 100644 --- a/__tests__/buildFile.test.js +++ b/__tests__/buildFile.test.js @@ -85,6 +85,25 @@ describe('buildFile', () => { expect(JSON.stringify(GroupMessages.fetchMessages(PROPERTY_NAME_COLLISION_WARNINGS))).toBe(expectJSON); }); + let destEmptyProperties = './__tests__/__output/test.emptyProperties'; + it('should warn when a file is not created because of empty properties', () => { + let properties = { + allProperties: [{ + name: 'someName', + attributes: { category: 'category1' }, + path: ['some', 'name', 'path1'], + value: 'value1' + }] + }; + + let filter = function(prop) { + return prop.attributes.category === 'category2'; + } + + buildFile(destEmptyProperties, format, {}, properties, filter); + expect(helpers.fileExists('./__tests__/__output/test.emptyProperties')).toBeFalsy(); + }); + it('should write to a file properly', () => { buildFile({ destination: 'test.txt', diff --git a/lib/buildFile.js b/lib/buildFile.js index 779052170..e6c5ad5f2 100644 --- a/lib/buildFile.js +++ b/lib/buildFile.js @@ -49,6 +49,17 @@ function buildFile(file = {}, platform = {}, dictionary = {}) { var filteredProperties = filterProperties(dictionary, filter); + // if properties object is empty, return without creating a file + if ( + filteredProperties.hasOwnProperty('properties') && + Object.keys(filteredProperties.properties).length === 0 && + filteredProperties.properties.constructor === Object + ) { + let warnNoFile = `No properties for ${destination}. File not created.`; + console.log(chalk.keyword('darkorange')(warnNoFile)); + return null; + } + // Check for property name Collisions var nameCollisionObj = {}; filteredProperties.allProperties && filteredProperties.allProperties.forEach((propertyData) => {