Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,50 @@
# 2.4.0
* Adds support for reducing `grid` identifiers
(thanks to @sylvainpolletvillard).
# 2.3.1
* Performance tweaks: now performs one AST pass instead of three.
# 2.3.0
* Adds support for a custom encoder function (thanks to @rauchg).
# 2.2.2
* Now compiled with babel 6.
# 2.2.1
* Updates postcss-value-parser to version 3 (thanks to @TrySound).
# 2.2.0
* Added options for customising what the module reduces (thanks to @TrySound).
* Replaced regex number test with postcss-value-parser unit method.
# 2.1.0
* Replaced reduce-function-call with postcss-value-parser (thanks to @TrySound).
# 2.0.0
* Upgraded to PostCSS 5.
# 1.0.3
* Improved performance by iterating the AST less times.
# 1.0.2
* Fixes an issue where multiple, comma separated animations with insufficient
whitespace were not being renamed.
# 1.0.1
* Documentation/metadata tweaks for plugin guidelines compatibility.
# 1.0.0
* Initial release.

View File

@@ -0,0 +1,22 @@
Copyright (c) Ben Briggs <beneb.info@gmail.com> (http://beneb.info)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,149 @@
# [postcss][postcss]-reduce-idents [![Build Status](https://travis-ci.org/ben-eb/postcss-reduce-idents.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/postcss-reduce-idents.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/postcss-reduce-idents.svg)][deps]
> Reduce [custom identifiers][idents] with PostCSS.
## Install
With [npm](https://npmjs.org/package/postcss-reduce-idents) do:
```
npm install postcss-reduce-idents --save
```
## Example
### Input
This module will rename custom identifiers in your CSS files; it does so by
converting each name to a index, which is then encoded into a legal identifier.
A legal custom identifier in CSS is case sensitive and must start with a
letter, but can contain digits, hyphens and underscores. There are over 3,000
possible two character identifiers, and 51 possible single character identifiers
that will be generated.
```css
@keyframes whiteToBlack {
0% {
color: #fff
}
to {
color: #000
}
}
.one {
animation-name: whiteToBlack
}
```
### Output
```css
@keyframes a {
0% {
color: #fff
}
to {
color: #000
}
}
.one {
animation-name: a
}
```
Note that this module does not handle identifiers that are not linked together.
The following example will not be transformed in any way:
```css
@keyframes fadeOut {
0% { opacity: 1 }
to { opacity: 0 }
}
.fadeIn {
animation-name: fadeIn;
}
```
It works for `@keyframes`, `@counter-style`, custom `counter` values and grid area definitions. See the
[documentation][idents] for more information, or the [tests](test.js) for more
examples.
## Usage
See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
examples for your environment.
## API
### reduceIdents([options])
#### options
##### counter
Type: `boolean`
Default: `true`
Pass `false` to disable reducing `content`, `counter-reset` and `counter-increment` declarations.
##### keyframes
Type: `boolean`
Default: `true`
Pass `false` to disable reducing `keyframes` rules and `animation` declarations.
##### counterStyle
Type: `boolean`
Default: `true`
Pass `false` to disable reducing `counter-style` rules and `list-style` and `system` declarations.
##### gridTemplate
Type: `boolean`
Default: `true`
Pass `false` to disable reducing `grid-template`, `grid-area` and `grid-template-areas` declarations.
##### encoder
Type: `function`
Default: [`lib/encode.js`](https://github.com/ben-eb/postcss-reduce-idents/blob/master/src/lib/encode.js)
Pass a custom function to encode the identifier with (e.g.: as a way of prefixing them automatically).
It receives two parameters:
- A `String` with the node value.
- A `Number` identifying the index of the occurrence.
## Contributors
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub>Ben Briggs</sub>](http://beneb.info)<br />[💻](https://github.com/ben-eb/postcss-reduce-idents/commits?author=ben-eb) [📖](https://github.com/ben-eb/postcss-reduce-idents/commits?author=ben-eb) 👀 [⚠️](https://github.com/ben-eb/postcss-reduce-idents/commits?author=ben-eb) | [<img src="https://avatars.githubusercontent.com/u/5635476?v=3" width="100px;"/><br /><sub>Bogdan Chadkin</sub>](https://github.com/TrySound)<br />[⚠️](https://github.com/ben-eb/postcss-reduce-idents/commits?author=TrySound) [💻](https://github.com/ben-eb/postcss-reduce-idents/commits?author=TrySound) | [<img src="https://avatars.githubusercontent.com/u/13041?v=3" width="100px;"/><br /><sub>Guillermo Rauch</sub>](http://twitter.com/rauchg)<br />[💻](https://github.com/ben-eb/postcss-reduce-idents/commits?author=rauchg) [📖](https://github.com/ben-eb/postcss-reduce-idents/commits?author=rauchg) [⚠️](https://github.com/ben-eb/postcss-reduce-idents/commits?author=rauchg) | [<img src="https://avatars.githubusercontent.com/u/566536?v=3" width="100px;"/><br /><sub>Sylvain Pollet-Villard</sub>](https://github.com/sylvainpolletvillard)<br />[💻](https://github.com/ben-eb/postcss-reduce-idents/commits?author=sylvainpolletvillard) [📖](https://github.com/ben-eb/postcss-reduce-idents/commits?author=sylvainpolletvillard) [⚠️](https://github.com/ben-eb/postcss-reduce-idents/commits?author=sylvainpolletvillard) |
| :---: | :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
## License
MIT © [Ben Briggs](http://beneb.info)
[ci]: https://travis-ci.org/ben-eb/postcss-reduce-idents
[deps]: https://gemnasium.com/ben-eb/postcss-reduce-idents
[idents]: https://developer.mozilla.org/en-US/docs/Web/CSS/custom-ident
[npm]: http://badge.fury.io/js/postcss-reduce-idents
[postcss]: https://github.com/postcss/postcss

View File

@@ -0,0 +1,62 @@
'use strict';
exports.__esModule = true;
var _postcss = require('postcss');
var _postcss2 = _interopRequireDefault(_postcss);
var _encode = require('./lib/encode');
var _encode2 = _interopRequireDefault(_encode);
var _counter = require('./lib/counter');
var _counter2 = _interopRequireDefault(_counter);
var _counterStyle = require('./lib/counter-style');
var _counterStyle2 = _interopRequireDefault(_counterStyle);
var _keyframes = require('./lib/keyframes');
var _keyframes2 = _interopRequireDefault(_keyframes);
var _gridTemplate = require('./lib/grid-template');
var _gridTemplate2 = _interopRequireDefault(_gridTemplate);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = _postcss2.default.plugin('postcss-reduce-idents', function () {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$counter = _ref.counter,
counter = _ref$counter === undefined ? true : _ref$counter,
_ref$counterStyle = _ref.counterStyle,
counterStyle = _ref$counterStyle === undefined ? true : _ref$counterStyle,
_ref$keyframes = _ref.keyframes,
keyframes = _ref$keyframes === undefined ? true : _ref$keyframes,
_ref$gridTemplate = _ref.gridTemplate,
gridTemplate = _ref$gridTemplate === undefined ? true : _ref$gridTemplate,
_ref$encoder = _ref.encoder,
encoder = _ref$encoder === undefined ? _encode2.default : _ref$encoder;
var reducers = [];
counter && reducers.push(_counter2.default);
counterStyle && reducers.push(_counterStyle2.default);
keyframes && reducers.push(_keyframes2.default);
gridTemplate && reducers.push(_gridTemplate2.default);
return function (css) {
css.walk(function (node) {
reducers.forEach(function (reducer) {
return reducer.collect(node, encoder);
});
});
reducers.forEach(function (reducer) {
return reducer.transform();
});
};
});
module.exports = exports['default'];

View File

@@ -0,0 +1,15 @@
"use strict";
exports.__esModule = true;
exports.default = function (value, encoder, cache) {
if (cache[value]) {
return;
}
cache[value] = {
ident: encoder(value, Object.keys(cache).length),
count: 0
};
};
module.exports = exports["default"];

View File

@@ -0,0 +1,65 @@
"use strict";
exports.__esModule = true;
var _postcssValueParser = require("postcss-value-parser");
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
var _cache = require("./cache");
var _cache2 = _interopRequireDefault(_cache);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var RESERVED_KEYWORDS = ["unset", "initial", "inherit", "none", "inline", "outside", "disc", "circle", "square", "decimal", "cjk-decimal", "decimal-leading-zero", "lower-roman", "upper-roman", "lower-greek", "lower-alpha", "lower-latin", "upper-alpha", "upper-latin", "arabic-indic", "armenian", "bengali", "cambodian", "cjk-earthly-branch", "cjk-heavenly-stem", "cjk-ideographic", "devanagari", "ethiopic-numeric", "georgian", "gujarati", "gurmukhi", "hebrew", "hiragana", "hiragana-iroha", "japanese-formal", "japanese-informal", "kannada", "katakana", "katakana-iroha", "khmer", "korean-hangul-formal", "korean-hanja-formal", "korean-hanja-informal", "lao", "lower-armenian", "malayalam", "mongolian", "myanmar", "oriya", "persian", "simp-chinese-formal", "simp-chinese-informal", "tamil", "telugu", "thai", "tibetan", "trad-chinese-formal", "trad-chinese-informal", "upper-armenian", "disclosure-open", "disclosure-close"];
var cache = {};
var atRules = [];
var decls = [];
exports.default = {
collect: function collect(node, encoder) {
var name = node.name,
prop = node.prop,
type = node.type;
if (type === 'atrule' && /counter-style/.test(name) && RESERVED_KEYWORDS.indexOf(node.params) === -1) {
(0, _cache2.default)(node.params, encoder, cache);
atRules.push(node);
}
if (type === 'decl' && /(list-style|system)/.test(prop)) {
decls.push(node);
}
},
transform: function transform() {
// Iterate each property and change their names
decls.forEach(function (decl) {
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(function (node) {
if (node.type === 'word' && node.value in cache) {
cache[node.value].count++;
node.value = cache[node.value].ident;
} else if (node.type === 'space') {
node.value = ' ';
} else if (node.type === 'div') {
node.before = node.after = '';
}
}).toString();
});
// Iterate each at rule and change their name if references to them have been found
atRules.forEach(function (rule) {
var cached = cache[rule.params];
if (cached && cached.count > 0) {
rule.params = cached.ident;
}
});
// reset cache after transform
cache = {};
atRules = [];
decls = [];
}
};
module.exports = exports["default"];

View File

@@ -0,0 +1,92 @@
"use strict";
exports.__esModule = true;
var _postcssValueParser = require("postcss-value-parser");
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
var _cache = require("./cache");
var _cache2 = _interopRequireDefault(_cache);
var _isNum = require("./isNum");
var _isNum2 = _interopRequireDefault(_isNum);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var RESERVED_KEYWORDS = ["unset", "initial", "inherit", "none"];
var cache = {};
var declOneCache = [];
var declTwoCache = [];
exports.default = {
collect: function collect(node, encoder) {
var prop = node.prop,
type = node.type;
if (type !== 'decl') {
return;
}
if (/counter-(reset|increment)/.test(prop)) {
node.value = (0, _postcssValueParser2.default)(node.value).walk(function (child) {
if (child.type === 'word' && !(0, _isNum2.default)(child) && RESERVED_KEYWORDS.indexOf(child.value) === -1) {
(0, _cache2.default)(child.value, encoder, cache);
child.value = cache[child.value].ident;
}
if (child.type === 'space') {
child.value = ' ';
}
});
declOneCache.push(node);
} else if (/content/.test(prop)) {
declTwoCache.push(node);
}
},
transform: function transform() {
declTwoCache.forEach(function (decl) {
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(function (node) {
var type = node.type,
value = node.value;
if (type === 'function' && (value === 'counter' || value === 'counters')) {
(0, _postcssValueParser.walk)(node.nodes, function (child) {
if (child.type === 'word' && child.value in cache) {
cache[child.value].count++;
child.value = cache[child.value].ident;
} else if (child.type === 'div') {
child.before = child.after = '';
}
});
}
if (type === 'space') {
node.value = ' ';
}
return false;
}).toString();
});
declOneCache.forEach(function (decl) {
decl.value = decl.value.walk(function (node) {
if (node.type === 'word' && !(0, _isNum2.default)(node)) {
Object.keys(cache).forEach(function (key) {
var cached = cache[key];
if (cached.ident === node.value && !cached.count) {
node.value = key;
}
});
}
}).toString();
});
// reset cache after transform
cache = {};
declOneCache = [];
declTwoCache = [];
}
};
module.exports = exports["default"];

View File

@@ -0,0 +1,22 @@
'use strict';
exports.__esModule = true;
exports.default = encode;
function encode(val, num) {
var base = 52;
var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var character = num % base;
var result = characters[character];
var remainder = Math.floor(num / base);
if (remainder) {
base = 64;
characters = characters + '0123456789-_';
while (remainder) {
character = remainder % base;
remainder = Math.floor(remainder / base);
result = result + characters[character];
}
}
return result;
};
module.exports = exports['default'];

View File

@@ -0,0 +1,78 @@
"use strict";
exports.__esModule = true;
var _postcssValueParser = require("postcss-value-parser");
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
var _cache = require("./cache");
var _cache2 = _interopRequireDefault(_cache);
var _isNum = require("./isNum");
var _isNum2 = _interopRequireDefault(_isNum);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var RESERVED_KEYWORDS = ["auto", "span", "inherit", "initial", "unset"];
var cache = {};
var declCache = [];
exports.default = {
collect: function collect(node, encoder) {
if (node.type !== 'decl') {
return;
}
if (/(grid-template|grid-template-areas)/.test(node.prop)) {
(0, _postcssValueParser2.default)(node.value).walk(function (child) {
if (child.type === 'string') {
child.value.split(/\s+/).forEach(function (word) {
if (/\.+/.test(word)) {
// reduce empty zones to a single `.`
node.value = node.value.replace(word, ".");
} else if (word && RESERVED_KEYWORDS.indexOf(word) === -1) {
(0, _cache2.default)(word, encoder, cache);
}
});
}
});
declCache.push(node);
} else if (node.prop === 'grid-area') {
(0, _postcssValueParser2.default)(node.value).walk(function (child) {
if (child.type === 'word' && RESERVED_KEYWORDS.indexOf(child.value) === -1) {
(0, _cache2.default)(child.value, encoder, cache);
}
});
declCache.push(node);
}
},
transform: function transform() {
declCache.forEach(function (decl) {
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(function (node) {
if (/(grid-template|grid-template-areas)/.test(decl.prop)) {
node.value.split(/\s+/).forEach(function (word) {
if (word in cache) {
node.value = node.value.replace(word, cache[word].ident);
}
});
node.value = node.value.replace(/\s+/g, " "); // merge white-spaces
}
if (decl.prop === 'grid-area' && !(0, _isNum2.default)(node)) {
if (node.value in cache) {
node.value = cache[node.value].ident;
}
}
return false;
}).toString();
});
// reset cache after transform
cache = {};
declCache = [];
}
};
module.exports = exports["default"];

View File

@@ -0,0 +1,11 @@
"use strict";
exports.__esModule = true;
exports.default = isNum;
var _postcssValueParser = require("postcss-value-parser");
function isNum(node) {
return (0, _postcssValueParser.unit)(node.value);
}
module.exports = exports["default"];

View File

@@ -0,0 +1,65 @@
"use strict";
exports.__esModule = true;
var _postcssValueParser = require("postcss-value-parser");
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
var _cache = require("./cache");
var _cache2 = _interopRequireDefault(_cache);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var RESERVED_KEYWORDS = ["none", "inherit", "initial", "unset"];
var cache = {};
var atRules = [];
var decls = [];
exports.default = {
collect: function collect(node, encoder) {
var name = node.name,
prop = node.prop,
type = node.type;
if (type === 'atrule' && /keyframes/.test(name) && RESERVED_KEYWORDS.indexOf(node.params) === -1) {
(0, _cache2.default)(node.params, encoder, cache);
atRules.push(node);
}
if (type === 'decl' && /animation/.test(prop)) {
decls.push(node);
}
},
transform: function transform() {
// Iterate each property and change their names
decls.forEach(function (decl) {
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(function (node) {
if (node.type === 'word' && node.value in cache) {
cache[node.value].count++;
node.value = cache[node.value].ident;
} else if (node.type === 'space') {
node.value = ' ';
} else if (node.type === 'div') {
node.before = node.after = '';
}
}).toString();
});
// Iterate each at rule and change their name if references to them have been found
atRules.forEach(function (rule) {
var cached = cache[rule.params];
if (cached && cached.count > 0) {
rule.params = cached.ident;
}
});
// reset cache after transform
cache = {};
atRules = [];
decls = [];
}
};
module.exports = exports["default"];

View File

@@ -0,0 +1,91 @@
{
"_args": [
[
"postcss-reduce-idents@2.4.0",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "postcss-reduce-idents@2.4.0",
"_id": "postcss-reduce-idents@2.4.0",
"_inBundle": false,
"_integrity": "sha1-wsbSDMlYKE9qv75j92Cb9AkFmtM=",
"_location": "/css-loader/postcss-reduce-idents",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "postcss-reduce-idents@2.4.0",
"name": "postcss-reduce-idents",
"escapedName": "postcss-reduce-idents",
"rawSpec": "2.4.0",
"saveSpec": null,
"fetchSpec": "2.4.0"
},
"_requiredBy": [
"/css-loader/cssnano"
],
"_resolved": "https://registry.npmjs.org/postcss-reduce-idents/-/postcss-reduce-idents-2.4.0.tgz",
"_spec": "2.4.0",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "Ben Briggs",
"email": "beneb.info@gmail.com",
"url": "http://beneb.info"
},
"ava": {
"require": "babel-register"
},
"bugs": {
"url": "https://github.com/ben-eb/postcss-reduce-idents/issues"
},
"dependencies": {
"postcss": "^5.0.4",
"postcss-value-parser": "^3.0.2"
},
"description": "Reduce custom identifiers with PostCSS.",
"devDependencies": {
"all-contributors-cli": "^3.0.7",
"ava": "^0.17.0",
"babel-cli": "^6.3.17",
"babel-core": "^6.3.26",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.3.13",
"babel-preset-es2015-loose": "^7.0.0",
"babel-preset-stage-0": "^6.3.13",
"babel-register": "^6.9.0",
"del-cli": "^0.2.0",
"eslint": "^3.0.0",
"eslint-config-cssnano": "^3.0.0",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-import": "^2.0.1"
},
"eslintConfig": {
"extends": "cssnano"
},
"files": [
"dist",
"LICENSE-MIT"
],
"homepage": "https://github.com/ben-eb/postcss-reduce-idents",
"keywords": [
"css",
"postcss",
"postcss-plugin"
],
"license": "MIT",
"main": "dist/index.js",
"name": "postcss-reduce-idents",
"repository": {
"type": "git",
"url": "git+https://github.com/ben-eb/postcss-reduce-idents.git"
},
"scripts": {
"contributorAdd": "all-contributors add",
"contributorGenerate": "all-contributors generate",
"prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/",
"pretest": "eslint src --fix",
"test": "ava src/__tests__/*.js",
"test-012": "ava src/__tests__/*.js"
},
"version": "2.4.0"
}