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

Adding eslint, chai, removing should, fixing tests, fixing eslint errors #1

Merged
merged 2 commits into from
Dec 16, 2016
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
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"env": {
"node": true,
"mocha": true
},
"globals": {
"Buffer": true,
"escape": true
},
"extends": "eslint:recommended",
"rules": {
"no-console": 0,
"no-unused-vars": 1
}
}
Empty file added CHANGELOG.md
Empty file.
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Contributing to the Style Dictionary

TBD

# What transforms/transform groups/formats/templates should be included?

TBD
2 changes: 2 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Style Dictionary
Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
properties: {},
allProperties: [],
defaultBuildPath: 'build/',

transform: require('./lib/common/transforms'),
transformGroup: require('./lib/common/transformGroups'),
format: require('./lib/common/formats'),
Expand All @@ -20,4 +20,4 @@ module.exports = {
buildAllPlatforms: require('./lib/buildAllPlatforms'),

extend: require('./lib/extend')
};
};
8 changes: 4 additions & 4 deletions lib/buildFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ function buildFile(destination, format, platform, dictionary) {
if (!destination)
throw new Error('Please enter a valid destination');

// platform.buildPath should always exist,
// if it is not defined in the config, a default
// one is added to the platform config.
destination = platform.buildPath + destination;
// if there is a build path, prepend the destination with it
if (platform.buildPath) {
destination = platform.buildPath + destination;
}

var dirname = path.dirname(destination);
if (!fs.existsSync(dirname))
Expand Down
4 changes: 2 additions & 2 deletions lib/common/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var _ = require('lodash'),


module.exports = {
"android/copyImages": function(dictionary, config) {
'android/copyImages': function(dictionary, config) {
var imagesDir = config.buildPath + 'android/main/res/drawable-';
_.each(dictionary.allProperties, function(prop) {
if (prop.attributes.category === 'asset' && prop.attributes.type === 'image') {
Expand All @@ -13,7 +13,7 @@ module.exports = {
});
},

"copy_assets": function(dictionary, config) {
'copy_assets': function(dictionary, config) {
console.log('Copying assets directory');
fs.copySync('assets', config.buildPath + 'assets');
}
Expand Down
37 changes: 11 additions & 26 deletions lib/common/formats.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
var _ = require('lodash'),
convertToBase64 = require('../utils/convertToBase64');
var font_before = "@font-face {font-family: 'scapp_iconsregular'; src: url(data:application/x-font-ttf;charset=utf-8;base64,";
var font_after = ") format('truetype'); font-weight: normal; font-style: normal; }";
var module_def = "module.exports = ";
var _ = require('lodash');
var module_def = 'module.exports = ';

module.exports = {
"scss/variables": function(dictionary) {
'scss/variables': function(dictionary) {
var to_ret;
return _.map(dictionary.allProperties, function (prop) {
if (prop.attributes.category !== 'asset') {
Expand All @@ -18,7 +15,7 @@ module.exports = {
}).join('\n');
},

"scss/icons": function(dictionary, config) {
'scss/icons': function(dictionary, config) {
return _.chain(dictionary.allProperties)
.filter(function(prop) {
return prop.attributes.category === 'content' && prop.attributes.type === 'icon';
Expand All @@ -32,42 +29,30 @@ module.exports = {
.value().join('\n');
},

"scss/font": function(dictionary) {
return _.chain(dictionary.allProperties)
.filter(function(prop) {
return prop.attributes.category === 'asset' && prop.attributes.type === 'font';
})
.map(function(prop) {
return font_before + convertToBase64(prop.value) + font_after;
})
.value().join('\n');
},


"javascript/module": function(dictionary) {
'javascript/module': function(dictionary) {
return module_def + JSON.stringify(dictionary.properties) + ';';
},

"javascript/object": function(dictionary, config) {
'javascript/object': function(dictionary, config) {
return 'var ' +
config.jsVariableName +
' = ' +
JSON.stringify(dictionary.properties, null, 2) +
';';
},

"json": function(dictionary) {
'json': function(dictionary) {
return JSON.stringify(dictionary.properties, null, 2);
},

"json/asset": function(dictionary) {
'json/asset': function(dictionary) {
return JSON.stringify({asset: dictionary.properties.asset}, null, 2);
},

"sketch/palette": function(dictionary, config) {
'sketch/palette': function(dictionary) {
var to_ret = {
"compatibleVersion":"1.0",
"pluginVersion":"1.1"
'compatibleVersion':'1.0',
'pluginVersion':'1.1'
};
to_ret.colors = _.chain(dictionary.allProperties)
.filter(function(prop) {
Expand Down
14 changes: 7 additions & 7 deletions lib/common/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ var androidColors = fs.readFileSync(__dirname + '/templates/android/colors.t
iosPlist = fs.readFileSync(__dirname + '/templates/ios/plist.template');

module.exports = {
"android/colors": _.template(androidColors),
"android/dimens": _.template(androidDimens),
"android/fontDimens": _.template(androidFontDimens),
"android/integers": _.template(androidIntegers),
"android/strings": _.template(androidStrings),
"ios/headers": _.template(iosHeaders),
"ios/plist": _.template(iosPlist)
'android/colors': _.template(androidColors),
'android/dimens': _.template(androidDimens),
'android/fontDimens': _.template(androidFontDimens),
'android/integers': _.template(androidIntegers),
'android/strings': _.template(androidStrings),
'ios/headers': _.template(iosHeaders),
'ios/plist': _.template(iosPlist)
};
12 changes: 6 additions & 6 deletions lib/common/transformGroups.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
module.exports = {
"web": [
'web': [
'attribute/cti',
'name/cti/kebab',
'size/px'
],
"scss": [
'scss': [
'attribute/cti',
'name/cti/kebab',
'time/seconds',
'content/icon',
'size/px'
],
"html": [
'html': [
'attribute/cti',
'attribute/color',
'name/human'
],
"android": [
'android': [
'attribute/cti',
'name/cti/snake',
'color/hex',
'size/sp',
'size/dp'
],
"ios": [
'ios': [
'attribute/cti',
'attribute/color',
'name/cti/constant',
'color/rgb_array'
],
"assets": [
'assets': [
'attribute/cti'
]
};
37 changes: 18 additions & 19 deletions lib/common/transforms.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
var Color = require('color'),
_ = require('lodash'),
path = require('path'),
convertToBase64 = require('../utils/convertToBase64');
convertToBase64 = require('../utils/convertToBase64'),
UNICODE_PATTERN = /\&\#x([^;]+)\;/g;

function isColor(prop) {
return prop.attributes.category === 'color';
}

module.exports = {
"attribute/color": {
'attribute/color': {
type: 'attribute',
matcher: function (prop) {
return prop.attributes.category === 'color' && prop.value.indexOf('{') < 0;
Expand All @@ -28,7 +27,7 @@ module.exports = {
}
},

"attribute/cti": {
'attribute/cti': {
type: 'attribute',
matcher: function() { return true; },
transformer: function(prop) {
Expand All @@ -42,7 +41,7 @@ module.exports = {
}
},

"name/human": {
'name/human': {
type: 'name',
transformer: function(prop) {
return [
Expand All @@ -52,59 +51,59 @@ module.exports = {
}
},

"name/cti/camel": {
'name/cti/camel': {
type: 'name',
transformer: function(prop, options) {
return _.camelCase( [options.prefix].concat(prop.path).join(' ') );
}
},

"name/cti/kebab": {
'name/cti/kebab': {
type: 'name',
transformer: function(prop, options) {
return _.kebabCase([options.prefix].concat(prop.path).join(' '));
}
},

"name/cti/snake": {
'name/cti/snake': {
type: 'name',
transformer: function(prop, options) {
return _.snakeCase( [options.prefix].concat(prop.path).join(' ') );
}
},

"name/cti/constant": {
'name/cti/constant': {
type: 'name',
transformer: function(prop, options) {
return _.snakeCase( [options.prefix].concat(prop.path).join(' ') ).toUpperCase();
}
},

"color/rgb": {
'color/rgb': {
type: 'value',
matcher: isColor,
transformer: function (prop) {
return Color(prop.original.value).rgbString();
}
},

"color/rgb_array": {
'color/rgb_array': {
type: 'value',
matcher: isColor,
transformer: function (prop) {
return Color(prop.original.value).rgbArray();
}
},

"color/hex": {
'color/hex': {
type: 'value',
matcher: isColor,
transformer: function (prop) {
return Color(prop.original.value).hexString();
}
},

"size/sp": {
'size/sp': {
type: 'value',
matcher: function(prop) {
return prop.attributes.category === 'size' &&
Expand All @@ -115,7 +114,7 @@ module.exports = {
}
},

"size/dp": {
'size/dp': {
type: 'value',
matcher: function(prop) {
return prop.attributes.category === 'size' &&
Expand All @@ -127,7 +126,7 @@ module.exports = {
}
},

"size/px": {
'size/px': {
type: 'value',
matcher: function(prop) {
return prop.attributes.category === 'size';
Expand All @@ -137,19 +136,19 @@ module.exports = {
}
},

"content/icon": {
'content/icon': {
type: 'value',
matcher: function (prop) {
return prop.attributes.category === 'content' && prop.attributes.type === 'icon';
},
transformer: function (prop) {
return prop.original.value.replace(UNICODE_PATTERN, function (match, variable) {
return "'\\" + variable + "'";
return '\'\\' + variable + '\'';
});
}
},

"time/seconds": {
'time/seconds': {
type: 'value',
matcher: function(prop) {
return prop.attributes.category === 'time';
Expand All @@ -160,7 +159,7 @@ module.exports = {
},


"asset/base64": {
'asset/base64': {
type: 'value',
matcher: function(prop) {
return prop.attributes.category === 'asset';
Expand Down
Loading