Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce option to control the generation of the "Do not edit" header #132

Merged
merged 6 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/package_structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

----
Expand Down
42 changes: 25 additions & 17 deletions lib/common/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@
*/

var _ = require('lodash');
var module_def = 'module.exports = ';
didoo marked this conversation as resolved.
Show resolved Hide resolved

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) {
Expand All @@ -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';
})
Expand Down Expand Up @@ -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';
},

/**
Expand All @@ -81,7 +89,7 @@ module.exports = {
* ```
*/
'scss/variables': function(dictionary) {
return fileHeader() + variablesWithPrefix('$', dictionary.allProperties);
return fileHeader(this.options) + variablesWithPrefix('$', dictionary.allProperties);
},

/**
Expand All @@ -96,7 +104,7 @@ module.exports = {
* ```
*/
'scss/icons': function(dictionary, config) {
return iconsWithPrefix('$', dictionary.allProperties, config);
return fileHeader(this.options) + iconsWithPrefix('$', dictionary.allProperties, config);
},

/**
Expand All @@ -111,7 +119,7 @@ module.exports = {
* ```
*/
'less/variables': function(dictionary) {
return fileHeader() + variablesWithPrefix('@', dictionary.allProperties);
return fileHeader(this.options) + variablesWithPrefix('@', dictionary.allProperties);
},

/**
Expand Down Expand Up @@ -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) + ';';
},

Expand All @@ -173,7 +181,7 @@ module.exports = {
* ```
*/
'javascript/object': function(dictionary) {
return fileHeader() +
return fileHeader(this.options) +
'var ' +
(this.name || '_styleDictionary') +
' = ' +
Expand Down Expand Up @@ -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' +
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion lib/common/templates/ios/colors.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 <UIKit/UIKit.h>
Expand Down
9 changes: 8 additions & 1 deletion lib/common/templates/ios/colors.m.template
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion lib/common/templates/ios/macros.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Foundation/Foundation.h>
Expand Down
13 changes: 9 additions & 4 deletions lib/common/templates/ios/plist.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ var props = _.filter(allProperties, function(prop) {
}); %>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
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("<!--\n Do not edit directly");
print("\n Generated on " + new Date());
print("\n-->");
}
%>
<plist version="1.0">
<dict>
<% _.each(props, function(prop) {
Expand Down
9 changes: 8 additions & 1 deletion lib/common/templates/ios/singleton.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Foundation/Foundation.h>
Expand Down
9 changes: 8 additions & 1 deletion lib/common/templates/ios/singleton.m.template
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion lib/common/templates/ios/static.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Foundation/Foundation.h>
Expand Down
9 changes: 8 additions & 1 deletion lib/common/templates/ios/static.m.template
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion lib/common/templates/ios/strings.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Foundation/Foundation.h>
Expand Down
9 changes: 8 additions & 1 deletion lib/common/templates/ios/strings.m.template
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down