first commit

This commit is contained in:
Benoît Rouleau
2018-05-03 01:27:28 -04:00
commit a174b8a747
11 changed files with 6651 additions and 0 deletions

12
.editorconfig Normal file
View File

@@ -0,0 +1,12 @@
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.{json,yml}]
indent_size = 2

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
node_modules/
npm-debug.log
yarn-error.log

10
.npmignore Normal file
View File

@@ -0,0 +1,10 @@
.npmignore
.gitignore
.editorconfig
node_modules/
npm-debug.log
yarn.lock
*.test.js
.travis.yml

9
.travis.yml Normal file
View File

@@ -0,0 +1,9 @@
language: node_js
cache: yarn
node_js:
- node
- "8"
- "6"
- "4"
install:
- YARN_IGNORE_ENGINES=true yarn

5
CHANGELOG.md Normal file
View File

@@ -0,0 +1,5 @@
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).
## [1.0.0] - 2018-05-03
- First release

20
LICENSE Normal file
View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright 2018 Benoît Rouleau <benoit.rouleau@icloud.com>
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.

20
README.md Normal file
View File

@@ -0,0 +1,20 @@
# PostCSS Partial Process [![Build Status][ci-img]][ci]
[PostCSS] plugin that runs other plugins on parts of a CSS file delimited by comments.
[PostCSS]: https://github.com/postcss/postcss
## Usage
```js
postcss([ require('postcss-partial-process')({
startComment: 'start postcss-partial-process', // default value
endComment: 'end postcss-partial-process', // default value
removeComments: true, // false by default
plugins = [
require('[any postcss plugin you want]'), // this will only affect the CSS between the comments "start postcss-partial-process" and "end postcss-partial-process"
],
}) ])
```
See [PostCSS] docs for examples for your environment.

66
index.js Normal file
View File

@@ -0,0 +1,66 @@
var postcss = require('postcss');
module.exports = postcss.plugin('postcss-partial-process', ({
startComment = 'start postcss-partial-process',
endComment = 'end postcss-partial-process',
removeComments = false,
plugins = []
} = {}) => {
return root => {
let processing = false;
let partialRoot = null;
let promises = [];
let end = (callback) => {
promises.push(
postcss(plugins).process(partialRoot, {
from: undefined
}).then(callback)
);
};
root.each(node => {
let starting = false;
let ending = false;
if (node.type === 'comment') {
let matches = node.toString().match(/\/\*\s*(.*?)\s*\*\//, '');
matches = matches || [];
if (matches.length > 1) {
starting = !processing && matches[1] === startComment;
ending = processing && matches[1] === endComment;
}
}
if (ending) {
end(result => {
node.before(result.root);
if (removeComments) {
node.remove();
}
});
processing = false;
}
if (processing) {
partialRoot.append(node);
}
if (starting) {
partialRoot = postcss.root();
if (removeComments) {
node.remove();
}
processing = true;
}
});
if (processing) {
end(result => {
root.append(result.root);
});
}
return Promise.all(promises);
};
});

15
index.test.js Normal file
View File

@@ -0,0 +1,15 @@
var postcss = require('postcss');
var plugin = require('./');
function run(input, output, opts) {
return postcss([ plugin(opts) ]).process(input)
.then(result => {
expect(result.css).toEqual(output);
expect(result.warnings().length).toBe(0);
});
}
it('compiles', () => {
return run('a{ }', 'a{ }', { });
});

6454
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

37
package.json Normal file
View File

@@ -0,0 +1,37 @@
{
"name": "postcss-partial-process",
"version": "1.0.0",
"description": "PostCSS plugin that runs other plugins on parts of a CSS file delimited by comments",
"keywords": [
"postcss",
"css",
"postcss-plugin"
],
"author": "Benoît Rouleau <benoit.rouleau@icloud.com>",
"license": "MIT",
"repository": "benface/postcss-partial-process",
"bugs": {
"url": "https://github.com/benface/postcss-partial-process/issues"
},
"homepage": "https://github.com/benface/postcss-partial-process",
"dependencies": {
"postcss": "^6.0.16"
},
"devDependencies": {
"eslint": "^4.18.2",
"eslint-config-postcss": "^2.0.2",
"jest": "^22.4.2"
},
"scripts": {
"test": "jest && eslint *.js"
},
"eslintConfig": {
"extends": "eslint-config-postcss/es5",
"env": {
"jest": true
}
},
"jest": {
"testEnvironment": "node"
}
}