@appdirect/sfb-toolkit 4.0.20 → 4.0.24

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 (73) hide show
  1. package/bin/index.js +93 -4
  2. package/config/index.js +1 -1
  3. package/coverage/clover.xml +2 -2
  4. package/coverage/lcov-report/constants/customUserAttributesMock.js.html +1 -1
  5. package/coverage/lcov-report/constants/index.html +1 -1
  6. package/coverage/lcov-report/constants/pageUrls.js.html +1 -1
  7. package/coverage/lcov-report/constants/userMock.js.html +1 -1
  8. package/coverage/lcov-report/controllers/controllers-utils/assetsUtils.js.html +1 -1
  9. package/coverage/lcov-report/controllers/controllers-utils/index.html +1 -1
  10. package/coverage/lcov-report/controllers/data-filters/bootstrap-data-filter.js.html +1 -1
  11. package/coverage/lcov-report/controllers/data-filters/call-to-actions-filter.js.html +1 -1
  12. package/coverage/lcov-report/controllers/data-filters/index.html +1 -1
  13. package/coverage/lcov-report/controllers/index.html +1 -1
  14. package/coverage/lcov-report/controllers/index.js.html +1 -1
  15. package/coverage/lcov-report/front-end-utils/src/components/base/ResultItem.js.html +1 -1
  16. package/coverage/lcov-report/front-end-utils/src/components/base/SearchBar.js.html +1 -1
  17. package/coverage/lcov-report/front-end-utils/src/components/base/index.html +1 -1
  18. package/coverage/lcov-report/front-end-utils/src/components/base/item.js.html +1 -1
  19. package/coverage/lcov-report/front-end-utils/src/components/container.js.html +1 -1
  20. package/coverage/lcov-report/front-end-utils/src/components/data-view.js.html +1 -1
  21. package/coverage/lcov-report/front-end-utils/src/components/header-view.js.html +1 -1
  22. package/coverage/lcov-report/front-end-utils/src/components/index.html +1 -1
  23. package/coverage/lcov-report/front-end-utils/src/components/search.js.html +1 -1
  24. package/coverage/lcov-report/front-end-utils/src/constants/index.html +1 -1
  25. package/coverage/lcov-report/front-end-utils/src/constants/pageUrl.js.html +1 -1
  26. package/coverage/lcov-report/front-end-utils/src/constants/roleType.js.html +1 -1
  27. package/coverage/lcov-report/front-end-utils/src/constants/searchType.js.html +1 -1
  28. package/coverage/lcov-report/front-end-utils/src/utils/debounce.js.html +1 -1
  29. package/coverage/lcov-report/front-end-utils/src/utils/index.html +1 -1
  30. package/coverage/lcov-report/index.html +1 -1
  31. package/coverage/lcov-report/middlewares/config.js.html +1 -1
  32. package/coverage/lcov-report/middlewares/index.html +1 -1
  33. package/coverage/lcov-report/tools/index.html +1 -1
  34. package/coverage/lcov-report/tools/proxy-fetch.js.html +1 -1
  35. package/customComponents/index.js +10 -2
  36. package/npm-shrinkwrap.json +314 -128
  37. package/package.json +4 -4
  38. package/readme.md +9 -0
  39. package/src/boilerplates/AddComponent/AddComponent.jsx +234 -0
  40. package/src/boilerplates/AddComponent/styles/AddComponent.scss +47 -0
  41. package/src/tools/.sfbconfig +1 -1
  42. package/src/tools/package-fonts.js +1 -1
  43. package/src/tools/prompt-questions.js +109 -14
  44. package/src/tools/toolkit-common-fun.js +41 -15
  45. package/src/tools/toolkit-common-vars-namespace.js +106 -0
  46. package/src/tools/toolkit-common-vars.js +2 -2
  47. package/src/tools/toolkit-components-add.js +334 -0
  48. package/src/tools/toolkit-components-copy.js +390 -0
  49. package/src/tools/toolkit-components-delete.js +370 -0
  50. package/src/tools/toolkit-components-fun.js +126 -7
  51. package/src/tools/toolkit-components-info.js +6 -4
  52. package/src/tools/toolkit-components-vars.js +50 -0
  53. package/src/tools/toolkit-components.js +1 -1
  54. package/src/tools/toolkit-create-extension.js +1 -1
  55. package/src/tools/toolkit-create.js +2 -3
  56. package/src/tools/toolkit-import.js +182 -0
  57. package/src/tools/toolkit-install.js +6 -5
  58. package/src/tools/toolkit-mock.js +1 -1
  59. package/src/tools/toolkit-package.js +3 -0
  60. package/src/tools/toolkit-setup.js +1 -1
  61. package/src/tools/toolkit-start.js +4 -1
  62. package/src/tools/toolkit-storybook.js +136 -48
  63. package/src/tools/toolkit-zip-utils.js +35 -0
  64. package/src/tools/zip-theme.js +62 -50
  65. package/themes-config.json +0 -7
  66. package/customComponents/atoms/label/Label.jsx +0 -20
  67. package/customComponents/atoms/label/stories/Label.story.mdx +0 -20
  68. package/customComponents/atoms/label/styles/Label.scss +0 -4
  69. package/customComponents/components/atoms-showcase-custom/AtomsShowcaseCustom.jsx +0 -8
  70. package/customComponents/components/atoms-showcase-custom/stories/AtomsShowcaseCustom.story.mdx +0 -17
  71. package/customComponents/components/atoms-showcase-modules/AtomsShowcaseModules.jsx +0 -223
  72. package/customComponents/components/atoms-showcase-modules/stories/AtomsShowcaseModules.story.mdx +0 -49
  73. package/customComponents/components/index.js +0 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appdirect/sfb-toolkit",
