@appdirect/sfb-toolkit 3.0.5 → 4.0.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 (66) hide show
  1. package/.babelrc +8 -13
  2. package/Dockerfile +2 -2
  3. package/bin/index.js +0 -14
  4. package/coverage/clover.xml +32 -32
  5. package/coverage/coverage-final.json +10 -10
  6. package/coverage/lcov-report/block-navigation.js +8 -0
  7. package/coverage/lcov-report/constants/customUserAttributesMock.js.html +8 -3
  8. package/coverage/lcov-report/constants/index.html +8 -3
  9. package/coverage/lcov-report/constants/pageUrls.js.html +8 -3
  10. package/coverage/lcov-report/constants/userMock.js.html +8 -3
  11. package/coverage/lcov-report/controllers/controllers-utils/assetsUtils.js.html +8 -3
  12. package/coverage/lcov-report/controllers/controllers-utils/index.html +8 -3
  13. package/coverage/lcov-report/controllers/data-filters/bootstrap-data-filter.js.html +9 -4
  14. package/coverage/lcov-report/controllers/data-filters/call-to-actions-filter.js.html +8 -3
  15. package/coverage/lcov-report/controllers/data-filters/index.html +12 -7
  16. package/coverage/lcov-report/controllers/index.html +8 -3
  17. package/coverage/lcov-report/controllers/index.js.html +11 -6
  18. package/coverage/lcov-report/favicon.png +0 -0
  19. package/coverage/lcov-report/front-end-utils/src/components/base/ResultItem.js.html +18 -13
  20. package/coverage/lcov-report/front-end-utils/src/components/base/SearchBar.js.html +11 -6
  21. package/coverage/lcov-report/front-end-utils/src/components/base/index.html +13 -8
  22. package/coverage/lcov-report/front-end-utils/src/components/base/item.js.html +19 -14
  23. package/coverage/lcov-report/front-end-utils/src/components/container.js.html +11 -6
  24. package/coverage/lcov-report/front-end-utils/src/components/data-view.js.html +10 -5
  25. package/coverage/lcov-report/front-end-utils/src/components/header-view.js.html +10 -5
  26. package/coverage/lcov-report/front-end-utils/src/components/index.html +17 -12
  27. package/coverage/lcov-report/front-end-utils/src/components/search.js.html +23 -18
  28. package/coverage/lcov-report/front-end-utils/src/constants/index.html +8 -3
  29. package/coverage/lcov-report/front-end-utils/src/constants/pageUrl.js.html +8 -3
  30. package/coverage/lcov-report/front-end-utils/src/constants/roleType.js.html +8 -3
  31. package/coverage/lcov-report/front-end-utils/src/constants/searchType.js.html +8 -3
  32. package/coverage/lcov-report/front-end-utils/src/utils/debounce.js.html +8 -3
  33. package/coverage/lcov-report/front-end-utils/src/utils/index.html +8 -3
  34. package/coverage/lcov-report/index.html +18 -13
  35. package/coverage/lcov-report/middlewares/config.js.html +8 -3
  36. package/coverage/lcov-report/middlewares/index.html +8 -3
  37. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  38. package/coverage/lcov-report/sorter.js +26 -0
  39. package/coverage/lcov.info +81 -81
  40. package/index.js +14 -8
  41. package/npm-shrinkwrap.json +34576 -7042
  42. package/package.json +99 -80
  43. package/readme.md +18 -6
  44. package/src/controllers/index.js +1 -1
  45. package/src/front-end-utils/dist/toolbar.bundle.js +2 -49
  46. package/src/front-end-utils/dist/toolbar.bundle.js.LICENSE.txt +52 -0
  47. package/src/front-end-utils/src/components/base/ResultItem.js +2 -2
  48. package/src/front-end-utils/src/components/base/SearchBar.js +1 -1
  49. package/src/front-end-utils/src/components/container.js +1 -1
  50. package/src/front-end-utils/src/components/data-view.js +1 -1
  51. package/src/front-end-utils/src/components/header-view.js +1 -1
  52. package/src/front-end-utils/src/components/search.js +1 -1
  53. package/src/tools/compiler-components-prod.js +1 -1
  54. package/src/tools/gulp-tasks.js +2 -2
  55. package/src/tools/toolkit-common-fun.js +88 -4
  56. package/src/tools/toolkit-common-vars.js +1 -1
  57. package/src/tools/toolkit-components.js +11 -5
  58. package/src/tools/toolkit-create.js +19 -2
  59. package/src/tools/toolkit-install.js +20 -2
  60. package/src/tools/toolkit-package.js +4 -3
  61. package/src/tools/toolkit-setup.js +41 -7
  62. package/src/tools/toolkit-storybook.js +5 -5
  63. package/{webpack-components.config.js → webpack-components.config.cjs} +1 -3
  64. package/{webpack-components.config.prod.js → webpack-components.config.prod.cjs} +1 -3
  65. package/{webpack.config.js → webpack.config.cjs} +8 -5
  66. package/src/tools/toolkit-tests.js +0 -99
