@bigcommerce/stencil-cli 7.2.3 → 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/lib/bundle-validator.js +7 -0
- package/lib/lang/validator.js +113 -0
- package/lib/stencil-start.js +4 -0
- 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/lib/bundle-validator.js
CHANGED
|
@@ -15,6 +15,7 @@ const privateThemeConfigValidationSchema = require('./schemas/privateThemeConfig
|
|
|
15
15
|
const themeConfigValidationSchema = require('./schemas/themeConfig.json');
|
|
16
16
|
const themeValidationSchema = require('./schemas/themeSchema.json');
|
|
17
17
|
const ScssValidator = require('./ScssValidator');
|
|
18
|
+
const LangHelpersValidator = require('./lang/validator');
|
|
18
19
|
|
|
19
20
|
const VALID_IMAGE_TYPES = ['.jpg', '.jpeg', '.png', '.gif'];
|
|
20
21
|
const WIDTH_COMPOSED = 600;
|
|
@@ -42,6 +43,7 @@ class BundleValidator {
|
|
|
42
43
|
this.objectsToValidate = ['head.scripts', 'footer.scripts'];
|
|
43
44
|
this.jsonSchemaValidatorOptions = { schemaId: 'auto', allErrors: true };
|
|
44
45
|
this.scssValidator = new ScssValidator(themePath, themeConfig);
|
|
46
|
+
this.langHelpersValidator = new LangHelpersValidator(themePath, themeConfig);
|
|
45
47
|
|
|
46
48
|
// Array of tasks used in async.series
|
|
47
49
|
this.validationTasks = [
|
|
@@ -50,6 +52,7 @@ class BundleValidator {
|
|
|
50
52
|
this._validateSchemaTranslations.bind(this),
|
|
51
53
|
this._validateTemplatesFrontmatter.bind(this),
|
|
52
54
|
this._validateCssFiles.bind(this),
|
|
55
|
+
this._validateLangFiles.bind(this),
|
|
53
56
|
];
|
|
54
57
|
|
|
55
58
|
if (!this.isPrivate) {
|
|
@@ -405,6 +408,10 @@ class BundleValidator {
|
|
|
405
408
|
return true;
|
|
406
409
|
}
|
|
407
410
|
|
|
411
|
+
async _validateLangFiles() {
|
|
412
|
+
await this.langHelpersValidator.run();
|
|
413
|
+
}
|
|
414
|
+
|
|
408
415
|
async _validateCssFiles() {
|
|
409
416
|
await this.scssValidator.run();
|
|
410
417
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
require('colors');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { recursiveReadDir } = require('../utils/fsUtils');
|
|
5
|
+
|
|
6
|
+
const LANG_HELPER_REGEXP = /{{\s*lang\s*(?:'|")((?:\w*(?:-\w*)*(\.\w*(?:-\w*)*)*)+)/gim;
|
|
7
|
+
|
|
8
|
+
class LangpathsValidator {
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param {String} themePath
|
|
12
|
+
*/
|
|
13
|
+
constructor(themePath) {
|
|
14
|
+
this.themePath = themePath;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async run(defaultLang = null) {
|
|
18
|
+
const templatesPath = path.join(this.themePath, 'templates');
|
|
19
|
+
const paths = await this.getLangHelpersPaths(templatesPath);
|
|
20
|
+
const dedupePaths = [...new Set(paths)];
|
|
21
|
+
const langFiles = await this.getLangFilesContent(defaultLang);
|
|
22
|
+
const errors = this.validate(dedupePaths, langFiles);
|
|
23
|
+
this.printErrors(errors);
|
|
24
|
+
return errors;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
printErrors(errors) {
|
|
28
|
+
if (errors.length > 0) {
|
|
29
|
+
console.log(
|
|
30
|
+
'Warning: Your theme has some missing translations used in the theme:'.yellow,
|
|
31
|
+
);
|
|
32
|
+
console.log(errors.join('\n').yellow);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
searchLangPaths(fileContent, langPath) {
|
|
37
|
+
const keys = langPath.split('.');
|
|
38
|
+
let value = fileContent;
|
|
39
|
+
|
|
40
|
+
for (const key of keys) {
|
|
41
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
42
|
+
if (value && value.hasOwnProperty(key)) {
|
|
43
|
+
value = value[key];
|
|
44
|
+
} else {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
validate(paths, langFiles) {
|
|
53
|
+
const errors = [
|
|
54
|
+
...this.checkLangFiles(langFiles),
|
|
55
|
+
...this.checkForMissingTranslations(paths, langFiles),
|
|
56
|
+
];
|
|
57
|
+
return errors;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
checkForMissingTranslations(paths, langFiles) {
|
|
61
|
+
const errors = [];
|
|
62
|
+
for (const langPath of paths) {
|
|
63
|
+
// eslint-disable-next-line no-restricted-syntax,guard-for-in
|
|
64
|
+
for (const langFile in langFiles) {
|
|
65
|
+
const translation = this.searchLangPaths(langFiles[langFile], langPath);
|
|
66
|
+
if (!translation) {
|
|
67
|
+
errors.push(`Missing translation for ${langPath} in ${langFile}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return errors;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
checkLangFiles(files) {
|
|
75
|
+
if (files.length === 0) {
|
|
76
|
+
return ['No lang files found in your theme'];
|
|
77
|
+
}
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async getLangHelpersPaths(templatesPath) {
|
|
82
|
+
const files = await recursiveReadDir(templatesPath);
|
|
83
|
+
const paths = [];
|
|
84
|
+
for await (const file of files) {
|
|
85
|
+
const content = await fs.promises.readFile(file, { encoding: 'utf-8' });
|
|
86
|
+
const result = content.matchAll(LANG_HELPER_REGEXP);
|
|
87
|
+
const arr = [...result];
|
|
88
|
+
if (arr.length > 0) {
|
|
89
|
+
const langPath = arr[0][1];
|
|
90
|
+
paths.push(langPath);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return paths;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async getLangFilesContent(defaultLang = null) {
|
|
97
|
+
const filesContent = {};
|
|
98
|
+
const langPath = path.join(this.themePath, 'lang');
|
|
99
|
+
let files = await recursiveReadDir(langPath);
|
|
100
|
+
|
|
101
|
+
if (defaultLang) {
|
|
102
|
+
files = files.filter((file) => file.includes(defaultLang));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for await (const file of files) {
|
|
106
|
+
const content = await fs.promises.readFile(file, { encoding: 'utf-8' });
|
|
107
|
+
filesContent[file] = JSON.parse(content);
|
|
108
|
+
}
|
|
109
|
+
return filesContent;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = LangpathsValidator;
|
package/lib/stencil-start.js
CHANGED
|
@@ -16,6 +16,7 @@ const cliCommonModule = require('./cliCommon');
|
|
|
16
16
|
const themeApiClientModule = require('./theme-api-client');
|
|
17
17
|
const storeSettingsApiClientModule = require('./store-settings-api-client');
|
|
18
18
|
const LangHelper = require('./lang-helper');
|
|
19
|
+
const LangValidator = require('./lang/validator');
|
|
19
20
|
|
|
20
21
|
class StencilStart {
|
|
21
22
|
constructor({
|
|
@@ -32,6 +33,7 @@ class StencilStart {
|
|
|
32
33
|
CyclesDetector = Cycles,
|
|
33
34
|
stencilPushUtils = stencilPushUtilsModule,
|
|
34
35
|
logger = console,
|
|
36
|
+
langValidator = new LangValidator(THEME_PATH),
|
|
35
37
|
} = {}) {
|
|
36
38
|
this._browserSync = browserSync;
|
|
37
39
|
this._themeApiClient = themeApiClient;
|
|
@@ -46,6 +48,7 @@ class StencilStart {
|
|
|
46
48
|
this._CyclesDetector = CyclesDetector;
|
|
47
49
|
this._stencilPushUtils = stencilPushUtils;
|
|
48
50
|
this._logger = logger;
|
|
51
|
+
this._langValidator = langValidator;
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
async run(cliOptions) {
|
|
@@ -289,6 +292,7 @@ class StencilStart {
|
|
|
289
292
|
} else {
|
|
290
293
|
try {
|
|
291
294
|
await this._langHelper.checkLangKeysPresence(filesPaths, defaultShopperLanguage);
|
|
295
|
+
await this._langValidator.run(defaultShopperLanguage);
|
|
292
296
|
} catch (e) {
|
|
293
297
|
this._logger.error(e);
|
|
294
298
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigcommerce/stencil-cli",
|
|
3
|
-
"version": "7.
|
|
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",
|