@videinfra/static-website-builder 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/lib/camelize-file-name.js +21 -0
- package/lib/get-file-names.js +23 -0
- package/lib/globs-helper.js +4 -1
- package/package.json +1 -2
- package/tasks/data/data-loader-js.js +5 -5
- package/tasks/data/get-data.js +3 -21
- package/tasks/stylesheets/preprocess-config.js +7 -7
- package/tasks/stylesheets/task.js +69 -69
- package/tests/camelize-file-name.test.js +11 -0
- package/tests/glob-helper.test.js +5 -0
- package/vendor/postcss-ignore-plugin/README.md +124 -0
- package/vendor/postcss-ignore-plugin/dist/add.js +82 -0
- package/vendor/postcss-ignore-plugin/dist/remove.js +83 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [1.5.0] - 2022-04-13
|
|
8
|
+
### Fixed
|
|
9
|
+
- Read files in `data` folder recursively
|
|
10
|
+
|
|
11
|
+
## [1.4.3] - 2022-03-08
|
|
12
|
+
### Fixed
|
|
13
|
+
- Fixed negative glob paths not working
|
|
14
|
+
|
|
15
|
+
## [1.4.2] - 2021-08-27
|
|
16
|
+
### Fixed
|
|
17
|
+
- Fixed postcss-ignore-plugin only removing and adding content in unrelated files
|
|
18
|
+
|
|
7
19
|
## [1.4.1] - 2021-05-20
|
|
8
20
|
### Fixed
|
|
9
21
|
- Enabled postcss-ignore-plugin only when cssnano is used
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camelize filename
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str File name
|
|
5
|
+
* @returns {string} Camelized name
|
|
6
|
+
*/
|
|
7
|
+
module.exports = function camelizeFileName (str) {
|
|
8
|
+
return str
|
|
9
|
+
// Remove extension
|
|
10
|
+
.replace(/(.+?)\..*$/ig, '$1')
|
|
11
|
+
// Remove dot
|
|
12
|
+
.replace(/\./g, '')
|
|
13
|
+
// Replace non alpha-numeric characters
|
|
14
|
+
.replace(/[^a-z0-9]/ig, ' ')
|
|
15
|
+
// Uppercase words
|
|
16
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
|
|
17
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
18
|
+
})
|
|
19
|
+
// Remove empty spaces
|
|
20
|
+
.replace(/\s+/g, '');
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns list of filenames in folder recursively
|
|
6
|
+
*
|
|
7
|
+
* @param {string} folder Folder path
|
|
8
|
+
* @param {string} [subFolder=''] Subfolder path
|
|
9
|
+
* @returns {array} List of filenames, relative to folder
|
|
10
|
+
*/
|
|
11
|
+
module.exports = function getFileNamesSync (folder, subFolder = '') {
|
|
12
|
+
let fileNames = []
|
|
13
|
+
|
|
14
|
+
fs.readdirSync(folder, { withFileTypes: true }).forEach(file => {
|
|
15
|
+
if (file.isDirectory()) {
|
|
16
|
+
fileNames = fileNames.concat(getFileNamesSync(path.join(folder, file.name), path.join(subFolder, file.name)));
|
|
17
|
+
} else {
|
|
18
|
+
fileNames.push(path.join(subFolder, file.name))
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return fileNames;
|
|
23
|
+
}
|
package/lib/globs-helper.js
CHANGED
|
@@ -22,7 +22,10 @@ class GlobObject {
|
|
|
22
22
|
if (this.pathsArr.length) {
|
|
23
23
|
this.map((basePath) => {
|
|
24
24
|
return pathsArr.map((subPath) => {
|
|
25
|
-
|
|
25
|
+
// If subpath starts with specia character "!" then prepend that to the begining of full paths
|
|
26
|
+
const negativePath = subPath[0] === '!' ? '!' : '';
|
|
27
|
+
const subPathNormalized = negativePath ? subPath.substr(1) : subPath;
|
|
28
|
+
return negativePath + path.join(basePath, subPathNormalized);
|
|
26
29
|
});
|
|
27
30
|
});
|
|
28
31
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@videinfra/static-website-builder",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Customizable static site project builder",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -51,7 +51,6 @@
|
|
|
51
51
|
"gulp-twig": "^1.2.0",
|
|
52
52
|
"minimist": "^1.2.5",
|
|
53
53
|
"nano-memoize": "^1.2.1",
|
|
54
|
-
"postcss-ignore-plugin": "^0.2.1",
|
|
55
54
|
"webpack": "^4.44.2",
|
|
56
55
|
"webpack-stream": "^5.2.1"
|
|
57
56
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
module.exports = function dataLoaderJS (fileName) {
|
|
2
|
-
// Re-load script each time this function is called
|
|
3
|
-
delete require.cache[require.resolve(fileName)];
|
|
4
|
-
return require(fileName);
|
|
5
|
-
};
|
|
1
|
+
module.exports = function dataLoaderJS (fileName) {
|
|
2
|
+
// Re-load script each time this function is called
|
|
3
|
+
delete require.cache[require.resolve(fileName)];
|
|
4
|
+
return require(fileName);
|
|
5
|
+
};
|
package/tasks/data/get-data.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
1
|
const path = require('path');
|
|
3
2
|
const reduce = require('lodash/reduce');
|
|
4
3
|
const micromatch = require('micromatch'); // gulp dependency
|
|
@@ -7,26 +6,9 @@ const merge = require('../../lib/merge');
|
|
|
7
6
|
const getPaths = require('../../lib/get-path');
|
|
8
7
|
const getConfig = require('../../lib/get-config');
|
|
9
8
|
const logError = require('../../lib/log-error');
|
|
9
|
+
const getFileNamesSync = require('../../lib/get-file-names');
|
|
10
|
+
const camelizeFileName = require('../../lib/camelize-file-name');
|
|
10
11
|
|
|
11
|
-
/**
|
|
12
|
-
* Camelize filename
|
|
13
|
-
*
|
|
14
|
-
* @param {string} str File name
|
|
15
|
-
* @returns {string} Camelized name
|
|
16
|
-
*/
|
|
17
|
-
function camelizeFileName (str) {
|
|
18
|
-
return str
|
|
19
|
-
// Remove extension
|
|
20
|
-
.replace(/\.[^.]+$/ig, '')
|
|
21
|
-
// Replace non alpha-numeric characters
|
|
22
|
-
.replace(/[^a-z0-9]/ig, ' ')
|
|
23
|
-
// Uppercase words
|
|
24
|
-
.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
|
|
25
|
-
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
26
|
-
})
|
|
27
|
-
// Remove empty spaces
|
|
28
|
-
.replace(/\s+/g, '');
|
|
29
|
-
}
|
|
30
12
|
|
|
31
13
|
module.exports = function getData () {
|
|
32
14
|
const folders = getPaths.getSourcePaths('data');
|
|
@@ -36,7 +18,7 @@ module.exports = function getData () {
|
|
|
36
18
|
const group = getConfig.getTaskConfig('data', 'groupByFileName');
|
|
37
19
|
|
|
38
20
|
const data = reduce(folders, (data, folder) => {
|
|
39
|
-
|
|
21
|
+
getFileNamesSync(folder).forEach(fileName => {
|
|
40
22
|
// Ignore files matching 'ignore' list
|
|
41
23
|
if (ignore.length && micromatch.isMatch(fileName, ignore)) {
|
|
42
24
|
return;
|
|
@@ -18,17 +18,17 @@ module.exports = function processStylesheetsConfig (config, fullConfig) {
|
|
|
18
18
|
if (config && config.postcss) {
|
|
19
19
|
config.postcss.plugins = config.postcss.plugins || [];
|
|
20
20
|
|
|
21
|
-
if (config.cssnano) {
|
|
22
|
-
// Add ignore plugin only if there is nano / minification
|
|
23
|
-
config.postcss.plugins.unshift(require('postcss-ignore-plugin/dist/remove').default);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
21
|
// Add autoprefixer
|
|
27
22
|
if (config.autoprefixer && !find(config.postcss.plugins, {'postcssPlugin': 'autoprefixer'})) {
|
|
28
23
|
config.postcss.plugins.push(autoprefixer(config.autoprefixer));
|
|
29
24
|
}
|
|
30
25
|
|
|
31
|
-
|
|
26
|
+
if (config.cssnano) {
|
|
27
|
+
// Add ignore plugin only if there is nano / minification
|
|
28
|
+
config.postcss.plugins.unshift(require('../../vendor/postcss-ignore-plugin/dist/remove').default);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// // Add CSS nano
|
|
32
32
|
if (config.cssnano && !find(config.postcss.plugins, {'postcssPlugin': 'cssnano'})) {
|
|
33
33
|
config.postcss.plugins.push(cssnano({
|
|
34
34
|
preset: [config.cssnano.preset, config.cssnano]
|
|
@@ -37,7 +37,7 @@ module.exports = function processStylesheetsConfig (config, fullConfig) {
|
|
|
37
37
|
|
|
38
38
|
if (config.cssnano) {
|
|
39
39
|
// Add ignore plugin only if there is nano / minification
|
|
40
|
-
config.postcss.plugins.push(require('postcss-ignore-plugin/dist/add').default);
|
|
40
|
+
config.postcss.plugins.push(require('../../vendor/postcss-ignore-plugin/dist/add').default);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
const gulp = require('gulp');
|
|
2
|
-
const gulpif = require('gulp-if');
|
|
3
|
-
const postcss = require('gulp-postcss');
|
|
4
|
-
const sourcemaps = require('gulp-sourcemaps');
|
|
5
|
-
const memoize = require('nano-memoize');
|
|
6
|
-
const cached = require('gulp-cached');
|
|
7
|
-
const dependents = require('gulp-dependents');
|
|
8
|
-
|
|
9
|
-
const globs = require('./../../lib/globs-helper');
|
|
10
|
-
const getPaths = require('../../lib/get-path');
|
|
11
|
-
const getConfig = require('../../lib/get-config');
|
|
12
|
-
|
|
13
|
-
const taskStart = require('../../lib/gulp/task-start');
|
|
14
|
-
const taskEnd = require('../../lib/gulp/task-end');
|
|
15
|
-
const taskBeforeDest = require('../../lib/gulp/task-before-dest');
|
|
16
|
-
const taskWatch = require('../../lib/gulp/task-watch');
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const getGlobPaths = memoize(function () {
|
|
20
|
-
const sourcePaths = getPaths.getSourcePaths('stylesheets');
|
|
21
|
-
const extensions = getConfig.getTaskConfig('stylesheets', 'extensions');
|
|
22
|
-
const ignore = getConfig.getTaskConfig('stylesheets', 'ignore');
|
|
23
|
-
|
|
24
|
-
return globs.generate(
|
|
25
|
-
globs.paths(sourcePaths).filesWithExtensions(extensions), // Files to watch
|
|
26
|
-
globs.paths(sourcePaths).paths(ignore).ignore(), // List of files which to ignore
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const getEngine = memoize(function () {
|
|
32
|
-
const engine = getConfig.getTaskConfig('stylesheets', 'engine');
|
|
33
|
-
return engine ? engine() : (() => {});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
function stylesheets () {
|
|
38
|
-
// console.log(getConfig.getTaskConfig('stylesheets', 'dependents'));
|
|
39
|
-
return gulp.src(getGlobPaths())
|
|
40
|
-
.pipe(taskStart())
|
|
41
|
-
|
|
42
|
-
// Faster incremental builds, skip files which didn't changed or their dependencies didn't changed
|
|
43
|
-
.pipe(gulpif(!!getConfig.getTaskConfig('stylesheets', 'dependents'), cached('stylesheets')))
|
|
44
|
-
.pipe(gulpif(!!getConfig.getTaskConfig('stylesheets', 'dependents'), dependents(getConfig.getTaskConfig('dependents'))))
|
|
45
|
-
|
|
46
|
-
.pipe(gulpif(!!getConfig.getTaskConfig('stylesheets', 'sourcemaps'), sourcemaps.init(getConfig.getTaskConfig('stylesheets', 'sourcemaps', 'init')))) // Start Sourcemaps
|
|
47
|
-
|
|
48
|
-
// Engine
|
|
49
|
-
.pipe(gulpif(!!getConfig.getTaskConfig('stylesheets', 'engine'), getEngine()))
|
|
50
|
-
|
|
51
|
-
// Autoprefixer, postcss
|
|
52
|
-
.pipe(gulpif(!!getConfig.getTaskConfig('stylesheets', 'postcss'), postcss(getConfig.getTaskConfig('stylesheets', 'postcss', 'plugins'), getConfig.getTaskConfig('stylesheets', 'postcss', 'options'))))
|
|
53
|
-
|
|
54
|
-
.pipe(gulpif(!!getConfig.getTaskConfig('stylesheets', 'sourcemaps'), sourcemaps.write('.', getConfig.getTaskConfig('stylesheets', 'sourcemaps', 'write'))))
|
|
55
|
-
|
|
56
|
-
.pipe(taskBeforeDest())
|
|
57
|
-
.pipe(gulp.dest(getPaths.getDestPath('stylesheets')))
|
|
58
|
-
|
|
59
|
-
// Reload on change
|
|
60
|
-
.pipe(taskEnd());
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function stylesheetsWatch () {
|
|
64
|
-
return taskWatch(getGlobPaths(), stylesheets);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
exports.build = stylesheets;
|
|
69
|
-
exports.watch = stylesheetsWatch;
|
|
1
|
+
const gulp = require('gulp');
|
|
2
|
+
const gulpif = require('gulp-if');
|
|
3
|
+
const postcss = require('gulp-postcss');
|
|
4
|
+
const sourcemaps = require('gulp-sourcemaps');
|
|
5
|
+
const memoize = require('nano-memoize');
|
|
6
|
+
const cached = require('gulp-cached');
|
|
7
|
+
const dependents = require('gulp-dependents');
|
|
8
|
+
|
|
9
|
+
const globs = require('./../../lib/globs-helper');
|
|
10
|
+
const getPaths = require('../../lib/get-path');
|
|
11
|
+
const getConfig = require('../../lib/get-config');
|
|
12
|
+
|
|
13
|
+
const taskStart = require('../../lib/gulp/task-start');
|
|
14
|
+
const taskEnd = require('../../lib/gulp/task-end');
|
|
15
|
+
const taskBeforeDest = require('../../lib/gulp/task-before-dest');
|
|
16
|
+
const taskWatch = require('../../lib/gulp/task-watch');
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const getGlobPaths = memoize(function () {
|
|
20
|
+
const sourcePaths = getPaths.getSourcePaths('stylesheets');
|
|
21
|
+
const extensions = getConfig.getTaskConfig('stylesheets', 'extensions');
|
|
22
|
+
const ignore = getConfig.getTaskConfig('stylesheets', 'ignore');
|
|
23
|
+
|
|
24
|
+
return globs.generate(
|
|
25
|
+
globs.paths(sourcePaths).filesWithExtensions(extensions), // Files to watch
|
|
26
|
+
globs.paths(sourcePaths).paths(ignore).ignore(), // List of files which to ignore
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const getEngine = memoize(function () {
|
|
32
|
+
const engine = getConfig.getTaskConfig('stylesheets', 'engine');
|
|
33
|
+
return engine ? engine() : (() => {});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
function stylesheets () {
|
|
38
|
+
// console.log(getConfig.getTaskConfig('stylesheets', 'dependents'));
|
|
39
|
+
return gulp.src(getGlobPaths())
|
|
40
|
+
.pipe(taskStart())
|
|
41
|
+
|
|
42
|
+
// Faster incremental builds, skip files which didn't changed or their dependencies didn't changed
|
|
43
|
+
.pipe(gulpif(!!getConfig.getTaskConfig('stylesheets', 'dependents'), cached('stylesheets')))
|
|
44
|
+
.pipe(gulpif(!!getConfig.getTaskConfig('stylesheets', 'dependents'), dependents(getConfig.getTaskConfig('dependents'))))
|
|
45
|
+
|
|
46
|
+
.pipe(gulpif(!!getConfig.getTaskConfig('stylesheets', 'sourcemaps'), sourcemaps.init(getConfig.getTaskConfig('stylesheets', 'sourcemaps', 'init')))) // Start Sourcemaps
|
|
47
|
+
|
|
48
|
+
// Engine
|
|
49
|
+
.pipe(gulpif(!!getConfig.getTaskConfig('stylesheets', 'engine'), getEngine()))
|
|
50
|
+
|
|
51
|
+
// Autoprefixer, postcss
|
|
52
|
+
.pipe(gulpif(!!getConfig.getTaskConfig('stylesheets', 'postcss'), postcss(getConfig.getTaskConfig('stylesheets', 'postcss', 'plugins'), getConfig.getTaskConfig('stylesheets', 'postcss', 'options'))))
|
|
53
|
+
|
|
54
|
+
.pipe(gulpif(!!getConfig.getTaskConfig('stylesheets', 'sourcemaps'), sourcemaps.write('.', getConfig.getTaskConfig('stylesheets', 'sourcemaps', 'write'))))
|
|
55
|
+
|
|
56
|
+
.pipe(taskBeforeDest())
|
|
57
|
+
.pipe(gulp.dest(getPaths.getDestPath('stylesheets')))
|
|
58
|
+
|
|
59
|
+
// Reload on change
|
|
60
|
+
.pipe(taskEnd());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function stylesheetsWatch () {
|
|
64
|
+
return taskWatch(getGlobPaths(), stylesheets);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
exports.build = stylesheets;
|
|
69
|
+
exports.watch = stylesheetsWatch;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const camelizeFileName = require('../lib/camelize-file-name');
|
|
2
|
+
|
|
3
|
+
test('Camelize file name', () => {
|
|
4
|
+
expect(camelizeFileName('test-file-name')).toBe('testFileName');
|
|
5
|
+
expect(camelizeFileName('testFileName')).toBe('testFileName');
|
|
6
|
+
expect(camelizeFileName('testFile_name')).toBe('testFileName');
|
|
7
|
+
expect(camelizeFileName('test-file-name.jpg')).toBe('testFileName');
|
|
8
|
+
expect(camelizeFileName('testFileName.jpg')).toBe('testFileName');
|
|
9
|
+
expect(camelizeFileName('test-āēūīķļ-name.jpg.png')).toBe('testName');
|
|
10
|
+
expect(camelizeFileName('.gitignore')).toBe('gitignore');
|
|
11
|
+
});
|
|
@@ -84,6 +84,11 @@ test('glob map', () => {
|
|
|
84
84
|
expect(output2).toEqual(['/a/some/folder/b', '/a/other/folder/b']);
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
+
test('glob negative', () => {
|
|
88
|
+
const output = glob.paths('/some/folder').paths('!/assets/**/*.*').generate();
|
|
89
|
+
expect(output).toEqual(['!/some/folder/assets/**/*.*']);
|
|
90
|
+
});
|
|
91
|
+
|
|
87
92
|
test('glob generate', () => {
|
|
88
93
|
const output = glob.generate(
|
|
89
94
|
glob.paths(['/a', '/b']).allFiles(),
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# postcss-ignore-plugin
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
Ignore postcss plugins operations in lines using comments
|
|
7
|
+
|
|
8
|
+
## Getting started
|
|
9
|
+
|
|
10
|
+
`$ yarn add postcss-ignore-plugin -D`
|
|
11
|
+
|
|
12
|
+
and add this it in your `postcss` config
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
// postcss.config.js
|
|
16
|
+
module.exports = {
|
|
17
|
+
plugins: [
|
|
18
|
+
require('postcss-ignore-plugin/remove'), // Important to keep this at the top of the plugins
|
|
19
|
+
require('cssnano'),
|
|
20
|
+
require('autoprefixer'),
|
|
21
|
+
require('stylelint'),
|
|
22
|
+
require('postcss-ignore-plugin/add'), // Important to keep it at the end
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Now use the following comments whenever you want to ignore any operation for other plugins
|
|
28
|
+
|
|
29
|
+
- for ignoring a particular line or declaration (css properties) inside of css rule
|
|
30
|
+
|
|
31
|
+
```css
|
|
32
|
+
/* postcss-ignore-line */
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
> Dont use `/* postcss-ignore-line */` for css rules
|
|
36
|
+
|
|
37
|
+
- for ignoring a whole rule
|
|
38
|
+
|
|
39
|
+
```css
|
|
40
|
+
/* postcss-ignore */
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## How it works
|
|
44
|
+
|
|
45
|
+
Currently we support only for declaration statement, that mean you can add this comment over CSS declaration line not over the selector list in Rule declaration
|
|
46
|
+
|
|
47
|
+
`example`
|
|
48
|
+
|
|
49
|
+
```css
|
|
50
|
+
.classname {
|
|
51
|
+
margin: auto;
|
|
52
|
+
/* postcss-ignore-line */
|
|
53
|
+
color: red;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* postcss-ignore */
|
|
57
|
+
.classname {
|
|
58
|
+
margin: auto;
|
|
59
|
+
color: red;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@media screen and (min-width: 480px) {
|
|
63
|
+
ul {
|
|
64
|
+
/* postcss-ignore-line */
|
|
65
|
+
list-style: none;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* postcss-ignore */
|
|
69
|
+
p {
|
|
70
|
+
font-size: 10px;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
It simple remove the next line before running the other plugins and then add them at the end.
|
|
76
|
+
|
|
77
|
+
## Rules
|
|
78
|
+
|
|
79
|
+
Use [`stylelint-postcss-ignore`](https://github.com/anikethsaha/stylelint-postcss-ignore) for rules regarding this plugin 's better use
|
|
80
|
+
|
|
81
|
+
## Tests
|
|
82
|
+
|
|
83
|
+
this plugins are tested with
|
|
84
|
+
|
|
85
|
+
- cssnano
|
|
86
|
+
- Autoprefixer
|
|
87
|
+
- postcss-preset-env
|
|
88
|
+
- stylelint
|
|
89
|
+
- some custom plugins meant to fail the op
|
|
90
|
+
- Indivial tests for each plugins
|
|
91
|
+
|
|
92
|
+
> There are not many test cases. More will be added soon
|
|
93
|
+
|
|
94
|
+
## FAQ
|
|
95
|
+
|
|
96
|
+
- **Can we ignore a whole css `atrules` (like media queries) ?**
|
|
97
|
+
|
|
98
|
+
No, you need to use `/* postcss-ignore */` before each rule inside the `atrules`
|
|
99
|
+
|
|
100
|
+
- **will those ignore rules/properties (declarations) will come back to there original position after all operations?**
|
|
101
|
+
|
|
102
|
+
No, both. rules and atrules will append at the end. declarations (rules's properties) will append at the rule itself. and if you have used `/* postcss-ignore */` for a rule inside of atrules, it will get appended for that atrule at the end
|
|
103
|
+
|
|
104
|
+
- **Does it effect the performance like the build time?**
|
|
105
|
+
|
|
106
|
+
Yes _(sometimes for code with many ignore comments )_, but not at a huge level. It slightly decreases the performance as there are 2-3 nested looks so you can notices some issue with huge code with many ignore comments
|
|
107
|
+
|
|
108
|
+
## Contributing Guidelines
|
|
109
|
+
|
|
110
|
+
Simply click on this
|
|
111
|
+
|
|
112
|
+
[](https://gitpod.io/#https://github.com/anikethsaha/postcss-ignore-plugin)
|
|
113
|
+
|
|
114
|
+
and starting working in it !
|
|
115
|
+
|
|
116
|
+
**OR**
|
|
117
|
+
|
|
118
|
+
- clone the repo
|
|
119
|
+
- Install the dependenices `yarn install`
|
|
120
|
+
- Build the code `yarn build`
|
|
121
|
+
- run the tests before working `yarn test:only` and `yarn test:integrations`
|
|
122
|
+
- start working
|
|
123
|
+
|
|
124
|
+
If you add a new feature or did some breaking change , update [`stylelint-postcss-ignore`](https://github.com/anikethsaha/stylelint-postcss-ignore) for consistency
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _postcss = require("postcss");
|
|
9
|
+
|
|
10
|
+
var _default = (0, _postcss.plugin)('postcss-ignore-plugin-add', () => {
|
|
11
|
+
return (root, result) => {
|
|
12
|
+
if (result.messages.type !== 'postcss-ignore-plugin') {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const msgs = result.messages;
|
|
17
|
+
let declToAdd = [],
|
|
18
|
+
rulesToAdd = [];
|
|
19
|
+
msgs.forEach(msg => {
|
|
20
|
+
if (msg['postcss-ignore-plugin'] !== undefined) {
|
|
21
|
+
msg['postcss-ignore-plugin'].ignoredLineData.forEach(ignoreData => {
|
|
22
|
+
if (root.source.input.file === ignoreData.fileName) {
|
|
23
|
+
declToAdd.push(ignoreData);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
msg['postcss-ignore-plugin'].ignoreRulesData.forEach(ignoredRule => {
|
|
27
|
+
if (root.source.input.file === ignoredRule.fileName) {
|
|
28
|
+
rulesToAdd.push(ignoredRule);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}); // add decl to atrules
|
|
33
|
+
|
|
34
|
+
root.walkAtRules(atRules => {
|
|
35
|
+
declToAdd.forEach(decl => {
|
|
36
|
+
if (decl.atRule !== undefined && atRules.name === decl.atRule.name && atRules.params === decl.atRule.params) {
|
|
37
|
+
atRules.walkRules(rules => {
|
|
38
|
+
if (rules.selector === decl.selector) {
|
|
39
|
+
rules.append({
|
|
40
|
+
prop: decl.prop,
|
|
41
|
+
value: decl.value
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}); // add decl only those with no atrules
|
|
48
|
+
|
|
49
|
+
root.walkRules(rules => {
|
|
50
|
+
declToAdd.forEach(decl => {
|
|
51
|
+
if (rules.selector === decl.selector && decl.atRule === undefined) {
|
|
52
|
+
rules.append({
|
|
53
|
+
prop: decl.prop,
|
|
54
|
+
value: decl.value
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}); // add rules
|
|
59
|
+
|
|
60
|
+
rulesToAdd = rulesToAdd.filter(rule => {
|
|
61
|
+
if (rule.parent.type !== 'atrule') {
|
|
62
|
+
root.append(rule.rule);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return true;
|
|
67
|
+
}); // add rules to artules
|
|
68
|
+
|
|
69
|
+
root.walkAtRules(atrule => {
|
|
70
|
+
rulesToAdd = rulesToAdd.filter(rule => {
|
|
71
|
+
if (atrule.params === rule.parent.params) {
|
|
72
|
+
atrule.append(rule.rule);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return true;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
exports.default = _default;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _postcss = require("postcss");
|
|
9
|
+
|
|
10
|
+
var _default = (0, _postcss.plugin)('postcss-ignore-plugin-remove', () => {
|
|
11
|
+
let ignoredLineData = [];
|
|
12
|
+
let commentsIgnoredRule = [];
|
|
13
|
+
let ignoreRulesData = []; // Work with options here
|
|
14
|
+
|
|
15
|
+
return (root, result) => {
|
|
16
|
+
// Transform CSS AST here
|
|
17
|
+
root.walkRules(rule => {
|
|
18
|
+
// Transform each rule here
|
|
19
|
+
rule.walkComments(comment => {
|
|
20
|
+
if (comment.text === 'postcss-ignore-line') {
|
|
21
|
+
let commentData = {
|
|
22
|
+
fileName: comment.source.input.file,
|
|
23
|
+
commentedLine: comment.source.start.line,
|
|
24
|
+
ignoredLine: comment.source.start.line + 1
|
|
25
|
+
};
|
|
26
|
+
comment.remove();
|
|
27
|
+
ignoredLineData.push(commentData);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
root.walkComments(comment => {
|
|
32
|
+
if (comment.text === 'postcss-ignore') {
|
|
33
|
+
commentsIgnoredRule.push({
|
|
34
|
+
fileName: comment.source.input.file,
|
|
35
|
+
commentLine: comment.source.start,
|
|
36
|
+
ruleIgnoreLineNo: comment.source.start.line + 1
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
comment.remove();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
root.walkRules(rule => {
|
|
43
|
+
rule.walkDecls(decl => {
|
|
44
|
+
const declLine = decl.source.start.line;
|
|
45
|
+
ignoredLineData.forEach(ignoreData => {
|
|
46
|
+
if (decl.source.input.file === ignoreData.fileName && ignoreData.ignoredLine === declLine) {
|
|
47
|
+
ignoreData.selector = decl.parent.selector;
|
|
48
|
+
ignoreData.prop = decl.prop;
|
|
49
|
+
ignoreData.value = decl.value;
|
|
50
|
+
|
|
51
|
+
if (decl.parent.parent.type === 'atrule') {
|
|
52
|
+
ignoreData.atRule = {
|
|
53
|
+
name: decl.parent.parent.name,
|
|
54
|
+
params: decl.parent.parent.params
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
decl.remove();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
commentsIgnoredRule.forEach(data => {
|
|
63
|
+
if (rule.source.input.file === data.fileName && rule.source.start.line === data.ruleIgnoreLineNo) {
|
|
64
|
+
ignoreRulesData.push({
|
|
65
|
+
rule,
|
|
66
|
+
parent: rule.parent,
|
|
67
|
+
fileName: data.fileName
|
|
68
|
+
});
|
|
69
|
+
rule.remove();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
result.messages.type = 'postcss-ignore-plugin';
|
|
74
|
+
result.messages.push({
|
|
75
|
+
'postcss-ignore-plugin': {
|
|
76
|
+
ignoredLineData,
|
|
77
|
+
ignoreRulesData
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
exports.default = _default;
|