This commit is contained in:
Valentin Silytuin 2022-02-01 20:32:12 +04:00
parent 1e6b8905d7
commit dba52852f7
12 changed files with 1288 additions and 192 deletions

View File

@ -1,7 +1,7 @@
root = true root = true
[*] [*]
indent_style = tab indent_style = space
indent_size = 4 indent_size = 4
end_of_line = lf end_of_line = lf
trim_trailing_whitespace = true trim_trailing_whitespace = true

97
.gitignore vendored Normal file → Executable file
View File

@ -53,6 +53,7 @@ Temporary Items
# Windows thumbnail cache files # Windows thumbnail cache files
Thumbs.db Thumbs.db
Thumbs.db:encryptable
ehthumbs.db ehthumbs.db
ehthumbs_vista.db ehthumbs_vista.db
@ -84,12 +85,15 @@ $RECYCLE.BIN/
*.rar *.rar
*.zip *.zip
*.gz *.gz
*.gzip
*.tgz *.tgz
*.bzip *.bzip
*.bzip2
*.bz2 *.bz2
*.xz *.xz
*.lzma *.lzma
*.cab *.cab
*.xar
# Packing-only formats # Packing-only formats
*.iso *.iso
@ -105,6 +109,7 @@ $RECYCLE.BIN/
*.msi *.msi
*.msm *.msm
*.msp *.msp
*.txz
# https://github.com/github/gitignore/blob/master/Global/Backup.gitignore # https://github.com/github/gitignore/blob/master/Global/Backup.gitignore
@ -114,88 +119,22 @@ $RECYCLE.BIN/
*.orig *.orig
*.tmp *.tmp
# https://github.com/github/gitignore/blob/master/Node.gitignore # Node
# Logs node_modules
logs npm-*.log
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data # Yarn
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover yarn-*.log
lib-cov .pnp.*
.yarn/*
# Coverage directory used by tools like istanbul !.yarn/patches
coverage !.yarn/plugins
!.yarn/releases
# nyc test coverage !.yarn/sdks
.nyc_output !.yarn/versions
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# Composer # Composer
vendor vendor

1
.nvmrc Normal file
View File

@ -0,0 +1 @@
16

View File

@ -1,15 +1,6 @@
{ {
"printWidth": 120, "printWidth": 120,
"tabWidth": 4, "tabWidth": 4,
"useTabs": true, "singleQuote": true,
"semi": true, "bracketSpacing": false
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "es5",
"bracketSpacing": false,
"arrowParens": "always",
"proseWrap": "preserve",
"htmlWhitespaceSensitivity": "css",
"vueIndentScriptAndStyle": false,
"endOfLine": "lf"
} }

File diff suppressed because one or more lines are too long

768
.yarn/releases/yarn-3.1.1.cjs vendored Executable file

File diff suppressed because one or more lines are too long

7
.yarnrc.yml Normal file
View File

@ -0,0 +1,7 @@
nodeLinker: node-modules
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
yarnPath: .yarn/releases/yarn-3.1.1.cjs

View File

@ -13,17 +13,19 @@ yarn add -D @advdominion/postcss-remove-bem-blocks
`postcss.config.js` `postcss.config.js`
```js ```js
import removeBemBlocks from '@advdominion/postcss-remove-bem-blocks';
const plugins = []; const plugins = [];
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
plugins.push( plugins.push(
require('@advdominion/postcss-remove-bem-blocks')({ removeBemBlocks({
blocks: ['.stylepage'], blocks: ['.stylepage'],
}) })
); );
} }
module.exports = { export default {
plugins, plugins,
}; };
``` ```

View File

@ -1,33 +1,35 @@
module.exports = (options = {blocks: []}) => { const plugin = (options = {blocks: []}) => {
return { return {
postcssPlugin: 'postcss-remove-bem-blocks', postcssPlugin: 'postcss-remove-bem-blocks',
Rule(rule) { Rule(rule) {
options.blocks.forEach((block) => { options.blocks.forEach((block) => {
if (rule.selector.includes(block)) { if (rule.selector.includes(block)) {
const regexp = new RegExp(`${block}(?![A-Za-z0-9-]+)`); const regexp = new RegExp(`${block}(?![A-Za-z0-9-]+)`);
if (rule.selectors.length === 1) { if (rule.selectors.length === 1) {
if (regexp.test(rule.selectors[0])) { if (regexp.test(rule.selectors[0])) {
rule.remove(); rule.remove();
} }
} else { } else {
const selectors = []; const selectors = [];
rule.selectors.forEach((selector) => { rule.selectors.forEach((selector) => {
if (!regexp.test(selector)) { if (!regexp.test(selector)) {
selectors.push(selector); selectors.push(selector);
} }
}); });
if (selectors.length) { if (selectors.length) {
const cloned = rule.clone(); const cloned = rule.clone();
cloned.selectors = selectors; cloned.selectors = selectors;
rule.replaceWith(cloned); rule.replaceWith(cloned);
} else { } else {
rule.remove(); rule.remove();
} }
} }
} }
}); });
}, },
}; };
}; };
module.exports.postcss = true; plugin.postcss = true;
export default plugin;

View File

@ -1,16 +1,21 @@
{ {
"name": "@advdominion/postcss-remove-bem-blocks", "name": "@advdominion/postcss-remove-bem-blocks",
"version": "1.0.1", "version": "2.0.0",
"main": "index.js", "type": "module",
"repository": { "engines": {
"type": "git", "node": "^16.0.0"
"url": "https://bitbucket.org/advdominion/postcss-remove-bem-blocks" },
}, "packageManager": "yarn@3.1.1",
"license": "MIT", "main": "index.js",
"peerDependencies": { "repository": {
"postcss": "8.x" "type": "git",
}, "url": "https://bitbucket.org/advdominion/postcss-remove-bem-blocks"
"devDependencies": { },
"postcss": "^8.2.8" "license": "MIT",
} "peerDependencies": {
"postcss": "8.x"
},
"devDependencies": {
"postcss": "^8.4.6"
}
} }

View File

@ -1,26 +1,21 @@
const fs = require('fs'); import {readFile, writeFile} from 'node:fs/promises';
const path = require('path'); import postcss from 'postcss';
const util = require('util'); import plugin from './../index.js';
const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);
const postcss = require('postcss');
const plugin = require('./../'); readFile('from.css', {
encoding: 'utf-8',
readFile(path.join(__dirname, 'from.css'), {
encoding: 'utf-8',
}) })
.then((css) => { .then((css) => {
return postcss([ return postcss([
plugin({ plugin({
blocks: ['.block-2'], blocks: ['.block-2'],
}), }),
]).process(css, { ]).process(css, {
from: path.join(__dirname, 'from.css'), from: 'from.css',
}); });
}) })
.then(({css}) => { .then(({css}) => {
writeFile(path.join(__dirname, 'to.css'), css, { writeFile('to.css', css, {
encoding: 'utf-8', encoding: 'utf-8',
}); });
}); });

View File

@ -1,27 +1,50 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # This file is generated by running "yarn install" inside your project.
# yarn lockfile v1 # Manual changes might be lost - proceed with caution!
__metadata:
version: 5
cacheKey: 8
nanocolors@^0.2.2: "@advdominion/postcss-remove-bem-blocks@workspace:.":
version "0.2.12" version: 0.0.0-use.local
resolved "https://registry.yarnpkg.com/nanocolors/-/nanocolors-0.2.12.tgz#4d05932e70116078673ea4cc6699a1c56cc77777" resolution: "@advdominion/postcss-remove-bem-blocks@workspace:."
integrity sha512-SFNdALvzW+rVlzqexid6epYdt8H9Zol7xDoQarioEFcFN0JHo4CYNztAxmtfgGTVRCmFlEOqqhBpoFGKqSAMug==
nanoid@^3.1.25:
version "3.1.28"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.28.tgz#3c01bac14cb6c5680569014cc65a2f26424c6bd4"
integrity sha512-gSu9VZ2HtmoKYe/lmyPFES5nknFrHa+/DT9muUFWFMi6Jh9E1I7bkvlQ8xxf1Kos9pi9o8lBnIOkatMhKX/YUw==
postcss@^8.2.8:
version "8.3.8"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.3.8.tgz#9ebe2a127396b4b4570ae9f7770e7fb83db2bac1"
integrity sha512-GT5bTjjZnwDifajzczOC+r3FI3Cu+PgPvrsjhQdRqa2kTJ4968/X9CUce9xttIB0xOs5c6xf0TCWZo/y9lF6bA==
dependencies: dependencies:
nanocolors "^0.2.2" postcss: ^8.4.6
nanoid "^3.1.25" peerDependencies:
source-map-js "^0.6.2" postcss: 8.x
languageName: unknown
linkType: soft
source-map-js@^0.6.2: "nanoid@npm:^3.2.0":
version "0.6.2" version: 3.2.0
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-0.6.2.tgz#0bb5de631b41cfbda6cfba8bd05a80efdfd2385e" resolution: "nanoid@npm:3.2.0"
integrity sha512-/3GptzWzu0+0MBQFrDKzw/DvvMTUORvgY6k6jd/VS6iCR4RDTKWH6v6WPwQoUO8667uQEf9Oe38DxAYWY5F/Ug== bin:
nanoid: bin/nanoid.cjs
checksum: 3d1d5a69fea84e538057cf64106e713931c4ef32af344068ecff153ff91252f39b0f2b472e09b0dfff43ac3cf520c92938d90e6455121fe93976e23660f4fccc
languageName: node
linkType: hard
"picocolors@npm:^1.0.0":
version: 1.0.0
resolution: "picocolors@npm:1.0.0"
checksum: a2e8092dd86c8396bdba9f2b5481032848525b3dc295ce9b57896f931e63fc16f79805144321f72976383fc249584672a75cc18d6777c6b757603f372f745981
languageName: node
linkType: hard
"postcss@npm:^8.4.6":
version: 8.4.6
resolution: "postcss@npm:8.4.6"
dependencies:
nanoid: ^3.2.0
picocolors: ^1.0.0
source-map-js: ^1.0.2
checksum: 60e7808f39c4a9d0fa067bfd5eb906168c4eb6d3ff0093f7d314d1979b001a16363deedccd368a7df869c63ad4ae350d27da439c94ff3fb0f8fc93d49fe38a90
languageName: node
linkType: hard
"source-map-js@npm:^1.0.2":
version: 1.0.2
resolution: "source-map-js@npm:1.0.2"
checksum: c049a7fc4deb9a7e9b481ae3d424cc793cb4845daa690bc5a05d428bf41bf231ced49b4cf0c9e77f9d42fdb3d20d6187619fc586605f5eabe995a316da8d377c
languageName: node
linkType: hard