@appdirect/sfb-toolkit 4.0.11 → 4.0.13
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 +11 -0
- package/coverage/clover.xml +16 -3
- package/coverage/coverage-final.json +2 -1
- 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 +2 -2
- 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 +24 -9
- 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 +116 -0
- package/coverage/lcov-report/tools/proxy-fetch.js.html +133 -0
- package/coverage/lcov.info +21 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/readme.md +15 -0
- package/src/controllers/index.js +1 -1
- package/src/tools/prompt-questions.js +15 -2
- package/src/tools/proxy-fetch.js +1 -1
- package/src/tools/toolkit-common-fun.js +4 -233
- package/src/tools/toolkit-components-fun.js +259 -0
- package/src/tools/toolkit-components-info.js +24 -0
- package/src/tools/toolkit-components.js +4 -4
|
@@ -8,6 +8,9 @@ const chalk = require("chalk")
|
|
|
8
8
|
const { CURRENT_PATH, TOOLKIT_PATH, BOOTSTRAP_FOLDERS, BOOTSTRAP_FILES, CONFIG_PATH, THEME_COMPONENT_MODULE,
|
|
9
9
|
THEME_COMPONENT_VERSION, ACTIVE_THEME_PATH, THEME_LOGS_PATH, THEME_LOGS_FILE_PATH, SASS_MODULE,
|
|
10
10
|
SASS_VERSION, SASS_LOADER_MODULE, SASS_LOADER_VERSION } = require("./toolkit-common-vars");
|
|
11
|
+
|
|
12
|
+
const { getCustomComponentsInfo } = require("./toolkit-components-fun");
|
|
13
|
+
|
|
11
14
|
const { has } = require("lodash");
|
|
12
15
|
|
|
13
16
|
// function to remove project's folders (used to revert changes on error)
|
|
@@ -188,237 +191,6 @@ const updateCustomComponentsMetadata = (data) => {
|
|
|
188
191
|
return data;
|
|
189
192
|
}
|
|
190
193
|
|
|
191
|
-
const removeCurrentFolderPathPrefix = (path) => {
|
|
192
|
-
return path.replace(/^\.\//, '').trim();
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const getExportList = (fileData, prefixPath = '') => {
|
|
196
|
-
const exportList = [];
|
|
197
|
-
const defaultExports = [];
|
|
198
|
-
const pathPattern = /['|"|`](.+)['|"|`]/;
|
|
199
|
-
const exportedComponentPattern = /default\s*as\s*(\w+).*['|"|`](.+)['|"|`]/;
|
|
200
|
-
const filterOutComments = fileData.replace(/\/\/+.*\s*/g, '');
|
|
201
|
-
const filterOutNewlines = filterOutComments.replace(/\r?\n$/g, '');
|
|
202
|
-
const dataList = filterOutNewlines.split(/\r?\n/);
|
|
203
|
-
dataList.forEach(item => {
|
|
204
|
-
const directExportItem = exportedComponentPattern.exec(item);
|
|
205
|
-
if(directExportItem) {
|
|
206
|
-
defaultExports.push({
|
|
207
|
-
alias: directExportItem[1].trim(),
|
|
208
|
-
path: prefixPath + removeCurrentFolderPathPrefix(directExportItem[2])
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
} else {
|
|
212
|
-
const exportItem = pathPattern.exec(item);
|
|
213
|
-
if(exportItem) {
|
|
214
|
-
exportList.push(prefixPath + removeCurrentFolderPathPrefix(exportItem[1]));
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
return {
|
|
220
|
-
exportList,
|
|
221
|
-
defaultExports
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const getPathToUse = (usePath) => {
|
|
226
|
-
let fullPath;
|
|
227
|
-
let isPathToFolder = false;
|
|
228
|
-
const basePath = `${ACTIVE_THEME_PATH}/customComponents/${usePath}`;
|
|
229
|
-
const jsFilePath = `${basePath}.js`;
|
|
230
|
-
const jsxFilePath = `${basePath}.jsx`;
|
|
231
|
-
const indexFilePath = `${basePath}/index.js`;
|
|
232
|
-
|
|
233
|
-
if(!(/\.jsx?$/.test(basePath))) {
|
|
234
|
-
if(fs.existsSync(jsxFilePath)) {
|
|
235
|
-
fullPath = jsxFilePath;
|
|
236
|
-
} else if (fs.existsSync(jsFilePath)) {
|
|
237
|
-
fullPath = jsFilePath;
|
|
238
|
-
} else if (fs.existsSync(indexFilePath)) {
|
|
239
|
-
fullPath = indexFilePath;
|
|
240
|
-
isPathToFolder = true;
|
|
241
|
-
}
|
|
242
|
-
} else {
|
|
243
|
-
if(fs.existsSync(basePath)) {
|
|
244
|
-
fullPath = basePath;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return {
|
|
249
|
-
fullPath,
|
|
250
|
-
isPathToFolder
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const customComponentsExportsTraversal = (pathsToTraverse) => {
|
|
255
|
-
let paths = [...pathsToTraverse];
|
|
256
|
-
let allDefaultExports = [];
|
|
257
|
-
const overridenScss = new Set();
|
|
258
|
-
while(paths.length > 0) {
|
|
259
|
-
let pathItem = paths.pop();
|
|
260
|
-
let usePath = pathItem.path || pathItem;
|
|
261
|
-
let prefixPath = usePath;
|
|
262
|
-
const { fullPath, isPathToFolder } = getPathToUse(usePath);
|
|
263
|
-
|
|
264
|
-
if (fullPath) {
|
|
265
|
-
const fileData = fs.readFileSync(fullPath, 'utf8');
|
|
266
|
-
const filterOutComments = fileData.replace(/\/\/+.*\s*/g, '');
|
|
267
|
-
|
|
268
|
-
// check if file content is a component
|
|
269
|
-
const component = filterOutComments.match(/export\s+default\s+(?:\w*\((\w+)\)|(\w+));?/);
|
|
270
|
-
|
|
271
|
-
if(component) {
|
|
272
|
-
foundComponent = component[1] || component[2];
|
|
273
|
-
const allScssImports = filterOutComments.matchAll(/['|"|`](.*\/(\w+)\.s?css)['|"|`]/g);
|
|
274
|
-
for(const match of allScssImports) {
|
|
275
|
-
const sfbLibraryScssImport = match[1].includes(THEME_COMPONENT_MODULE);
|
|
276
|
-
if(!sfbLibraryScssImport) {
|
|
277
|
-
if(pathItem.alias) {
|
|
278
|
-
overridenScss.add(pathItem.alias);
|
|
279
|
-
} else {
|
|
280
|
-
// catches the case: export * from 'somePath'
|
|
281
|
-
overridenScss.add(match[2]);
|
|
282
|
-
allDefaultExports.push(match[2]);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
} else {
|
|
287
|
-
if(!isPathToFolder || usePath.match(/jsx?/)) {
|
|
288
|
-
prefixPath = usePath.match(/(.+)\/.*$/)[1];
|
|
289
|
-
};
|
|
290
|
-
const {
|
|
291
|
-
exportList,
|
|
292
|
-
defaultExports
|
|
293
|
-
} = getExportList(fileData, prefixPath + "/");
|
|
294
|
-
paths.push(...exportList);
|
|
295
|
-
paths.push(...defaultExports);
|
|
296
|
-
|
|
297
|
-
allDefaultExports.push(...defaultExports);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
return {
|
|
303
|
-
// converts to Set to filter duplicates then back to a list
|
|
304
|
-
allDefaultExports: [...new Set(allDefaultExports)],
|
|
305
|
-
overridenScss: [...overridenScss]
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const getSfbThemeComponentsList = () => {
|
|
310
|
-
const sfbThemeComponentsPath = `${ACTIVE_THEME_PATH}/node_modules/${THEME_COMPONENT_MODULE}/src/components/index.js`;
|
|
311
|
-
const sfbThemeComponents = fs.existsSync(sfbThemeComponentsPath);
|
|
312
|
-
const defaultExportAliasList = []
|
|
313
|
-
if (sfbThemeComponents) {
|
|
314
|
-
const fileData = fs.readFileSync(sfbThemeComponentsPath, 'utf8');
|
|
315
|
-
const { defaultExports } = getExportList(fileData);
|
|
316
|
-
for(const exportItem of defaultExports) {
|
|
317
|
-
defaultExportAliasList.push(exportItem.alias);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return defaultExportAliasList;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
const getCustomComponentsInfo = () => {
|
|
324
|
-
try {
|
|
325
|
-
const overridesJavaScript = new Set();
|
|
326
|
-
const overridesSass = new Set();
|
|
327
|
-
const userDefinedCustomComponents = new Set();
|
|
328
|
-
const sfbConfigPath = CURRENT_PATH;
|
|
329
|
-
const currentTheme = JSON.parse(fs.readFileSync(`${sfbConfigPath}/.sfbconfig`)).current;
|
|
330
|
-
const customComponentsFilesPath = `${sfbConfigPath}/themes/${currentTheme}/customComponents/index.js`;
|
|
331
|
-
const customComponents = fs.existsSync(customComponentsFilesPath);
|
|
332
|
-
|
|
333
|
-
if(customComponents) {
|
|
334
|
-
let componentsPathsLoadedBeforeUiLibrary = [];
|
|
335
|
-
let componentsPathsLoadedAfterUiLibrary = [];
|
|
336
|
-
let uiLibraryPassed = false;
|
|
337
|
-
const indexFileData = fs.readFileSync(customComponentsFilesPath, 'utf8');
|
|
338
|
-
const { exportList, defaultExports }= getExportList(indexFileData);
|
|
339
|
-
const sfbDirectExportsList = getSfbThemeComponentsList();
|
|
340
|
-
const {
|
|
341
|
-
overridenScss: rootIndexOverridenScss
|
|
342
|
-
} = customComponentsExportsTraversal(defaultExports);
|
|
343
|
-
|
|
344
|
-
defaultExports.forEach(exportedItem => {
|
|
345
|
-
if(sfbDirectExportsList.includes(exportedItem.alias)) {
|
|
346
|
-
overridesJavaScript.add(exportedItem.alias);
|
|
347
|
-
if(rootIndexOverridenScss.includes(exportedItem.alias)) {
|
|
348
|
-
overridesSass.add(exportedItem.alias);
|
|
349
|
-
}
|
|
350
|
-
} else {
|
|
351
|
-
userDefinedCustomComponents.add(exportedItem.alias);
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
exportList.forEach(exportPath => {
|
|
356
|
-
if(uiLibraryPassed) {
|
|
357
|
-
componentsPathsLoadedAfterUiLibrary.push(exportPath);
|
|
358
|
-
} else {
|
|
359
|
-
if(exportPath.includes(THEME_COMPONENT_MODULE)) {
|
|
360
|
-
uiLibraryPassed = true;
|
|
361
|
-
} else {
|
|
362
|
-
componentsPathsLoadedBeforeUiLibrary.push(exportPath);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
const {
|
|
368
|
-
allDefaultExports: directExportsBeforeUiLibrary,
|
|
369
|
-
overridenScss: overridenScssBefore
|
|
370
|
-
} = customComponentsExportsTraversal(componentsPathsLoadedBeforeUiLibrary);
|
|
371
|
-
|
|
372
|
-
const {
|
|
373
|
-
allDefaultExports: directExportsAfterUiLibrary,
|
|
374
|
-
overridenScss: overridenScssAfter
|
|
375
|
-
} = customComponentsExportsTraversal(componentsPathsLoadedAfterUiLibrary);
|
|
376
|
-
|
|
377
|
-
directExportsBeforeUiLibrary.forEach(exportedItem => {
|
|
378
|
-
if(sfbDirectExportsList.includes(exportedItem.alias)) {
|
|
379
|
-
overridesJavaScript.add(exportedItem.alias);
|
|
380
|
-
if(overridenScssBefore.includes(exportedItem.alias)) {
|
|
381
|
-
overridesSass.add(exportedItem.alias);
|
|
382
|
-
}
|
|
383
|
-
} else if (sfbDirectExportsList.includes(exportedItem)) {
|
|
384
|
-
if(overridenScssBefore.includes(exportedItem)) {
|
|
385
|
-
overridesSass.add(exportedItem);
|
|
386
|
-
}
|
|
387
|
-
} else {
|
|
388
|
-
userDefinedCustomComponents.add(exportedItem.alias);
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
directExportsAfterUiLibrary.forEach(exportedItem => {
|
|
393
|
-
if(sfbDirectExportsList.includes(exportedItem.alias)) {
|
|
394
|
-
if(overridenScssAfter.includes(exportedItem.alias)) {
|
|
395
|
-
overridesSass.add(exportedItem.alias);
|
|
396
|
-
}
|
|
397
|
-
} else if(sfbDirectExportsList.includes(exportedItem)) {
|
|
398
|
-
if(overridenScssAfter.includes(exportedItem)) {
|
|
399
|
-
overridesSass.add(exportedItem);
|
|
400
|
-
}
|
|
401
|
-
} else {
|
|
402
|
-
userDefinedCustomComponents.add(exportedItem.alias);
|
|
403
|
-
}
|
|
404
|
-
})
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
return {
|
|
408
|
-
overridesJavaScript: [...overridesJavaScript].sort(),
|
|
409
|
-
overridesSass: [...overridesSass].sort(),
|
|
410
|
-
userDefinedCustomComponents: [...userDefinedCustomComponents].sort()
|
|
411
|
-
}
|
|
412
|
-
} catch (error) {
|
|
413
|
-
console.error(chalk.red(`\n ERROR: Unable to obtain Custom Components information due to: ${error}.\n`));
|
|
414
|
-
return {
|
|
415
|
-
overridesJavaScript: [],
|
|
416
|
-
overridesSass: [],
|
|
417
|
-
userDefinedCustomComponents: []
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
194
|
const addMetadata = (metadata = {}, themePath) => {
|
|
423
195
|
const sfbConfigPath = themePath || CURRENT_PATH;
|
|
424
196
|
const currentTheme = JSON.parse(fs.readFileSync(`${sfbConfigPath}/.sfbconfig`)).current;
|
|
@@ -516,6 +288,5 @@ module.exports = {
|
|
|
516
288
|
createCustomThemePacakgeJson,
|
|
517
289
|
updateCustomComponentsMetadata,
|
|
518
290
|
addMetadata,
|
|
519
|
-
installSass
|
|
520
|
-
getCustomComponentsInfo
|
|
291
|
+
installSass
|
|
521
292
|
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
const fs = require("fs-extra");
|
|
2
|
+
const chalk = require("chalk");
|
|
3
|
+
const { CURRENT_PATH, THEME_COMPONENT_MODULE, ACTIVE_THEME_PATH} = require("./toolkit-common-vars");
|
|
4
|
+
|
|
5
|
+
const removeCurrentFolderPathPrefix = (path) => {
|
|
6
|
+
return path.replace(/^\.\//, '').trim();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const getExportList = (fileData, prefixPath = '') => {
|
|
10
|
+
const exportList = [];
|
|
11
|
+
const defaultExports = [];
|
|
12
|
+
const pathPattern = /['|"|`](.+)['|"|`]/;
|
|
13
|
+
const exportedComponentPattern = /default\s*as\s*(\w+).*['|"|`](.+)['|"|`]/;
|
|
14
|
+
const filterOutComments = fileData.replace(/\/\/+.*\s*/g, '');
|
|
15
|
+
const filterOutNewlines = filterOutComments.replace(/\r?\n$/g, '');
|
|
16
|
+
const dataList = filterOutNewlines.split(/\r?\n/);
|
|
17
|
+
dataList.forEach(item => {
|
|
18
|
+
const directExportItem = exportedComponentPattern.exec(item);
|
|
19
|
+
if(directExportItem) {
|
|
20
|
+
defaultExports.push({
|
|
21
|
+
alias: directExportItem[1].trim(),
|
|
22
|
+
path: prefixPath + removeCurrentFolderPathPrefix(directExportItem[2])
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
} else {
|
|
26
|
+
const exportItem = pathPattern.exec(item);
|
|
27
|
+
if(exportItem) {
|
|
28
|
+
exportList.push(prefixPath + removeCurrentFolderPathPrefix(exportItem[1]));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
exportList,
|
|
35
|
+
defaultExports
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const getPathToUse = (usePath) => {
|
|
40
|
+
let fullPath;
|
|
41
|
+
let isPathToFolder = false;
|
|
42
|
+
const basePath = `${ACTIVE_THEME_PATH}/customComponents/${usePath}`;
|
|
43
|
+
const jsFilePath = `${basePath}.js`;
|
|
44
|
+
const jsxFilePath = `${basePath}.jsx`;
|
|
45
|
+
const indexFilePath = `${basePath}/index.js`;
|
|
46
|
+
|
|
47
|
+
if(!(/\.jsx?$/.test(basePath))) {
|
|
48
|
+
if(fs.existsSync(jsxFilePath)) {
|
|
49
|
+
fullPath = jsxFilePath;
|
|
50
|
+
} else if (fs.existsSync(jsFilePath)) {
|
|
51
|
+
fullPath = jsFilePath;
|
|
52
|
+
} else if (fs.existsSync(indexFilePath)) {
|
|
53
|
+
fullPath = indexFilePath;
|
|
54
|
+
isPathToFolder = true;
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
if(fs.existsSync(basePath)) {
|
|
58
|
+
fullPath = basePath;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
fullPath,
|
|
64
|
+
isPathToFolder
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const customComponentsEnabled = () => {
|
|
69
|
+
const customComponentsPath = `${ACTIVE_THEME_PATH}/customComponents`
|
|
70
|
+
return fs.existsSync(customComponentsPath);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const customComponentsExportsTraversal = (pathsToTraverse) => {
|
|
74
|
+
let paths = [...pathsToTraverse];
|
|
75
|
+
let allDefaultExports = [];
|
|
76
|
+
const overridenScss = new Set();
|
|
77
|
+
while(paths.length > 0) {
|
|
78
|
+
let pathItem = paths.pop();
|
|
79
|
+
let usePath = pathItem.path || pathItem;
|
|
80
|
+
let prefixPath = usePath;
|
|
81
|
+
const { fullPath, isPathToFolder } = getPathToUse(usePath);
|
|
82
|
+
|
|
83
|
+
if (fullPath) {
|
|
84
|
+
const fileData = fs.readFileSync(fullPath, 'utf8');
|
|
85
|
+
const filterOutComments = fileData.replace(/\/\/+.*\s*/g, '');
|
|
86
|
+
|
|
87
|
+
// check if file content is a component
|
|
88
|
+
const component = filterOutComments.match(/export\s+default\s+(?:\w*\((\w+)\)|(\w+));?/);
|
|
89
|
+
|
|
90
|
+
if(component) {
|
|
91
|
+
foundComponent = component[1] || component[2];
|
|
92
|
+
const allScssImports = filterOutComments.matchAll(/['|"|`](.*\/(\w+)\.s?css)['|"|`]/g);
|
|
93
|
+
for(const match of allScssImports) {
|
|
94
|
+
const sfbLibraryScssImport = match[1].includes(THEME_COMPONENT_MODULE);
|
|
95
|
+
if(!sfbLibraryScssImport) {
|
|
96
|
+
if(pathItem.alias) {
|
|
97
|
+
overridenScss.add(pathItem.alias);
|
|
98
|
+
} else {
|
|
99
|
+
// catches the case: export * from 'somePath'
|
|
100
|
+
overridenScss.add(match[2]);
|
|
101
|
+
allDefaultExports.push(match[2]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
if(!isPathToFolder || usePath.match(/jsx?/)) {
|
|
107
|
+
prefixPath = usePath.match(/(.+)\/.*$/)[1];
|
|
108
|
+
};
|
|
109
|
+
const {
|
|
110
|
+
exportList,
|
|
111
|
+
defaultExports
|
|
112
|
+
} = getExportList(fileData, prefixPath + "/");
|
|
113
|
+
paths.push(...exportList);
|
|
114
|
+
paths.push(...defaultExports);
|
|
115
|
+
|
|
116
|
+
allDefaultExports.push(...defaultExports);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
// converts to Set to filter duplicates then back to a list
|
|
123
|
+
allDefaultExports: [...new Set(allDefaultExports)],
|
|
124
|
+
overridenScss: [...overridenScss]
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const getSfbThemeComponentsList = () => {
|
|
129
|
+
const sfbThemeComponentsPath = `${ACTIVE_THEME_PATH}/node_modules/${THEME_COMPONENT_MODULE}/src/components/index.js`;
|
|
130
|
+
const sfbThemeComponents = fs.existsSync(sfbThemeComponentsPath);
|
|
131
|
+
const defaultExportAliasList = []
|
|
132
|
+
if (sfbThemeComponents) {
|
|
133
|
+
const fileData = fs.readFileSync(sfbThemeComponentsPath, 'utf8');
|
|
134
|
+
const { defaultExports } = getExportList(fileData);
|
|
135
|
+
for(const exportItem of defaultExports) {
|
|
136
|
+
defaultExportAliasList.push(exportItem.alias);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return defaultExportAliasList;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const getCustomComponentsInfo = () => {
|
|
143
|
+
try {
|
|
144
|
+
const overridesJavaScript = new Set();
|
|
145
|
+
const overridesSass = new Set();
|
|
146
|
+
const userDefinedCustomComponents = new Set();
|
|
147
|
+
const sfbConfigPath = CURRENT_PATH;
|
|
148
|
+
const currentTheme = JSON.parse(fs.readFileSync(`${sfbConfigPath}/.sfbconfig`)).current;
|
|
149
|
+
const customComponentsFilesPath = `${sfbConfigPath}/themes/${currentTheme}/customComponents/index.js`;
|
|
150
|
+
const customComponents = fs.existsSync(customComponentsFilesPath);
|
|
151
|
+
|
|
152
|
+
if(customComponents) {
|
|
153
|
+
let componentsPathsLoadedBeforeUiLibrary = [];
|
|
154
|
+
let componentsPathsLoadedAfterUiLibrary = [];
|
|
155
|
+
let uiLibraryPassed = false;
|
|
156
|
+
const indexFileData = fs.readFileSync(customComponentsFilesPath, 'utf8');
|
|
157
|
+
const { exportList, defaultExports }= getExportList(indexFileData);
|
|
158
|
+
const sfbDirectExportsList = getSfbThemeComponentsList();
|
|
159
|
+
const {
|
|
160
|
+
overridenScss: rootIndexOverridenScss
|
|
161
|
+
} = customComponentsExportsTraversal(defaultExports);
|
|
162
|
+
|
|
163
|
+
defaultExports.forEach(exportedItem => {
|
|
164
|
+
if(sfbDirectExportsList.includes(exportedItem.alias)) {
|
|
165
|
+
overridesJavaScript.add(exportedItem.alias);
|
|
166
|
+
if(rootIndexOverridenScss.includes(exportedItem.alias)) {
|
|
167
|
+
overridesSass.add(exportedItem.alias);
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
userDefinedCustomComponents.add(exportedItem.alias);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
exportList.forEach(exportPath => {
|
|
175
|
+
if(uiLibraryPassed) {
|
|
176
|
+
componentsPathsLoadedAfterUiLibrary.push(exportPath);
|
|
177
|
+
} else {
|
|
178
|
+
if(exportPath.includes(THEME_COMPONENT_MODULE)) {
|
|
179
|
+
uiLibraryPassed = true;
|
|
180
|
+
} else {
|
|
181
|
+
componentsPathsLoadedBeforeUiLibrary.push(exportPath);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const {
|
|
187
|
+
allDefaultExports: directExportsBeforeUiLibrary,
|
|
188
|
+
overridenScss: overridenScssBefore
|
|
189
|
+
} = customComponentsExportsTraversal(componentsPathsLoadedBeforeUiLibrary);
|
|
190
|
+
|
|
191
|
+
const {
|
|
192
|
+
allDefaultExports: directExportsAfterUiLibrary,
|
|
193
|
+
overridenScss: overridenScssAfter
|
|
194
|
+
} = customComponentsExportsTraversal(componentsPathsLoadedAfterUiLibrary);
|
|
195
|
+
|
|
196
|
+
directExportsBeforeUiLibrary.forEach(exportedItem => {
|
|
197
|
+
if(sfbDirectExportsList.includes(exportedItem.alias)) {
|
|
198
|
+
overridesJavaScript.add(exportedItem.alias);
|
|
199
|
+
if(overridenScssBefore.includes(exportedItem.alias)) {
|
|
200
|
+
overridesSass.add(exportedItem.alias);
|
|
201
|
+
}
|
|
202
|
+
} else if (sfbDirectExportsList.includes(exportedItem)) {
|
|
203
|
+
if(overridenScssBefore.includes(exportedItem)) {
|
|
204
|
+
overridesSass.add(exportedItem);
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
userDefinedCustomComponents.add(exportedItem.alias);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
directExportsAfterUiLibrary.forEach(exportedItem => {
|
|
212
|
+
if(sfbDirectExportsList.includes(exportedItem.alias)) {
|
|
213
|
+
if(overridenScssAfter.includes(exportedItem.alias)) {
|
|
214
|
+
overridesSass.add(exportedItem.alias);
|
|
215
|
+
}
|
|
216
|
+
} else if(sfbDirectExportsList.includes(exportedItem)) {
|
|
217
|
+
if(overridenScssAfter.includes(exportedItem)) {
|
|
218
|
+
overridesSass.add(exportedItem);
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
userDefinedCustomComponents.add(exportedItem.alias);
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
overridesJavaScript: [...overridesJavaScript].sort(),
|
|
228
|
+
overridesSass: [...overridesSass].sort(),
|
|
229
|
+
userDefinedCustomComponents: [...userDefinedCustomComponents].sort()
|
|
230
|
+
}
|
|
231
|
+
} catch (error) {
|
|
232
|
+
console.error(chalk.red(`\n ERROR: Unable to obtain Custom Components information due to: ${error}.\n`));
|
|
233
|
+
return {
|
|
234
|
+
overridesJavaScript: [],
|
|
235
|
+
overridesSass: [],
|
|
236
|
+
userDefinedCustomComponents: []
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const getSfbThemeComponentsVersion = () => {
|
|
242
|
+
let sfbThemeComponentsVersion = "N/A";
|
|
243
|
+
const hasPackageJson = fs.existsSync(`${ACTIVE_THEME_PATH}/package.json`);
|
|
244
|
+
if (hasPackageJson) {
|
|
245
|
+
const themePackageJson = JSON.parse(fs.readFileSync(`${ACTIVE_THEME_PATH}/package.json`));
|
|
246
|
+
const sfbVersion = themePackageJson.dependencies['@appdirect/sfb-theme-components'];
|
|
247
|
+
const foundSfbVersion = sfbVersion && sfbVersion.match(/\d+\.\d+\.\d+/)[0];
|
|
248
|
+
if(foundSfbVersion) {
|
|
249
|
+
sfbThemeComponentsVersion = foundSfbVersion;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
return sfbThemeComponentsVersion;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
module.exports = {
|
|
256
|
+
getCustomComponentsInfo,
|
|
257
|
+
customComponentsEnabled,
|
|
258
|
+
getSfbThemeComponentsVersion
|
|
259
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const chalk = require("chalk");
|
|
2
|
+
|
|
3
|
+
const { shouldBeProjectFolder } = require("./toolkit-common-fun");
|
|
4
|
+
|
|
5
|
+
const { getCustomComponentsInfo, customComponentsEnabled } = require("./toolkit-components-fun");
|
|
6
|
+
|
|
7
|
+
// check if user is in correct location
|
|
8
|
+
shouldBeProjectFolder(true);
|
|
9
|
+
|
|
10
|
+
(() => {
|
|
11
|
+
try {
|
|
12
|
+
if(customComponentsEnabled) {
|
|
13
|
+
const { overridesJavaScript, overridesSass, userDefinedCustomComponents } = getCustomComponentsInfo();
|
|
14
|
+
console.log('Overrides Components JS:', overridesJavaScript);
|
|
15
|
+
console.log('Overrides Components:', overridesSass);
|
|
16
|
+
console.log('User Defined Components/Atoms:', userDefinedCustomComponents);
|
|
17
|
+
} else {
|
|
18
|
+
console.log('Custom components are not enabled for this theme.');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
} catch ( err ) {
|
|
22
|
+
console.error(chalk.red(`\n ERROR: Unable to find configuration for current project due to: ${err}.\n`));
|
|
23
|
+
}
|
|
24
|
+
})();
|
|
@@ -4,7 +4,7 @@ const prompt = require("./prompt-questions");
|
|
|
4
4
|
const { shouldBeProjectFolder, installSfbThemeComponents,
|
|
5
5
|
createPackageJson, updateCustomComponentsMetadata, installSass } = require("./toolkit-common-fun");
|
|
6
6
|
const { ACTIVE_THEME_PATH, TOOLKIT_PATH } = require("./toolkit-common-vars");
|
|
7
|
-
|
|
7
|
+
const { customComponentsEnabled } = require("./toolkit-components-fun");
|
|
8
8
|
shouldBeProjectFolder(true);
|
|
9
9
|
|
|
10
10
|
const addCustomCompToBase = (baseFilePath, data) => {
|
|
@@ -21,9 +21,9 @@ const settingsSchemaData = `{ "useComponents": true }`;
|
|
|
21
21
|
(async () => {
|
|
22
22
|
const baseFilePath = `${ACTIVE_THEME_PATH}/content/layout/base.html`;
|
|
23
23
|
const customComponentsPath = `${ACTIVE_THEME_PATH}/customComponents`
|
|
24
|
-
const
|
|
24
|
+
const areCustomComponentsEnabled = customComponentsEnabled();
|
|
25
25
|
|
|
26
|
-
if(!
|
|
26
|
+
if(!areCustomComponentsEnabled) {
|
|
27
27
|
const customComponents = await prompt.ask(["InstallCustomComponents"]);
|
|
28
28
|
if(customComponents.InstallCustomComponents.toLowerCase() !== "y") {
|
|
29
29
|
return;
|
|
@@ -42,7 +42,7 @@ const settingsSchemaData = `{ "useComponents": true }`;
|
|
|
42
42
|
})
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
if (!
|
|
45
|
+
if (!areCustomComponentsEnabled) {
|
|
46
46
|
try {
|
|
47
47
|
fs.copySync(`${TOOLKIT_PATH}/customComponents`, customComponentsPath)
|
|
48
48
|
} catch (error) {
|