@bigcommerce/stencil-cli 7.0.1 → 7.1.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 +41 -20
- package/lib/stencil-push.utils.js +1 -1
- package/package.json +2 -2
package/lib/ScssValidator.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
require('colors');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
|
+
const cheerio = require('cheerio');
|
|
4
5
|
|
|
5
6
|
const cssCompiler = require('./css/compile');
|
|
6
7
|
const { recursiveReadDir } = require('./utils/fsUtils');
|
|
7
8
|
|
|
8
9
|
/* eslint-disable no-useless-escape */
|
|
9
|
-
const STYLESHEET_REGEXP = /{{\s*stylesheet\s*([\/a-zA-Z'"\.-]+)\s*}}/
|
|
10
|
+
const STYLESHEET_REGEXP = /{{\s*stylesheet\s*([\/a-zA-Z'"\.-]+)\s*}}/gi;
|
|
10
11
|
|
|
11
12
|
class ScssValidator {
|
|
12
13
|
/**
|
|
@@ -36,7 +37,6 @@ class ScssValidator {
|
|
|
36
37
|
);
|
|
37
38
|
} catch (e) {
|
|
38
39
|
const message = this.parseStencilStylesError(e);
|
|
39
|
-
console.log(e.file);
|
|
40
40
|
throw new Error(
|
|
41
41
|
`${message} while compiling css files from "${stylesPath}/${file}".`.red,
|
|
42
42
|
);
|
|
@@ -58,15 +58,18 @@ class ScssValidator {
|
|
|
58
58
|
const cssFiles = [];
|
|
59
59
|
for await (const file of files) {
|
|
60
60
|
const content = await fs.promises.readFile(file, { encoding: 'utf-8' });
|
|
61
|
-
const result = content.
|
|
61
|
+
const result = content.matchAll(STYLESHEET_REGEXP);
|
|
62
62
|
if (result) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
+
!this.isStyleSheetAComment(content, filePath) &&
|
|
69
|
+
!cssFiles.includes(fileName)
|
|
70
|
+
) {
|
|
71
|
+
cssFiles.push(fileName);
|
|
72
|
+
}
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
}
|
|
@@ -74,28 +77,46 @@ class ScssValidator {
|
|
|
74
77
|
return cssFiles;
|
|
75
78
|
}
|
|
76
79
|
|
|
80
|
+
isStyleSheetAComment(content, cssFilePath) {
|
|
81
|
+
const $ = cheerio.load(content);
|
|
82
|
+
const comments = $('*')
|
|
83
|
+
.contents()
|
|
84
|
+
.filter(function () {
|
|
85
|
+
return this.nodeType === 8;
|
|
86
|
+
});
|
|
87
|
+
for (const comment of comments) {
|
|
88
|
+
const { data } = comment;
|
|
89
|
+
if (data && data.includes('stylesheet') && data.includes(cssFilePath)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
77
97
|
// returns relative path starting from root scss/css folder
|
|
78
|
-
tryToResolveCssFileLocation(
|
|
98
|
+
tryToResolveCssFileLocation(filePath) {
|
|
79
99
|
const possibleLocations = [
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
100
|
+
filePath,
|
|
101
|
+
filePath.replace('/css/', '/scss/'),
|
|
102
|
+
filePath.replace('/scss/', '/css/'),
|
|
103
|
+
filePath.replace('/css/', '/scss/').replace('.css', '.scss'),
|
|
104
|
+
filePath.replace('/scss/', '/css/').replace('.scss', '.css'),
|
|
85
105
|
];
|
|
86
106
|
|
|
87
107
|
for (const location of possibleLocations) {
|
|
88
|
-
const
|
|
89
|
-
if (fs.existsSync(
|
|
108
|
+
const fullFilePath = path.join(this.themePath, location);
|
|
109
|
+
if (fs.existsSync(fullFilePath)) {
|
|
90
110
|
if (!this.isRootCssFile(location)) {
|
|
91
111
|
return this.getCssFileWithoutRootFolder(location);
|
|
92
112
|
}
|
|
93
|
-
const fileParts = path.parse(
|
|
113
|
+
const fileParts = path.parse(fullFilePath);
|
|
94
114
|
return fileParts.name;
|
|
95
115
|
}
|
|
96
116
|
}
|
|
97
117
|
|
|
98
|
-
|
|
118
|
+
console.log(`Couldn't validate scss compilation for this file path: ${filePath}`.yellow);
|
|
119
|
+
return null;
|
|
99
120
|
}
|
|
100
121
|
|
|
101
122
|
// root folders are /assets/css /assets/scss
|
|
@@ -515,7 +515,7 @@ utils.requestToApplyVariation = async (options) => {
|
|
|
515
515
|
};
|
|
516
516
|
|
|
517
517
|
utils.notifyUserOfCompletion = (options, callback) => {
|
|
518
|
-
callback(null,
|
|
518
|
+
callback(null, `Stencil Push Finished. Variation ID: ${options.variationId}`);
|
|
519
519
|
};
|
|
520
520
|
|
|
521
521
|
module.exports = utils;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigcommerce/stencil-cli",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"description": "CLI tool to run BigCommerce Stores locally for theme development.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"async": "^3.2.3",
|
|
62
62
|
"axios": "^0.27.2",
|
|
63
63
|
"browser-sync": "^2.27.9",
|
|
64
|
-
"cheerio": "^1.0.0-rc.
|
|
64
|
+
"cheerio": "^1.0.0-rc.12",
|
|
65
65
|
"colors": "1.4.0",
|
|
66
66
|
"commander": "^6.1.0",
|
|
67
67
|
"confidence": "^5.0.1",
|