@appdirect/sfb-toolkit 4.0.22 → 4.0.25

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/index.js +92 -14
  2. package/coverage/clover.xml +32 -32
  3. package/coverage/coverage-final.json +4 -4
  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 +7 -7
  16. package/coverage/lcov-report/front-end-utils/src/components/base/SearchBar.js.html +3 -3
  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 +11 -11
  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 +13 -13
  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/coverage/lcov.info +81 -81
  36. package/customComponents/index.js +10 -2
  37. package/npm-shrinkwrap.json +144 -20
  38. package/package.json +4 -4
  39. package/readme.md +9 -0
  40. package/src/boilerplates/AddComponent/AddComponent.jsx +234 -0
  41. package/src/boilerplates/AddComponent/styles/AddComponent.scss +47 -0
  42. package/src/tools/prompt-questions.js +109 -14
  43. package/src/tools/toolkit-common-fun.js +30 -15
  44. package/src/tools/toolkit-common-vars-namespace.js +106 -0
  45. package/src/tools/toolkit-common-vars.js +1 -1
  46. package/src/tools/toolkit-components-add.js +334 -0
  47. package/src/tools/toolkit-components-copy.js +78 -46
  48. package/src/tools/toolkit-components-delete.js +370 -0
  49. package/src/tools/toolkit-components-fun.js +126 -7
  50. package/src/tools/toolkit-components-info.js +6 -4
  51. package/src/tools/toolkit-components-vars.js +50 -0
  52. package/src/tools/toolkit-components.js +1 -1
  53. package/src/tools/toolkit-create.js +2 -3
  54. package/src/tools/toolkit-import.js +182 -0
  55. package/src/tools/toolkit-install.js +6 -5
  56. package/src/tools/toolkit-package.js +3 -0
  57. package/src/tools/toolkit-setup.js +1 -1
  58. package/src/tools/toolkit-start.js +4 -1
  59. package/src/tools/toolkit-storybook.js +136 -48
  60. package/src/tools/toolkit-zip-utils.js +35 -0
  61. package/src/tools/zip-theme.js +62 -50
  62. package/themes-config.json +0 -7
  63. package/customComponents/atoms/label/Label.jsx +0 -20
  64. package/customComponents/atoms/label/stories/Label.story.mdx +0 -20
  65. package/customComponents/atoms/label/styles/Label.scss +0 -4
  66. package/customComponents/components/atoms-showcase-custom/AtomsShowcaseCustom.jsx +0 -8
  67. package/customComponents/components/atoms-showcase-custom/stories/AtomsShowcaseCustom.story.mdx +0 -17
  68. package/customComponents/components/atoms-showcase-modules/AtomsShowcaseModules.jsx +0 -223
  69. package/customComponents/components/atoms-showcase-modules/stories/AtomsShowcaseModules.story.mdx +0 -49
  70. package/customComponents/components/index.js +0 -2
@@ -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 workspace 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 workspace 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,
@@ -160,12 +158,12 @@ const createCustomThemePacakgeJson = (themeName, themePackageName, createdBy) =>
160
158
 
161
159
  const getSfbThemeComponentsVersion = () => {
162
160
  const themePackageJson = JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
163
- return themePackageJson.dependencies['@appdirect/sfb-theme-components'];
161
+ return themePackageJson.dependencies?.['@appdirect/sfb-theme-components'];
164
162
  }
165
163
 
166
164
  const getToolkitVersionUsedToCreateTheme = () => {
167
165
  const themePackageJson = JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
168
- return themePackageJson.metadata.toolkitVersion;
166
+ return themePackageJson.metadata?.toolkitVersion;
169
167
  }
170
168
 
