@bigcommerce/stencil-cli 8.3.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.
Files changed (70) hide show
  1. package/bin/stencil-bundle.js +7 -18
  2. package/bin/stencil-debug.js +5 -9
  3. package/bin/stencil-download.js +7 -19
  4. package/bin/stencil-init.js +4 -8
  5. package/bin/stencil-pull.js +5 -11
  6. package/bin/stencil-push.js +5 -8
  7. package/bin/stencil-release.js +5 -10
  8. package/bin/stencil-scss-autofix.js +6 -11
  9. package/bin/stencil-start.js +6 -9
  10. package/bin/stencil.js +2 -3
  11. package/constants.js +9 -9
  12. package/lib/BuildConfigManager.js +25 -23
  13. package/lib/Cycles.js +3 -12
  14. package/lib/ScssValidator.js +5 -9
  15. package/lib/StencilCLISettings.js +1 -3
  16. package/lib/StencilConfigManager.js +6 -22
  17. package/lib/StencilDebug.js +7 -10
  18. package/lib/archiveManager.js +7 -23
  19. package/lib/bundle-validator.js +28 -64
  20. package/lib/cliCommon.js +11 -21
  21. package/lib/commander.js +2 -3
  22. package/lib/content-api-client.js +5 -13
  23. package/lib/css/compile.js +3 -6
  24. package/lib/graphql/query.js +5 -8
  25. package/lib/lang/validator.js +5 -11
  26. package/lib/lang-assembler.js +4 -10
  27. package/lib/lang-helper.js +3 -6
  28. package/lib/nodeSass/AutoFixer.js +10 -19
  29. package/lib/nodeSass/BaseFixer.js +5 -7
  30. package/lib/nodeSass/BaseRulesFixer.js +3 -8
  31. package/lib/nodeSass/CommaRemovalFixer.js +3 -8
  32. package/lib/nodeSass/ConditionalImportFixer.js +3 -9
  33. package/lib/nodeSass/UndefinedVariableFixer.js +3 -6
  34. package/lib/parse-json.js +10 -9
  35. package/lib/regions.js +3 -23
  36. package/lib/release/questions.js +3 -13
  37. package/lib/release/release.js +16 -55
  38. package/lib/spinner.js +1 -2
  39. package/lib/stencil-bundle.js +15 -75
  40. package/lib/stencil-download.js +5 -6
  41. package/lib/stencil-download.utils.js +5 -18
  42. package/lib/stencil-init.js +8 -24
  43. package/lib/stencil-pull.js +4 -5
  44. package/lib/stencil-pull.utils.js +5 -28
  45. package/lib/stencil-push.js +3 -4
  46. package/lib/stencil-push.utils.js +12 -102
  47. package/lib/stencil-start.js +19 -48
  48. package/lib/store-settings-api-client.js +4 -7
  49. package/lib/template-assembler.js +6 -45
  50. package/lib/theme-api-client.js +7 -30
  51. package/lib/theme-config.js +16 -59
  52. package/lib/utils/NetworkUtils.js +6 -16
  53. package/lib/utils/asyncUtils.js +2 -3
  54. package/lib/utils/frontmatter.js +4 -5
  55. package/lib/utils/fsUtils.js +6 -10
  56. package/lib/validator/schema-translations.js +5 -7
  57. package/package.json +11 -8
  58. package/server/config.js +3 -7
  59. package/server/index.js +29 -29
  60. package/server/lib/page-type-util.js +2 -5
  61. package/server/lib/show-logo.js +3 -3
  62. package/server/lib/utils.js +6 -11
  63. package/server/manifest.js +7 -11
  64. package/server/plugins/renderer/renderer.module.js +38 -100
  65. package/server/plugins/renderer/responses/index.js +7 -4
  66. package/server/plugins/renderer/responses/pencil-response.js +4 -32
  67. package/server/plugins/renderer/responses/raw-response.js +6 -14
  68. package/server/plugins/renderer/responses/redirect-response.js +1 -4
  69. package/server/plugins/router/router.module.js +9 -14
  70. package/server/plugins/theme-assets/theme-assets.module.js +15 -27