@@ -0,0 +1,52 @@
1
+ /*
2
+ object-assign
3
+ (c) Sindre Sorhus
4
+ @license MIT
5
+ */
6
+
7
+ /*! js-cookie v3.0.1 | MIT */
8
+
9
+ /**
10
+ * Prism: Lightweight, robust, elegant syntax highlighting
11
+ *
12
+ * @license MIT <https://opensource.org/licenses/MIT>
13
+ * @author Lea Verou <https://lea.verou.me>
14
+ * @namespace
15
+ * @public
16
+ */
17
+
18
+ /** @license React v0.19.1
19
+ * scheduler.production.min.js
20
+ *
21
+ * Copyright (c) Facebook, Inc. and its affiliates.
22
+ *
23
+ * This source code is licensed under the MIT license found in the
24
+ * LICENSE file in the root directory of this source tree.
25
+ */
26
+
27
+ /** @license React v16.13.1
28
+ * react-is.production.min.js
29
+ *
30
+ * Copyright (c) Facebook, Inc. and its affiliates.
31
+ *
32
+ * This source code is licensed under the MIT license found in the
33
+ * LICENSE file in the root directory of this source tree.
34
+ */
35
+
36
+ /** @license React v16.14.0
37
+ * react-dom.production.min.js
38
+ *
39
+ * Copyright (c) Facebook, Inc. and its affiliates.
40
+ *
41
+ * This source code is licensed under the MIT license found in the
42
+ * LICENSE file in the root directory of this source tree.
43
+ */
44
+
45
+ /** @license React v16.14.0
46
+ * react.production.min.js
47
+ *
48
+ * Copyright (c) Facebook, Inc. and its affiliates.
49
+ *
50
+ * This source code is licensed under the MIT license found in the
51
+ * LICENSE file in the root directory of this source tree.
52
+ */
@@ -1,9 +1,9 @@
1
1
  import React from "react"
2
2
  import PropTypes from "prop-types"
3
3
  import styled from "styled-components"
4
- import SyntaxHighlighter from "react-syntax-highlighter/prism"
4
+ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"
5
5
  import ReactJson from "react-json-view"
6
- import { atomDark } from "react-syntax-highlighter/styles/prism"
6
+ import { atomDark } from "react-syntax-highlighter/dist/cjs/styles/prism"
7
7
 
8
8
  import { SEARCH_TYPES } from "../../constants/searchType"
9
9
 
@@ -1,7 +1,7 @@
1
1
  import React from "react"
2
2
  import PropTypes from "prop-types"
3
3
  import styled from "styled-components"
4
- import FontAwesomeIcon from "@fortawesome/react-fontawesome"
4
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
5
5
  import { faSearch, faAngleDown } from "@fortawesome/free-solid-svg-icons"
6
6
 
