@appdirect/sfb-toolkit 4.0.19 → 4.0.22

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 (47) hide show
  1. package/bin/index.js +26 -7
  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/npm-shrinkwrap.json +329 -252
  36. package/package.json +5 -5
  37. package/readme.md +6 -0
  38. package/src/tools/.sfbconfig +1 -1
  39. package/src/tools/package-fonts.js +1 -1
  40. package/src/tools/toolkit-common-fun.js +35 -21
  41. package/src/tools/toolkit-common-utils.js +63 -0
  42. package/src/tools/toolkit-common-vars.js +1 -1
  43. package/src/tools/toolkit-components-copy.js +358 -0
  44. package/src/tools/toolkit-create-extension.js +71 -9
  45. package/src/tools/toolkit-mock.js +1 -1
  46. package/src/tools/toolkit-start.js +1 -2
  47. package/src/tools/zip-theme.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appdirect/sfb-toolkit",
3
- "version": "4.0.19",
3
+ "version": "4.0.22",
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.19",
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.79",
61
60
  "@appdirect/storefront-utils": "latest",
62
61
  "@babel/core": "^7.19.1",
63
62
  "@babel/plugin-proposal-class-properties": "^7.18.6",
@@ -125,7 +124,8 @@
125
124
  "webpack": "^5.74.0",
126
125
  "webpack-cli": "^4.10.0",
127
126
  "webpack-dev-middleware": "^5.3.3",
128
- "webpack-hot-middleware": "^2.25.2"
127
+ "webpack-hot-middleware": "^2.25.2",
128
+ "@appdirect/sfb-theme-classic": "0.0.27"
129
129
  },
130
130
  "devDependencies": {
131
131
  "@babel/plugin-transform-modules-commonjs": "^7.18.6",
package/readme.md CHANGED
@@ -10,6 +10,12 @@ It can be easily mixed with eg. HTML, CSS, JavaScript, jQuery, SASS.
10
10
 
11
11
  ### Release Notes:
12
12
 
13
+ **4.0.20**
14
+ - Updated internal packages
15
+
16
+ **4.0.19**
17
+ - Updated internal packages
18
+
13
19
  **4.0.18**
14
20
  - Updated documentation links
15
21
 
@@ -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
@@ -1,9 +1,8 @@
1
1
  const fs = require("fs-extra");
2
- const moment = require("moment");
3
- const prompt = require("./prompt-questions");
4
- const packageJson = require('package-json');
2
+ const chalk = require("chalk");
3
+ const packageJson = require("package-json");
5
4
  const { spawnSync } = require("child_process");
6
- const chalk = require("chalk")
5
+ const prompt = require("./prompt-questions");
7
6
 
8
7
  const { CURRENT_PATH, TOOLKIT_PATH, BOOTSTRAP_FOLDERS, BOOTSTRAP_FILES, CONFIG_PATH, THEME_COMPONENT_MODULE,
9
8
  THEME_COMPONENT_VERSION, ACTIVE_THEME_PATH, THEME_LOGS_PATH, THEME_LOGS_FILE_PATH, SASS_MODULE,
@@ -11,8 +10,6 @@ const { CURRENT_PATH, TOOLKIT_PATH, BOOTSTRAP_FOLDERS, BOOTSTRAP_FILES, CONFIG_P
11
10
 
12
11
  const { getCustomComponentsInfo } = require("./toolkit-components-fun");
13
12
 
14
- const { has } = require("lodash");
15
-
16
13
  // function to remove project's folders (used to revert changes on error)
17
14
  const selfDestruction = (dir) => BOOTSTRAP_FOLDERS.forEach( file => fs.removeSync(`${dir}/${file}`));
18
15
 
@@ -24,18 +21,23 @@ const isProjectsFolder = (dir) => fs.readdirSync(dir).filter( item => BOOTSTRAP_
24
21
 
25
22
  // simple check if current folder is Project's folder, and give specific message
26
23
  const shouldBeProjectFolder = (should) => {
27
- const isProjectFolder = isProjectsFolder(CURRENT_PATH);
28
- switch(true){
29
- case !should && isProjectFolder:
30
- console.error(chalk.red(` ERROR: Unable to perform requested action. Please navigate away from the project folder.`));
31
- process.exit(1);
32
- break;
33
- case should && !isProjectFolder:
34
- console.error(chalk.red(` ERROR: Unable to perform requested action. Please navigate to a project folder.`));
35
- process.exit(1);
36
- break;
37
- }
38
- }
24
+ const isProjectFolder = isProjectsFolder(CURRENT_PATH);
25
+
26
+ const errorMessagePrefix = chalk.bgRed(" ERROR ");
27
+ 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}`));
31
+ process.exit(1);
32
+ }
33
+
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}`));
38
+ process.exit(1);
39
+ }
40
+ };
39
41
 