171
169
  const updateCustomComponentsMetadata = (data) => {
@@ -233,13 +231,13 @@ const addMetadata = (metadata = {}, themePath) => {
233
231
  } else {
234
232
  const hasPackageJson = fs.existsSync(`${ACTIVE_THEME_PATH}/package.json`);
235
233
  const themePackageJson = hasPackageJson && JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
236
- const hasPackageMetadata = themePackageJson && themePackageJson.metadata && Object.keys(themePackageJson.metadata).length;
237
- 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;
238
236
  const customComponentsPath = `${ACTIVE_THEME_PATH}/customComponents`;
239
237
  customComponents = fs.existsSync(customComponentsPath);
240
238
 
241
239
  sfbThemeComponentsVersion = customComponents && hasPackageDependencies
242
- ? themePackageJson.dependencies['@appdirect/sfb-theme-components']
240
+ ? themePackageJson.dependencies?.['@appdirect/sfb-theme-components']
243
241
  : 'latest'
244
242
 
245
243
  if (hasPackageMetadata) {
@@ -285,6 +283,20 @@ const installSass = () => {
285
283
  })
286
284
  }
287
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
+
288
300
  module.exports = {
289
301
  selfDestruction,
290
302
  filesCounter,
@@ -302,5 +314,8 @@ module.exports = {
302
314
  installSass,
303
315
  isProjectsFolder,
304
316
  getSfbThemeComponentsVersion,
305
- getToolkitVersionUsedToCreateTheme
317
+ getToolkitVersionUsedToCreateTheme,
318
+ convertPascalCaseToKebabCase,
319
+ convertPascalCaseToCamelCase,
320
+ convertPascalCaseToSentenceCase
306
321
  }
@@ -0,0 +1,106 @@
1
+ const chalk = require("chalk");
2
+
3
+ const { ACTIVE_THEME_PATH } = require("./toolkit-common-vars");
4
+
5
+ const NAMESPACE_FILE_PATHS = {
6
+ "NAMESPACES.home": `${ACTIVE_THEME_PATH}/content/pages/home/home.html`,
7
+ "NAMESPACES.listing": `${ACTIVE_THEME_PATH}/content/pages/listing/listing.html`,
8
+ "NAMESPACES.bundle": `${ACTIVE_THEME_PATH}/content/pages/bundle/bundle.html`,
9
+ "NAMESPACES.profile": `${ACTIVE_THEME_PATH}/content/pages/profile/profile.html`,
10
+ "NAMESPACES.profileEditions": `${ACTIVE_THEME_PATH}/content/pages/profile/profile-editions.html`,
11
+ "NAMESPACES.profileFeatures": `${ACTIVE_THEME_PATH}/content/pages/profile/profile-features.html`,
12
+ "NAMESPACES.help": `${ACTIVE_THEME_PATH}/content/pages/help/help.html`,
13
+ };
14
+
15
+ const NAMESPACE_ORDERABLE_PAGE_SETTINGS_KEYS = {
16
+ "NAMESPACES.home": "home",
17
+ "NAMESPACES.profile": "profile",
18
+ };
19
+
20
+ const PAGE_NAME_TO_NAMESPACE = {
21
+ none: "none",
22
+ home: "NAMESPACES.home",
23
+ listing: "NAMESPACES.listing",
24
+ bundle: "NAMESPACES.bundle",
25
+ profile: "NAMESPACES.profile",
26
+ profileEditions: "NAMESPACES.profileEditions",
27
+ profileFeatures: "NAMESPACES.profileFeatures",
28
+ help: "NAMESPACES.help",
29
+ };
30
+
31
+ const PAGE_NAME_AND_ORDERABLE_TYPE_PROMPT = [
32
+ {
33
+ name: chalk.yellowBright("Do nothing"),
34
+ value: null,
35
+ },
36
+ {
37
+ name: "Home page (orderable)",
38
+ value: {
39
+ namespace: "NAMESPACES.home",
40
+ orderable: true,
41
+ },
42
+ },
43
+ {
44
+ name: "Home page (non-orderable)",
45
+ value: {
46
+ namespace: "NAMESPACES.home",
47
+ orderable: false,
48
+ },
49
+ },
50
+ {
51
+ name: "Listing page (non-orderable)",
52
+ value: {
53
+ namespace: "NAMESPACES.listing",
54
+ orderable: false,
55
+ },
56
+ },
57
+ {
58
+ name: "Product Bundle page (non-orderable)",
59
+ value: {
60
+ namespace: "NAMESPACES.bundle",
61
+ orderable: false,
62
+ },
63
+ },
64
+ {
65
+ name: "Product Profile page (orderable)",
66
+ value: {
67
+ namespace: "NAMESPACES.profile",
68
+ orderable: true,
69
+ },
70
+ },
71
+ {
72
+ name: "Product Profile page (non-orderable)",
73
+ value: {
74
+ namespace: "NAMESPACES.profile",
75
+ orderable: false,
76
+ },
77
+ },
78
+ {
79
+ name: "Product Profile Editions & Pricing page (non-orderable)",
80
+ value: {
81
+ namespace: "NAMESPACES.profileEditions",
82
+ orderable: false,
83
+ },
84
+ },
85
+ {
86
+ name: "Product Profile Feature Details page (non-orderable)",
87
+ value: {
88
+ namespace: "NAMESPACES.profileFeatures",
89
+ orderable: false,
90
+ },
91
+ },
92
+ {
93
+ name: "FAQ page (non-orderable)",
94
+ value: {
95
+ namespace: "NAMESPACES.help",
96
+ orderable: false,
97
+ },
98
+ },
99
+ ];
100
+
101
+ module.exports = {
102
+ PAGE_NAME_AND_ORDERABLE_TYPE_PROMPT,
103
+ NAMESPACE_FILE_PATHS,
104
+ NAMESPACE_ORDERABLE_PAGE_SETTINGS_KEYS,
105
+ PAGE_NAME_TO_NAMESPACE,
106
+ };
@@ -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.342";
18
+ const THEME_COMPONENT_VERSION = "0.0.352";
19
19
  const SASS_MODULE = "sass";
20
20
  const SASS_VERSION = "1.57.1";
21
21
  const SASS_LOADER_MODULE = "sass-loader";