7
7
  const SelectContainer = styled.div`
@@ -1,6 +1,6 @@
1
1
  import React from "react"
2
2
  import styled from "styled-components"
3
- import FontAwesomeIcon from "@fortawesome/react-fontawesome"
3
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
4
4
  import {
5
5
  faAngleDoubleLeft,
6
6
  faAngleDoubleRight,
@@ -1,7 +1,7 @@
1
1
  import React from "react"
2
2
  import PropTypes from "prop-types"
3
3
  import styled from "styled-components"
4
- import FontAwesomeIcon from "@fortawesome/react-fontawesome"
4
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
5
5
  import ReactJson from "react-json-view"
6
6
  import { faDatabase } from "@fortawesome/free-solid-svg-icons"
7
7
 
@@ -2,7 +2,7 @@ import React from "react"
2
2
  import Cookies from "js-cookie"
3
3
  import PropTypes from "prop-types"
4
4
  import styled from "styled-components"
5
- import FontAwesomeIcon from "@fortawesome/react-fontawesome"
5
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
6
6
  import { NO_ROLE, MARKETPLACE_MANAGER, USER } from '../constants/roleType'
7
7
  import { HOME_PAGE_URL, MOCK_ADMIN_PAGE_URL } from '../constants/pageUrl'
8
8
 
@@ -1,7 +1,7 @@
1
1
  import React from "react"
2
2
  import PropTypes from "prop-types"
3
3
  import styled from "styled-components"
4
- import FontAwesomeIcon from "@fortawesome/react-fontawesome"
4
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
5
5
  import { faSearch, faTimes } from "@fortawesome/free-solid-svg-icons"
6
6
 
7
7
  import debounce from "../utils/debounce"
@@ -3,7 +3,7 @@ const fs = require("fs")
3
3
  const fsExtra = require("fs-extra")
4
4
  const { TOOLKIT_PATH } = require("./toolkit-common-vars")
5
5
 
6
- const getConfigComponentsProdWebpack = require(`${TOOLKIT_PATH}/webpack-components.config.prod`)
6
+ const getConfigComponentsProdWebpack = require(`${TOOLKIT_PATH}/webpack-components.config.prod.cjs`)
7
7
  const currentPath = process.cwd() // used to get current dev folder
8
8
  const config = require(`${currentPath}/config`)
9
9
  const customComponentsAssets = `${currentPath}/themes/${
@@ -1,5 +1,5 @@
1
- const { src, dest, series, watch } = require('gulp');
2
- const sass = require("gulp-sass")
1
+ const { src, dest, series, watch } = require("gulp");
2
+ const sass = require("gulp-sass")(require("sass"))
3
3
  const concat = require("gulp-concat")
4
4
  const sourcemaps = require("gulp-sourcemaps")
5
5
 
@@ -3,10 +3,11 @@ const moment = require("moment");
3
3
  const colors = require("colors");
4
4
  const prompt = require("./prompt-questions");
5
5
  const packageJson = require('package-json');
6
- const { spawnSync } = require("child_process")
6
+ const { spawnSync } = require("child_process");
7
7
 
8
8
  const { CURRENT_PATH, TOOLKIT_PATH, BOOTSTRAP_FOLDERS, BOOTSTRAP_FILES, CONFIG_PATH, THEME_COMPONENT_MODULE,
9
- THEME_COMPONENT_VERSION, ACTIVE_THEME_PATH, THEME_LOGS_PATH, THEME_LOGS_FILE_PATH } = require("./toolkit-common-vars")
9
+ THEME_COMPONENT_VERSION, ACTIVE_THEME_PATH, THEME_LOGS_PATH, THEME_LOGS_FILE_PATH } = require("./toolkit-common-vars");
10
+ const { has } = require("lodash");
10
11
 
11
12
 
12
13
  // function to remove project's folders (used to revert changes on error)
