@bigcommerce/stencil-cli 7.3.0 → 7.3.1
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/lib/ScssValidator.js +4 -92
- package/package.json +2 -2
package/lib/ScssValidator.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
require('colors');
|
|
2
|
-
const fs = require('fs');
|
|
3
2
|
const path = require('path');
|
|
4
|
-
const
|
|
3
|
+
const StencilStyles = require('@bigcommerce/stencil-styles');
|
|
5
4
|
|
|
6
5
|
const cssCompiler = require('./css/compile');
|
|
7
|
-
const { recursiveReadDir } = require('./utils/fsUtils');
|
|
8
|
-
|
|
9
|
-
/* eslint-disable no-useless-escape */
|
|
10
|
-
const STYLESHEET_REGEXP = /{{\s*stylesheet\s*([\/a-zA-Z'"\.-]+)\s*}}/gi;
|
|
11
6
|
|
|
12
7
|
class ScssValidator {
|
|
13
8
|
/**
|
|
@@ -52,92 +47,9 @@ class ScssValidator {
|
|
|
52
47
|
return e.message;
|
|
53
48
|
}
|
|
54
49
|
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const cssFiles = [];
|
|
59
|
-
for await (const file of files) {
|
|
60
|
-
const content = await fs.promises.readFile(file, { encoding: 'utf-8' });
|
|
61
|
-
const result = content.matchAll(STYLESHEET_REGEXP);
|
|
62
|
-
if (result) {
|
|
63
|
-
for (const item of result) {
|
|
64
|
-
// remove quotes
|
|
65
|
-
const filePath = item[1].slice(1, -1);
|
|
66
|
-
const fileName = this.tryToResolveCssFileLocation(filePath);
|
|
67
|
-
if (
|
|
68
|
-
fileName &&
|
|
69
|
-
!this.isStyleSheetAComment(content, filePath) &&
|
|
70
|
-
!cssFiles.includes(fileName)
|
|
71
|
-
) {
|
|
72
|
-
cssFiles.push(fileName);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return cssFiles;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
isStyleSheetAComment(content, cssFilePath) {
|
|
82
|
-
const $ = cheerio.load(content);
|
|
83
|
-
const comments = $('*')
|
|
84
|
-
.contents()
|
|
85
|
-
.filter(function () {
|
|
86
|
-
return this.nodeType === 8;
|
|
87
|
-
});
|
|
88
|
-
for (const comment of comments) {
|
|
89
|
-
const { data } = comment;
|
|
90
|
-
if (data && data.includes('stylesheet') && data.includes(cssFilePath)) {
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// returns relative path starting from root scss/css folder
|
|
99
|
-
tryToResolveCssFileLocation(filePath) {
|
|
100
|
-
const possibleLocations = [
|
|
101
|
-
filePath,
|
|
102
|
-
filePath.replace('/css/', '/scss/'),
|
|
103
|
-
filePath.replace('/scss/', '/css/'),
|
|
104
|
-
filePath.replace('/css/', '/scss/').replace('.css', '.scss'),
|
|
105
|
-
filePath.replace('/scss/', '/css/').replace('.scss', '.css'),
|
|
106
|
-
];
|
|
107
|
-
|
|
108
|
-
for (const location of possibleLocations) {
|
|
109
|
-
const fullFilePath = path.join(this.themePath, location);
|
|
110
|
-
if (fs.existsSync(fullFilePath)) {
|
|
111
|
-
if (fullFilePath.endsWith('.css')) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
if (!this.isRootCssFile(location)) {
|
|
115
|
-
return this.getCssFileWithoutRootFolder(location);
|
|
116
|
-
}
|
|
117
|
-
const fileParts = path.parse(fullFilePath);
|
|
118
|
-
return fileParts.name;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
console.log(`Couldn't validate scss compilation for this file path: ${filePath}`.yellow);
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// root folders are /assets/css /assets/scss
|
|
127
|
-
// so after split, there can be 3 or 4 elements in the array (depending if the leading slash is present)
|
|
128
|
-
isRootCssFile(location) {
|
|
129
|
-
return location.split('/').length <= 4;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
getCssFileWithoutRootFolder(location) {
|
|
133
|
-
const locationParts = location.split('/');
|
|
134
|
-
if (locationParts[0] === '') {
|
|
135
|
-
locationParts.shift();
|
|
136
|
-
}
|
|
137
|
-
locationParts.shift();
|
|
138
|
-
locationParts.shift();
|
|
139
|
-
|
|
140
|
-
return locationParts.join('/');
|
|
50
|
+
getCssFiles() {
|
|
51
|
+
const styles = new StencilStyles();
|
|
52
|
+
return styles.getCssFiles(this.themePath);
|
|
141
53
|
}
|
|
142
54
|
}
|
|
143
55
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigcommerce/stencil-cli",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.1",
|
|
4
4
|
"description": "CLI tool to run BigCommerce Stores locally for theme development.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@bigcommerce/stencil-paper": "4.10.4",
|
|
52
|
-
"@bigcommerce/stencil-styles": "5.
|
|
52
|
+
"@bigcommerce/stencil-styles": "5.2.0",
|
|
53
53
|
"@hapi/boom": "^10.0.0",
|
|
54
54
|
"@hapi/glue": "^8.0.0",
|
|
55
55
|
"@hapi/h2o2": "^9.1.0",
|