Skip to content

Commit

Permalink
fix(tests): upgrade node-sass to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
Netanel Basal committed May 13, 2018
1 parent 01c3ef2 commit b4e66f5
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 105 deletions.
4 changes: 1 addition & 3 deletions __tests__/test.util.ts
@@ -1,11 +1,9 @@
import {minifyCSS} from "../src/helpers/css.util";

const cleanCSS = require("clean-css");
const glob = require("glob");
const path = require('path');
const fs = require('fs');
const postcss = require('postcss');
const sass = require('postcss-node-sass');
const sass = require('@datorama/postcss-node-sass');

import {ProcessOptions} from "postcss";
import palette from './palettes/palette';
Expand Down
1 change: 1 addition & 0 deletions dist/helpers/css.util.d.ts
@@ -0,0 +1 @@
export declare function minifyCSS(css: any): string;
8 changes: 8 additions & 0 deletions dist/helpers/css.util.js
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _cleanCSS = require('clean-css');
var cleanCSS = new _cleanCSS({});
function minifyCSS(css) {
return cleanCSS.minify(css).styles;
}
exports.minifyCSS = minifyCSS;
96 changes: 67 additions & 29 deletions dist/index.js
Expand Up @@ -9,13 +9,12 @@ var __assign = (this && this.__assign) || Object.assign || function(t) {
};
Object.defineProperty(exports, "__esModule", { value: true });
var json_util_1 = require("./helpers/json.util");
var css_util_1 = require("./helpers/css.util");
var postcss = require('postcss');
var fs = require('fs-extra');
var hexToRgba = require('hex-to-rgba');
var THEMIFY = 'themify';
var JSToSass = require('./helpers/js-sass');
var _cleanCSS = require('clean-css');
var cleanCSS = new _cleanCSS();
var defaultOptions = {
createVars: true,
palette: {},
Expand Down Expand Up @@ -165,6 +164,9 @@ function themify(options) {
*/
function processRules(root) {
root.walkRules(function (rule) {
if (!hasThemify(rule.toString())) {
return;
}
var aggragatedSelectorsMap = {};
var aggragatedSelectors = [];
var createdRules = [];
Expand All @@ -180,9 +182,9 @@ function themify(options) {
var defaultVariationValue = variationValueMap[defaultVariation];
decl.value = defaultVariationValue;
// indicate if we have a global rule, that cannot be nested
var isGlobalRule = rule.parent && rule.parent.type === 'atrule' && /keyframes/.test(rule.parent.name);
var createNonDefaultVariationRules = isAtRule(rule);
// don't create extra CSS for global rules
if (isGlobalRule) {
if (createNonDefaultVariationRules) {
return;
}
// create a new declaration and append it to each rule
Expand Down Expand Up @@ -225,6 +227,14 @@ function themify(options) {
var _a;
});
}
/**
* indicate if we have a global rule, that cannot be nested
* @param rule
* @return {boolean}
*/
function isAtRule(rule) {
return rule.parent && rule.parent.type === 'atrule';
}
/**
* Walk through all rules, and generate a CSS fallback for legacy browsers.
* Two files shall be created for full compatibility:
Expand All @@ -243,14 +253,64 @@ function themify(options) {
variationValues.forEach(function (variation) { return (output["DYNAMIC_EXPRESSION" /* DYNAMIC_EXPRESSION */][variation] = []); });
// define which modes need to be processed
var execModes = ["CSS_COLOR" /* CSS_COLOR */, "DYNAMIC_EXPRESSION" /* DYNAMIC_EXPRESSION */];
walkFallbackAtRules(root, execModes, output);
walkFallbackRules(root, execModes, output);
writeFallbackCSS(output);
var _a;
}
function writeFallbackCSS(output) {
// write the CSS & JSON to external files
if (output["CSS_COLOR" /* CSS_COLOR */].length) {
// write CSS fallback;
var fallbackCss = output["CSS_COLOR" /* CSS_COLOR */].join('');
writeToFile(options.fallback.cssPath, css_util_1.minifyCSS(fallbackCss));
// creating a JSON for the dynamic expressions
var jsonOutput_1 = {};
variationValues.forEach(function (variationName) {
jsonOutput_1[variationName] = output["DYNAMIC_EXPRESSION" /* DYNAMIC_EXPRESSION */][variationName] || [];
jsonOutput_1[variationName] = json_util_1.minifyJSON(jsonOutput_1[variationName].join(''));
// minify the CSS output
jsonOutput_1[variationName] = css_util_1.minifyCSS(jsonOutput_1[variationName]);
});
// stringify and save
var dynamicCss = JSON.stringify(jsonOutput_1);
writeToFile(options.fallback.dynamicPath, dynamicCss);
}
}
function walkFallbackAtRules(root, execModes, output) {
root.walkAtRules(function (atRule) {
if (atRule.nodes && hasThemify(atRule.toString())) {
execModes.forEach(function (mode) {
var clonedAtRule = atRule.clone();
clonedAtRule.nodes.forEach(function (rule) {
rule.walkDecls(function (decl) {
var propertyValue = decl.value;
// replace the themify token, if exists
if (hasThemify(propertyValue)) {
var colorMap = getThemifyValue(propertyValue, mode);
decl.value = colorMap[defaultVariation];
}
});
});
var rulesOutput = mode === "DYNAMIC_EXPRESSION" /* DYNAMIC_EXPRESSION */ ? output[mode][defaultVariation] : output[mode];
rulesOutput.push(clonedAtRule);
});
}
});
}
function walkFallbackRules(root, execModes, output) {
root.walkRules(function (rule) {
if (isAtRule(rule) || !hasThemify(rule.toString())) {
return;
}
var ruleModeMap = {};
rule.walkDecls(function (decl) {
var propertyValue = decl.value;
if (!hasThemify(propertyValue))
return;
var property = decl.prop;
execModes.forEach(function (mode) {
var colorMap = getThemifyValue(propertyValue, mode);
// lazily creating a new rule for each variation, for the specific mode
if (!ruleModeMap.hasOwnProperty(mode)) {
ruleModeMap[mode] = {};
Expand All @@ -264,15 +324,11 @@ function themify(options) {
}
// push the new rule into the right place,
// so we can write them later to external file
var rulesOutput = output[mode];
if (!Array.isArray(rulesOutput)) {
rulesOutput = rulesOutput[variationName];
}
var rulesOutput = mode === "DYNAMIC_EXPRESSION" /* DYNAMIC_EXPRESSION */ ? output[mode][variationName] : output[mode];
rulesOutput.push(newRule);
ruleModeMap[mode][variationName] = newRule;
});
}
var colorMap = getThemifyValue(propertyValue, mode);
// create and append a new declaration
variationValues.forEach(function (variationName) {
var underlineColor = colorMap[variationName];
Expand All @@ -284,24 +340,6 @@ function themify(options) {
});
});
});
// write the CSS & JSON to external files
if (output["CSS_COLOR" /* CSS_COLOR */].length) {
// write CSS fallback;
var fallbackCss = output["CSS_COLOR" /* CSS_COLOR */].join('');
writeToFile(options.fallback.cssPath, fallbackCss);
// creating a JSON for the dynamic expressions
var jsonOutput_1 = {};
variationValues.forEach(function (variationName) {
jsonOutput_1[variationName] = output["DYNAMIC_EXPRESSION" /* DYNAMIC_EXPRESSION */][variationName] || [];
jsonOutput_1[variationName] = json_util_1.minifyJSON(jsonOutput_1[variationName].join(''));
// minify the CSS output
jsonOutput_1[variationName] = cleanCSS.minify(jsonOutput_1[variationName]).styles;
});
// stringify and save
var dynamicCss = JSON.stringify(jsonOutput_1);
writeToFile(options.fallback.dynamicPath, dynamicCss);
}
var _a;
}
function createDecl(prop, value) {
return postcss.decl({ prop: prop, value: value });
Expand Down Expand Up @@ -335,8 +373,8 @@ function themify(options) {
})
.join(',');
}
function cloneEmptyRule(rule) {
var clonedRule = rule.clone();
function cloneEmptyRule(rule, overrideConfig) {
var clonedRule = rule.clone(overrideConfig);
// remove all the declaration from this rule
clonedRule.removeAll();
return clonedRule;
Expand Down
51 changes: 42 additions & 9 deletions dist/package.json
@@ -1,27 +1,28 @@
{
"name": "@datorama/themify",
"version": "0.2.0-beta",
"description": "CSS themes made easy",
"version": "0.0.0-development",
"description": "CSS themes made easy. A robust, opinionated solution to manage themes in your web application",
"main": "index.js",
"gh-pages-deploy": {
"staticpath": "playground",
"commit": "pages"
},
"scripts": {
"setup": "semantic-release-cli setup",
"github-pages": "gh-pages-deploy",
"contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate",
"play": "cross-env NODE_ENV=test gulp --gulpfile ./playground/gulpfile.js",
"play": "gulp --gulpfile ./playground/gulpfile.js",
"commit": "git-cz",
"build": "npm run sass:support && npm run clean:dist && tsc && npm run copy:dist",
"build": "npm run clean:dist && tsc && npm run copy:dist",
"copy:dist": "cp -R src/sass/. package.json dist",
"clean:dist": "rimraf dist",
"format": "prettier --write --config .prettierrc src/*.ts src/**/*.ts playground/*.js",
"test": "cross-env NODE_ENV=test npm run sass:support && jest",
"test": "jest",
"commitmsg": "commitlint -e $GIT_PARAMS",
"precommit": "lint-staged",
"sass:support": "node replace.js",
"ts": "gulp --gulpfile playground/gulpfile.js ts"
"travis-deploy-once": "travis-deploy-once",
"semantic-release": "semantic-release"
},
"jest": {
"moduleFileExtensions": [
Expand Down Expand Up @@ -56,9 +57,15 @@
"path": "./node_modules/cz-conventional-changelog"
}
},
"dependencies": {
"@datorama/postcss-node-sass": "^1.0.0"
},
"devDependencies": {
"@commitlint/cli": "^6.1.3",
"@commitlint/config-angular": "^6.1.3",
"@semantic-release/changelog": "^2.0.1",
"@semantic-release/git": "^4.0.1",
"@semantic-release/npm": "^3.2.2",
"@types/jest": "^22.2.0",
"@types/node": "^9.4.6",
"all-contributors-cli": "^4.11.1",
Expand All @@ -79,12 +86,38 @@
"lint-staged": "^7.0.0",
"node-sass": "^4.8.3",
"postcss": "^6.0.19",
"postcss-node-sass": "2.1.4",
"prettier": "^1.11.1",
"replace-in-file": "^3.4.0",
"rimraf": "^2.6.2",
"semantic-release": "^15.3.1",
"semantic-release-cli": "^4.0.1",
"tmp": "0.0.33",
"travis-deploy-once": "^5.0.0",
"ts-jest": "^22.4.1",
"typescript": "^2.7.2"
},
"release": {
"verifyConditions": [
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git"
],
"prepare": [
"@semantic-release/changelog",
{
"path": "@semantic-release/npm",
"pkgRoot": "dist"
},
"@semantic-release/git"
],
"publish": [
{
"path": "@semantic-release/npm",
"pkgRoot": "dist"
}
]
},
"repository": {
"type": "git",
"url": "https://github.com/datorama/themify.git"
}
}
Empty file added dist/rule-processor.d.ts
Empty file.
1 change: 1 addition & 0 deletions dist/rule-processor.js
@@ -0,0 +1 @@
"use strict";
20 changes: 9 additions & 11 deletions package.json
Expand Up @@ -12,16 +12,15 @@
"github-pages": "gh-pages-deploy",
"contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate",
"play": "cross-env NODE_ENV=test gulp --gulpfile ./playground/gulpfile.js",
"play": "gulp --gulpfile ./playground/gulpfile.js",
"commit": "git-cz",
"build": "npm run sass:support && npm run clean:dist && tsc && npm run copy:dist",
"build": "npm run clean:dist && tsc && npm run copy:dist",
"copy:dist": "cp -R src/sass/. package.json dist",
"clean:dist": "rimraf dist",
"format": "prettier --write --config .prettierrc src/*.ts src/**/*.ts playground/*.js",
"test": "cross-env NODE_ENV=test npm run sass:support && jest",
"test": "jest",
"commitmsg": "commitlint -e $GIT_PARAMS",
"precommit": "lint-staged",
"sass:support": "node replace.js",
"travis-deploy-once": "travis-deploy-once",
"semantic-release": "semantic-release"
},
Expand Down Expand Up @@ -61,6 +60,10 @@
"devDependencies": {
"@commitlint/cli": "^6.1.3",
"@commitlint/config-angular": "^6.1.3",
"@datorama/postcss-node-sass": "^1.0.0",
"@semantic-release/changelog": "^2.0.1",
"@semantic-release/git": "^4.0.1",
"@semantic-release/npm": "^3.2.2",
"@types/jest": "^22.2.0",
"@types/node": "^9.4.6",
"all-contributors-cli": "^4.11.1",
Expand All @@ -81,19 +84,14 @@
"lint-staged": "^7.0.0",
"node-sass": "^4.8.3",
"postcss": "^6.0.19",
"postcss-node-sass": "2.1.4",
"prettier": "^1.11.1",
"replace-in-file": "^3.4.0",
"rimraf": "^2.6.2",
"semantic-release": "^15.3.1",
"semantic-release-cli": "^4.0.1",
"tmp": "0.0.33",
"travis-deploy-once": "^5.0.0",
"ts-jest": "^22.4.1",
"typescript": "^2.7.2",
"@semantic-release/changelog": "^2.0.1",
"@semantic-release/git": "^4.0.1",
"@semantic-release/npm": "^3.2.2",
"travis-deploy-once": "^5.0.0"
"typescript": "^2.7.2"
},
"release": {
"verifyConditions": [
Expand Down
2 changes: 1 addition & 1 deletion playground/gulpfile.js
@@ -1,5 +1,5 @@
const rename = require('gulp-rename');
const sass = require('postcss-node-sass');
const sass = require('@datorama/postcss-node-sass');
const postcss = require('gulp-postcss');
const gulp = require('gulp');
const { initThemify, themify } = require('../dist');
Expand Down
25 changes: 0 additions & 25 deletions replace.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/sass/encode/encode/api/_json.scss
Expand Up @@ -14,7 +14,7 @@
$type: type-of($value);

@if function-exists('_json-encode--#{$type}') {
@return call('_json-encode--#{$type}', $value);
@return call(get-function('_json-encode--#{$type}'), $value);
}

@error 'Unknown type for #{$value} (#{$type}).';
Expand Down

0 comments on commit b4e66f5

Please sign in to comment.