@bigcommerce/stencil-cli 8.2.0 → 8.4.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/bin/stencil-bundle.js +7 -18
- package/bin/stencil-debug.js +5 -9
- package/bin/stencil-download.js +7 -19
- package/bin/stencil-init.js +4 -8
- package/bin/stencil-pull.js +5 -11
- package/bin/stencil-push.js +5 -8
- package/bin/stencil-release.js +5 -10
- package/bin/stencil-scss-autofix.js +6 -11
- package/bin/stencil-start.js +6 -9
- package/bin/stencil.js +2 -3
- package/constants.js +9 -9
- package/lib/BuildConfigManager.js +25 -23
- package/lib/Cycles.js +3 -12
- package/lib/ScssValidator.js +5 -9
- package/lib/StencilCLISettings.js +1 -3
- package/lib/StencilConfigManager.js +6 -22
- package/lib/StencilDebug.js +7 -10
- package/lib/archiveManager.js +7 -23
- package/lib/bundle-validator.js +28 -64
- package/lib/cliCommon.js +11 -21
- package/lib/commander.js +2 -3
- package/lib/content-api-client.js +5 -13
- package/lib/css/compile.js +5 -11
- package/lib/graphql/query.js +5 -8
- package/lib/lang/validator.js +5 -11
- package/lib/lang-assembler.js +4 -10
- package/lib/lang-helper.js +3 -6
- package/lib/nodeSass/AutoFixer.js +10 -19
- package/lib/nodeSass/BaseFixer.js +5 -7
- package/lib/nodeSass/BaseRulesFixer.js +3 -8
- package/lib/nodeSass/CommaRemovalFixer.js +3 -8
- package/lib/nodeSass/ConditionalImportFixer.js +3 -9
- package/lib/nodeSass/UndefinedVariableFixer.js +3 -6
- package/lib/parse-json.js +10 -9
- package/lib/regions.js +3 -23
- package/lib/release/questions.js +3 -13
- package/lib/release/release.js +16 -55
- package/lib/spinner.js +1 -2
- package/lib/stencil-bundle.js +19 -78
- package/lib/stencil-download.js +5 -6
- package/lib/stencil-download.utils.js +5 -18
- package/lib/stencil-init.js +8 -24
- package/lib/stencil-pull.js +4 -5
- package/lib/stencil-pull.utils.js +5 -28
- package/lib/stencil-push.js +3 -4
- package/lib/stencil-push.utils.js +12 -102
- package/lib/stencil-start.js +19 -48
- package/lib/store-settings-api-client.js +4 -7
- package/lib/template-assembler.js +6 -45
- package/lib/theme-api-client.js +7 -30
- package/lib/theme-config.js +16 -59
- package/lib/utils/NetworkUtils.js +6 -16
- package/lib/utils/asyncUtils.js +2 -3
- package/lib/utils/frontmatter.js +4 -5
- package/lib/utils/fsUtils.js +6 -10
- package/lib/validator/schema-translations.js +5 -7
- package/package.json +12 -9
- package/server/config.js +3 -7
- package/server/index.js +29 -29
- package/server/lib/page-type-util.js +2 -5
- package/server/lib/show-logo.js +3 -3
- package/server/lib/utils.js +6 -11
- package/server/manifest.js +7 -11
- package/server/plugins/renderer/renderer.module.js +38 -100
- package/server/plugins/renderer/responses/index.js +7 -4
- package/server/plugins/renderer/responses/pencil-response.js +4 -32
- package/server/plugins/renderer/responses/raw-response.js +6 -14
- package/server/plugins/renderer/responses/redirect-response.js +1 -4
- package/server/plugins/router/router.module.js +9 -14
- package/server/plugins/theme-assets/theme-assets.module.js +15 -27
- package/lib/css-assembler.js +0 -99
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import 'colors';
|
|
2
|
+
import NetworkUtils from './utils/NetworkUtils.js';
|
|
3
|
+
import {
|
|
4
4
|
renderedRegionsByPageTypeQuery,
|
|
5
5
|
renderedRegionsByPageTypeAndEntityIdQuery,
|
|
6
|
-
}
|
|
6
|
+
} from './graphql/query.js';
|
|
7
7
|
|
|
8
8
|
const networkUtils = new NetworkUtils();
|
|
9
|
-
|
|
10
9
|
/**
|
|
11
10
|
* @param {object} options
|
|
12
11
|
* @param {string} options.accessToken
|
|
@@ -17,7 +16,6 @@ const networkUtils = new NetworkUtils();
|
|
|
17
16
|
async function getRenderedRegionsByPageType({ accessToken, storeUrl, pageType }) {
|
|
18
17
|
try {
|
|
19
18
|
const query = renderedRegionsByPageTypeQuery(pageType);
|
|
20
|
-
|
|
21
19
|
const response = await networkUtils.sendApiRequest({
|
|
22
20
|
url: `${storeUrl}/graphql`,
|
|
23
21
|
headers: {
|
|
@@ -30,7 +28,6 @@ async function getRenderedRegionsByPageType({ accessToken, storeUrl, pageType })
|
|
|
30
28
|
query,
|
|
31
29
|
}),
|
|
32
30
|
});
|
|
33
|
-
|
|
34
31
|
if (!response.data.data) {
|
|
35
32
|
return { renderedRegions: [] };
|
|
36
33
|
}
|
|
@@ -41,13 +38,11 @@ async function getRenderedRegionsByPageType({ accessToken, storeUrl, pageType })
|
|
|
41
38
|
},
|
|
42
39
|
},
|
|
43
40
|
} = response.data.data;
|
|
44
|
-
|
|
45
41
|
return { renderedRegions: regions };
|
|
46
42
|
} catch (err) {
|
|
47
43
|
throw new Error(`Could not fetch the rendered regions for this page type: ${err.message}`);
|
|
48
44
|
}
|
|
49
45
|
}
|
|
50
|
-
|
|
51
46
|
/**
|
|
52
47
|
* @param {object} options
|
|
53
48
|
* @param {string} options.accessToken
|
|
@@ -64,7 +59,6 @@ async function getRenderedRegionsByPageTypeAndEntityId({
|
|
|
64
59
|
}) {
|
|
65
60
|
try {
|
|
66
61
|
const query = renderedRegionsByPageTypeAndEntityIdQuery(pageType, entityId);
|
|
67
|
-
|
|
68
62
|
const response = await networkUtils.sendApiRequest({
|
|
69
63
|
url: `${storeUrl}/graphql`,
|
|
70
64
|
headers: {
|
|
@@ -77,7 +71,6 @@ async function getRenderedRegionsByPageTypeAndEntityId({
|
|
|
77
71
|
query,
|
|
78
72
|
}),
|
|
79
73
|
});
|
|
80
|
-
|
|
81
74
|
if (!response.data.data) {
|
|
82
75
|
return { renderedRegions: [] };
|
|
83
76
|
}
|
|
@@ -88,7 +81,6 @@ async function getRenderedRegionsByPageTypeAndEntityId({
|
|
|
88
81
|
},
|
|
89
82
|
},
|
|
90
83
|
} = response.data.data;
|
|
91
|
-
|
|
92
84
|
return {
|
|
93
85
|
renderedRegions: regions,
|
|
94
86
|
};
|
|
@@ -97,7 +89,7 @@ async function getRenderedRegionsByPageTypeAndEntityId({
|
|
|
97
89
|
}
|
|
98
90
|
}
|
|
99
91
|
|
|
100
|
-
|
|
92
|
+
export default {
|
|
101
93
|
getRenderedRegionsByPageType,
|
|
102
94
|
getRenderedRegionsByPageTypeAndEntityId,
|
|
103
95
|
};
|
package/lib/css/compile.js
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { promisify } = require('util');
|
|
4
|
-
|
|
5
|
-
const cssAssembler = require('../css-assembler');
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import StencilStyles from '@bigcommerce/stencil-styles';
|
|
6
3
|
|
|
7
4
|
const SASS_ENGINE_NAME = 'node-sass';
|
|
8
|
-
|
|
9
5
|
const compile = async (configuration, themeAssetsPath, fileName, engineName = SASS_ENGINE_NAME) => {
|
|
10
6
|
const fileParts = path.parse(fileName);
|
|
11
7
|
const ext = configuration.css_compiler === 'css' ? configuration.css_compiler : 'scss';
|
|
12
8
|
const pathToFile = path.join(fileParts.dir, `${fileParts.name}.${ext}`);
|
|
13
9
|
const basePath = path.join(themeAssetsPath, `${ext}`);
|
|
10
|
+
const stencilStyles = new StencilStyles(console);
|
|
14
11
|
|
|
15
12
|
let files;
|
|
16
13
|
try {
|
|
17
|
-
files = await
|
|
14
|
+
files = await stencilStyles.assembleCssFiles(pathToFile, basePath, `${ext}`, {});
|
|
18
15
|
} catch (err) {
|
|
19
16
|
console.error(err);
|
|
20
17
|
throw err;
|
|
21
18
|
}
|
|
22
|
-
|
|
23
19
|
const params = {
|
|
24
20
|
data: files[pathToFile],
|
|
25
21
|
files,
|
|
@@ -31,13 +27,11 @@ const compile = async (configuration, themeAssetsPath, fileName, engineName = SA
|
|
|
31
27
|
overrideBrowserslist: configuration.autoprefixer_browsers,
|
|
32
28
|
},
|
|
33
29
|
};
|
|
34
|
-
const stencilStyles = new StencilStyles(console);
|
|
35
30
|
stencilStyles.activateEngine(engineName);
|
|
36
|
-
|
|
37
31
|
return stencilStyles.compileCss('scss', params);
|
|
38
32
|
};
|
|
39
33
|
|
|
40
|
-
|
|
34
|
+
export default {
|
|
41
35
|
compile,
|
|
42
36
|
SASS_ENGINE_NAME,
|
|
43
37
|
};
|
package/lib/graphql/query.js
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
* @param {string} pageType
|
|
3
3
|
* @returns {string}>}
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
const renderedRegionsByPageTypeQuery = (pageType) =>
|
|
7
|
-
`query {
|
|
5
|
+
const renderedRegionsByPageTypeQuery = (pageType) => `query {
|
|
8
6
|
site {
|
|
9
7
|
content {
|
|
10
8
|
renderedRegionsByPageType(pageType: ${pageType}) {
|
|
@@ -16,14 +14,12 @@ const renderedRegionsByPageTypeQuery = (pageType) =>
|
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
}`;
|
|
19
|
-
|
|
20
17
|
/**
|
|
21
18
|
* @param {string} pageType
|
|
22
19
|
* @param {number} entityId
|
|
23
20
|
* @returns {string}>}
|
|
24
21
|
*/
|
|
25
|
-
const renderedRegionsByPageTypeAndEntityIdQuery = (pageType, entityId) =>
|
|
26
|
-
`query {
|
|
22
|
+
const renderedRegionsByPageTypeAndEntityIdQuery = (pageType, entityId) => `query {
|
|
27
23
|
site {
|
|
28
24
|
content {
|
|
29
25
|
renderedRegionsByPageTypeAndEntityId(entityPageType: ${pageType}, entityId: ${entityId}) {
|
|
@@ -35,8 +31,9 @@ const renderedRegionsByPageTypeAndEntityIdQuery = (pageType, entityId) =>
|
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
33
|
}`;
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
export { renderedRegionsByPageTypeQuery };
|
|
35
|
+
export { renderedRegionsByPageTypeAndEntityIdQuery };
|
|
36
|
+
export default {
|
|
40
37
|
renderedRegionsByPageTypeQuery,
|
|
41
38
|
renderedRegionsByPageTypeAndEntityIdQuery,
|
|
42
39
|
};
|
package/lib/lang/validator.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import 'colors';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { recursiveReadDir } from '../utils/fsUtils.js';
|
|
5
5
|
|
|
6
6
|
const LANG_HELPER_REGEXP = /{{\s*lang\s*(?:'|")((?:\w*(?:-\w*)*(\.\w*(?:-\w*)*)*)+)/gim;
|
|
7
|
-
|
|
8
7
|
class LangpathsValidator {
|
|
9
8
|
/**
|
|
10
9
|
*
|
|
@@ -36,7 +35,6 @@ class LangpathsValidator {
|
|
|
36
35
|
searchLangPaths(fileContent, langPath) {
|
|
37
36
|
const keys = langPath.split('.');
|
|
38
37
|
let value = fileContent;
|
|
39
|
-
|
|
40
38
|
for (const key of keys) {
|
|
41
39
|
// eslint-disable-next-line no-prototype-builtins
|
|
42
40
|
if (value && value.hasOwnProperty(key)) {
|
|
@@ -45,7 +43,6 @@ class LangpathsValidator {
|
|
|
45
43
|
return false;
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
|
-
|
|
49
46
|
return value;
|
|
50
47
|
}
|
|
51
48
|
|
|
@@ -97,11 +94,9 @@ class LangpathsValidator {
|
|
|
97
94
|
const filesContent = {};
|
|
98
95
|
const langPath = path.join(this.themePath, 'lang');
|
|
99
96
|
let files = await recursiveReadDir(langPath);
|
|
100
|
-
|
|
101
97
|
if (defaultLang) {
|
|
102
98
|
files = files.filter((file) => file.includes(defaultLang));
|
|
103
99
|
}
|
|
104
|
-
|
|
105
100
|
for await (const file of files) {
|
|
106
101
|
const content = await fs.promises.readFile(file, { encoding: 'utf-8' });
|
|
107
102
|
filesContent[file] = JSON.parse(content);
|
|
@@ -109,5 +104,4 @@ class LangpathsValidator {
|
|
|
109
104
|
return filesContent;
|
|
110
105
|
}
|
|
111
106
|
}
|
|
112
|
-
|
|
113
|
-
module.exports = LangpathsValidator;
|
|
107
|
+
export default LangpathsValidator;
|
package/lib/lang-assembler.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import async from 'async';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
4
|
|
|
5
5
|
const LOCALE_DIRECTORY = 'lang';
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* Assembles together all of the lang files.
|
|
9
8
|
* This simply loads the files from the lang directory and puts them in an object where
|
|
@@ -17,27 +16,22 @@ function assemble(callback) {
|
|
|
17
16
|
callback(err);
|
|
18
17
|
return;
|
|
19
18
|
}
|
|
20
|
-
|
|
21
19
|
// Ignore hidden files
|
|
22
20
|
// @example: MAC generates .DS_STORE
|
|
23
21
|
const filteredLocaleFiles = localeFiles.filter((fileName) => fileName[0] !== '.');
|
|
24
22
|
const localesToLoad = {};
|
|
25
|
-
|
|
26
23
|
for (const localeFile of filteredLocaleFiles) {
|
|
27
24
|
const localeName = path.basename(localeFile, '.json');
|
|
28
|
-
|
|
29
25
|
localesToLoad[localeName.toLowerCase()] = (cb2) => {
|
|
30
26
|
const localeFilePath = `${LOCALE_DIRECTORY}/${localeFile}`;
|
|
31
|
-
|
|
32
27
|
fs.readFile(localeFilePath, 'utf-8', cb2);
|
|
33
28
|
};
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
async.parallel(localesToLoad, callback);
|
|
37
31
|
});
|
|
38
32
|
}
|
|
39
33
|
|
|
40
|
-
|
|
34
|
+
export default {
|
|
41
35
|
assemble,
|
|
42
36
|
LOCALE_DIRECTORY,
|
|
43
37
|
};
|
package/lib/lang-helper.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import 'colors';
|
|
2
|
+
import fsUtilsModule from './utils/fsUtils.js';
|
|
3
3
|
|
|
4
4
|
function flattenObject(object, result = {}, parentKey = '') {
|
|
5
5
|
return Object.entries(object).reduce((currentLayer, [key, innerValue]) => {
|
|
@@ -12,7 +12,6 @@ function flattenObject(object, result = {}, parentKey = '') {
|
|
|
12
12
|
return currentLayer;
|
|
13
13
|
}, result);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
15
|
class LangHelper {
|
|
17
16
|
constructor({ fsUtils = fsUtilsModule, logger = console } = {}) {
|
|
18
17
|
this._fsUtils = fsUtils;
|
|
@@ -27,7 +26,6 @@ class LangHelper {
|
|
|
27
26
|
const defaultLangFile = await this._fsUtils.parseJsonFile(defaultLangFilePath);
|
|
28
27
|
const flattenedDefaultLang = flattenObject(defaultLangFile);
|
|
29
28
|
const alreadyWarnedKey = [];
|
|
30
|
-
|
|
31
29
|
for await (const filePath of filesPaths) {
|
|
32
30
|
if (!filePath.includes(themeLangFilename)) {
|
|
33
31
|
const langFile = await this._fsUtils.parseJsonFile(filePath);
|
|
@@ -55,5 +53,4 @@ class LangHelper {
|
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
|
-
|
|
59
|
-
module.exports = LangHelper;
|
|
56
|
+
export default LangHelper;
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const BaseRulesFixer = require('./BaseRulesFixer');
|
|
11
|
-
const ConditionaImportFixer = require('./ConditionalImportFixer');
|
|
12
|
-
const CommaRemovalFixer = require('./CommaRemovalFixer');
|
|
13
|
-
const UndefinedVariableFixer = require('./UndefinedVariableFixer');
|
|
1
|
+
import 'colors';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import ScssValidator from '../ScssValidator.js';
|
|
5
|
+
import cssCompiler from '../css/compile.js';
|
|
6
|
+
import BaseRulesFixer from './BaseRulesFixer.js';
|
|
7
|
+
import ConditionaImportFixer from './ConditionalImportFixer.js';
|
|
8
|
+
import CommaRemovalFixer from './CommaRemovalFixer.js';
|
|
9
|
+
import UndefinedVariableFixer from './UndefinedVariableFixer.js';
|
|
14
10
|
|
|
15
11
|
const CONDITIONAL_IMPORT = 'conditional-import';
|
|
16
12
|
const BASE_LEVEL_RULES = 'base-level-rules';
|
|
17
13
|
const POSSIBLE_WRONG_COMMA = 'possible-wrong-comma';
|
|
18
14
|
const UNDEFINED_VARIABLE = 'undefined-variable';
|
|
19
|
-
|
|
20
15
|
class AutoFixer {
|
|
21
16
|
/**
|
|
22
17
|
*
|
|
@@ -28,7 +23,6 @@ class AutoFixer {
|
|
|
28
23
|
this.themePath = themePath;
|
|
29
24
|
this.themeConfig = themeConfig;
|
|
30
25
|
this.cliOptions = cliOptions;
|
|
31
|
-
|
|
32
26
|
this.validator = new ScssValidator(themePath, themeConfig);
|
|
33
27
|
}
|
|
34
28
|
|
|
@@ -36,7 +30,6 @@ class AutoFixer {
|
|
|
36
30
|
const assetsPath = path.join(this.themePath, 'assets');
|
|
37
31
|
const rawConfig = await this.themeConfig.getConfig();
|
|
38
32
|
const cssFiles = await this.validator.getCssFiles();
|
|
39
|
-
|
|
40
33
|
let issuesDetected = false;
|
|
41
34
|
/* eslint-disable-next-line no-useless-catch */
|
|
42
35
|
try {
|
|
@@ -117,7 +110,6 @@ class AutoFixer {
|
|
|
117
110
|
return UNDEFINED_VARIABLE;
|
|
118
111
|
}
|
|
119
112
|
}
|
|
120
|
-
|
|
121
113
|
return null;
|
|
122
114
|
}
|
|
123
115
|
|
|
@@ -139,5 +131,4 @@ class AutoFixer {
|
|
|
139
131
|
}
|
|
140
132
|
}
|
|
141
133
|
}
|
|
142
|
-
|
|
143
|
-
module.exports = AutoFixer;
|
|
134
|
+
export default AutoFixer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import postcss from 'postcss';
|
|
4
|
+
import postcssScss from 'postcss-scss';
|
|
5
5
|
|
|
6
6
|
class BaseFixer {
|
|
7
7
|
constructor(dirname, brokenFile) {
|
|
@@ -35,7 +35,6 @@ class BaseFixer {
|
|
|
35
35
|
}
|
|
36
36
|
return filePathWithUnderscore;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
38
|
return filePath;
|
|
40
39
|
}
|
|
41
40
|
|
|
@@ -52,5 +51,4 @@ class BaseFixer {
|
|
|
52
51
|
return fileNameWithUnderscore;
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
module.exports = BaseFixer;
|
|
54
|
+
export default BaseFixer;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const BaseFixer = require('./BaseFixer');
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import BaseFixer from './BaseFixer.js';
|
|
6
3
|
|
|
7
4
|
class BaseRulesFixer extends BaseFixer {
|
|
8
5
|
async run() {
|
|
9
6
|
const scss = fs.readFileSync(this.filePath, 'utf8');
|
|
10
7
|
const processedFile = await this.processCss(scss, this.transform());
|
|
11
|
-
|
|
12
8
|
return [{ filePath: this.filePath, data: processedFile.css }];
|
|
13
9
|
}
|
|
14
10
|
|
|
@@ -36,5 +32,4 @@ class BaseRulesFixer extends BaseFixer {
|
|
|
36
32
|
return rule.toString().replace(/\/\*(.*)\*\//g, '//$1');
|
|
37
33
|
}
|
|
38
34
|
}
|
|
39
|
-
|
|
40
|
-
module.exports = BaseRulesFixer;
|
|
35
|
+
export default BaseRulesFixer;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const BaseFixer = require('./BaseFixer');
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import BaseFixer from './BaseFixer.js';
|
|
6
3
|
|
|
7
4
|
class CommaRemovalFixer extends BaseFixer {
|
|
8
5
|
async run() {
|
|
9
6
|
const scss = fs.readFileSync(this.filePath, 'utf8');
|
|
10
7
|
const processedFile = await this.processCss(scss, this.transform());
|
|
11
|
-
|
|
12
8
|
return [{ filePath: this.filePath, data: processedFile.css }];
|
|
13
9
|
}
|
|
14
10
|
|
|
@@ -24,5 +20,4 @@ class CommaRemovalFixer extends BaseFixer {
|
|
|
24
20
|
};
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
module.exports = CommaRemovalFixer;
|
|
23
|
+
export default CommaRemovalFixer;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign, operator-assignment */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const BaseFixer = require('./BaseFixer');
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import BaseFixer from './BaseFixer.js';
|
|
5
4
|
|
|
6
5
|
class ConditionalImportFixer extends BaseFixer {
|
|
7
6
|
async run() {
|
|
8
7
|
const files = [];
|
|
9
8
|
const scss = fs.readFileSync(this.filePath, 'utf8');
|
|
10
9
|
const result = await this.processCss(scss, this.transformConditionalImport());
|
|
11
|
-
|
|
12
10
|
files.push({ filePath: this.filePath, data: result.css });
|
|
13
11
|
const imports = this.mapFilesToRootFile(result.messages, this.filePath);
|
|
14
12
|
const toUpdateNestedImports = [];
|
|
15
|
-
|
|
16
13
|
for await (const fileImport of imports) {
|
|
17
14
|
const importFile = this.findImportedFile(fileImport.file, fileImport.rootFile);
|
|
18
15
|
const importFileScss = fs.readFileSync(importFile, { encoding: 'utf8' });
|
|
@@ -32,7 +29,6 @@ class ConditionalImportFixer extends BaseFixer {
|
|
|
32
29
|
});
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
if (this.shouldUpdateMixinNameInRootFile(toUpdateNestedImports)) {
|
|
37
33
|
const mixins = this.mapMixinNameToImportFileName(result.mixins);
|
|
38
34
|
// the target file is not updated right away, so the fresh content is in files object
|
|
@@ -214,7 +210,6 @@ class ConditionalImportFixer extends BaseFixer {
|
|
|
214
210
|
if (hasTabSpace) {
|
|
215
211
|
return '\t';
|
|
216
212
|
}
|
|
217
|
-
|
|
218
213
|
return ' ';
|
|
219
214
|
}
|
|
220
215
|
|
|
@@ -226,5 +221,4 @@ class ConditionalImportFixer extends BaseFixer {
|
|
|
226
221
|
return fileName.replace(/['"]+/g, '');
|
|
227
222
|
}
|
|
228
223
|
}
|
|
229
|
-
|
|
230
|
-
module.exports = ConditionalImportFixer;
|
|
224
|
+
export default ConditionalImportFixer;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import BaseFixer from './BaseFixer.js';
|
|
3
3
|
|
|
4
4
|
class UndefinedVariableFixer extends BaseFixer {
|
|
5
5
|
async run(errorMessage) {
|
|
6
6
|
const varName = this.getUndefinedVariableName(errorMessage);
|
|
7
7
|
const value = await this.guessVariableValue(varName);
|
|
8
|
-
|
|
9
8
|
const scss = fs.readFileSync(this.filePath, 'utf8');
|
|
10
9
|
const processedFile = await this.processCss(scss, this.transform(varName, value));
|
|
11
|
-
|
|
12
10
|
return [{ filePath: this.filePath, data: processedFile.css }];
|
|
13
11
|
}
|
|
14
12
|
|
|
@@ -56,5 +54,4 @@ class UndefinedVariableFixer extends BaseFixer {
|
|
|
56
54
|
};
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
|
-
|
|
60
|
-
module.exports = UndefinedVariableFixer;
|
|
57
|
+
export default UndefinedVariableFixer;
|
package/lib/parse-json.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import parseJson from 'parse-json';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
export function parse(jsonString, file = '') {
|
|
4
|
+
try {
|
|
5
|
+
return parseJson(jsonString);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
throw new Error(`${file} - ${e.message}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export default {
|
|
11
|
+
parse,
|
|
11
12
|
};
|
package/lib/regions.js
CHANGED
|
@@ -7,19 +7,15 @@
|
|
|
7
7
|
*/
|
|
8
8
|
function buildTemplateIncludes(templates, currentPartial, visited = {}) {
|
|
9
9
|
const includeRegex = /{{2}>\s*([_|\-|a-zA-Z0-9/]+)[^{]*?}{2}/g;
|
|
10
|
-
|
|
11
10
|
// eslint-disable-next-line no-param-reassign
|
|
12
11
|
visited[currentPartial] = true;
|
|
13
|
-
|
|
14
12
|
return templates[currentPartial].replace(includeRegex, (_, partial) => {
|
|
15
13
|
if (visited[partial]) {
|
|
16
14
|
return '';
|
|
17
15
|
}
|
|
18
|
-
|
|
19
16
|
return buildTemplateIncludes(templates, partial, visited);
|
|
20
17
|
});
|
|
21
18
|
}
|
|
22
|
-
|
|
23
19
|
/**
|
|
24
20
|
* Insert all #partial blocks in the corresponding #block block
|
|
25
21
|
* @param {string} template
|
|
@@ -29,17 +25,14 @@ function parsePartialBlocks(template) {
|
|
|
29
25
|
const partialRegex = /{{2}\s*#partial\s+.*?["|']([\w-]+)["|'].*?}{2}([\s\S]*?){{2}\/partial}{2}?/g;
|
|
30
26
|
const blockRegex = /{{2}\s*#block\s+.*?["|']([\w-]+)["|'].*?}{2}([\s\S]*?){{2}\/block}{2}?/g;
|
|
31
27
|
const partials = {};
|
|
32
|
-
|
|
33
28
|
const output = template.replace(partialRegex, (_, name, content) => {
|
|
34
29
|
partials[name] = content;
|
|
35
30
|
return '';
|
|
36
31
|
});
|
|
37
|
-
|
|
38
32
|
return output.replace(blockRegex, (_, name, content) => {
|
|
39
33
|
return content + (partials[name] || '');
|
|
40
34
|
});
|
|
41
35
|
}
|
|
42
|
-
|
|
43
36
|
/**
|
|
44
37
|
* Replace all occurrences of dynamicComponent with the content of the partials
|
|
45
38
|
* @param {Object} templates
|
|
@@ -48,7 +41,6 @@ function parsePartialBlocks(template) {
|
|
|
48
41
|
*/
|
|
49
42
|
function parseDynamicComponents(templates, template) {
|
|
50
43
|
const dynamicComponentRegex = /{{\s*?dynamicComponent\s*(?:'|")([_|\-|a-zA-Z0-9/]+)(?:'|").*?}}/g;
|
|
51
|
-
|
|
52
44
|
return template.replace(dynamicComponentRegex, (_, path) => {
|
|
53
45
|
// insert dynamic components in the template
|
|
54
46
|
return Object.keys(templates)
|
|
@@ -58,7 +50,6 @@ function parseDynamicComponents(templates, template) {
|
|
|
58
50
|
}, '');
|
|
59
51
|
});
|
|
60
52
|
}
|
|
61
|
-
|
|
62
53
|
/**
|
|
63
54
|
* Builds a template with all include partials and include all dynamic components
|
|
64
55
|
* @param {Object} templates
|
|
@@ -69,10 +60,8 @@ function buildPageTemplate(templates, page) {
|
|
|
69
60
|
let pageTemplate = buildTemplateIncludes(templates, page);
|
|
70
61
|
pageTemplate = parsePartialBlocks(pageTemplate);
|
|
71
62
|
pageTemplate = parseDynamicComponents(templates, pageTemplate);
|
|
72
|
-
|
|
73
63
|
return pageTemplate;
|
|
74
64
|
}
|
|
75
|
-
|
|
76
65
|
/**
|
|
77
66
|
* Returns a boolean if there are two regions with the same name
|
|
78
67
|
* @param {Object} regions
|
|
@@ -88,10 +77,8 @@ function checkDuplicateRegionName(regions, regionData) {
|
|
|
88
77
|
break;
|
|
89
78
|
}
|
|
90
79
|
}
|
|
91
|
-
|
|
92
80
|
return result;
|
|
93
81
|
}
|
|
94
|
-
|
|
95
82
|
/**
|
|
96
83
|
* Parse a template content and return an array of unique region objects
|
|
97
84
|
* @param {string} content
|
|
@@ -103,28 +90,23 @@ function parseRegions(content) {
|
|
|
103
90
|
const regions = new Set();
|
|
104
91
|
let regionMatch;
|
|
105
92
|
const translationMatch = translationRegex.exec(content);
|
|
106
|
-
|
|
107
93
|
// eslint-disable-next-line
|
|
108
94
|
while ((regionMatch = regionRegex.exec(content))) {
|
|
109
95
|
const regionData = {};
|
|
110
96
|
// eslint-disable-next-line prefer-destructuring
|
|
111
97
|
regionData.name = regionMatch[1];
|
|
112
|
-
|
|
113
98
|
// If there is a translation match and regionName match is valid, add data to region
|
|
114
99
|
if (translationMatch && regionMatch[1]) {
|
|
115
100
|
// eslint-disable-next-line prefer-destructuring
|
|
116
101
|
regionData.translation = translationMatch[1];
|
|
117
102
|
}
|
|
118
|
-
|
|
119
103
|
if (!checkDuplicateRegionName(regions, regionData)) {
|
|
120
104
|
regions.add(regionData);
|
|
121
105
|
}
|
|
122
106
|
}
|
|
123
107
|
const regionArray = Array.from(regions);
|
|
124
|
-
|
|
125
108
|
return regionArray.map(({ name, translation }) => ({ name, translation }));
|
|
126
109
|
}
|
|
127
|
-
|
|
128
110
|
/**
|
|
129
111
|
* Returns an object of regions for the manifest file
|
|
130
112
|
* @param {Object} templates
|
|
@@ -134,17 +116,15 @@ function parseRegions(content) {
|
|
|
134
116
|
function fetchRegions(templates, partials) {
|
|
135
117
|
const pages = partials.filter((partial) => partial.match(/^pages\//));
|
|
136
118
|
const regions = {};
|
|
137
|
-
|
|
138
119
|
pages.forEach((page) => {
|
|
139
120
|
const template = buildPageTemplate(templates[page], page);
|
|
140
|
-
|
|
141
121
|
regions[page] = parseRegions(template);
|
|
142
122
|
});
|
|
143
|
-
|
|
144
123
|
return regions;
|
|
145
124
|
}
|
|
146
|
-
|
|
147
|
-
|
|
125
|
+
export { fetchRegions };
|
|
126
|
+
export { parseRegions };
|
|
127
|
+
export default {
|
|
148
128
|
fetchRegions,
|
|
149
129
|
parseRegions,
|
|
150
130
|
};
|