3
- "version": "4.0.20",
3
+ "version": "4.0.24",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -55,9 +55,8 @@
55
55
  "name": "appdirect/sfb-toolkit"
56
56
  },
57
57
  "dependencies": {
58
- "@appdirect/public-custom-app-ui": "^0.0.21",
59
- "@appdirect/sfb-theme-classic": "0.0.27",
60
- "@appdirect/sfb-theme-plaza": "0.0.78",
58
+ "@appdirect/public-custom-app-ui": "^0.0.23",
59
+ "@appdirect/sfb-theme-plaza": "0.0.82",
61
60
  "@appdirect/storefront-utils": "latest",
62
61
  "@babel/core": "^7.19.1",
63
62
  "@babel/plugin-proposal-class-properties": "^7.18.6",
@@ -83,6 +82,7 @@
83
82
  "css-loader": "^6.7.1",
84
83
  "directory-tree": "^3.3.1",
85
84
  "express": "^4.18.1",
85
+ "extract-zip": "^2.0.1",
86
86
  "fs-extra": "^10.1.0",
87
87
  "glob": "^8.0.3",
88
88
  "gulp": "^4.0.2",
package/readme.md CHANGED
@@ -10,6 +10,15 @@ It can be easily mixed with eg. HTML, CSS, JavaScript, jQuery, SASS.
10
10
 
11
11
  ### Release Notes:
12
12
 
13
+ **4.0.23**
14
+ - Removed `Classic` option when creating theme
15
+ - Updated `sfb-theme-components` library to version [0.0.352](https://www.npmjs.com/package/@appdirect/sfb-theme-components/v/0.0.352)
16
+ - `[DEPRECATED]` `sfb-toolkit storybook` command
17
+ - `[BETA]` added `sfb-toolkit import` command
18
+ - `[BETA]` added `sfb-toolkit components-add` command
19
+ - `[BETA]` added `sfb-toolkit components-copy` command
20
+ - `[BETA]` added `sfb-toolkit components-delete` command
21
+
13
22
  **4.0.20**
14
23
  - Updated internal packages
15
24
 
@@ -0,0 +1,234 @@
1
+ import React from "react"
2
+ import "./styles/{{COMPONENT_NAME_PASCAL_CASE}}.scss"
3
+ import PropTypes from "prop-types"
4
+ import withListener from "@appdirect/sfb-theme-components/src/components/withListener"
5
+ import { createNamespace } from "@appdirect/sfb-theme-components/src/tools/namingTools"
6
+ {{COMPONENT_ORDERABLE_NAMESPACE_IMPORT}}
7
+ import {
8
+ INPUT,
9
+ TOGGLE,
10
+ TEXTAREA,
11
+ COLORPICKER,
12
+ DROPDOWN,
13
+ RADIO,
14
+ CHECKBOX,
15
+ SLIDER,
16
+ GROUP_HEADER,
17
+ } from "@appdirect/sfb-theme-components/src/constants/schemaComponentTypes"
18
+
19
+ const n = createNamespace("{{COMPONENT_NAME_PASCAL_CASE}}")
20
+
21
+ export function {{COMPONENT_NAME_PASCAL_CASE}}(props) {
22
+ const { settings = {} } = props
23
+ const {
24
+ title,
25
+ description,
26
+ isDescriptionVisible,
27
+ backgroundColor,
28
+ headerType,
29
+ descriptionSize,
30
+ textStyling,
31
+ textOpacity,
32
+ } = settings
33
+
34
+ const modifiers = [descriptionSize]
35
+
36
+ if (textStyling && textStyling.length) {
37
+ modifiers.push(...textStyling)
38
+ }
39
+ const styleProps = {
40
+ ...(textOpacity && {
41
+ style: { opacity: textOpacity },
42
+ }),
43
+ }
44
+
45
+ const containerVariables = {
46
+ "background-color": backgroundColor,
47
+ }
48
+
49
+ return (
50
+ <div
51
+ {...n("container").withTestId().withVariables(containerVariables).props}
52
+ >
53
+ <div {...n("row").props}>
54
+ {headerType === "header1" && <h1>{title}</h1>}
55
+ {headerType === "header2" && <h2>{title}</h2>}
56
+ {headerType === "header3" && <h3>{title}</h3>}
57
+ {!headerType && <span>{title}</span>}
58
+ </div>
59
+
60
+ <div {...n("row").props}>
61
+ {isDescriptionVisible && (
62
+ <p
63
+ {...n("description", modifiers).withTestId().props}
64
+ {...styleProps}
65
+ >
66
+ {description}
67
+ </p>
68
+ )}
69
+ </div>
70
+ </div>
71
+ )
72
+ }
73
+
74
+ const HEADER_TYPE_OPTIONS = [
75
+ {
76
+ value: "header1",
77
+ label: "Header1",
78
+ caption: "Sample caption",
79
+ },
80
+ {
81
+ value: "header2",
82
+ label: "Header2",
83
+ caption: "Sample caption",
84
+ },
85
+ {
86
+ value: "header3",
87
+ label: "Header3",
88
+ caption: "Sample caption",
89
+ },
90
+ ]
91
+
92
+ const DESCRIPTION_SIZE_OPTIONS = [
93
+ {
94
+ value: "bigger",
95
+ label: "Bigger",
96
+ caption: "Sample caption",
97
+ },
98
+ {
99
+ value: "standard",
100
+ label: "Standard",
101
+ caption: "Sample caption",
102
+ },
103
+ {
104
+ value: "smaller",
105
+ label: "Smaller",
106
+ caption: "Sample caption",
107
+ },
108
+ ]
109
+
110
+ const TEXT_STYLING_OPTIONS = [
111
+ {
112
+ value: "bold",
113
+ label: "Bold",
114
+ },
115
+ {
116
+ value: "italic",
117
+ label: "Italic",
118
+ },
119
+ {
120
+ value: "strikethrough",
121
+ label: "Strikethrough",
122
+ },
123
+ {
124
+ value: "underline",
125
+ label: "Underline",
126
+ },
127
+ ]
128
+
129
+ {{COMPONENT_NAME_PASCAL_CASE}}.schema = () => ({
130
+ name: "{{COMPONENT_NAME_PASCAL_CASE}}",
131
+ title: "{{COMPONENT_NAME_SENTENCE_CASE}}",
132
+ iconName: "carousel",{{COMPONENT_ORDERABLE_SECTION}}
133
+ form: {
134
+ title: {
135
+ title: "Title",
136
+ placeholder: "Type here ...",
137
+ defaultValue: "My new component: {{COMPONENT_NAME_PASCAL_CASE}}",
138
+ type: INPUT,
139
+ required: true,
140
+ },
141
+ backgroundColor: {
142
+ title: "Background color",
143
+ defaultValue: "#F4F4F4",
144
+ type: COLORPICKER,
145
+ },
146
+ headerType: {
147
+ title: "Header type",
148
+ type: DROPDOWN,
149
+ required: true,
150
+ defaultValue: HEADER_TYPE_OPTIONS[1].value,
151
+ options: HEADER_TYPE_OPTIONS,
152
+ },
153
+ descriptionHeader: {
154
+ type: GROUP_HEADER,
155
+ title: "Description settings",
156
+ symbol: "description-settings",
157
+ },
158
+ isDescriptionVisible: {
159
+ labelOn: "Toggle description",
160
+ labelOff: "Toggle description",
161
+ defaultValue: true,
162
+ type: TOGGLE,
163
+ },
164
+ description: {
165
+ title: "Component description",
166
+ defaultValue: "This is a new component created using sfb-toolkit components-add command.",
167
+ type: TEXTAREA,
168
+ required: true,
169
+ validation: {
170
+ pattern: /^[^!"#$%&']*$/gm,
171
+ message: "This field is invalid",
172
+ },
173
+ },
174
+ descriptionSize: {
175
+ title: "Text size",
176
+ type: RADIO,
177
+ required: true,
178
+ defaultValue: DESCRIPTION_SIZE_OPTIONS[1].value,
179
+ options: DESCRIPTION_SIZE_OPTIONS,
180
+ },
181
+ textStyling: {
182
+ title: "Text styling",
183
+ type: CHECKBOX,
184
+ required: false,
185
+ defaultValue: [TEXT_STYLING_OPTIONS[0].value],
186
+ options: TEXT_STYLING_OPTIONS,
187
+ },
188
+ textOpacity: {
189
+ title: "Text opacity",
190
+ type: SLIDER,
191
+ required: false,
192
+ defaultValue: 1,
193
+ options: {
194
+ step: 0.1,
195
+ min: 0.1,
196
+ max: 1,
197
+ },
198
+ },
199
+ },
200
+ })
201
+
202
+ const SETTINGS = {{COMPONENT_NAME_PASCAL_CASE}}.schema().form
203
+
204
+ {{COMPONENT_NAME_PASCAL_CASE}}.propTypes = {
205
+ settings: PropTypes.shape({
206
+ title: PropTypes.string,
207
+ description: PropTypes.string,
208
+ isDescriptionVisible: PropTypes.bool,
209
+ backgroundColor: PropTypes.string,
210
+ headerType: PropTypes.oneOf(HEADER_TYPE_OPTIONS.map(({ value }) => value)),
211
+ descriptionSize: PropTypes.oneOf(
212
+ DESCRIPTION_SIZE_OPTIONS.map(({ value }) => value)
213
+ ),
214
+ textStyling: PropTypes.oneOf(
215
+ TEXT_STYLING_OPTIONS.map(({ value }) => value)
216
+ ),
217
+ textOpacity: PropTypes.number,
218
+ }),
219
+ }
220
+
221
+ {{COMPONENT_NAME_PASCAL_CASE}}.defaultProps = {
222
+ settings: {
223
+ title: SETTINGS.title.defaultValue,
224
+ description: SETTINGS.description.defaultValue,
225
+ isDescriptionVisible: SETTINGS.isDescriptionVisible.defaultValue,
226
+ backgroundColor: SETTINGS.backgroundColor.defaultValue,
227
+ headerType: SETTINGS.headerType.defaultValue,
228
+ descriptionSize: SETTINGS.descriptionSize.defaultValue,
229
+ textStyling: SETTINGS.textStyling.defaultValue,
230
+ textOpacity: SETTINGS.textOpacity.defaultValue,
231
+ },
232
+ }
233
+
234
+ export default withListener({{COMPONENT_NAME_PASCAL_CASE}})
@@ -0,0 +1,47 @@
1
+ .{{COMPONENT_NAME_CAMEL_CASE}} {
2
+ display: flex;
3
+ width: 100%;
4
+
5
+ &_container {
6
+ color: var(--text-color, #474747);
7
+ background-color: var(--background-color, #F5F5F5);
8
+
9
+ display: flex;
10
+ flex-direction: column;
11
+ margin-top: 20px;
12
+ margin-bottom: 20px;
13
+ padding: 10px 25px 25px 25px;
14
+ }
15
+
16
+ &_description {
17
+ &--bigger {
18
+ font-size: 130%;
19
+ }
20
+ &--standard {
21
+ font-size: 100%;
22
+ }
23
+ &--smaller {
24
+ font-size: 70%;
25
+ }
26
+ &--bold {
27
+ font-weight: bold;
28
+ }
29
+ &--italic {
30
+ font-style: italic;
31
+ }
32
+ &--strikethrough {
33
+ text-decoration: line-through;
34
+ }
35
+ &--underline {
36
+ text-decoration: underline;
37
+ }
38
+ }
39
+
40
+ &_row {
41
+ display: flex;
42
+ flex-direction: row;
43
+ flex-grow: 1;
44
+ justify-content: flex-start;
45
+ align-items: center;
46
+ }
47
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "defaultValues": {
3
3
  "projectName": "sfb-themes",
4
- "themeName": "classic",
4
+ "themeName": "plaza",
5
5
  "marketplacePath": "https://marketplace.appdirect.com",
6
6
  "pageObjectsPath": "https://marketplace.appdirect.com/api/internal/storefront/v1"
7
7
  }
@@ -2,7 +2,7 @@ const fs = require("fs")
2
2
  const currentPath = process.cwd() // used to get current dev folder
3
3
  const config = require(`${currentPath}/config`)
4
4
 
5
- const theme = config.theme || "classic"
5
+ const theme = config.theme || "plaza"
6
6
  const themeRootDirectory = `${currentPath}/themes/${theme}`
7
7
  const fontFilePathWithoutExtention = `${themeRootDirectory}/header-footer/header`
8
8
  const { supportedFontExtensions } = config
@@ -6,22 +6,71 @@ const {
6
6
  TOOLKIT_GLOBAL_CONFIG,
7
7
  THEME_TEMPLATES,
8
8
  WHO_ARE_YOU_PROMPT,
9
- EXTENSION_PROMPT,
10
9
  } = require("./toolkit-common-vars");
11
10
 
12
- const { getCustomComponentsInfo, getSfbThemeComponentsVersion } = require('./toolkit-components-fun');
11
+ const {
12
+ PAGE_NAME_AND_ORDERABLE_TYPE_PROMPT,
13
+ } = require("./toolkit-common-vars-namespace");
14
+
15
+ const {
16
+ getCustomComponentsInfo,
17
+ getSfbThemeComponentsVersion,
18
+ getSfbThemeComponentsList,
19
+ } = require("./toolkit-components-fun");
13
20
 
14
21
  // small function to check if item has been defined
15
22
  const isDefined = (answer) => !!answer;
16
23
 
24
+ const componentNameExists = (componentName) => {
25
+ const { userDefinedCustomComponents } = getCustomComponentsInfo();
26
+ const sfbThemeComponentsList = getSfbThemeComponentsList();
27
+
28
+ const existingComponentsLowerCase = [
29
+ ...userDefinedCustomComponents,
30
+ ...sfbThemeComponentsList,
31
+ ].map((component) => component.toLowerCase());
32
+
33
+ const componentAlreadyExist = existingComponentsLowerCase.includes(
34
+ componentName.toLowerCase()
35
+ );
36
+
37
+ if (componentAlreadyExist) {
38
+ console.error(
39
+ chalk.red(
40
+ `\nERROR: ${componentName} already exists. Please choose a different name.`
41
+ )
42
+ );
43
+ }
44
+
45
+ return componentAlreadyExist;
46
+ };
47
+
48
+ const isValidComponentName = (toTest) => {
49
+ const pattern = new RegExp(/^[A-Z-a-z][A-Za-z0-9]*$/, "i");
50
+ const result = pattern.test(toTest);
51
+ if (!result) {
52
+ console.error(
53
+ chalk.red(
54
+ `\nERROR: ${toTest} is not a valid component name. It should start with a letter and contain only letters and numbers.`
55
+ )
56
+ );
57
+ }
58
+ return toTest !== "undefined" && result;
59
+ };
60
+
61
+ const isComponentNameValidAndAvailable = (toTest) =>
62
+ toTest !== "undefined" &&
63
+ isValidComponentName(toTest) &&
64
+ !componentNameExists(toTest);
65
+
17
66
  // checks if the string provided is valid folder name
18
67
  const isValidFolderName = (toTest) => {
19
68
  const pattern = new RegExp(/^[a-z0-9_-]+$/, "i");
20
69
  const result = pattern.test(toTest);
21
70
  if (!result) {
22
- console.error(chalk.red(`\n${toTest} does not seem as valid folder name.`));
71
+ console.error(chalk.red(`\n${toTest} is not a valid folder name.`));
23
72
  }
24
- return toTest !== "undefined" && result;
73
+ return toTest && toTest !== "undefined" && result;
25
74
  };
26
75
 
27
76
  // gets only origin from the url
@@ -42,13 +91,13 @@ const isValidURL = (toTest) => {
42
91
  );
43
92
  const result = pattern.test(toTest);
44
93
  if (!result) {
45
- console.error(chalk.red(`\n"${toTest}" does not seem as valid URL.`));
94
+ console.error(chalk.red(`\n"${toTest}" does not seem to be a valid URL.`));
46
95
  }
47
96
  return result;
48
97
  };
49
98
  const isValidMarketplaceURL = async (toTest) => {
50
99
  if (!toTest || !isValidURL(toTest)) return false;
51
- console.log("\n\n Verifiying Marketplace URL...");
100
+ console.log("\n\n Verifying Marketplace URL...");
52
101
  try {
53
102
  const response = await fetch(`${toTest}/api/session/v1/frontend-context`);
54
103
  const data = await response.json();
@@ -81,13 +130,37 @@ const licenseText = ` In order to use this software, please type 'agree' to acce
81
130
 
82
131
  const customComponentsHints = () => {
83
132
  const { overridesJavaScript, overridesSass } = getCustomComponentsInfo();
84
- return (overridesJavaScript.length || overridesSass.length)
85
- ? '\nSee below a list (none exhaustive) of custom components that should be ' +
86
- `tested after changing the ${chalk.cyan("@appdirect/sfb-theme-components")} version:` +
87
- (overridesJavaScript.length ? `\n\nOverrides Components JS:\n ` + chalk.green(overridesJavaScript.join(',\n ')) : '') +
88
- (overridesSass.length ? `\n\nOverrides Components SCSS:\n ` + chalk.green(overridesSass.join(',\n ')) : '')
89
- : '';
90
- }
133
+ return overridesJavaScript.length || overridesSass.length
134
+ ? `\nSee below a list (none exhaustive) of custom components that should be ` +
135
+ `tested after changing the ${chalk.cyan(
136
+ "@appdirect/sfb-theme-components"
137
+ )} version:${
138
+ overridesJavaScript.length
139
+ ? `\n\nOverrides Components JS:\n ${chalk.green(
140
+ overridesJavaScript.join(",\n ")
141
+ )}`
142
+ : ""
143
+ }${
144
+ overridesSass.length
145
+ ? `\n\nOverrides Components SCSS:\n ${chalk.green(
146
+ overridesSass.join(",\n ")
147
+ )}`
148
+ : ""
149
+ }`
150
+ : "";
151
+ };
152
+
153
+ const isValidThemeFilePath = (toTest) => {
154
+ if (!fs.existsSync(toTest) && !fs.existsSync(`${toTest}.zip`)) {
155
+ console.error(
156
+ chalk.red(
157
+ `\n ERROR: The theme file ${toTest} does not exist. The file should be located in the workspace folder.\n`
158
+ )
159
+ );
160
+ return false;
161
+ }
162
+ return true;
163
+ };
91
164
 
92
165
  // list of default questions that could be prompt to user
93
166
  const QUESTIONS = [
@@ -122,7 +195,9 @@ const QUESTIONS = [
122
195
  )} library.` +
123
196
  ` Please note your current ${chalk.cyan(
124
197
  "@appdirect/sfb-theme-components"
125
- )} version (${chalk.bgRed.yellowBright(getSfbThemeComponentsVersion())}) before going forward in the event you need to revert.
198
+ )} version (${chalk.bgRed.yellowBright(
199
+ getSfbThemeComponentsVersion()
200
+ )}) before going forward in the event you need to revert.
126
201
  \u2022 ${chalk.bgRed.yellowBright(
127
202
  "Ensure you thoroughly test your theme before deploying this new version."
128
203
  )}
@@ -202,6 +277,23 @@ const QUESTIONS = [
202
277
  "Path to the extension you want to build on the marketplace /app/:mypath (letter & dash, only) (This can be changed later):",
203
278
  validate: isValidFolderName,
204
279
  },
280
+ {
281
+ type: "input",
282
+ name: "ComponentName",
283
+ message: "Name of the component to add (letters and numbers only):",
284
+ validate: isComponentNameValidAndAvailable,
285
+ },
286
+ {
287
+ type: "list",
288
+ name: "PageNameAndOrderableType",
289
+ choices: PAGE_NAME_AND_ORDERABLE_TYPE_PROMPT,
290
+ message: `Please select the page you wish to add the component to:`,
291
+ },
292
+ {
293
+ name: "ThemeFilePath",
294
+ message: "Path to the theme .zip file:",
295
+ validate: isValidThemeFilePath,
296
+ },
205
297
  ];
206
298
 
207
299
  // use only selected question
@@ -227,10 +319,13 @@ const ask = (questions = [], custom = []) => {
227
319
  : chooseQuestions(questions);
228
320
  return inquirer.prompt(toAsk);
229
321
  };
322
+
230
323
  module.exports = {
231
324
  ask,
232
325
  validateFun: {
233
326
  isValidFolderName,
234
327
  isValidURL,
328
+ isComponentNameValidAndAvailable,
329
+ isValidMarketplaceURL,
235
330
  },
236
331
  };
@@ -23,18 +23,16 @@ const isProjectsFolder = (dir) => fs.readdirSync(dir).filter( item => BOOTSTRAP_
23
23
  const shouldBeProjectFolder = (should) => {
24
24
  const isProjectFolder = isProjectsFolder(CURRENT_PATH);
25
25
 
26
- const errorMessagePrefix = chalk.bgRed(" ERROR ");
26
+ const getErrorMessage = (errorMessage) =>
27
+ chalk.bold(`${chalk.bgRed(" ERROR ")}: ${errorMessage}`);
28
+
27
29
  if (!should && isProjectFolder) {
28
- const errorMessage =
29
- "Unable to perform requested action. Please navigate away from the project folder.";
30
- console.error(chalk.bold(`${errorMessagePrefix}: ${errorMessage}`));
30
+ console.error(getErrorMessage("Unable to perform requested action. Please navigate away from the workspace folder."));
31
31
  process.exit(1);
32
32
  }
33
33
 
34
34
  if (should && !isProjectFolder) {
35
- const errorMessage =
36
- "Unable to perform requested action. Please navigate to a project folder.";
37
- console.error(chalk.bold(`${errorMessagePrefix}: ${errorMessage}`));
35
+ console.error(getErrorMessage("Unable to perform requested action. Please navigate to a workspace folder."));
38
36
  process.exit(1);
39
37
  }
40
38
  };
@@ -86,7 +84,7 @@ const getAvailableFolderWithPrompt = async (path, name, askFor, createIfNotExist
86
84
  // check if empty
87
85
  return resolve(`${path}/${name}`);
88
86
  }
89
- console.error(chalk.red(` ERROR: Unable to use a path ${path}/${name}. Folder already exists and is not empty. Try different name or try removing existing folder.`));
87
+ console.error(chalk.red(` ERROR: Unable to use path ${path}/${name}. Folder already exists and is not empty. Try a different name or try removing the existing folder.`));
90
88
  const userAnswer = await prompt.ask([askFor]);
91
89
  return resolve(getAvailableFolderWithPrompt(path, userAnswer[askFor], askFor, createIfNotExists, canBeEmpty));
92
90
  });
@@ -137,7 +135,7 @@ const createPackageJson = () => {
137
135
 
138
136
  const createCustomThemePacakgeJson = (themeName, themePackageName, createdBy) => {
139
137
  const toolkitPackageJson = JSON.parse(fs.readFileSync(`${TOOLKIT_PATH}/package.json`));
140
- const version = toolkitPackageJson.dependencies[`${themePackageName}`];
138
+ const version = toolkitPackageJson.dependencies?.[`${themePackageName}`];
141
139
  const customThemePackageJson = {
142
140
  "name": themeName.toLocaleLowerCase(),
143
141
  "version": version,
@@ -158,11 +156,20 @@ const createCustomThemePacakgeJson = (themeName, themePackageName, createdBy) =>
158
156
  return JSON.stringify(customThemePackageJson, null, 2);
159
157
  }
160
158
 
159
+ const getSfbThemeComponentsVersion = () => {
160
+ const themePackageJson = JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
161
+ return themePackageJson.dependencies?.['@appdirect/sfb-theme-components'];
162
+ }
163
+
164
+ const getToolkitVersionUsedToCreateTheme = () => {
165
+ const themePackageJson = JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
166
+ return themePackageJson.metadata?.toolkitVersion;
167
+ }
168
+
161
169
  const updateCustomComponentsMetadata = (data) => {
162
170
  const hasPackageJson = fs.existsSync(`${ACTIVE_THEME_PATH}/package.json`);
163
171
  if (hasPackageJson) {
164
- const themePackageJson = JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
165
- const sfbThemeComponentsVersion = themePackageJson.dependencies['@appdirect/sfb-theme-components'];
172
+ const sfbThemeComponentsVersion = getSfbThemeComponentsVersion();
166
173
  const customComponentsPath = `${ACTIVE_THEME_PATH}/customComponents`;
167
174
  const customComponents = fs.existsSync(customComponentsPath);
168
175
  if (customComponents && sfbThemeComponentsVersion) {
@@ -224,13 +231,13 @@ const addMetadata = (metadata = {}, themePath) => {
224
231
  } else {
225
232
  const hasPackageJson = fs.existsSync(`${ACTIVE_THEME_PATH}/package.json`);
226
233
  const themePackageJson = hasPackageJson && JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
227
- const hasPackageMetadata = themePackageJson && themePackageJson.metadata && Object.keys(themePackageJson.metadata).length;
228
- const hasPackageDependencies = themePackageJson && themePackageJson.dependencies && Object.keys(themePackageJson.dependencies).length;
234
+ const hasPackageMetadata = themePackageJson?.metadata && Object.keys(themePackageJson.metadata).length;
235
+ const hasPackageDependencies = themePackageJson?.dependencies && Object.keys(themePackageJson.dependencies).length;
229
236
  const customComponentsPath = `${ACTIVE_THEME_PATH}/customComponents`;
230
237
  customComponents = fs.existsSync(customComponentsPath);
231
238
 
232
239
  sfbThemeComponentsVersion = customComponents && hasPackageDependencies
233
- ? themePackageJson.dependencies['@appdirect/sfb-theme-components']
240
+ ? themePackageJson.dependencies?.['@appdirect/sfb-theme-components']
234
241
  : 'latest'
235
242
 
236
243
  if (hasPackageMetadata) {
@@ -276,6 +283,20 @@ const installSass = () => {
276
283
  })
277
284
  }
278
285
 
286
+ const convertPascalCaseToKebabCase = (str) =>
287
+ str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
288
+
289
+ const convertPascalCaseToCamelCase = (str) =>
290
+ str.replace(/^[A-Z]/, (match) => match.toLowerCase());
291
+
292
+ // Capitalize the first letter
293
+ const convertPascalCaseToSentenceCase = (str) =>
294
+ str
295
+ .replace(/([A-Z])/g, " $1")
296
+ .trim()
297
+ .toLowerCase()
298
+ .replace(/^./, (match) => match.toUpperCase());
299
+
279
300
  module.exports = {
280
301
  selfDestruction,
281
302
  filesCounter,
@@ -291,5 +312,10 @@ module.exports = {
291
312
  updateCustomComponentsMetadata,
292
313
  addMetadata,
293
314
  installSass,
294
- isProjectsFolder
315
+ isProjectsFolder,
316
+ getSfbThemeComponentsVersion,
317
+ getToolkitVersionUsedToCreateTheme,
318
+ convertPascalCaseToKebabCase,
319
+ convertPascalCaseToCamelCase,
320
+ convertPascalCaseToSentenceCase
295
321
  }