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
[*]
indent_style = tab
indent_style = space
indent_size = 4
end_of_line = lf
trim_trailing_whitespace = true

97
.gitignore vendored Normal file → Executable file
View File

@ -53,6 +53,7 @@ Temporary Items
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
@ -84,12 +85,15 @@ $RECYCLE.BIN/
*.rar
*.zip
*.gz
*.gzip
*.tgz
*.bzip
*.bzip2
*.bz2
*.xz
*.lzma
*.cab
*.xar
# Packing-only formats
*.iso
@ -105,6 +109,7 @@ $RECYCLE.BIN/
*.msi
*.msm
*.msp
*.txz
# https://github.com/github/gitignore/blob/master/Global/Backup.gitignore
@ -114,88 +119,22 @@ $RECYCLE.BIN/
*.orig
*.tmp
# https://github.com/github/gitignore/blob/master/Node.gitignore
# Node
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
node_modules
npm-*.log
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Yarn
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# 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/
yarn-*.log
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
# Composer
vendor

1
.nvmrc Normal file
View File

@ -0,0 +1 @@
16

View File

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

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`
```js
import removeBemBlocks from '@advdominion/postcss-remove-bem-blocks';
const plugins = [];
if (process.env.NODE_ENV === 'production') {
plugins.push(
require('@advdominion/postcss-remove-bem-blocks')({
blocks: ['.stylepage'],
})
);
plugins.push(
removeBemBlocks({
blocks: ['.stylepage'],
})
);
}
module.exports = {
plugins,
export default {
plugins,
};
```

View File

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

View File

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

View File

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

View File

@ -1,27 +1,50 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!
__metadata:
version: 5
cacheKey: 8
nanocolors@^0.2.2:
version "0.2.12"
resolved "https://registry.yarnpkg.com/nanocolors/-/nanocolors-0.2.12.tgz#4d05932e70116078673ea4cc6699a1c56cc77777"
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==
"@advdominion/postcss-remove-bem-blocks@workspace:.":
version: 0.0.0-use.local
resolution: "@advdominion/postcss-remove-bem-blocks@workspace:."
dependencies:
nanocolors "^0.2.2"
nanoid "^3.1.25"
source-map-js "^0.6.2"
postcss: ^8.4.6
peerDependencies:
postcss: 8.x
languageName: unknown
linkType: soft
source-map-js@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-0.6.2.tgz#0bb5de631b41cfbda6cfba8bd05a80efdfd2385e"
integrity sha512-/3GptzWzu0+0MBQFrDKzw/DvvMTUORvgY6k6jd/VS6iCR4RDTKWH6v6WPwQoUO8667uQEf9Oe38DxAYWY5F/Ug==
"nanoid@npm:^3.2.0":
version: 3.2.0
resolution: "nanoid@npm:3.2.0"
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