Comparing version 5.0.0-beta.5 to 5.0.0-beta.6
@@ -5,2 +5,6 @@ 'use strict'; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
/* eslint new-cap: off */ | ||
@@ -25,2 +29,3 @@ /* | ||
var tinycolor = require('tinycolor2'); | ||
var JSON5 = require('json5'); | ||
@@ -40,11 +45,11 @@ var util = require('./util'); | ||
function cleanOutput(output) { | ||
var cleanOutput = function cleanOutput(output) { | ||
return output.replace(/^ {4}/gm, '').replace(/^\s*\n/gm, '').trim(); | ||
} | ||
}; | ||
function remToPx(prop, meta) { | ||
var remToPx = function remToPx(prop, meta) { | ||
var baseFontPercentage = typeof meta.baseFontPercentage === 'number' ? meta.baseFontPercentage : 100; | ||
var baseFontPixel = typeof meta.baseFontPixel === 'number' ? meta.baseFontPixel : 16; | ||
return util.remToPx(prop.value, baseFontPercentage, baseFontPixel); | ||
} | ||
}; | ||
@@ -57,3 +62,3 @@ // ////////////////////////////////////////////////////////////////// | ||
function registerValueTransform(name, matcher, transformer) { | ||
var registerValueTransform = function registerValueTransform(name, matcher, transformer) { | ||
if (typeof name !== 'string') { | ||
@@ -72,3 +77,3 @@ throw TheoError('valueTransform name must be a string'); | ||
}; | ||
} | ||
}; | ||
@@ -120,7 +125,7 @@ registerValueTransform('color/rgb', function (prop) { | ||
function registerTransform(name, valueTransforms) { | ||
var registerTransform = function registerTransform(name, valueTransforms) { | ||
if (typeof name !== 'string') { | ||
throw TheoError('transform name must be a string'); | ||
} | ||
if (!_.isArray(valueTransforms)) { | ||
if (!Array.isArray(valueTransforms)) { | ||
throw TheoError('valueTransforms must be an array of registered value transforms'); | ||
@@ -134,3 +139,3 @@ } | ||
TRANSFORMS[name] = valueTransforms; | ||
} | ||
}; | ||
@@ -153,3 +158,3 @@ registerTransform('raw', []); | ||
function registerFormat(name, formatter) { | ||
var registerFormat = function registerFormat(name, formatter) { | ||
if (typeof name !== 'string') { | ||
@@ -162,9 +167,8 @@ throw TheoError('format name must be a string'); | ||
FORMATS[name] = formatter; | ||
} | ||
}; | ||
registerFormat('json', function (json) { | ||
var output = {}; | ||
_.forEach(json.props, function (prop) { | ||
output[prop.name] = prop.value; | ||
}); | ||
var output = Object.assign.apply(Object, [{}].concat(_toConsumableArray(Object.keys(json.props).map(function (key) { | ||
return _defineProperty({}, json.props[key].name, json.props[key].value); | ||
})))); | ||
return JSON.stringify(output, null, 2); | ||
@@ -179,3 +183,4 @@ }); | ||
var output = { | ||
properties: _.map(json.props, function (prop) { | ||
properties: Object.keys(json.props).map(function (key) { | ||
var prop = json.props[key]; | ||
prop.name = camelCase(prop.name); | ||
@@ -195,3 +200,4 @@ return prop; | ||
}; | ||
var props = _.map(json.props, function (prop) { | ||
var props = Object.keys(json.props).map(function (key) { | ||
var prop = json.props[key]; | ||
var tag = getTag(prop); | ||
@@ -206,5 +212,4 @@ var name = prop.name.toUpperCase(); | ||
registerFormat('scss', function (json) { | ||
return _.map(json.props, function (prop) { | ||
var name = kebabCase(prop.name); | ||
return '$' + name + ': ' + prop.value + ';'; | ||
return Object.keys(json.props).map(function (prop) { | ||
return '$' + kebabCase(json.props[prop].name) + ': ' + json.props[prop].value + ';'; | ||
}).join('\n'); | ||
@@ -214,5 +219,4 @@ }); | ||
registerFormat('default.scss', function (json) { | ||
return _.map(json.props, function (prop) { | ||
var name = kebabCase(prop.name); | ||
return '$' + name + ': ' + prop.value + ' !default;'; | ||
return Object.keys(json.props).map(function (prop) { | ||
return '$' + kebabCase(json.props[prop].name) + ': ' + json.props[prop].value + ' !default;'; | ||
}).join('\n'); | ||
@@ -222,4 +226,4 @@ }); | ||
registerFormat('list.scss', function (json, options) { | ||
var items = _.isArray(json.items) ? json.items : []; | ||
items = _.map(items, function (item) { | ||
var items = Array.isArray(json.items) ? json.items : []; | ||
items = items.map(function (item) { | ||
return '"' + item + '"'; | ||
@@ -229,5 +233,5 @@ }).join(',\n '); | ||
var name = basename + '-list'; | ||
if (_.isFunction(options.name)) { | ||
if (typeof options.name === 'function') { | ||
var n = options.name(basename, options.path); | ||
if (_.isString(n)) { | ||
if (typeof n === 'string') { | ||
name = n; | ||
@@ -244,11 +248,10 @@ } | ||
}); | ||
var items = _.map(json.props, function (prop) { | ||
var name = kebabCase(prop.name); | ||
return '"' + name + '": (' + prop.value + ')'; | ||
var items = Object.keys(json.props).map(function (prop) { | ||
return '"' + kebabCase(json.props[prop].name) + '": (' + json.props[prop].value + ')'; | ||
}).join(',\n '); | ||
var basename = path.basename(options.path, path.extname(options.path)).replace(/\..*/g, ''); | ||
var name = '' + basename + options.nameSuffix; | ||
if (_.isFunction(options.name)) { | ||
if (typeof options.name === 'function') { | ||
var n = options.name(basename, options.path); | ||
if (_.isString(n)) { | ||
if (typeof n === 'string') { | ||
name = n; | ||
@@ -273,5 +276,4 @@ } | ||
registerFormat('sass', function (json) { | ||
return _.map(json.props, function (prop) { | ||
var name = kebabCase(prop.name); | ||
return '$' + name + ': ' + prop.value; | ||
return Object.keys(json.props).map(function (prop) { | ||
return '$' + kebabCase(json.props[prop].name) + ': ' + json.props[prop].value; | ||
}).join('\n'); | ||
@@ -281,5 +283,4 @@ }); | ||
registerFormat('default.sass', function (json) { | ||
return _.map(json.props, function (prop) { | ||
var name = kebabCase(prop.name); | ||
return '$' + name + ': ' + prop.value + ' !default'; | ||
return Object.keys(json.props).map(function (prop) { | ||
return '$' + kebabCase(json.props[prop].name) + ': ' + json.props[prop].value + ' !default'; | ||
}).join('\n'); | ||
@@ -289,5 +290,4 @@ }); | ||
registerFormat('less', function (json) { | ||
return _.map(json.props, function (prop) { | ||
var name = kebabCase(prop.name); | ||
return '@' + name + ': ' + prop.value + ';'; | ||
return Object.keys(json.props).map(function (prop) { | ||
return '@' + kebabCase(json.props[prop].name) + ': ' + json.props[prop].value + ';'; | ||
}).join('\n'); | ||
@@ -297,5 +297,4 @@ }); | ||
registerFormat('styl', function (json) { | ||
return _.map(json.props, function (prop) { | ||
var name = kebabCase(prop.name); | ||
return name + ' = ' + prop.value; | ||
return Object.keys(json.props).map(function (prop) { | ||
return kebabCase(json.props[prop].name) + ' = ' + json.props[prop].value; | ||
}).join('\n'); | ||
@@ -305,10 +304,9 @@ }); | ||
registerFormat('aura.theme', function (json) { | ||
var auraImports = _.isArray(json.auraImports) ? json.auraImports : []; | ||
var auraExtends = _.isString(json.auraExtends) ? json.auraExtends : null; | ||
var auraImports = Array.isArray(json.auraImports) ? json.auraImports : []; | ||
var auraExtends = typeof json.auraExtends === 'string' ? json.auraExtends : null; | ||
auraImports = auraImports.map(function (theme) { | ||
return '<aura:importTheme name="' + theme + '" />'; | ||
}).join('\n '); | ||
var props = _.map(json.props, function (prop) { | ||
var name = camelCase(prop.name); | ||
return '<aura:var name="' + name + '" value="' + prop.value + '" />'; | ||
var props = Object.keys(json.props).map(function (prop) { | ||
return '<aura:var name="' + camelCase(json.props[prop].name) + '" value="' + json.props[prop].value + '" />'; | ||
}).join('\n '); | ||
@@ -324,7 +322,8 @@ var openTag = auraExtends ? '<aura:theme extends="' + auraExtends + '">' : '<aura:theme>'; | ||
}).join('\n '); | ||
var auraExtends = _.isString(json.auraExtends) ? json.auraExtends : null; | ||
var props = _.map(json.props, function (prop) { | ||
var auraExtends = typeof json.auraExtends === 'string' ? json.auraExtends : null; | ||
var props = Object.keys(json.props).map(function (key) { | ||
var prop = json.props[key]; | ||
var name = camelCase(prop.name); | ||
var cssProperties = function () { | ||
if (_.isArray(prop.cssProperties)) { | ||
if (Array.isArray(prop.cssProperties)) { | ||
return 'property="' + prop.cssProperties.join(',') + '"'; | ||
@@ -344,3 +343,4 @@ } | ||
registerFormat('common.js', function (json) { | ||
var values = _.map(json.props, function (prop) { | ||
var values = Object.keys(json.props).map(function (key) { | ||
var prop = json.props[key]; | ||
var name = camelCase(prop.name); | ||
@@ -360,3 +360,4 @@ var value = prop.value; | ||
registerFormat('amd.js', function (json) { | ||
var values = _.map(json.props, function (prop) { | ||
var values = Object.keys(json.props).map(function (key) { | ||
var prop = json.props[key]; | ||
var name = camelCase(prop.name); | ||
@@ -404,3 +405,2 @@ var value = prop.value; | ||
}, | ||
/** | ||
@@ -435,3 +435,2 @@ * Transform the prop values | ||
/** | ||
@@ -453,3 +452,2 @@ * Convert the vinyl '.json' file to a JSON primative | ||
/** | ||
@@ -501,3 +499,3 @@ * Format the props JSON into a new output format | ||
}, {}); | ||
json.propKeys = _.keys(json.props); | ||
json.propKeys = Object.keys(json.props); | ||
// Format the json | ||
@@ -508,6 +506,7 @@ var formatted = formatter(json, _.merge({}, options, { | ||
// Set the file contents to the result of the formatter | ||
newFile.contents = new Buffer(formatted); | ||
newFile.contents = Buffer.from(formatted, 'utf8'); | ||
next(null, newFile); | ||
}); | ||
} | ||
}, | ||
@@ -534,3 +533,2 @@ | ||
/** | ||
@@ -548,3 +546,2 @@ * Get a registered valueTransform | ||
/** | ||
@@ -568,3 +565,2 @@ * Register a new transform. If a transform with the provided | ||
/** | ||
@@ -582,3 +578,2 @@ * Get a registered format | ||
/** | ||
@@ -602,3 +597,2 @@ * Register a new format. If a format with the provided | ||
/** | ||
@@ -616,3 +610,2 @@ * Get a registered format | ||
/** | ||
@@ -619,0 +612,0 @@ * Transform a string to kebabCase |
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -21,2 +23,3 @@ | ||
var fs = require('fs'); | ||
var JSON5 = require('json5'); | ||
var _ = require('lodash'); | ||
@@ -46,3 +49,3 @@ var gutil = require('gulp-util'); | ||
this.valueTransforms = valueTransforms; | ||
this.options = _.assign({}, defaults, options); | ||
this.options = Object.assign({}, defaults, options); | ||
@@ -112,3 +115,3 @@ this._init(); | ||
value: function toBuffer() { | ||
return new Buffer(this.toJSON()); | ||
return Buffer.from(this.toJSON(), 'utf8'); | ||
} | ||
@@ -121,3 +124,3 @@ }, { | ||
// Provide the keys for easy iteration | ||
def.propKeys = _.keys(def.props); | ||
def.propKeys = Object.keys(def.props); | ||
// Go | ||
@@ -129,5 +132,5 @@ return JSON.stringify(def, null, 2); | ||
value: function _resolveGlobals(def) { | ||
if (_.keys(def.global).length === 0) return; | ||
if (Object.keys(def.global).length === 0) return; | ||
_.forEach(def.props, function (prop, key) { | ||
def.props[key] = _.assign({}, def.global, prop); | ||
def.props[key] = Object.assign({}, def.global, prop); | ||
}); | ||
@@ -139,3 +142,3 @@ delete def.global; | ||
value: function _validate(def) { | ||
if (_.isArray(def.props)) { | ||
if (Array.isArray(def.props)) { | ||
throw TheoError('Design Token "props" key must be an object'); | ||
@@ -161,15 +164,15 @@ } | ||
var options = this.options; | ||
// convert all aliases to object format | ||
_.forEach(def.aliases, function (value, key) { | ||
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== 'object') { | ||
def.aliases[key] = { 'value': value }; | ||
} | ||
}); | ||
_.forEach(def.aliases, function (replace, key) { | ||
var s = _.escapeRegExp(key); | ||
var v = _.isString(value) ? value : value.value; | ||
_.forEach(def.aliases, function (value, key) { | ||
if (_.isString(value)) { | ||
def.aliases[key] = _this._replaceAliasedValues(s, value, v, def, type); | ||
} else { | ||
def.aliases[key]['value'] = _this._replaceAliasedValues(s, value.value, v, def, type); | ||
} | ||
_.forEach(def.aliases, function (alias) { | ||
alias.value = _this._replaceAliasedValues(s, alias.value, replace.value, def, type); | ||
}); | ||
_.forEach(def.props, function (prop) { | ||
prop.value = _this._replaceAliasedValues(s, prop.value, v, def, type); | ||
prop.value = _this._replaceAliasedValues(s, prop.value, replace.value, def, type); | ||
}); | ||
@@ -183,15 +186,13 @@ }); | ||
var isAliasStructure = RegExp('{![^}]*}', 'g'); | ||
if (_.isString(haystack)) { | ||
// Value contains an alias | ||
if (isAlias.test(haystack)) { | ||
// Resolve the alias | ||
haystack = haystack.replace(isAlias, replacement); | ||
} | ||
if (type !== 'local' && isAliasStructure.test(haystack)) { | ||
_.forEach(haystack.match(isAliasStructure), function (a) { | ||
var alias = a.toString().replace('{!', '').replace('}', ''); | ||
if (!def.aliases[alias]) throw new Error('Alias ' + a + ' not found'); | ||
}); | ||
} | ||
// Value contains an alias | ||
if (isAlias.test(haystack)) { | ||
// Resolve the alias | ||
haystack = haystack.replace(isAlias, replacement); | ||
} | ||
if (type !== 'local' && isAliasStructure.test(haystack)) { | ||
_.forEach(haystack.match(isAliasStructure), function (a) { | ||
var alias = a.toString().replace('{!', '').replace('}', ''); | ||
if (!def.aliases[alias]) throw new Error('Alias ' + a + ' not found'); | ||
}); | ||
} | ||
return haystack; | ||
@@ -204,3 +205,3 @@ } | ||
if (!_.isArray(def.imports)) return []; | ||
if (!Array.isArray(def.imports)) return []; | ||
return def.imports.map(function (i) { | ||
@@ -217,3 +218,3 @@ var p = path.resolve(path.dirname(_this2.path), i); | ||
path: p, | ||
contents: new Buffer(f) | ||
contents: Buffer.from(f, 'utf8') | ||
}); | ||
@@ -246,4 +247,4 @@ return new PropSet(v, _this2._transform, _this2.options); | ||
_.forEach(this.valueTransforms, function (v) { | ||
var p = _.assign({}, prop); | ||
var m = _.assign({}, meta); | ||
var p = Object.assign({}, prop); | ||
var m = Object.assign({}, meta); | ||
if (v.matcher(p, m) === true) { | ||
@@ -250,0 +251,0 @@ prop.value = v.transformer(p, m); |
@@ -16,2 +16,3 @@ 'use strict'; | ||
var yaml = require('js-yaml'); | ||
var JSON5 = require('json5'); | ||
var path = require('path'); | ||
@@ -33,5 +34,5 @@ | ||
default: | ||
return JSON.parse(file.contents.toString()); | ||
return JSON5.parse(file.contents.toString()); | ||
} | ||
} | ||
}; |
@@ -21,2 +21,3 @@ 'use strict'; | ||
var gutil = require('gulp-util'); | ||
var JSON5 = require('json5'); | ||
@@ -43,3 +44,2 @@ module.exports = { | ||
/** | ||
@@ -60,3 +60,2 @@ * Filter a stream by files that match the provided regular expression | ||
/** | ||
@@ -87,3 +86,2 @@ * Pass the first item in the stream through and optionally pass a callback | ||
/** | ||
@@ -117,3 +115,3 @@ * Transform a stream of files into a single JSON file with the filenames as an array | ||
}; | ||
function transform(file, enc, next) { | ||
var transform = function transform(file, enc, next) { | ||
var ext = path.extname(file.relative); | ||
@@ -123,15 +121,14 @@ var name = options.includeExtension !== true ? file.relative.replace(ext, '') : file.relative; | ||
next(null, null); | ||
} | ||
function flush(next) { | ||
}; | ||
var flush = function flush(next) { | ||
var file = new gutil.File({ | ||
path: options.name + '.json', | ||
contents: new Buffer(JSON.stringify(json, null, 2)) | ||
contents: Buffer.from(JSON.stringify(json, null, 2), 'utf8') | ||
}); | ||
this.push(file); | ||
next(); | ||
} | ||
}; | ||
return through.obj(transform, flush); | ||
}, | ||
/** | ||
@@ -149,3 +146,2 @@ * Log the path of each file in the stream | ||
/** | ||
@@ -171,7 +167,7 @@ * Merge a stream of JSON files | ||
var items = [{}]; | ||
function transform(file, enc, next) { | ||
var transform = function transform(file, enc, next) { | ||
var ext = path.extname(file.relative); | ||
if (ext === '.json') { | ||
try { | ||
var json = JSON.parse(file.contents.toString()); | ||
var json = JSON5.parse(file.contents.toString()); | ||
items.push(json); | ||
@@ -184,16 +180,15 @@ } catch (e) { | ||
next(); | ||
} | ||
function flush(next) { | ||
}; | ||
var flush = function flush(next) { | ||
var content = _.merge.apply(null, items); | ||
var file = new gutil.File({ | ||
path: options.name + '.json', | ||
contents: new Buffer(JSON.stringify(content, null, 2)) | ||
contents: Buffer.from(JSON.stringify(content, null, 2), 'utf8') | ||
}); | ||
this.push(file); | ||
next(); | ||
} | ||
}; | ||
return through.obj(transform, flush); | ||
}, | ||
/** | ||
@@ -215,3 +210,2 @@ * Call the provided function for each item in the stream | ||
/** | ||
@@ -229,3 +223,3 @@ * Convert the vinyl '.json' file to a JSON primative | ||
try { | ||
var json = JSON.parse(file.contents.toString()); | ||
var json = JSON5.parse(file.contents.toString()); | ||
if (typeof callback === 'function') { | ||
@@ -241,2 +235,3 @@ callback(json); | ||
} | ||
}; |
{ | ||
"name": "theo", | ||
"version": "5.0.0-beta.5", | ||
"version": "5.0.0-beta.6", | ||
"license": "SEE LICENSE IN README.md", | ||
@@ -22,3 +22,3 @@ "description": "A set of Gulp plugins for transforming and formatting Design Tokens", | ||
"dist": "babel src --out-dir dist", | ||
"test": "npm run dist && mocha --recursive --reporter min --require intelli-espower-loader", | ||
"test": "mocha --recursive --reporter min --require intelli-espower-loader --compilers js:babel-core/register", | ||
"prepublish": "npm run dist", | ||
@@ -46,2 +46,3 @@ "lint": "eslint . --ext .js,.jsx --format codeframe" | ||
"lodash": "^4.17.2", | ||
"no-case": "^2.3.0", | ||
"react": "^15.4.1", | ||
@@ -64,3 +65,2 @@ "react-dom": "^15.4.1", | ||
"mocha": "^3.2.0", | ||
"no-case": "^2.3.0", | ||
"power-assert": "^1.4.2", | ||
@@ -67,0 +67,0 @@ "sinon": "^1.17.6" |
@@ -185,3 +185,3 @@ # <img src="https://raw.githubusercontent.com/salesforce-ux/theo/master/assets/theo.png" alt="Theo logo" width="28" /> Theo | ||
gulp.src('./design/props.json') | ||
.pipe(theo.plugins.transform('web', { | ||
.pipe(theo.plugins.transform('web', { | ||
includeRawValue: true, | ||
@@ -191,3 +191,3 @@ jsonPreProcess: json => { | ||
return json | ||
} | ||
} | ||
})) | ||
@@ -397,3 +397,3 @@ ``` | ||
```json | ||
```json5 | ||
{ | ||
@@ -412,3 +412,3 @@ "props": { | ||
```json | ||
```json5 | ||
{ | ||
@@ -415,0 +415,0 @@ "properties": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79882
12
1467
9
+ Addedno-case@^2.3.0
+ Addedlower-case@1.1.4(transitive)
+ Addedno-case@2.3.2(transitive)