@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.
- package/bin/index.js +93 -4
- package/config/index.js +1 -1
- package/coverage/clover.xml +2 -2
- package/coverage/lcov-report/constants/customUserAttributesMock.js.html +1 -1
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/pageUrls.js.html +1 -1
- package/coverage/lcov-report/constants/userMock.js.html +1 -1
- package/coverage/lcov-report/controllers/controllers-utils/assetsUtils.js.html +1 -1
- package/coverage/lcov-report/controllers/controllers-utils/index.html +1 -1
- package/coverage/lcov-report/controllers/data-filters/bootstrap-data-filter.js.html +1 -1
- package/coverage/lcov-report/controllers/data-filters/call-to-actions-filter.js.html +1 -1
- package/coverage/lcov-report/controllers/data-filters/index.html +1 -1
- package/coverage/lcov-report/controllers/index.html +1 -1
- package/coverage/lcov-report/controllers/index.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/base/ResultItem.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/base/SearchBar.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/base/index.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/base/item.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/container.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/data-view.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/header-view.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/index.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/search.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/constants/index.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/constants/pageUrl.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/constants/roleType.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/constants/searchType.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/utils/debounce.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/utils/index.html +1 -1
- package/coverage/lcov-report/index.html +1 -1
- package/coverage/lcov-report/middlewares/config.js.html +1 -1
- package/coverage/lcov-report/middlewares/index.html +1 -1
- package/coverage/lcov-report/tools/index.html +1 -1
- package/coverage/lcov-report/tools/proxy-fetch.js.html +1 -1
- package/customComponents/index.js +10 -2
- package/npm-shrinkwrap.json +314 -128
- package/package.json +4 -4
- package/readme.md +9 -0
- package/src/boilerplates/AddComponent/AddComponent.jsx +234 -0
- package/src/boilerplates/AddComponent/styles/AddComponent.scss +47 -0
- package/src/tools/.sfbconfig +1 -1
- package/src/tools/package-fonts.js +1 -1
- package/src/tools/prompt-questions.js +109 -14
- package/src/tools/toolkit-common-fun.js +41 -15
- package/src/tools/toolkit-common-vars-namespace.js +106 -0
- package/src/tools/toolkit-common-vars.js +2 -2
- package/src/tools/toolkit-components-add.js +334 -0
- package/src/tools/toolkit-components-copy.js +390 -0
- package/src/tools/toolkit-components-delete.js +370 -0
- package/src/tools/toolkit-components-fun.js +126 -7
- package/src/tools/toolkit-components-info.js +6 -4
- package/src/tools/toolkit-components-vars.js +50 -0
- package/src/tools/toolkit-components.js +1 -1
- package/src/tools/toolkit-create-extension.js +1 -1
- package/src/tools/toolkit-create.js +2 -3
- package/src/tools/toolkit-import.js +182 -0
- package/src/tools/toolkit-install.js +6 -5
- package/src/tools/toolkit-mock.js +1 -1
- package/src/tools/toolkit-package.js +3 -0
- package/src/tools/toolkit-setup.js +1 -1
- package/src/tools/toolkit-start.js +4 -1
- package/src/tools/toolkit-storybook.js +136 -48
- package/src/tools/toolkit-zip-utils.js +35 -0
- package/src/tools/zip-theme.js +62 -50
- package/themes-config.json +0 -7
- package/customComponents/atoms/label/Label.jsx +0 -20
- package/customComponents/atoms/label/stories/Label.story.mdx +0 -20
- package/customComponents/atoms/label/styles/Label.scss +0 -4
- package/customComponents/components/atoms-showcase-custom/AtomsShowcaseCustom.jsx +0 -8
- package/customComponents/components/atoms-showcase-custom/stories/AtomsShowcaseCustom.story.mdx +0 -17
- package/customComponents/components/atoms-showcase-modules/AtomsShowcaseModules.jsx +0 -223
- package/customComponents/components/atoms-showcase-modules/stories/AtomsShowcaseModules.story.mdx +0 -49
- package/customComponents/components/index.js +0 -2
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const { customComponentsEnabled } = require("./toolkit-components-fun");
|
|
3
|
+
const { getSfbThemeComponentsVersion, getToolkitVersionUsedToCreateTheme,
|
|
4
|
+
shouldBeProjectFolder } = require("./toolkit-common-fun");
|
|
5
|
+
const {
|
|
6
|
+
COPIED, NO_MATCH, SUCCESS, FOUND, ERROR, SKIP,
|
|
7
|
+
INDEX_EXPORT_NO_CHANGE, INDEX_EXPORT_COMMENT_OUT, INDEX_EXPORT_REPLACE,
|
|
8
|
+
FEATURE_AVAILABLE_SINCE_TOOLKIT_VERSION, BLACKLISTED_COMPONENTS,
|
|
9
|
+
PATH_TO_CUSTOM_COMPONENTS_INDEX, BASE_PATH_TO_COMPONENTS_INDEX,
|
|
10
|
+
COMPONENTS_NOT_INSTALLED_ERROR, FEATURE_AVAILABLE_SINCE_SFB_THEME_VERSION
|
|
11
|
+
} = require("./toolkit-components-vars");
|
|
12
|
+
const chalk = require("chalk");
|
|
13
|
+
const inquirer = require("inquirer");
|
|
14
|
+
|
|
15
|
+
// check if user is in correct location
|
|
16
|
+
shouldBeProjectFolder(true);
|
|
17
|
+
|
|
18
|
+
let sfbThemeComponentsVersionCustom;
|
|
19
|
+
const themeToolkitVersion = getToolkitVersionUsedToCreateTheme();
|
|
20
|
+
|
|
21
|
+
const PAGE_ORDERABLE_CONTAINER_DIR = 'page-orderable-container'
|
|
22
|
+
const PAGE_ORDERABLE_CONTAINER_BASE_PATH = `@appdirect/sfb-theme-components/src/components/${PAGE_ORDERABLE_CONTAINER_DIR}`
|
|
23
|
+
const getPathToCopyTo = (path) => (path.replace('node_modules/@appdirect/sfb-theme-components',
|
|
24
|
+
`customComponents/sfb_theme_components_${sfbThemeComponentsVersionCustom}`));
|
|
25
|
+
|
|
26
|
+
const formattedComponentStatus = ({ data, statusMessage, statusType, path = '', 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}]`) + `[${path && chalk.dim(path)}]`);
|
|
31
|
+
break;
|
|
32
|
+
case SKIP:
|
|
33
|
+
console.log(chalk.greenBright(`${data.padEnd(formattingOffset, ".")}[${statusMessage}]`) + `[${path && chalk.dim(path)}]`);
|
|
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 && 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 && indexExportStrategy !== INDEX_EXPORT_NO_CHANGE) {
|
|
123
|
+
return indexFileData.trim() + template;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
return indexFileData;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const sfbThemeComponentsDeepCopy = (
|
|
131
|
+
pathsToFileList,
|
|
132
|
+
maxComponentStringLength,
|
|
133
|
+
indexExportStrategy = INDEX_EXPORT_NO_CHANGE
|
|
134
|
+
) => {
|
|
135
|
+
|
|
136
|
+
const componentsToCopy = pathsToFileList;
|
|
137
|
+
const paths = [...Object.keys(pathsToFileList).reverse()];
|
|
138
|
+
const allPaths = [...Object.keys(pathsToFileList)];
|
|
139
|
+
|
|
140
|
+
let indexFileData = fs.readFileSync(PATH_TO_CUSTOM_COMPONENTS_INDEX, 'utf8');
|
|
141
|
+
const indexFileDataOriginalLength = indexFileData.length;
|
|
142
|
+
|
|
143
|
+
let componentBeingCopied = {};
|
|
144
|
+
|
|
145
|
+
while(paths.length > 0) {
|
|
146
|
+
const path = paths.pop();
|
|
147
|
+
let isScssFile = path.match(/.scss/);
|
|
148
|
+
let fileData;
|
|
149
|
+
|
|
150
|
+
if(fs.existsSync(path)) {
|
|
151
|
+
fileData = fs.readFileSync(path, 'utf8').replace(/^\/\/+.*\s*/g, '');
|
|
152
|
+
} else {
|
|
153
|
+
if(componentBeingCopied.name) {
|
|
154
|
+
formattedComponentStatus({
|
|
155
|
+
data: componentBeingCopied.name,
|
|
156
|
+
statusMessage: COPIED,
|
|
157
|
+
statusType: SUCCESS,
|
|
158
|
+
maxComponentStringLength,
|
|
159
|
+
path: componentBeingCopied.pathToCopyTo
|
|
160
|
+
});
|
|
161
|
+
indexFileData = addDefaultExport(componentBeingCopied, indexFileData);
|
|
162
|
+
}
|
|
163
|
+
if(componentsToCopy[path]) {
|
|
164
|
+
formattedComponentStatus({
|
|
165
|
+
data: componentsToCopy[path],
|
|
166
|
+
statusMessage: NO_MATCH,
|
|
167
|
+
statusType: ERROR,
|
|
168
|
+
maxComponentStringLength});
|
|
169
|
+
}
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const pathToCopyTo = getPathToCopyTo(path);
|
|
174
|
+
|
|
175
|
+
if(!fs.existsSync(pathToCopyTo)) {
|
|
176
|
+
const folderPath = pathToCopyTo.slice(0, pathToCopyTo.lastIndexOf('/'));
|
|
177
|
+
fs.mkdirSync(folderPath, { recursive: true });
|
|
178
|
+
|
|
179
|
+
fileData = replacePageOrderableContainerImports(fileData)
|
|
180
|
+
|
|
181
|
+
fs.writeFileSync(pathToCopyTo, fileData);
|
|
182
|
+
if(componentsToCopy[path]) {
|
|
183
|
+
if(componentBeingCopied.name) {
|
|
184
|
+
formattedComponentStatus({
|
|
185
|
+
data: componentBeingCopied.name,
|
|
186
|
+
statusMessage: COPIED,
|
|
187
|
+
statusType: SUCCESS,
|
|
188
|
+
maxComponentStringLength,
|
|
189
|
+
path: componentBeingCopied.pathToCopyTo
|
|
190
|
+
});
|
|
191
|
+
indexFileData = addDefaultExport(componentBeingCopied, indexFileData, indexExportStrategy);
|
|
192
|
+
|
|
193
|
+
};
|
|
194
|
+
componentBeingCopied = {
|
|
195
|
+
name: componentsToCopy[path],
|
|
196
|
+
pathToCopyTo
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
} else {
|
|
201
|
+
if(componentsToCopy[path]) {
|
|
202
|
+
if(componentBeingCopied.name) {
|
|
203
|
+
formattedComponentStatus({
|
|
204
|
+
data: componentBeingCopied.name,
|
|
205
|
+
statusMessage: COPIED,
|
|
206
|
+
statusType: SUCCESS,
|
|
207
|
+
maxComponentStringLength,
|
|
208
|
+
path: componentBeingCopied.pathToCopyTo
|
|
209
|
+
});
|
|
210
|
+
indexFileData = addDefaultExport(componentBeingCopied, indexFileData, indexExportStrategy);
|
|
211
|
+
componentBeingCopied = {};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
formattedComponentStatus({
|
|
215
|
+
data: componentsToCopy[path],
|
|
216
|
+
statusMessage: FOUND,
|
|
217
|
+
statusType: SKIP,
|
|
218
|
+
maxComponentStringLength,
|
|
219
|
+
path: pathToCopyTo
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const foundComponentPattern = new RegExp(
|
|
223
|
+
`export.*\\s${componentsToCopy[path]}[\\s|}].*`
|
|
224
|
+
+ `${sfbThemeComponentsVersionCustom}.*${componentsToCopy[path]}.*`, 'g');
|
|
225
|
+
const foundComponent = indexFileData.match(foundComponentPattern);
|
|
226
|
+
|
|
227
|
+
if(!foundComponent) {
|
|
228
|
+
const foundComponentData = {
|
|
229
|
+
name: componentsToCopy[path],
|
|
230
|
+
pathToCopyTo: getPathToCopyTo(path)
|
|
231
|
+
}
|
|
232
|
+
indexFileData = addDefaultExport(foundComponentData, indexFileData, indexExportStrategy);
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
let imports;
|
|
239
|
+
|
|
240
|
+
if(isScssFile) {
|
|
241
|
+
imports = fileData.matchAll(/@import.*\s+['|"](.+)['|"]/g);
|
|
242
|
+
} else {
|
|
243
|
+
imports = fileData.matchAll(/import.*\s+['|"](\.+.+)['|"]|from\s+['|"](\.+.+)['|"]/g);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
for(const importPaths of imports) {
|
|
247
|
+
const usePath = importPaths[1] || importPaths[2];
|
|
248
|
+
let fullPath = constructPath(path, usePath);
|
|
249
|
+
if(!allPaths.includes(fullPath)) {
|
|
250
|
+
// skip copying page-orderable-container imports
|
|
251
|
+
// since we re-write their usages to point to library
|
|
252
|
+
if (fullPath.includes(PAGE_ORDERABLE_CONTAINER_DIR)) {
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
paths.push(fullPath);
|
|
257
|
+
allPaths.push(fullPath);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if(paths.length === 0 && componentBeingCopied.name) {
|
|
262
|
+
formattedComponentStatus({
|
|
263
|
+
data: componentBeingCopied.name,
|
|
264
|
+
statusMessage: COPIED,
|
|
265
|
+
statusType: SUCCESS,
|
|
266
|
+
maxComponentStringLength,
|
|
267
|
+
path: componentBeingCopied.pathToCopyTo
|
|
268
|
+
});
|
|
269
|
+
indexFileData = addDefaultExport(componentBeingCopied, indexFileData, indexExportStrategy);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if(indexFileDataOriginalLength < indexFileData.length || indexExportStrategy === INDEX_EXPORT_REPLACE) {
|
|
273
|
+
fs.writeFileSync(PATH_TO_CUSTOM_COMPONENTS_INDEX, `${indexFileData.trim()}\n`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
(async () => {
|
|
278
|
+
try {
|
|
279
|
+
const isCustomComponentsEnabled = await customComponentsEnabled();
|
|
280
|
+
let indexExportStrategy;
|
|
281
|
+
|
|
282
|
+
if(isCustomComponentsEnabled) {
|
|
283
|
+
const componentMap = {};
|
|
284
|
+
|
|
285
|
+
const sfbThemeComponentsVersion = getSfbThemeComponentsVersion().replace('^', '');
|
|
286
|
+
sfbThemeComponentsVersionCustom = sfbThemeComponentsVersion.replaceAll('.', '_');
|
|
287
|
+
|
|
288
|
+
if(sfbThemeComponentsVersion < FEATURE_AVAILABLE_SINCE_SFB_THEME_VERSION) {
|
|
289
|
+
return console.log(chalk.red(
|
|
290
|
+
`[ERROR] This feature is only available starting from sfb-theme-components version: `
|
|
291
|
+
+ `${chalk.green(FEATURE_AVAILABLE_SINCE_SFB_THEME_VERSION)}`
|
|
292
|
+
));
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const componentsFile = fs.readFileSync(BASE_PATH_TO_COMPONENTS_INDEX, 'utf8').replace(/\/\/+.*\s*/g, '');
|
|
296
|
+
const componentMatches = [...componentsFile.matchAll(/.*as\s+(\w+)\s+.*from\s+['|"](\.+\/.+)['|"]/g)];
|
|
297
|
+
let maxComponentStringLength = 0;
|
|
298
|
+
let selectedComponentsList;
|
|
299
|
+
|
|
300
|
+
componentMatches.forEach(component => {
|
|
301
|
+
if(!BLACKLISTED_COMPONENTS.includes(component[1])) {
|
|
302
|
+
maxComponentStringLength = maxComponentStringLength < component[1].length
|
|
303
|
+
? component[1].length
|
|
304
|
+
: maxComponentStringLength;
|
|
305
|
+
componentMap[component[1].toLowerCase()] = {
|
|
306
|
+
path: component[2],
|
|
307
|
+
componentExportName: component[1]
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
if(process.argv[2] !== 'false') {
|
|
313
|
+
const data = Object.entries(JSON.parse(process.argv[2]));
|
|
314
|
+
if(data.length > 0) {
|
|
315
|
+
indexExportStrategy = data[0][0];
|
|
316
|
+
selectedComponentsList = data[0][1].sort();
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
319
|
+
const selectedComponents = await inquirer.prompt([{
|
|
320
|
+
type: 'checkbox',
|
|
321
|
+
name: 'components',
|
|
322
|
+
message: 'Please select a component(s) to copy:',
|
|
323
|
+
choices: Object.values(componentMap).map(data => data.componentExportName)
|
|
324
|
+
}]);
|
|
325
|
+
selectedComponentsList = selectedComponents.components;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const selectedComponentsFilePaths = {};
|
|
329
|
+
if(!selectedComponentsList || selectedComponentsList.length === 0) {
|
|
330
|
+
console.log(chalk.cyanBright(`[INFO] No components were selected.`));
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
selectedComponentsList.forEach(component => {
|
|
335
|
+
const hasComponent = componentMap[component.toLowerCase()];
|
|
336
|
+
if(hasComponent) {
|
|
337
|
+
const componentPathSfb = constructPath(BASE_PATH_TO_COMPONENTS_INDEX, hasComponent.path)?.replaceAll("\\", "/");
|
|
338
|
+
selectedComponentsFilePaths[componentPathSfb] = hasComponent.componentExportName;
|
|
339
|
+
} else {
|
|
340
|
+
// account for user passed arguments/components that do not exist
|
|
341
|
+
maxComponentStringLength = maxComponentStringLength < component.length
|
|
342
|
+
? component.length
|
|
343
|
+
: maxComponentStringLength;
|
|
344
|
+
const componentPathSfb = constructPath(BASE_PATH_TO_COMPONENTS_INDEX, component)?.replaceAll("\\", "/");
|
|
345
|
+
selectedComponentsFilePaths[componentPathSfb] = component;
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
if(themeToolkitVersion && themeToolkitVersion >= FEATURE_AVAILABLE_SINCE_TOOLKIT_VERSION) {
|
|
350
|
+
while(!indexExportStrategy) {
|
|
351
|
+
indexExportStrategy = (await inquirer.prompt({
|
|
352
|
+
type: 'list',
|
|
353
|
+
name: 'strategy',
|
|
354
|
+
message: 'Please select how the copied components should be exported:',
|
|
355
|
+
choices: [{
|
|
356
|
+
name: 'Comment out existing exported components and add those selected.',
|
|
357
|
+
value: INDEX_EXPORT_COMMENT_OUT
|
|
358
|
+
}, {
|
|
359
|
+
name: 'Replace existing exported components with those selected.',
|
|
360
|
+
value: INDEX_EXPORT_REPLACE
|
|
361
|
+
}, {
|
|
362
|
+
name: 'Do nothing. (Manual index update will be required)',
|
|
363
|
+
value: INDEX_EXPORT_NO_CHANGE
|
|
364
|
+
}]
|
|
365
|
+
})).strategy;
|
|
366
|
+
|
|
367
|
+
if(indexExportStrategy === INDEX_EXPORT_REPLACE) {
|
|
368
|
+
const deepCopyChoice = (await inquirer.prompt({
|
|
369
|
+
type: 'confirm',
|
|
370
|
+
name: 'choice',
|
|
371
|
+
message: 'This action is irreversible, are you certain you wish to proceed?'
|
|
372
|
+
})).choice;
|
|
373
|
+
|
|
374
|
+
if(!deepCopyChoice) {
|
|
375
|
+
indexExportStrategy = undefined;
|
|
376
|
+
process.stdout.moveCursor(0, -2);
|
|
377
|
+
process.stdout.clearLine(0);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
sfbThemeComponentsDeepCopy(selectedComponentsFilePaths, maxComponentStringLength, indexExportStrategy);
|
|
383
|
+
|
|
384
|
+
} else {
|
|
385
|
+
console.log(COMPONENTS_NOT_INSTALLED_ERROR);
|
|
386
|
+
}
|
|
387
|
+
} catch (err) {
|
|
388
|
+
console.error(chalk.red(`\n ERROR: Unable to copy components due to: ${err}.\n`));
|
|
389
|
+
}
|
|
390
|
+
})();
|