@@ -1,12 +1,11 @@
1
- require('colors');
2
- const NetworkUtils = require('./utils/NetworkUtils');
3
- const {
1
+ import 'colors';
2
+ import NetworkUtils from './utils/NetworkUtils.js';
3
+ import {
4
4
  renderedRegionsByPageTypeQuery,
5
5
  renderedRegionsByPageTypeAndEntityIdQuery,
6
- } = require('./graphql/query');
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
- module.exports = {
92
+ export default {
101
93
  getRenderedRegionsByPageType,
102
94
  getRenderedRegionsByPageTypeAndEntityId,
103
95
  };
@@ -1,8 +1,7 @@
1
- const path = require('path');
2
- const StencilStyles = require('@bigcommerce/stencil-styles');
1
+ import path from 'path';
2
+ import StencilStyles from '@bigcommerce/stencil-styles';
3
3
 
4
4
  const SASS_ENGINE_NAME = 'node-sass';
5
-
6
5
  const compile = async (configuration, themeAssetsPath, fileName, engineName = SASS_ENGINE_NAME) => {
7
6
  const fileParts = path.parse(fileName);
8
7
  const ext = configuration.css_compiler === 'css' ? configuration.css_compiler : 'scss';
@@ -17,7 +16,6 @@ const compile = async (configuration, themeAssetsPath, fileName, engineName = SA
17
16
  console.error(err);
18
17
  throw err;
19
18
  }
20
-
21
19
  const params = {
22
20
  data: files[pathToFile],
23
21
  files,
@@ -30,11 +28,10 @@ const compile = async (configuration, themeAssetsPath, fileName, engineName = SA
30
28
  },
31
29
  };
32
30
  stencilStyles.activateEngine(engineName);
33
-
34
31
  return stencilStyles.compileCss('scss', params);
35
32
  };
36
33
 
37
- module.exports = {
34
+ export default {
38
35
  compile,
39
36
  SASS_ENGINE_NAME,
40
37
  };
@@ -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
- module.exports = {
34
+ export { renderedRegionsByPageTypeQuery };
35
+ export { renderedRegionsByPageTypeAndEntityIdQuery };
36
+ export default {
40
37
  renderedRegionsByPageTypeQuery,
41
38
  renderedRegionsByPageTypeAndEntityIdQuery,
42
39
  };
@@ -1,10 +1,9 @@
1
- require('colors');
2
- const fs = require('fs');
3
- const path = require('path');
4
- const { recursiveReadDir } = require('../utils/fsUtils');
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;
@@ -1,9 +1,8 @@
1
- const async = require('async');
2
- const fs = require('fs');
3
- const path = require('path');
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
- module.exports = {
34
+ export default {
41
35
  assemble,
42
36
  LOCALE_DIRECTORY,
43
37
  };
@@ -1,5 +1,5 @@
1
- require('colors');
2
- const fsUtilsModule = require('./utils/fsUtils');
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
- /* eslint-disable no-param-reassign, operator-assignment */
2
- require('colors');
3
-
4
- const fs = require('fs');
5
- const path = require('path');
6
-
7
- const ScssValidator = require('../ScssValidator');
8
- const cssCompiler = require('../css/compile');
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
- const fs = require('fs');
2
- const path = require('path');
3
- const postcss = require('postcss');
4
- const postcssScss = require('postcss-scss');
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
- // Since previously a broken css was produced which had no effect on the page (browsers are smart enough to ignore unprocessable css)
2
- // we can just comment out that part of code
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
- // There can be the case, when you have a comma at the beginning or at the end of the selector, which now is not allowed.
2
- // Previously it was just ignored, but now it will cause an error.
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
- const fs = require('fs');
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
- const fs = require('fs');
2
- const BaseFixer = require('./BaseFixer');
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
- const parseJson = require('parse-json');
1
+ import parseJson from 'parse-json';
2
2
 
3
- module.exports = {
4
- parse(jsonString, file = '') {
5
- try {
6
- return parseJson(jsonString);
7
- } catch (e) {
8
- throw new Error(`${file} - ${e.message}`);
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
- module.exports = {
125
+ export { fetchRegions };
126
+ export { parseRegions };
127
+ export default {
148
128
  fetchRegions,
149
129
  parseRegions,
150
130
  };
@@ -1,24 +1,21 @@
1
- const inquirer = require('inquirer');
2
- const semver = require('semver');
1
+ import inquirer from 'inquirer';
2
+ import semver from 'semver';
3
3
 
4
4
  const dateFormatOptions = {
5
5
  year: 'numeric',
6
6
  month: '2-digit',
7
7
  day: '2-digit',
8
8
  };
9
-
10
9
  async function askQuestions(currentVersion, githubToken, remotes) {
11
10
  const remoteChoices = remotes.map((remote) => {
12
11
  return { value: remote, name: `${remote.name}: ${remote.url}` };
13
12
  });
14
-
15
13
  const nextPatchVersion = semver.inc(currentVersion, 'patch');
16
14
  const nextMinorVersion = semver.inc(currentVersion, 'minor');
17
15
  const nextMajorVersion = semver.inc(currentVersion, 'major');
18
16
  const nextReleaseCandidate = currentVersion.includes('-rc.')
19
17
  ? semver.inc(currentVersion, 'prerelease', 'rc')
20
18
  : `${nextMinorVersion}-rc.1`;
21
-
22
19
  const questions = [
23
20
  {
24
21
  name: 'version',
@@ -67,7 +64,6 @@ async function askQuestions(currentVersion, githubToken, remotes) {
67
64
  when: (answers) => answers.version === 'custom',
68
65
  validate: (value) => {
69
66
  const valid = semver.valid(value) && true;
70
-
71
67
  return valid || 'Must be a valid semver, such as 1.2.3';
72
68
  },
73
69
  },
@@ -97,18 +93,12 @@ async function askQuestions(currentVersion, githubToken, remotes) {
97
93
  message: 'Proceed?',
98
94
  },
99
95
  ];
100
-
101
96
  const answers = await inquirer.prompt(questions);
102
-
103
97
  if (!answers.proceed) {
104
98
  throw new Error('Operation cancelled');
105
99
  }
106
-
107
100
  answers.githubToken = answers.githubToken || githubToken;
108
-
109
101
  answers.date = new Date().toLocaleString('en-US', dateFormatOptions).split('/').join('-');
110
-
111
102
  return answers;
112
103
  }
113
-
114
- module.exports = askQuestions;
104
+ export default askQuestions;