From 73b945e8f6c81b5aa6d81022382d6512019508c7 Mon Sep 17 00:00:00 2001 From: indexzero Date: Tue, 11 Apr 2017 17:33:23 -0700 Subject: [PATCH 1/9] [fix] Update babel usage to be modern. --- package.json | 3 ++- src/jsonSass.js | 5 +++++ src/test-init.js | 5 ++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index a2bc62f..f97371c 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "author": "Andrew Clark ", "license": "ISC", "dependencies": { - "babel": "~4.1.0", "lodash": "~2.4.1", "lodash-node": "~2.4.1", "minimist": "~1.1.0", @@ -23,6 +22,8 @@ "through2": "~0.6.3" }, "devDependencies": { + "babel-cli": "^6.24.1", + "babel-polyfill": "^6.23.0", "chai": "~1.9.2", "mocha": "~2.0.1" } diff --git a/src/jsonSass.js b/src/jsonSass.js index 77e958d..95f0141 100644 --- a/src/jsonSass.js +++ b/src/jsonSass.js @@ -21,6 +21,11 @@ function jsonSass(options) { }); } +// +// Cover all require use cases. +// +jsonSass.convertJs = jsToSassString; module.exports = jsonSass; + export default jsonSass; export { jsToSassString as convertJs }; diff --git a/src/test-init.js b/src/test-init.js index 399332b..00ff120 100644 --- a/src/test-init.js +++ b/src/test-init.js @@ -1,4 +1,3 @@ -import 'babel/polyfill'; +require('babel-polyfill'); -import { expect } from 'chai'; -global.expect = expect; +global.expect = require('chai').expect; From 650a11bdf75f0e84e497b0d8ed0e6d2bdc51f123 Mon Sep 17 00:00:00 2001 From: Frederik Bosch Date: Wed, 16 Nov 2016 17:30:37 +0100 Subject: [PATCH 2/9] Quote every non color string --- src/__tests__/jsToSassString-test.js | 4 ++-- src/jsToSassString.js | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/__tests__/jsToSassString-test.js b/src/__tests__/jsToSassString-test.js index 25331a5..d115f29 100644 --- a/src/__tests__/jsToSassString-test.js +++ b/src/__tests__/jsToSassString-test.js @@ -13,7 +13,7 @@ var foo = new Foo(); describe('JS to Sass', function() { it('should handle strings', function() { - expect(jsToSassString('foo')).to.equal('foo'); + expect(jsToSassString('foo')).to.equal('"foo"'); }); it('should handle booleans', function() { @@ -49,6 +49,6 @@ describe('JS to Sass', function() { }, }; - expect(jsToSassString(obj)).to.equal('(\n foo: bar,\n bar: (\n baz: foo\n )\n)') + expect(jsToSassString(obj)).to.equal('(\n foo: "bar",\n bar: (\n baz: "foo"\n )\n)') }) }); diff --git a/src/jsToSassString.js b/src/jsToSassString.js index a6553e9..d3aab72 100644 --- a/src/jsToSassString.js +++ b/src/jsToSassString.js @@ -13,7 +13,7 @@ function jsToSassString(value) { case 'number': return value.toString(); case 'string': - return value; + return quoteString(value); case 'object': if (isPlainObject(value)) { indentLevel += 1; @@ -68,4 +68,11 @@ function isNotUndefined(value) { return typeof value !== 'undefined'; } +function quoteString(value) { + if (value.substring(0,1) === '#') { + return value; + } + return "\"" + value + "\""; +} + export default jsToSassString; From ca09d4cb9ba629dba13ebf61c985b4cc45ac7083 Mon Sep 17 00:00:00 2001 From: indexzero Date: Tue, 11 Apr 2017 17:42:20 -0700 Subject: [PATCH 3/9] [fix doc] Correct json example in readme (copy / paste from #12) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 32a6465..9bbcdbb 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Example source file `theme.json`: "array": [1, 2, 3], "object": { "foo": "bar" - } + }, "null": null } From b82ec1f126415641e56ee60ec6469a79e98514e3 Mon Sep 17 00:00:00 2001 From: Brian Deitte Date: Tue, 8 Dec 2015 09:11:55 -0500 Subject: [PATCH 4/9] Catch JSON.parse error --- src/jsonSass.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/jsonSass.js b/src/jsonSass.js index 95f0141..4c0852d 100644 --- a/src/jsonSass.js +++ b/src/jsonSass.js @@ -13,7 +13,13 @@ function jsonSass(options) { let options = assign({}, DEFAULTS, options); return through(function(chunk, enc, callback) { - let jsValue = JSON.parse(chunk); + let jsValue; + try { + jsValue = JSON.parse(chunk); + } + catch (err) { + return callback(err); + } let sassString = jsToSassString(jsValue); sassString = options.prefix + sassString + options.suffix; this.push(sassString); From 7a560282ed1b99992709d17c24341bd96c24bdb6 Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 8 Jul 2015 14:48:59 -0500 Subject: [PATCH 5/9] Add repository field to package.json When installing this package via npm, I get the following warning: > npm WARN package.json json-sass@1.3.5 No repository field. Documentation: https://docs.npmjs.com/files/package.json#repository Adding this field to the package.json file should make this warning disappear. Fixes #3. --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index f97371c..a039102 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,10 @@ ], "author": "Andrew Clark ", "license": "ISC", + "repository": { + "type": "git", + "url": "https://github.com/acdlite/json-sass.git" + }, "dependencies": { "lodash": "~2.4.1", "lodash-node": "~2.4.1", From 5d62f9cdde21f47039ab4b7116b1a5b51cb357f4 Mon Sep 17 00:00:00 2001 From: indexzero Date: Tue, 11 Apr 2017 17:49:02 -0700 Subject: [PATCH 6/9] [fix] Various transpilation errors. --- src/jsToSassString.js | 7 ++++--- src/jsonSass.js | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/jsToSassString.js b/src/jsToSassString.js index d3aab72..8f66470 100644 --- a/src/jsToSassString.js +++ b/src/jsToSassString.js @@ -39,10 +39,11 @@ function jsToSassString(value) { return result; } else if (isArray(value)) { - let sassVals = [ - for (v of value) if (isNotUndefined(v)) + const sassVals = value.map(v => { + if (isNotUndefined(v)) { _jsToSassString(v, indentLevel) - ]; + } + }).filter(Boolean); return '(' + sassVals.join(', ') + ')'; } diff --git a/src/jsonSass.js b/src/jsonSass.js index 4c0852d..6ec1c0c 100644 --- a/src/jsonSass.js +++ b/src/jsonSass.js @@ -9,8 +9,8 @@ let DEFAULTS = { suffix: ';', }; -function jsonSass(options) { - let options = assign({}, DEFAULTS, options); +function jsonSass(opts) { + const options = assign({}, DEFAULTS, opts); return through(function(chunk, enc, callback) { let jsValue; From 82df5efc7cdeccc92b0ab04b39739c8bb7416685 Mon Sep 17 00:00:00 2001 From: indexzero Date: Tue, 11 Apr 2017 17:55:39 -0700 Subject: [PATCH 7/9] [refactor] Move to `npm` scripts instead of Make. --- Makefile | 23 ----------------------- package.json | 13 +++++++++++-- 2 files changed, 11 insertions(+), 25 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 451999c..0000000 --- a/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -BABEL_CMD=./node_modules/.bin/babel -MOCHA_CMD=./node_modules/.bin/mocha - -SRC_JS = $(shell find src -name "*.js") -LIB_JS = $(patsubst src/%.js,lib/%.js,$(SRC_JS)) - -build: js - -test: build - $(MOCHA_CMD) lib/**/__tests__/*-test.js --require ./lib/test-init.js - -js: $(LIB_JS) lib/bin/json-sass - -$(LIB_JS): lib/%.js: src/%.js - mkdir -p $(dir $@) && $(BABEL_CMD) $< -o $@ --experimental - -lib/bin/json-sass: - mkdir -p $(dir $@) && $(BABEL_CMD) src/bin/json-sass -o $@ --experimental - -clean: - rm -rf lib/ - -.PHONY: build test js clean diff --git a/package.json b/package.json index a039102..c84c320 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,10 @@ "main": "lib/jsonSass.js", "bin": "lib/bin/json-sass", "scripts": { - "test": "make test", - "prepublish": "npm test" + "build": "rm -rf lib && babel ./src -d ./lib", + "pretest": "npm run build", + "test": "mocha --require ./lib/test-init.js lib/**/__tests__/*-test.js", + "prepublish": "in-install || npm test" }, "keywords": [ "sass", @@ -18,7 +20,13 @@ "type": "git", "url": "https://github.com/acdlite/json-sass.git" }, + "babel": { + "presets": [ + "babel-preset-es2015" + ] + }, "dependencies": { + "in-publish": "^2.0.0", "lodash": "~2.4.1", "lodash-node": "~2.4.1", "minimist": "~1.1.0", @@ -28,6 +36,7 @@ "devDependencies": { "babel-cli": "^6.24.1", "babel-polyfill": "^6.23.0", + "babel-preset-es2015": "^6.24.1", "chai": "~1.9.2", "mocha": "~2.0.1" } From ddb99a2d311b8f0aeaf140e25b60eae47e70a7f7 Mon Sep 17 00:00:00 2001 From: indexzero Date: Tue, 11 Apr 2017 17:55:55 -0700 Subject: [PATCH 8/9] [fix] Add missing `return`. --- src/jsToSassString.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jsToSassString.js b/src/jsToSassString.js index 8f66470..a03be72 100644 --- a/src/jsToSassString.js +++ b/src/jsToSassString.js @@ -41,7 +41,7 @@ function jsToSassString(value) { else if (isArray(value)) { const sassVals = value.map(v => { if (isNotUndefined(v)) { - _jsToSassString(v, indentLevel) + return _jsToSassString(v, indentLevel) } }).filter(Boolean); From 758fb7c1929e63619d13ad2b99d4a9b38857dc90 Mon Sep 17 00:00:00 2001 From: indexzero Date: Tue, 11 Apr 2017 18:10:54 -0700 Subject: [PATCH 9/9] [fix] Do not transpile bin/ for a single `import` statement. --- {src/bin => bin}/json-sass | 18 +++++++++--------- package.json | 7 +++++-- 2 files changed, 14 insertions(+), 11 deletions(-) rename {src/bin => bin}/json-sass (86%) diff --git a/src/bin/json-sass b/bin/json-sass similarity index 86% rename from src/bin/json-sass rename to bin/json-sass index 3e9dedd..0963347 100755 --- a/src/bin/json-sass +++ b/bin/json-sass @@ -6,17 +6,17 @@ let jsonSass = require('../jsonSass'); let fs = require('fs'); let path = require('path'); let minimist = require('minimist'); -import { Readable } from 'stream'; +let Readable = require('stream').Readable; let argv = minimist(process.argv.slice(2), { - alias: { - i: 'infile', - o: 'outfile', - h: 'help', - p: 'prefix', - s: 'suffix', - }, - default: { i: '-', o: '-' } + alias: { + i: 'infile', + o: 'outfile', + h: 'help', + p: 'prefix', + s: 'suffix', + }, + default: { i: '-', o: '-' } }); if (argv.help) return showHelp(0); diff --git a/package.json b/package.json index c84c320..f004997 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "json-sass", "version": "1.3.5", - "description": "Transform JSON into scss syntax Sass.", + "description": "Transform JSON into SCSS variable syntax.", "main": "lib/jsonSass.js", - "bin": "lib/bin/json-sass", + "bin": "bin/json-sass", "scripts": { "build": "rm -rf lib && babel ./src -d ./lib", "pretest": "npm run build", @@ -16,6 +16,9 @@ ], "author": "Andrew Clark ", "license": "ISC", + "contributors": [ + "Charlie Robbins " + ], "repository": { "type": "git", "url": "https://github.com/acdlite/json-sass.git"