40
42
  // simple check if current folder is Project's folder, and give specific message
41
43
  const licenseAgreement = () => {
@@ -156,11 +158,20 @@ const createCustomThemePacakgeJson = (themeName, themePackageName, createdBy) =>
156
158
  return JSON.stringify(customThemePackageJson, null, 2);
157
159
  }
158
160
 
161
+ const getSfbThemeComponentsVersion = () => {
162
+ const themePackageJson = JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
163
+ return themePackageJson.dependencies['@appdirect/sfb-theme-components'];
164
+ }
165
+
166
+ const getToolkitVersionUsedToCreateTheme = () => {
167
+ const themePackageJson = JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
168
+ return themePackageJson.metadata.toolkitVersion;
169
+ }
170
+
159
171
  const updateCustomComponentsMetadata = (data) => {
160
172
  const hasPackageJson = fs.existsSync(`${ACTIVE_THEME_PATH}/package.json`);
161
173
  if (hasPackageJson) {
162
- const themePackageJson = JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
163
- const sfbThemeComponentsVersion = themePackageJson.dependencies['@appdirect/sfb-theme-components'];
174
+ const sfbThemeComponentsVersion = getSfbThemeComponentsVersion();
164
175
  const customComponentsPath = `${ACTIVE_THEME_PATH}/customComponents`;
165
176
  const customComponents = fs.existsSync(customComponentsPath);
166
177
  if (customComponents && sfbThemeComponentsVersion) {
@@ -288,5 +299,8 @@ module.exports = {
288
299
  createCustomThemePacakgeJson,
289
300
  updateCustomComponentsMetadata,
290
301
  addMetadata,
291
- installSass
302
+ installSass,
303
+ isProjectsFolder,
304
+ getSfbThemeComponentsVersion,
305
+ getToolkitVersionUsedToCreateTheme
292
306
  }
@@ -0,0 +1,63 @@
1
+ const chalk = require("chalk");
2
+ const path = require("path");
3
+ const { isProjectsFolder } = require("./toolkit-common-fun");
4
+
5
+ const isInsideCreatedExtension = (currentPath) => {
6
+ if (!currentPath) {
7
+ return false;
8
+ }
9
+ const [extensionsPathMatch] =
10
+ currentPath.match(/extensions\/[a-zA-Z-0-9]*/gm) || [];
11
+
12
+ return !!extensionsPathMatch;
13
+ };
14
+
15
+ const isInsideExtensionsFolder = () => {
16
+ const currentDir = process.cwd();
17
+ const previousDir = path.resolve(currentDir, "../");
18
+ const previousDirName = path.basename(previousDir);
19
+
20
+ const [pathMatch] = currentDir.match(/extensions\/?[a-zA-Z-0-9]*/gm) || [];
21
+ const isPrevDirRootFolder = isProjectsFolder(previousDir);
22
+ const isPrevDirExtensionsFolder = previousDirName === "extensions";
23
+
24
+ if ((isPrevDirRootFolder || isPrevDirExtensionsFolder) && !!pathMatch) {
25
+ return {
26
+ pathMatch,
27
+ isInsideCreatedExtensionFolder: isInsideCreatedExtension(pathMatch),
28
+ };
29
+ }
30
+
31
+ return { pathMatch: undefined, isInsideCreatedExtensionFolder: false };
32
+ };
33
+
34
+ const shouldNotBeInExtensionsFolder = () => {
35
+ const { pathMatch, isInsideCreatedExtensionFolder } =
36
+ isInsideExtensionsFolder();
37
+
38
+ if (pathMatch) {
39
+ const errorPrefixString = chalk.bgRed(" ERROR ");
40
+ const mainErrorMessage = `You are currently inside the "${pathMatch}" folder. The "sfb-toolkit" commands are unavailable in this folder.`;
41
+
42
+ console.error(
43
+ `${chalk.bold(`${errorPrefixString} ${mainErrorMessage}`)}\n`
44
+ );
45
+
46
+ if (isInsideCreatedExtensionFolder) {
47
+ console.error(
48
+ `You can try running ${chalk.bold(
49
+ "npm install && npm start"
50
+ )} to install your dependencies and get started. \n`
51
+ );
52
+ }
53
+
54
+ console.error(
55
+ `For more information, consult the documentation on Extensions: ${chalk.underline.bold(
56
+ "https://developer.appdirect.com/user-guides/extensions"
57
+ )}\n`
58
+ );
59
+ process.exit(1);
60
+ }
61
+ };
62
+
63
+ module.exports = { shouldNotBeInExtensionsFolder };
@@ -27,7 +27,7 @@ try {
27
27
  } catch (e) {
28
28
  WORKSPACE_CONFIG = {}
29
29
  }
30
- const ACTIVE_THEME = WORKSPACE_CONFIG.theme || "classic";
30
+ const ACTIVE_THEME = WORKSPACE_CONFIG.theme || "plaza";
31
31
  const ACTIVE_THEME_PATH = `${CURRENT_PATH}/themes/${ACTIVE_THEME}`;
32
32
  const THEME_LOGS_PATH = `${CURRENT_PATH}/theme-logs`;
33
33
  const THEME_LOGS_FILE_PATH = `${THEME_LOGS_PATH}/${ACTIVE_THEME}`;
@@ -0,0 +1,358 @@
1
+ const fs = require("fs");
2
+ const { COMMAND_PARAM, ACTIVE_THEME_PATH } = require("./toolkit-common-vars");
3
+ const { customComponentsEnabled } = require("./toolkit-components-fun");
4
+ const { getSfbThemeComponentsVersion, getToolkitVersionUsedToCreateTheme,
5
+ shouldBeProjectFolder } = require("./toolkit-common-fun");
6
+ const chalk = require("chalk");
7
+ const inquirer = require("inquirer");
8
+
9
+ // check if user is in correct location
10
+ shouldBeProjectFolder(true);
11
+
12
+ const commandLineComponents = COMMAND_PARAM;
13
+ const INDEX_EXPORT_NO_CHANGE = 'nothing';
14
+ const INDEX_EXPORT_COMMENT_OUT = 'comment';
15
+ const INDEX_EXPORT_REPLACE = 'replace';
16
+ const FEATURE_AVAILABLE_SINCE_TOOLKIT_VERSION = '4.0.21';
17
+ const BLACKLISTED_COMPONENTS = ["PageOrderableContainer"];
18
+ const PATH_TO_CUSTOM_COMPONENTS_INDEX = `${ACTIVE_THEME_PATH}/customComponents/index.js`;
19
+ const BASE_PATH_TO_COMPONENTS_INDEX = `${ACTIVE_THEME_PATH}/node_modules/@appdirect/sfb-theme-components/src/components/index.js`;
20
+ const sfbThemeComponentsVersion = getSfbThemeComponentsVersion().replace(/\.|\^/g, '_');
21
+ const themeToolkitVersion = getToolkitVersionUsedToCreateTheme();
22
+
23
+ const PAGE_ORDERABLE_CONTAINER_DIR = 'page-orderable-container'
24
+ const PAGE_ORDERABLE_CONTAINER_BASE_PATH = `@appdirect/sfb-theme-components/src/components/${PAGE_ORDERABLE_CONTAINER_DIR}`
25
+
26
+ const formattedComponentStatus = ({ data, statusMessage, statusType, maxStringLength = 30 }) => {
27
+ const formattingOffset = (maxStringLength + 20) <= 50 ? 50 : maxStringLength + 20;
28
+ switch(statusType) {
29
+ case 'success':
30
+ console.log(chalk.green(`${data.padEnd(formattingOffset, ".")}[${statusMessage}]`));
31
+ break;
32
+ case 'skip':
33
+ console.log(chalk.greenBright(`${data.padEnd(formattingOffset, ".")}[${statusMessage}]`));
34
+ break;
35
+ case 'error':
36
+ console.log(chalk.red(`${data.padEnd(formattingOffset, ".")}[${statusMessage}]`));
37
+ break;
38
+ }
39
+ }
40
+
41
+ const getPathToFile = (path) => {
42
+ let fullPath = path;
43
+ const hasExtension = fullPath.match(/(.scss|.jsx?)/);
44
+ if(!hasExtension) {
45
+ const jsFile = `${fullPath}.js`;
46
+ const indexJsFile = `${fullPath}/index.js`;
47
+ const jsxFile = `${fullPath}.jsx`;
48
+ const scssFile = `${fullPath}.scss`;
49
+
50
+ if(fs.existsSync(jsFile)) {
51
+ fullPath = jsFile;
52
+ } else if(fs.existsSync(jsxFile)) {
53
+ fullPath = jsxFile;
54
+ } else if(fs.existsSync(scssFile)) {
55
+ fullPath = scssFile;
56
+ } else if(fs.existsSync(indexJsFile)) {
57
+ fullPath = indexJsFile;
58
+ } else {
59
+ const split = fullPath.split('/');
60
+ split[split.length - 1] = `_${split[split.length - 1]}.scss`;
61
+ const updatedPathToFile = split.join('/');
62
+ if(fs.existsSync(updatedPathToFile)) {
63
+ fullPath = updatedPathToFile;
64
+ }
65
+ }
66
+ }
67
+ return fullPath;
68
+ }
69
+
70
+ const constructPath = (currentPath, goToRelativePath) => {
71
+ const levelsToGoUp = (goToRelativePath.match(/\.\.\//g) || []).length + 1;
72
+ const currentPathDepthIndices = [];
73
+ for(let i=0; i < currentPath.length; i++) {
74
+ if (currentPath[i] === '/') {
75
+ currentPathDepthIndices.push(i);
76
+ }
77
+ }
78
+ const newCurrentPath = currentPath.slice(0, currentPathDepthIndices[currentPathDepthIndices.length - levelsToGoUp]);
79
+ const newGoToPath = goToRelativePath.replace(/\.+\//g, '');
80
+ return getPathToFile(`${newCurrentPath}/${newGoToPath}`);
81
+ }
82
+
83
+ const replacePageOrderableContainerImports = (fileData) => {
84
+ if (fileData.includes(PAGE_ORDERABLE_CONTAINER_DIR)) {
85
+ // replace all page-orderable-container paths
86
+ const pageOrderableRegex = new RegExp(`[\\\/.]+${PAGE_ORDERABLE_CONTAINER_DIR}`, 'g')
87
+ return fileData.replace(pageOrderableRegex, PAGE_ORDERABLE_CONTAINER_BASE_PATH)
88
+ }
89
+ return fileData
90
+ }
91
+
92
+ const addDefaultExport = (data, indexFileData, indexExportStrategy) => {
93
+ if(themeToolkitVersion >= FEATURE_AVAILABLE_SINCE_TOOLKIT_VERSION) {
94
+ const { name, pathToCopyTo } = data;
95
+ const updatedPath = pathToCopyTo.split('customComponents')[1].replace(/.jsx?/g, '');
96
+ const template = `\nexport { default as ${name} } from '.${updatedPath}'`;
97
+ let componentAlreadyExported = false;
98
+
99
+ if (indexExportStrategy === INDEX_EXPORT_COMMENT_OUT) {
100
+ const nonCommentedOutExports = new RegExp(`(?<!\/\/\\s*)export.*\\s${name}[\\s|}].*`, 'g');
101
+ const matchedValues = indexFileData.matchAll(nonCommentedOutExports);
102
+
103
+ for (const match of matchedValues) {
104
+ if(match[0].search(updatedPath) === -1) {
105
+ indexFileData = indexFileData.replace(match[0], `// ${match[0]}`);
106
+ } else {
107
+ componentAlreadyExported = true;
108
+ }
109
+ }
110
+ } else if (indexExportStrategy === INDEX_EXPORT_REPLACE) {
111
+ const nonCommentedOutExports = new RegExp(`(?<!\/\/\\s*)export.*\\s${name}[\\s|}].*\\r?\\n?`, 'g');
112
+ const matchedValues = indexFileData.matchAll(nonCommentedOutExports);
113
+
114
+ for (const match of matchedValues) {
115
+ if(match[0].search(updatedPath) === -1) {
116
+ indexFileData = indexFileData.replace(match[0], '');
117
+ } else {
118
+ componentAlreadyExported = true;
119
+ }
120
+ }
121
+ }
122
+ if (!componentAlreadyExported) {
123
+ return indexFileData + template;
124
+ }
125
+ };
126
+
127
+ return indexFileData;
128
+ }
129
+
130
+ const sfbThemeComponentsDeepCopy = (
131
+ pathsToFileList,
132
+ maxComponentStringLength,
133
+ indexExportStrategy = INDEX_EXPORT_NO_CHANGE
134
+ ) => {
135
+ const COPIED = 'COPIED';
136
+ const NO_MATCH = 'NO_MATCH';
137
+ const SUCCESS = 'success';
138
+ const FOUND = 'FOUND';
139
+ const ERROR = 'error';
140
+ const SKIP = 'skip';
141
+
142
+ const componentsToCopy = pathsToFileList;
143
+ const paths = [...Object.keys(pathsToFileList).reverse()];
144
+ const allPaths = [...Object.keys(pathsToFileList)];
145
+
146
+ let indexFileData = fs.readFileSync(PATH_TO_CUSTOM_COMPONENTS_INDEX, 'utf8');
147
+ const indexFileDataOriginalLength = indexFileData.length;
148
+
149
+ let componentBeingCopied = {};
150
+
151
+ while(paths.length > 0) {
152
+ const path = paths.pop();
153
+ let isScssFile = path.match(/.scss/);
154
+ let fileData;
155
+
156
+ if(fs.existsSync(path)) {
157
+ fileData = fs.readFileSync(path, 'utf8').replace(/^\/\/+.*\s*/g, '');
158
+ } else {
159
+ if(componentBeingCopied.name) {
160
+ formattedComponentStatus({
161
+ data: componentBeingCopied.name,
162
+ statusMessage: COPIED,
163
+ statusType: SUCCESS,
164
+ maxComponentStringLength
165
+ });
166
+ indexFileData = addDefaultExport(componentBeingCopied, indexFileData);
167
+ }
168
+ if(componentsToCopy[path]) {
169
+ formattedComponentStatus({
170
+ data: componentsToCopy[path],
171
+ statusMessage: NO_MATCH,
172
+ statusType: ERROR,
173
+ maxComponentStringLength});
174
+ }
175
+ continue;
176
+ }
177
+
178
+ const pathToCopyTo = path.replace('node_modules/@appdirect/sfb-theme-components',
179
+ `customComponents/sfb_theme_components${sfbThemeComponentsVersion}`);
180
+
181
+ if(!fs.existsSync(pathToCopyTo)) {
182
+ const folderPath = pathToCopyTo.slice(0, pathToCopyTo.lastIndexOf('/'));
183
+ fs.mkdirSync(folderPath, { recursive: true });
184
+
185
+ fileData = replacePageOrderableContainerImports(fileData)
186
+
187
+ fs.writeFileSync(pathToCopyTo, fileData);
188
+ if(componentsToCopy[path]) {
189
+ if(componentBeingCopied.name) {
190
+ formattedComponentStatus({
191
+ data: componentBeingCopied.name,
192
+ statusMessage: COPIED,
193
+ statusType: SUCCESS,
194
+ maxComponentStringLength
195
+ });
196
+ indexFileData = addDefaultExport(componentBeingCopied, indexFileData, indexExportStrategy);
197
+
198
+ };
199
+ componentBeingCopied = {
200
+ name: componentsToCopy[path],
201
+ pathToCopyTo
202
+ }
203
+
204
+ }
205
+ } else {
206
+ if(componentsToCopy[path]) {
207
+ if(componentBeingCopied.name) {
208
+ formattedComponentStatus({
209
+ data: componentBeingCopied.name,
210
+ statusMessage: COPIED,
211
+ statusType: SUCCESS,
212
+ maxComponentStringLength
213
+ });
214
+ indexFileData = addDefaultExport(componentBeingCopied, indexFileData, indexExportStrategy);
215
+ componentBeingCopied = {};
216
+ }
217
+ formattedComponentStatus({
218
+ data: componentsToCopy[path],
219
+ statusMessage: FOUND,
220
+ statusType: SKIP,
221
+ maxComponentStringLength
222
+ });
223
+ }
224
+ };
225
+
226
+ let imports;
227
+
228
+ if(isScssFile) {
229
+ imports = fileData.matchAll(/@import.*\s+['|"](.+)['|"]/g);
230
+ } else {
231
+ imports = fileData.matchAll(/import.*\s+['|"](\.+.+)['|"]|from\s+['|"](\.+.+)['|"]/g);
232
+ }
233
+
234
+ for(const importPaths of imports) {
235
+ const usePath = importPaths[1] || importPaths[2];
236
+ let fullPath = constructPath(path, usePath);
237
+ if(!allPaths.includes(fullPath)) {
238
+ // skip copying page-orderable-container imports
239
+ // since we re-write their usages to point to library
240
+ if (fullPath.includes(PAGE_ORDERABLE_CONTAINER_DIR)) {
241
+ continue;
242
+ }
243
+
244
+ paths.push(fullPath);
245
+ allPaths.push(fullPath);
246
+ }
247
+ }
248
+
249
+ if(paths.length === 0 && componentBeingCopied.name) {
250
+ formattedComponentStatus({
251
+ data: componentBeingCopied.name,
252
+ statusMessage: COPIED,
253
+ statusType: SUCCESS,
254
+ maxComponentStringLength
255
+ });
256
+ indexFileData = addDefaultExport(componentBeingCopied, indexFileData, indexExportStrategy);
257
+ }
258
+ }
259
+ if(indexFileDataOriginalLength < indexFileData.length || indexExportStrategy === INDEX_EXPORT_REPLACE) {
260
+ fs.writeFileSync(PATH_TO_CUSTOM_COMPONENTS_INDEX, `${indexFileData}`);
261
+ }
262
+ }
263
+
264
+ (async () => {
265
+ try {
266
+ if(customComponentsEnabled) {
267
+ const componentMap = {};
268
+ const componentsFile = fs.readFileSync(BASE_PATH_TO_COMPONENTS_INDEX, 'utf8').replace(/\/\/+.*\s*/g, '');
269
+ const componentMatches = [...componentsFile.matchAll(/.*as\s+(\w+)\s+.*from\s+['|"](\.+\/.+)['|"]/g)];
270
+ let maxComponentStringLength = 0;
271
+ let selectedComponentsList;
272
+
273
+ componentMatches.forEach(component => {
274
+ if(!BLACKLISTED_COMPONENTS.includes(component[1])) {
275
+ maxComponentStringLength = maxComponentStringLength < component[1].length
276
+ ? component[1].length
277
+ : maxComponentStringLength;
278
+ componentMap[component[1].toLowerCase()] = {
279
+ path: component[2],
280
+ componentExportName: component[1]
281
+ };
282
+ }
283
+ })
284
+
285
+ if(commandLineComponents) {
286
+ selectedComponentsList = commandLineComponents.split(",").sort();
287
+ } else {
288
+ const selectedComponents = await inquirer.prompt([{
289
+ type: 'checkbox',
290
+ name: 'components',
291
+ message: 'Please select a component(s) to copy:',
292
+ choices: Object.values(componentMap).map(data => data.componentExportName)
293
+ }]);
294
+ selectedComponentsList = selectedComponents.components;
295
+ }
296
+
297
+ const selectedComponentsFilePaths = {};
298
+
299
+ selectedComponentsList.forEach(component => {
300
+ const hasComponent = componentMap[component.toLowerCase()];
301
+ if(hasComponent) {
302
+ const componentPathSfb = constructPath(BASE_PATH_TO_COMPONENTS_INDEX, hasComponent.path);
303
+ selectedComponentsFilePaths[componentPathSfb] = hasComponent.componentExportName;
304
+ } else {
305
+ // account for user passed arguments/components that do not exist
306
+ maxComponentStringLength = maxComponentStringLength < component.length
307
+ ? component.length
308
+ : maxComponentStringLength;
309
+ const componentPathSfb = constructPath(BASE_PATH_TO_COMPONENTS_INDEX, component);
310
+ selectedComponentsFilePaths[componentPathSfb] = component;
311
+ }
312
+ });
313
+
314
+ let indexExportStrategy;
315
+
316
+ if(themeToolkitVersion >= FEATURE_AVAILABLE_SINCE_TOOLKIT_VERSION) {
317
+ while(!indexExportStrategy) {
318
+ indexExportStrategy = (await inquirer.prompt({
319
+ type: 'list',
320
+ name: 'strategy',
321
+ message: 'Please select how the copied components should be exported:',
322
+ choices: [{
323
+ name: 'Comment out existing exported components and add those selected.',
324
+ value: INDEX_EXPORT_COMMENT_OUT
325
+ }, {
326
+ name: 'Replace existing exported components with those selected.',
327
+ value: INDEX_EXPORT_REPLACE
328
+ }, {
329
+ name: 'Do nothing. (Manual index update will be required)',
330
+ value: INDEX_EXPORT_NO_CHANGE
331
+ }]
332
+ })).strategy;
333
+
334
+ if(indexExportStrategy === INDEX_EXPORT_REPLACE) {
335
+ const deepCopyChoice = (await inquirer.prompt({
336
+ type: 'confirm',
337
+ name: 'choice',
338
+ message: 'This action is irreversible, are you certain you wish to proceed?'
339
+ })).choice;
340
+
341
+ if(!deepCopyChoice) {
342
+ indexExportStrategy = undefined;
343
+ process.stdout.moveCursor(0, -2);
344
+ process.stdout.clearLine(0);
345
+ }
346
+ }
347
+ }
348
+ }
349
+
350
+ sfbThemeComponentsDeepCopy(selectedComponentsFilePaths, maxComponentStringLength, indexExportStrategy);
351
+
352
+ } else {
353
+ console.log(chalk.red('Custom components are not enabled for this theme.'));
354
+ }
355
+ } catch (err) {
356
+ console.error(chalk.red(`\n ERROR: Unable to copy components due to: ${err}.\n`));
357
+ }
358
+ })();