Skip to content

Commit

Permalink
fix(formats): change less and scss comments to short version (#306)
Browse files Browse the repository at this point in the history
Fixes #305
  • Loading branch information
dbanksdesign authored and chazzmoney committed Jul 17, 2019
1 parent 9ad6437 commit 4f13f57
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
32 changes: 14 additions & 18 deletions __tests__/formats/__snapshots__/all.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -532,21 +532,19 @@ exports[`formats all should match json/nested snapshot 1`] = `
`;
exports[`formats all should match less/icons snapshot 1`] = `
"/**
* Do not edit directly
* Generated on Sat, 01 Jan 2000 00:00:00 GMT
*/
"
// Do not edit directly
// Generated on Sat, 01 Jan 2000 00:00:00 GMT
"
`;
exports[`formats all should match less/variables snapshot 1`] = `
"/**
* Do not edit directly
* Generated on Sat, 01 Jan 2000 00:00:00 GMT
*/
"
// Do not edit directly
// Generated on Sat, 01 Jan 2000 00:00:00 GMT
@color_red: #FF0000; /* comment */"
@color_red: #FF0000; // comment"
`;
exports[`formats all should match sass/map-deep snapshot 1`] = `
Expand Down Expand Up @@ -581,10 +579,9 @@ $tokens: (
`;
exports[`formats all should match scss/icons snapshot 1`] = `
"/**
* Do not edit directly
* Generated on Sat, 01 Jan 2000 00:00:00 GMT
*/
"
// Do not edit directly
// Generated on Sat, 01 Jan 2000 00:00:00 GMT
"
`;
Expand Down Expand Up @@ -621,12 +618,11 @@ $tokens: (
`;
exports[`formats all should match scss/variables snapshot 1`] = `
"/**
* Do not edit directly
* Generated on Sat, 01 Jan 2000 00:00:00 GMT
*/
"
// Do not edit directly
// Generated on Sat, 01 Jan 2000 00:00:00 GMT
$color_red: #FF0000; /* comment */"
$color_red: #FF0000; // comment"
`;
exports[`formats all should match sketch/palette snapshot 1`] = `
Expand Down
37 changes: 25 additions & 12 deletions lib/common/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,39 @@ var fs = require('fs'),

var SASS_MAP_FORMAT_DEPRECATION_WARNINGS = GroupMessages.GROUP.SassMapFormatDeprecationWarnings;

function fileHeader(options) {
function fileHeader(options, commentStyle) {
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().toUTCString() + '\n';
to_ret += ' */\n\n';
if (commentStyle === 'short') {
to_ret += '\n';
to_ret += '// Do not edit directly\n';
to_ret += '// Generated on ' + new Date().toUTCString() + '\n';
to_ret += '\n';
} else {
to_ret += '/**\n';
to_ret += ' * Do not edit directly\n';
to_ret += ' * Generated on ' + new Date().toUTCString() + '\n';
to_ret += ' */\n\n';
}
}

return to_ret;
}

function variablesWithPrefix(prefix, properties) {
function variablesWithPrefix(prefix, properties, commentStyle) {
return _.map(properties, function(prop) {
var to_ret_prop = prefix + prop.name + ': ' + (prop.attributes.category==='asset' ? '"'+prop.value+'"' : prop.value) + ';';

if (prop.comment)
to_ret_prop = to_ret_prop.concat(' /* ' + prop.comment + ' */');
if (prop.comment) {
if (commentStyle === 'short') {
to_ret_prop = to_ret_prop.concat(' // ' + prop.comment);
} else {
to_ret_prop = to_ret_prop.concat(' /* ' + prop.comment + ' */');
}
}

return to_ret_prop;
})
.filter(function(strVal) { return !!strVal })
Expand Down Expand Up @@ -173,7 +186,7 @@ module.exports = {
* ```
*/
'scss/variables': function(dictionary) {
return fileHeader(this.options) + variablesWithPrefix('$', dictionary.allProperties);
return fileHeader(this.options, 'short') + variablesWithPrefix('$', dictionary.allProperties, 'short');
},

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

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

/**
Expand All @@ -218,7 +231,7 @@ module.exports = {
* ```
*/
'less/icons': function(dictionary, config) {
return fileHeader(this.options) + iconsWithPrefix('@', dictionary.allProperties, config);
return fileHeader(this.options, 'short') + iconsWithPrefix('@', dictionary.allProperties, config, 'short');
},

/**
Expand Down

0 comments on commit 4f13f57

Please sign in to comment.