diff --git a/README.md b/README.md index 47f7b1f21..d9551c8c2 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,8 @@ This tells the style dictionary build system how and what to build. The default | platform.file.destination | String (optional) | Location to build the file, will be appended to the buildPath. | | platform.file.format | String (optional) | Format used to generate the file. Can be a built-in one or you can create your own. Must declare a format or a template. | | platform.file.template | String (optional) | Template used to generate the file. Can be a built-in one or you can create your own. [More on formats and templates](https://amzn.github.io/style-dictionary/formats_and_templates) | +| platform.file.options | Object (optional) | A set of extra options associated with the file. | +| platform.file.options.showFileHeader | Boolean | If the generated file should have a "Do not edit + Timestamp" header (where the format supports it). By default is "true". | ### Properties ```json diff --git a/docs/package_structure.md b/docs/package_structure.md index 0e0c8b6b9..61e523b74 100644 --- a/docs/package_structure.md +++ b/docs/package_structure.md @@ -59,6 +59,8 @@ The default way is to use a config.json file in the root of your package. Here i | platform.file.format | String (optional) | [Format](formats.md) used to generate the file. Can be a built-in one or you can create your own. Must declare a format or a template. | | platform.file.filter | Function/Object (optional) | A function or object used to filter the properties that will be included in the file. If a function is provided, each property will be passed to the function and the result (true or false) will determine whether the property is included. If an object is provided, each property will be matched against the object using a partial deep comparison to determine whether the property is included. | | platform.file.template | String (optional) | [Template](templates.md) used to generate the file. Can be a built-in one or you can create your own. | +| platform.file.options | Object (optional) | A set of extra options associated with the file. | +| platform.file.options.showFileHeader | Boolean | If the generated file should have a "Do not edit + Timestamp" header (where the format supports it). By default is "true". | | platform.actions | Array[String] (optional) | [Actions](actions.md) to be performed after the files are built for that platform. Actions can be any arbitrary code you want to run like copying files, generating assets, etc. You can use pre-defined actions or create custom actions. | ---- diff --git a/lib/common/formats.js b/lib/common/formats.js index 29e5fd8ce..20ac96204 100644 --- a/lib/common/formats.js +++ b/lib/common/formats.js @@ -12,13 +12,19 @@ */ var _ = require('lodash'); -var module_def = 'module.exports = '; -function fileHeader() { - return '/**\n' + - ' * Do not edit directly\n' + - ' * Generated on ' + new Date() + '\n' + - ' */\n\n'; +function fileHeader(options) { + var to_ret = ''; + // for backward compatibility we need to have the user explicitly hide them + var showFileHeader = (options) ? options.showFileHeader : true; + if (showFileHeader) { + to_ret += '/**\n'; + to_ret += ' * Do not edit directly\n'; + to_ret += ' * Generated on ' + new Date() + '\n'; + to_ret += ' */\n\n'; + } + + return to_ret; } function variablesWithPrefix(prefix, properties) { @@ -34,7 +40,7 @@ function variablesWithPrefix(prefix, properties) { } function iconsWithPrefix(prefix, properties, config) { - return fileHeader() + _.chain(properties) + return _.chain(properties) .filter(function(prop) { return prop.attributes.category === 'content' && prop.attributes.type === 'icon'; }) @@ -65,8 +71,10 @@ module.exports = { * ``` */ 'css/variables': function(dictionary) { - var root_vars = ':root {\n' + variablesWithPrefix(' --', dictionary.allProperties) + '\n}\n'; - return fileHeader() + root_vars; + return fileHeader(this.options) + + ':root {\n' + + variablesWithPrefix(' --', dictionary.allProperties) + + '\n}\n'; }, /** @@ -81,7 +89,7 @@ module.exports = { * ``` */ 'scss/variables': function(dictionary) { - return fileHeader() + variablesWithPrefix('$', dictionary.allProperties); + return fileHeader(this.options) + variablesWithPrefix('$', dictionary.allProperties); }, /** @@ -96,7 +104,7 @@ module.exports = { * ``` */ 'scss/icons': function(dictionary, config) { - return iconsWithPrefix('$', dictionary.allProperties, config); + return fileHeader(this.options) + iconsWithPrefix('$', dictionary.allProperties, config); }, /** @@ -111,7 +119,7 @@ module.exports = { * ``` */ 'less/variables': function(dictionary) { - return fileHeader() + variablesWithPrefix('@', dictionary.allProperties); + return fileHeader(this.options) + variablesWithPrefix('@', dictionary.allProperties); }, /** @@ -148,8 +156,8 @@ module.exports = { * ``` */ 'javascript/module': function(dictionary) { - return fileHeader() + - module_def + + return fileHeader(this.options) + + 'module.exports = ' + JSON.stringify(dictionary.properties, null, 2) + ';'; }, @@ -173,7 +181,7 @@ module.exports = { * ``` */ 'javascript/object': function(dictionary) { - return fileHeader() + + return fileHeader(this.options) + 'var ' + (this.name || '_styleDictionary') + ' = ' + @@ -213,7 +221,7 @@ module.exports = { */ 'javascript/umd': function(dictionary) { var name = this.name || '_styleDictionary' - return fileHeader() + + return fileHeader(this.options) + '(function(root, factory) {\n' + ' if (typeof module === "object" && module.exports) {\n' + ' module.exports = factory();\n' + @@ -262,7 +270,7 @@ module.exports = { * ``` */ 'javascript/es6': function(dictionary) { - return fileHeader() + + return fileHeader(this.options) + _.map(dictionary.allProperties, function(prop) { var to_ret_prop = 'export const ' + prop.name + ' = ' + JSON.stringify(prop.value) + ';'; if (prop.comment) diff --git a/lib/common/templates/ios/colors.h.template b/lib/common/templates/ios/colors.h.template index f035785b4..dffe2f89e 100644 --- a/lib/common/templates/ios/colors.h.template +++ b/lib/common/templates/ios/colors.h.template @@ -16,7 +16,14 @@ // // <%= this.destination %> // -// Do not edit directly, generated on <%= new Date() %> +<% + // for backward compatibility we need to have the user explicitly hide it + var showFileHeader = (this.options && this.options.hasOwnProperty('showFileHeader')) ? this.options.showFileHeader : true; + if(showFileHeader) { + print("// Do not edit directly\n"); + print("// Generated on " + new Date()); + } +%> // #import diff --git a/lib/common/templates/ios/colors.m.template b/lib/common/templates/ios/colors.m.template index bddd81349..721718920 100644 --- a/lib/common/templates/ios/colors.m.template +++ b/lib/common/templates/ios/colors.m.template @@ -16,7 +16,14 @@ // // <%= this.destination %> // -// Do not edit directly, generated on <%= new Date() %> +<% + // for backward compatibility we need to have the user explicitly hide it + var showFileHeader = (this.options && this.options.hasOwnProperty('showFileHeader')) ? this.options.showFileHeader : true; + if(showFileHeader) { + print("// Do not edit directly\n"); + print("// Generated on " + new Date()); + } +%> // #import "<%= this.className %>.h" diff --git a/lib/common/templates/ios/macros.template b/lib/common/templates/ios/macros.template index df9c1c084..99b6fa69e 100644 --- a/lib/common/templates/ios/macros.template +++ b/lib/common/templates/ios/macros.template @@ -16,7 +16,14 @@ // // <%= this.destination %> // -// Do not edit directly, generated on <%= new Date() %> +<% + // for backward compatibility we need to have the user explicitly hide it + var showFileHeader = (this.options && this.options.hasOwnProperty('showFileHeader')) ? this.options.showFileHeader : true; + if(showFileHeader) { + print("// Do not edit directly\n"); + print("// Generated on " + new Date()); + } +%> // #import diff --git a/lib/common/templates/ios/plist.template b/lib/common/templates/ios/plist.template index 9c41944bf..3a046b8d3 100644 --- a/lib/common/templates/ios/plist.template +++ b/lib/common/templates/ios/plist.template @@ -21,10 +21,15 @@ var props = _.filter(allProperties, function(prop) { }); %> - +<% + // for backward compatibility we need to have the user explicitly hide it + var showFileHeader = (this.options && this.options.hasOwnProperty('showFileHeader')) ? this.options.showFileHeader : true; + if(showFileHeader) { + print(""); + } +%> <% _.each(props, function(prop) { diff --git a/lib/common/templates/ios/singleton.h.template b/lib/common/templates/ios/singleton.h.template index b2c684429..63d3c4603 100644 --- a/lib/common/templates/ios/singleton.h.template +++ b/lib/common/templates/ios/singleton.h.template @@ -16,7 +16,14 @@ // // <%= this.destination %> // -// Do not edit directly, generated on <%= new Date() %> +<% + // for backward compatibility we need to have the user explicitly hide it + var showFileHeader = (this.options && this.options.hasOwnProperty('showFileHeader')) ? this.options.showFileHeader : true; + if(showFileHeader) { + print("// Do not edit directly\n"); + print("// Generated on " + new Date()); + } +%> // #import diff --git a/lib/common/templates/ios/singleton.m.template b/lib/common/templates/ios/singleton.m.template index b013532c1..de497e41b 100644 --- a/lib/common/templates/ios/singleton.m.template +++ b/lib/common/templates/ios/singleton.m.template @@ -16,7 +16,14 @@ // // <%= this.destination %> // -// Do not edit directly, generated on <%= new Date() %> +<% + // for backward compatibility we need to have the user explicitly hide it + var showFileHeader = (this.options && this.options.hasOwnProperty('showFileHeader')) ? this.options.showFileHeader : true; + if(showFileHeader) { + print("// Do not edit directly\n"); + print("// Generated on " + new Date()); + } +%> // #import "<%= this.className %>.h" diff --git a/lib/common/templates/ios/static.h.template b/lib/common/templates/ios/static.h.template index 55cf4701e..675a258ca 100644 --- a/lib/common/templates/ios/static.h.template +++ b/lib/common/templates/ios/static.h.template @@ -16,7 +16,14 @@ %> // <%= this.destination %> // -// Do not edit directly, generated on <%= new Date() %> +<% + // for backward compatibility we need to have the user explicitly hide it + var showFileHeader = (this.options && this.options.hasOwnProperty('showFileHeader')) ? this.options.showFileHeader : true; + if(showFileHeader) { + print("// Do not edit directly\n"); + print("// Generated on " + new Date()); + } +%> // #import diff --git a/lib/common/templates/ios/static.m.template b/lib/common/templates/ios/static.m.template index 31efc76cc..0fdbfb5da 100644 --- a/lib/common/templates/ios/static.m.template +++ b/lib/common/templates/ios/static.m.template @@ -16,7 +16,14 @@ // // <%= this.destination %> // -// Do not edit directly, generated on <%= new Date() %> +<% + // for backward compatibility we need to have the user explicitly hide it + var showFileHeader = (this.options && this.options.hasOwnProperty('showFileHeader')) ? this.options.showFileHeader : true; + if(showFileHeader) { + print("// Do not edit directly\n"); + print("// Generated on " + new Date()); + } +%> // #import "<%= this.className %>.h" diff --git a/lib/common/templates/ios/strings.h.template b/lib/common/templates/ios/strings.h.template index b6bf384e2..b529021b5 100644 --- a/lib/common/templates/ios/strings.h.template +++ b/lib/common/templates/ios/strings.h.template @@ -16,7 +16,14 @@ // // <%= this.destination %> // -// Do not edit directly, generated on <%= new Date() %> +<% + // for backward compatibility we need to have the user explicitly hide it + var showFileHeader = (this.options && this.options.hasOwnProperty('showFileHeader')) ? this.options.showFileHeader : true; + if(showFileHeader) { + print("// Do not edit directly\n"); + print("// Generated on " + new Date()); + } +%> // #import diff --git a/lib/common/templates/ios/strings.m.template b/lib/common/templates/ios/strings.m.template index 8641435a4..34c87e283 100644 --- a/lib/common/templates/ios/strings.m.template +++ b/lib/common/templates/ios/strings.m.template @@ -16,7 +16,14 @@ // // <%= this.destination %> // -// Do not edit directly, generated on <%= new Date() %> +<% + // for backward compatibility we need to have the user explicitly hide it + var showFileHeader = (this.options && this.options.hasOwnProperty('showFileHeader')) ? this.options.showFileHeader : true; + if(showFileHeader) { + print("// Do not edit directly\n"); + print("// Generated on " + new Date()); + } +%> // #import "<%= this.className %>.h"