@bigcommerce/stencil-cli 7.1.0 → 7.1.2

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.
@@ -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*}}/i;
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.match(STYLESHEET_REGEXP);
61
+ const result = content.matchAll(STYLESHEET_REGEXP);
62
62
  if (result) {
63
- // remove quotes
64
- const fileName = result[1].slice(1, -1);
65
-
66
- const filePath = this.tryToResolveCssFileLocation(fileName, result);
67
- if (!cssFiles.includes(filePath)) {
68
- // check if file exist
69
- cssFiles.push(filePath);
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(fileName, result) {
98
+ tryToResolveCssFileLocation(filePath) {
79
99
  const possibleLocations = [
80
- fileName,
81
- fileName.replace('/css/', '/scss/'),
82
- fileName.replace('/scss/', '/css/'),
83
- fileName.replace('/css/', '/scss/').replace('.css', '.scss'),
84
- fileName.replace('/scss/', '/css/').replace('.scss', '.css'),
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 filePath = path.join(this.themePath, location);
89
- if (fs.existsSync(filePath)) {
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(filePath);
113
+ const fileParts = path.parse(fullFilePath);
94
114
  return fileParts.name;
95
115
  }
96
116
  }
97
117
 
98
- throw new Error(`Couldn't find file for this statement: ${result[0]}`.red);
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
@@ -12,6 +12,7 @@ function stencilPull(options = {}, callback) {
12
12
  stencilPushUtils.promptUserForChannel,
13
13
  stencilPullUtils.getChannelActiveTheme,
14
14
  stencilPullUtils.getThemeConfiguration,
15
+ stencilPullUtils.getCurrentVariation,
15
16
  stencilPullUtils.mergeThemeConfiguration,
16
17
  ],
17
18
  callback,
@@ -26,6 +26,28 @@ utils.getChannelActiveTheme = async (options) => {
26
26
  return { ...options, activeTheme };
27
27
  };
28
28
 
29
+ utils.getCurrentVariation = async (options) => {
30
+ const {
31
+ config: { accessToken },
32
+ storeHash,
33
+ activeTheme,
34
+ saved,
35
+ remoteThemeConfiguration,
36
+ } = options;
37
+ const apiHost = options.apiHost || options.config.apiHost;
38
+ const themeId = activeTheme.active_theme_uuid;
39
+ const variations = await themeApiClient.getVariationsByThemeId({
40
+ accessToken,
41
+ apiHost,
42
+ storeHash,
43
+ themeId,
44
+ });
45
+ const variation = variations.find((v) => v.uuid === remoteThemeConfiguration.variation_uuid);
46
+
47
+ console.log('ok'.green + ` -- Fetched ${saved ? 'saved' : 'active'} variation name`);
48
+ return { ...options, variation };
49
+ };
50
+
29
51
  utils.getThemeConfiguration = async (options) => {
30
52
  const {
31
53
  config: { accessToken },
@@ -59,6 +81,7 @@ utils.mergeThemeConfiguration = async (options) => {
59
81
  const { remoteThemeConfiguration } = options;
60
82
 
61
83
  const localConfig = await parseJsonFile('config.json');
84
+ const variation = localConfig.variations.find((v) => v.name === options.variation.name);
62
85
  let diffDetected = false;
63
86
 
64
87
  // For any keys the remote configuration has in common with the local configuration,
@@ -67,19 +90,22 @@ utils.mergeThemeConfiguration = async (options) => {
67
90
  if (!(key in localConfig.settings)) {
68
91
  continue;
69
92
  }
70
- const localVal = localConfig.settings[key];
93
+ const defaultVal = localConfig.settings[key];
71
94
 
72
95
  // Check for different types, and throw an error if they are found
73
- if (typeof localVal !== typeof remoteVal) {
96
+ if (typeof defaultVal !== typeof remoteVal) {
74
97
  throw new Error(
75
98
  `Theme configuration key "${key}" cannot be merged because it is not of the same type. ` +
76
- `Remote configuration is of type ${typeof remoteVal} while local configuration is of type ${typeof localVal}.`,
99
+ `Remote configuration is of type ${typeof remoteVal} while local configuration is of type ${typeof defaultVal}.`,
77
100
  );
78
101
  }
79
102
 
80
103
  // If a different value is found, overwrite the local config
81
- if (!_.isEqual(localVal, remoteVal)) {
82
- localConfig.settings[key] = remoteVal;
104
+ if (!_.isEqual(defaultVal, remoteVal)) {
105
+ if (!variation.settings) {
106
+ variation.settings = {};
107
+ }
108
+ variation.settings[key] = remoteVal;
83
109
  diffDetected = true;
84
110
  }
85
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigcommerce/stencil-cli",
3
- "version": "7.1.0",
3
+ "version": "7.1.2",
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.10",
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",