@@ -110,7 +111,7 @@ const installSfbThemeComponents = () => {
110
111
 
111
112
  // check if sfb-theme-components is installed otherwise install it
112
113
  spawnSync('npm',
113
- [`ls ${THEME_COMPONENT_MODULE} 2>&1 | (findstr ${THEME_COMPONENT_MODULE} || grep ${THEME_COMPONENT_MODULE}) > ${THEME_LOGS_FILE_PATH} 2>&1 || npm i -S ${THEME_COMPONENT_MODULE}@${THEME_COMPONENT_VERSION} --production`], {
114
+ [`ls ${THEME_COMPONENT_MODULE} 2>&1 | (findstr ${THEME_COMPONENT_MODULE} || grep ${THEME_COMPONENT_MODULE}) > ${THEME_LOGS_FILE_PATH} 2>&1 || npm i -S ${THEME_COMPONENT_MODULE}@${THEME_COMPONENT_VERSION} --production --legacy-peer-deps`], {
114
115
  cwd: ACTIVE_THEME_PATH,
115
116
  stdio: "inherit",
116
117
  shell: true
@@ -152,6 +153,87 @@ const createCustomThemePacakgeJson = (themeName, themePackageName, createdBy) =>
152
153
  return JSON.stringify(customThemePackageJson, null, 2);
153
154
  }
154
155
 
156
+ const updateCustomComponentsMetadata = (data) => {
157
+ const hasPackageJson = fs.existsSync(`${ACTIVE_THEME_PATH}/package.json`);
158
+ if (hasPackageJson) {
159
+ const themePackageJson = JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
160
+ const sfbThemeComponentsVersion = themePackageJson.dependencies['@appdirect/sfb-theme-components'];
161
+ data = data.replace('data-custom-components="false"', 'data-custom-components="true"');
162
+ if(sfbThemeComponentsVersion)
163
+ data = data.replace(/data-sfb-theme-components-version=".*"/, `data-sfb-theme-components-version="${sfbThemeComponentsVersion}"`);
164
+ }
165
+ return data;
166
+ }
167
+
168
+ const addMetadata = (metadata = {}, themePath) => {
169
+ const sfbConfigPath = themePath || CURRENT_PATH;
170
+ const currentTheme = JSON.parse(fs.readFileSync(`${sfbConfigPath}/.sfbconfig`)).current;
171
+ const baseFilePath = `${sfbConfigPath}/themes/${currentTheme}/content/layout/base.html`;
172
+ const baseFileData = fs.readFileSync(baseFilePath, 'utf8');
173
+ const hasMetadata = baseFileData.includes('ad-theme');
174
+ if (hasMetadata) {
175
+ const updatedMetadata = updateCustomComponentsMetadata(baseFileData);
176
+ fs.writeFileSync(baseFilePath, updatedMetadata);
177
+ return;
178
+ }
179
+ const headElemIndex = baseFileData.indexOf('<head>');
180
+ const headElemLength = '<head>'.length;
181
+ const providedMetadata = Object.keys(metadata).length;
182
+
183
+ let themeTemplate;
184
+ let themeVersion;
185
+ let createdBy;
186
+ let createdAt;
187
+ let customComponents;
188
+ let sfbThemeComponentsVersion;
189
+
190
+ if (providedMetadata) {
191
+ themeTemplate = metadata.themeTemplate;
192
+ themeVersion = metadata.themeVersion;
193
+ createdBy = metadata.createdBy;
194
+ createdAt = metadata.createdAt;
195
+ customComponents = metadata.customComponents;
196
+ sfbThemeComponentsVersion = metadata.sfbThemeComponentsVersion;
197
+ } else {
198
+ const hasPackageJson = fs.existsSync(`${ACTIVE_THEME_PATH}/package.json`);
199
+ const themePackageJson = hasPackageJson && JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
200
+ const hasPackageMetadata = themePackageJson && themePackageJson.metadata && Object.keys(themePackageJson.metadata).length;
201
+ const hasPackageDependencies = themePackageJson && themePackageJson.dependencies && Object.keys(themePackageJson.dependencies).length;
202
+ const customComponentsPath = `${ACTIVE_THEME_PATH}/customComponents`;
203
+ customComponents = fs.existsSync(customComponentsPath);
204
+
205
+ sfbThemeComponentsVersion = customComponents && hasPackageDependencies
206
+ ? themePackageJson.dependencies['@appdirect/sfb-theme-components']
207
+ : 'latest'
208
+
209
+ if (hasPackageMetadata) {
210
+ themeTemplate = themePackageJson.metadata.themeTemplate;
211
+ themeVersion = themePackageJson.metadata.themeVersion;
212
+ createdBy = themePackageJson.metadata.createdBy;
213
+ createdAt = new Date(themePackageJson.metadata.createdAt).toString();
214
+ } else {
215
+ const hasSettingsSchema = fs.existsSync(`${ACTIVE_THEME_PATH}/settings-schema.json`);
216
+ const isClassicTheme = baseFileData.includes('cloudflare') || !hasSettingsSchema;
217
+ themeTemplate = isClassicTheme
218
+ ? '@appdirect/sfb-theme-classic'
219
+ : '@appdirect/sfb-theme-plaza'
220
+ }
221
+ }
222
+
223
+ const output = baseFileData.substring(0, headElemIndex + headElemLength)
224
+ + `\n <ad-theme`
225
+ + (themeTemplate ? `\n data-theme-template="${themeTemplate}"` : '')
226
+ + (themeVersion ? `\n data-theme-version="${themeVersion}"` : '')
227
+ + (createdBy ? `\n data-created-by="${createdBy}"` :'')
228
+ + (createdAt ? `\n data-created-at="${createdAt}"` : '')
229
+ + `\n data-custom-components="${customComponents}"`
230
+ + `\n data-sfb-theme-components-version="${sfbThemeComponentsVersion}">`
231
+ + `\n </ad-theme>`
232
+ + baseFileData.substring(headElemIndex + headElemLength);
233
+
234
+ fs.writeFileSync(baseFilePath, output);
235
+ }
236
+
155
237
  module.exports = {
156
238
  selfDestruction,
157
239
  filesCounter,
@@ -163,5 +245,7 @@ module.exports = {
163
245
  installSfbThemeComponents,
164
246
  createPackageJson,
165
247
  createThemeLogsFolder,
166
- createCustomThemePacakgeJson
248
+ createCustomThemePacakgeJson,
249
+ updateCustomComponentsMetadata,
250
+ addMetadata
167
251
  }
@@ -15,7 +15,7 @@ const THEME_TEMPLATES_CONFIG_PATH = `${TOOLKIT_PATH}/themes-config.json`;
15
15
  const THEME_TEMPLATES = JSON.parse(fs.readFileSync(THEME_TEMPLATES_CONFIG_PATH));
16
16
  const PAGE_OBJECTS_SUFFIX = "/api/internal/storefront/v1";
17
17
  const THEME_COMPONENT_MODULE = "@appdirect/sfb-theme-components";
18
- const THEME_COMPONENT_VERSION = "0.0.272";
18
+ const THEME_COMPONENT_VERSION = "0.0.293";
19
19
 
20
20
  let WORKSPACE_CONFIG;
21
21
  try {
@@ -1,5 +1,6 @@
1
1
  const fs = require("fs-extra")
2
- const { shouldBeProjectFolder, installSfbThemeComponents, createPackageJson } = require("./toolkit-common-fun");
2
+ const { shouldBeProjectFolder, installSfbThemeComponents,
3
+ createPackageJson, updateCustomComponentsMetadata } = require("./toolkit-common-fun");
3
4
  const { ACTIVE_THEME_PATH } = require("./toolkit-common-vars");
4
5
 
5
6
  shouldBeProjectFolder(true);
@@ -18,7 +19,7 @@ const settingsSchemaData = `{ "useComponents": true }`;
18
19
  (() => {
19
20
  const baseFilePath = `${ACTIVE_THEME_PATH}/content/layout/base.html`;
20
21
  const customComponentsPath = `${ACTIVE_THEME_PATH}/customComponents`
21
- const existsCustomComponents = fs.existsSync(customComponentsPath);
22
+ const customComponentsEnabled = fs.existsSync(customComponentsPath);
22
23
 
23
24
  createPackageJson();
24
25
 
@@ -30,7 +31,7 @@ const settingsSchemaData = `{ "useComponents": true }`;
30
31
  })
31
32
  }
32
33
 
33
- if (!existsCustomComponents) {
34
+ if (!customComponentsEnabled) {
34
35
  fs.copy(`${__dirname}/../../customComponents`, customComponentsPath, err => {
35
36
  if (err) return console.error(' ERROR: Unable to copy required files'.red);
36
37
  })
@@ -40,7 +41,7 @@ const settingsSchemaData = `{ "useComponents": true }`;
40
41
  if (err) return console.error(` ERROR: Unable to read the base layout file. Tried: ${baseFilePath}`.red);
41
42
 
42
43
  const cdnComponents = data.match(/\S+.+channelCanonicalBaseUrl.+(css|js).+/g);
43
- const assetsComponents = data.match(/\S+.+r\(.+assets.+sfb-components.+(css|js).+/g)
44
+ const assetsComponents = data.match(/\S+.+r\(.+assets.+sfb-components.+(css|js).+/g);
44
45
 
45
46
  if (cdnComponents !== null) {
46
47
  data = data.replace(/\S+.+channelCanonicalBaseUrl.+css.+/,
@@ -49,15 +50,20 @@ const settingsSchemaData = `{ "useComponents": true }`;
49
50
  data = data.replace(/\S+.+channelCanonicalBaseUrl.+js.+/,
50
51
  '<script src="{{ r("/assets/js/components/sfb-components.js") }}"></script>')
51
52
 
53
+ data = updateCustomComponentsMetadata(data);
54
+
52
55
  addCustomCompToBase(baseFilePath, data);
53
56
 
54
57
  } else if (assetsComponents === null) {
58
+ data = updateCustomComponentsMetadata(data);
59
+
55
60
  const headElemIndex = data.indexOf('</head>');
56
61
  const output = data.substring(0, headElemIndex)
57
62
  + ' <link rel="stylesheet" type="text/css" href="{{ r("/assets/js/components/sfb-components.css") }}">\n'
58
63
  + ' <script src="{{ r("/assets/js/components/sfb-components.js") }}"></script>\n'
59
64
  + data.substring(headElemIndex);
60
-
65
+
66
+
61
67
  addCustomCompToBase(baseFilePath, output);
62
68
 
63
69
  } else {
@@ -4,8 +4,9 @@ const { spawn } = require("child_process")
4
4
  const colors = require("colors")
5
5
  const prompt = require("./prompt-questions");
6
6
 
7
- const { CURRENT_PATH, TOOLKIT_PATH, COMMAND_PARAM, COMPILERCSS_PATH, PAGE_OBJECTS_SUFFIX } = require("./toolkit-common-vars");
8
- const { shouldBeProjectFolder, getAvailableFolderWithPrompt, createCustomThemePacakgeJson } = require("./toolkit-common-fun");
7
+ const { CURRENT_PATH, TOOLKIT_PATH, COMMAND_PARAM, COMPILERCSS_PATH,
8
+ PAGE_OBJECTS_SUFFIX, ACTIVE_THEME_PATH } = require("./toolkit-common-vars");
9
+ const { shouldBeProjectFolder, getAvailableFolderWithPrompt, createCustomThemePacakgeJson, addMetadata } = require("./toolkit-common-fun");
9
10
  const { LOCAL_CONFIG } = require("./toolkit-config");
10
11
 
11
12
  shouldBeProjectFolder(true);
@@ -103,6 +104,22 @@ shouldBeProjectFolder(true);
103
104
  process.exit(1);
104
105
  }
105
106
 
107
+ try {
108
+ const toolkitPackageJson = JSON.parse(fs.readFileSync(`${TOOLKIT_PATH}/package.json`));
109
+ const themeVersion = toolkitPackageJson.dependencies[`${userThemeAnswer.ThemeTemplates.dependency}`];
110
+ addMetadata({
111
+ themeTemplate: userThemeAnswer.ThemeTemplates.dependency,
112
+ themeVersion,
113
+ createdBy: themeCreatedBy.WhoAreYou,
114
+ createdAt: new Date(),
115
+ customComponents: false,
116
+ sfbThemeComponentsVersion: 'latest'
117
+ })
118
+
119
+ } catch (err) {
120
+ console.error(` ERROR: Unable to save metadata due to: ${err}`.red);
121
+ }
122
+
106
123
  spawn('node',
107
124
  [`"${TOOLKIT_PATH}/${COMPILERCSS_PATH}"`], {
108
125
  stdio: "inherit",
@@ -1,4 +1,5 @@
1
- const { shouldBeProjectFolder, createPackageJson } = require("./toolkit-common-fun");
1
+ const fs = require("fs-extra");
2
+ const { shouldBeProjectFolder, createPackageJson, updateCustomComponentsMetadata } = require("./toolkit-common-fun");
2
3
  const { spawn } = require("child_process")
3
4
  const { COMMAND_PARAM, ACTIVE_THEME_PATH } = require("./toolkit-common-vars");
4
5
 
@@ -19,5 +20,22 @@ if(npmModule === 'undefined'){
19
20
  stdio: "inherit",
20
21
  shell: true
21
22
  }
22
- )
23
+ ).on('exit', () => {
24
+ if (npmModule.includes('@appdirect/sfb-theme-components')) {
25
+ const baseFilePath = `${ACTIVE_THEME_PATH}/content/layout/base.html`;
26
+ const customComponentsPath = `${ACTIVE_THEME_PATH}/customComponents`
27
+ const customComponentsEnabled = fs.existsSync(customComponentsPath);
28
+
29
+ if (customComponentsEnabled) {
30
+ fs.readFile(baseFilePath, 'utf8', (err, data) => {
31
+ if (err) return console.error(` ERROR: Unable to read the base layout file. Tried: ${baseFilePath}`.red);
32
+ const updatedMetadata = updateCustomComponentsMetadata(data);
33
+ fs.writeFile(baseFilePath, updatedMetadata, (err) => {
34
+ if (err) return console.error(` ERROR: Unable to update metadata due to: ${err}.`.red);
35
+ });
36
+ });
37
+ };
38
+ };
39
+ });
40
+
23
41
  })();
@@ -17,7 +17,7 @@ const {
17
17
  COMPILERCSS_PATH,
18
18
  ACTIVE_THEME_PATH
19
19
  } = require("./toolkit-common-vars")
20
- const { shouldBeProjectFolder } = require("./toolkit-common-fun")
20
+ const { shouldBeProjectFolder, addMetadata } = require("./toolkit-common-fun")
21
21
 
22
22
  shouldBeProjectFolder(true)
23
23
 
@@ -29,10 +29,9 @@ const hasTranslationErrors = async () => {
29
29
  const translationsPath = `${currentPath}/themes/${config.theme}/translations`
30
30
  try {
31
31
  const translationsFiles = await fsProm.readdir(translationsPath)
32
-
33
32
  translationsFiles.forEach(langFile => {
34
33
  try {
35
- yaml.safeLoad(fs.readFileSync(`${translationsPath}/${langFile}`))
34
+ yaml.load(fs.readFileSync(`${translationsPath}/${langFile}`))
36
35
  } catch (err) {
37
36
  yamlErrorFlag = true
38
37
  if (err.name === "YAMLException") {
@@ -62,6 +61,8 @@ const includeSettings = async shouldIncludeSettings => {
62
61
  let shouldIncludeTranslations = true
63
62
  let shouldIncludeSettings = true
64
63
 
64
+ addMetadata();
65
+
65
66
  if (process.env.PACK_ALL !== "true") {
66
67
  const userAnswerTranslations = await prompt.ask(["PackTranslationsChoice"])
67
68
  shouldIncludeTranslations = userAnswerTranslations.PackTranslationsChoice
@@ -4,7 +4,8 @@ const colors = require("colors")
4
4
  const prompt = require("./prompt-questions");
5
5
 
6
6
  const { CURRENT_PATH, TOOLKIT_PATH, COMMAND_PARAM, BOOTSTRAP_FOLDERS, CONFIG_PATH, PAGE_OBJECTS_SUFFIX } = require("./toolkit-common-vars");
7
- const { selfDestruction, filesCounter, shouldBeProjectFolder, getAvailableFolderWithPrompt, licenseAgreement, versionCheck } = require("./toolkit-common-fun");
7
+ const { selfDestruction, filesCounter, shouldBeProjectFolder, getAvailableFolderWithPrompt,
8
+ licenseAgreement, versionCheck, createCustomThemePacakgeJson, addMetadata } = require("./toolkit-common-fun");
8
9
  const { LOCAL_CONFIG } = require("./toolkit-config");
9
10
  const projectName = COMMAND_PARAM; // [optional] project name
10
11
 
@@ -13,6 +14,9 @@ let freshLocalConfig = {
13
14
  defaultValues: {}
14
15
  };
15
16
 
17
+ let themeName;
18
+ let userThemeAnswer;
19
+
16
20
  (async () => {
17
21
  try {
18
22
  await licenseAgreement();
@@ -52,26 +56,40 @@ let freshLocalConfig = {
52
56
  }
53
57
  });
54
58
 
59
+ const themeCreatedBy = await prompt.ask(["WhoAreYou"]);
55
60
 
56
61
  // copy theme folder
57
62
  try {
58
- const userThemeAnswer = await prompt.ask(["ThemeTemplates"]);
59
- const userAnswer = await prompt.ask(["ThemeName"], [{name:"ThemeName", default: userThemeAnswer.ThemeTemplates.name}]);
60
-
63
+ userThemeAnswer = await prompt.ask(["ThemeTemplates"]);
64
+ themeName = await prompt.ask(["ThemeName"], [{name:"ThemeName", default: userThemeAnswer.ThemeTemplates.name}]);
61
65
  await copy(
62
66
  `${TOOLKIT_PATH}/node_modules/${userThemeAnswer.ThemeTemplates.dependency}`,
63
- `${projectPath}/themes/${userAnswer.ThemeName}`
67
+ `${projectPath}/themes/${themeName.ThemeName}`
64
68
  );
65
69
  await remove(
66
- `${projectPath}/themes/${userAnswer.ThemeName}/package.json`
70
+ `${projectPath}/themes/${themeName.ThemeName}/package.json`
67
71
  );
68
- freshLocalConfig.defaultValues.themeName = userAnswer.ThemeName;
72
+ freshLocalConfig.defaultValues.themeName = themeName.ThemeName;
69
73
  } catch (err) {
70
74
  console.error(` Could not copy clasic theme due to: \n ${err}`.red);
71
75
  selfDestruction(projectPath); // revert changes
72
76
  process.exit(1);
73
77
  }
74
78
 
79
+ try{
80
+ fs.writeFileSync(
81
+ `${projectPath}/themes/${themeName.ThemeName}/package.json`,
82
+ createCustomThemePacakgeJson(
83
+ themeName.ThemeName,
84
+ userThemeAnswer.ThemeTemplates.dependency,
85
+ themeCreatedBy.WhoAreYou
86
+ )
87
+ );
88
+ } catch(err) {
89
+ console.error(` ERROR: Unable to create ${themeName.ThemeName}'s package.json file due to ${err}.`.red);
90
+ process.exit(1);
91
+ }
92
+
75
93
  // copy config/index.js file
76
94
  try {
77
95
  await copy(
@@ -107,6 +125,22 @@ let freshLocalConfig = {
107
125
  process.exit(1);
108
126
  }
109
127
 
128
+ try {
129
+ const toolkitPackageJson = JSON.parse(fs.readFileSync(`${TOOLKIT_PATH}/package.json`));
130
+ const themeVersion = toolkitPackageJson.dependencies[`${userThemeAnswer.ThemeTemplates.dependency}`];
131
+ addMetadata({
132
+ themeTemplate: userThemeAnswer.ThemeTemplates.dependency,
133
+ themeVersion,
134
+ createdBy: themeCreatedBy.WhoAreYou,
135
+ createdAt: new Date(),
136
+ customComponents: false,
137
+ sfbThemeComponentsVersion: 'latest'
138
+ }, projectPath);
139
+
140
+ } catch (err) {
141
+ console.error(` ERROR: Unable to save metadata due to: ${err}`.red);
142
+ }
143
+
110
144
  console.log(` Theme location: ${projectPath}/`.green)
111
145
  console.log(` Configuration file location: ${projectPath}/config/`.green)
112
146
  console.log(`\n All done! You can start your server by running \`sfb-toolkit start\` inside the project root folder: ${projectPath}\n`.green);
@@ -5,9 +5,9 @@ const { ACTIVE_THEME_PATH, THEME_LOGS_FILE_PATH } = require("./toolkit-common-va
5
5
 
6
6
  shouldBeProjectFolder(true);
7
7
  const storybookDependencies = [
8
- "@babel/core@7.14.0",
8
+ "@babel/core@7.19.0",
9
9
  "@babel/plugin-proposal-class-properties@7.13.0",
10
- "@babel/preset-env@7.14.1",
10
+ "@babel/preset-env@7.19.0",
11
11
  "@storybook/addon-actions@6.3.1",
12
12
  "@storybook/addon-essentials@6.2.9",
13
13
  "@storybook/addon-knobs@6.2.9",
@@ -15,14 +15,14 @@ const storybookDependencies = [
15
15
  "@storybook/addon-a11y@6.3.1",
16
16
  "@storybook/addon-docs@6.3.1",
17
17
  "@storybook/react@6.3.1",
18
- "babel-loader@8.2.2",
18
+ "babel-loader@8.2.5",
19
19
  "core-js@3.12.1",
20
20
  "preset-react@1.0.0",
21
21
  "react@16.14.0",
22
22
  "react-content-loader@5.1.4",
23
23
  "react-dom@16.14.0",
24
24
  "sass@1.32.12",
25
- "sass-loader@10.2.0"
25
+ "sass-loader@10.3.1"
26
26
  ].join(' ');
27
27
 
28
28
  const storybookModule = "@storybook/react";
@@ -39,7 +39,7 @@ const storybookModule = "@storybook/react";
39
39
 
40
40
  // check if storybook module is installed otherwise install storybook dependencies
41
41
  spawnSync('npm',
42
- [`ls ${storybookModule} 2>&1 | (findstr ${storybookModule} || grep ${storybookModule}) > ${THEME_LOGS_FILE_PATH} 2>&1 || npm i -S ${storybookDependencies} --production`], {
42
+ [`ls ${storybookModule} 2>&1 | (findstr ${storybookModule} || grep ${storybookModule}) > ${THEME_LOGS_FILE_PATH} 2>&1 || npm i -S ${storybookDependencies} --legacy-peer-deps --production`], {
43
43
  cwd: ACTIVE_THEME_PATH,
44
44
  stdio: "inherit",
45
45
  shell: true
@@ -58,9 +58,7 @@ module.exports = (currentPath, config, isAsset) => {
58
58
  ),
59
59
  path.resolve(
60
60
  currentPath,
61
- `themes/${
62
- config.theme
63
- }/node_modules/@appdirect/sfb-theme-components`
61
+ `themes/${config.theme}/node_modules/@appdirect/sfb-theme-components`
64
62
  )
65
63
  ]
66
64
  }
@@ -48,9 +48,7 @@ module.exports = (currentPath, config) => {
48
48
  ),
49
49
  path.resolve(
50
50
  currentPath,
51
- `themes/${
52
- config.theme
53
- }/node_modules/@appdirect/sfb-theme-components`
51
+ `themes/${config.theme}/node_modules/@appdirect/sfb-theme-components`
54
52
  )
55
53
  ]
56
54
  }
@@ -1,18 +1,21 @@
1
- "use strict"
2
-
3
1
  module.exports = {
4
- entry: ["./src/front-end-utils/toolbar.js"],
2
+ entry: "./src/front-end-utils/toolbar.js",
5
3
  module: {
6
4
  rules: [
7
5
  {
8
6
  test: /\.(js|jsx)$/,
9
7
  exclude: /node_modules/,
10
- use: ["babel-loader"]
8
+ use: {
9
+ loader: "babel-loader",
10
+ },
11
+ resolve: {
12
+ fullySpecified: false,
13
+ }
11
14
  }
12
15
  ]
13
16
  },
14
17
  resolve: {
15
- extensions: ["*", ".js", ".jsx"]
18
+ extensions: [".js", ".jsx"]
16
19
  },
17
20
  output: {
18
21
  path: `${__dirname}/src/front-end-utils/dist`,