Skip to content

Commit a1e6eef

Browse files
authored
Merge 9fe896a into ae6c7dc
2 parents ae6c7dc + 9fe896a commit a1e6eef

File tree

51 files changed

+101439
-5210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+101439
-5210
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ jobs:
4444
- uses: actions/checkout@v2
4545
with:
4646
fetch-depth: 0
47-
4847
- uses: actions/setup-node@v2
4948
with:
5049
node-version: 14
@@ -56,20 +55,14 @@ jobs:
5655
stamp: package.json
5756
setCommonVars: true
5857
setAllVars: true
59-
6058
- run: |
6159
echo 'NpmPackageVersion: ${{ steps.nbgv.outputs.NpmPackageVersion }}'
6260
6361
- run: npm install
64-
if: github.event_name == 'push'
65-
6662
- run: npm run build
67-
if: github.event_name == 'push'
68-
6963
- run: npm publish --access=public
7064
env:
7165
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
72-
if: github.event_name == 'push'
7366

7467
- uses: actions/create-release@v1
7568
env:
@@ -78,5 +71,4 @@ jobs:
7871
tag_name: v${{ steps.nbgv.outputs.NpmPackageVersion }}
7972
release_name: v${{ steps.nbgv.outputs.NpmPackageVersion }} Release
8073
draft: false
81-
prerelease: false
82-
if: github.event_name == 'push'
74+
prerelease: ${{ github.event_name != 'push' }}

clean_non_color_attr.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// Based on https://github.com/dinhani/gulp-css-remove-attributes/blob/master/index.js
3+
//
4+
const through = require('through2');
5+
const css = require('css');
6+
7+
const PLUGIN_NAME = 'gulp-css-clean-non-color-attributes';
8+
module.exports = function (options) {
9+
const attributesNotToRemove = [
10+
'color',
11+
'background',
12+
'background-color',
13+
'background-image',
14+
'border',
15+
'border-color',
16+
'border-top',
17+
'border-right',
18+
'border-bottom',
19+
'border-left',
20+
'box-shadow',
21+
'outline-color',
22+
'text-shadow',
23+
];
24+
25+
// INPUT
26+
function parseInputCss(inputFile, encoding, options) {
27+
let fileContent = inputFile.contents.toString(encoding);
28+
let parsedCss = css.parse(fileContent, options);
29+
return parsedCss;
30+
}
31+
32+
// PARSING
33+
function removeCssAttributes(parsedCss) {
34+
parsedCss.stylesheet.rules = mapRules(parsedCss.stylesheet.rules);
35+
return parsedCss;
36+
}
37+
38+
function mapRules(rules) {
39+
return rules.map((rule) => {
40+
// only filter rules, the other types are just kept
41+
if (rule.type === 'rule') {
42+
rule.declarations = rule.declarations.filter((declaration) => attributesNotToRemove.includes(declaration.property));
43+
}
44+
if (rule.type === 'media') {
45+
rule.rules = mapRules(rule.rules);
46+
}
47+
return rule;
48+
});
49+
}
50+
51+
// OUTPUT
52+
function outputFinalCss(modifiedCss, options) {
53+
return css.stringify(modifiedCss, options);
54+
}
55+
56+
// MAIN
57+
let transform = function (file, encoding, callback) {
58+
let parsedCss = parseInputCss(file, encoding, options);
59+
let modifiedCss = removeCssAttributes(parsedCss, attributesNotToRemove);
60+
let finalCss = outputFinalCss(modifiedCss, options);
61+
file.contents = Buffer.from(finalCss);
62+
63+
// success
64+
callback(null, file);
65+
};
66+
67+
//
68+
return through.obj(transform);
69+
};

0 commit comments

Comments
 (0)