@schalkneethling/miyagi-core 4.0.2

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 (138) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +43 -0
  3. package/api/app.js +39 -0
  4. package/api/index.js +236 -0
  5. package/bin/miyagi.js +2 -0
  6. package/dist/css/iframe.css +31 -0
  7. package/dist/css/main.css +1 -0
  8. package/dist/js/_iframe-links-DdifIr4P.js +1 -0
  9. package/dist/js/_mock-data-Dypo4Bl_.js +1 -0
  10. package/dist/js/_prism-By3NMwUd.js +1 -0
  11. package/dist/js/iframe.build.js +1 -0
  12. package/dist/js/iframe.js +1 -0
  13. package/dist/js/index-BKDKaBC6.js +1 -0
  14. package/dist/js/jsontree.js +1 -0
  15. package/dist/js/main.build.js +1 -0
  16. package/dist/js/main.js +1 -0
  17. package/frontend/assets/css/iframe/accordion-tabs.css +77 -0
  18. package/frontend/assets/css/iframe/jsontree.js.css +325 -0
  19. package/frontend/assets/css/iframe/prism.css +132 -0
  20. package/frontend/assets/css/iframe/styleguide/colors.css +61 -0
  21. package/frontend/assets/css/iframe/styleguide/fonts.css +37 -0
  22. package/frontend/assets/css/iframe/styleguide/index.css +109 -0
  23. package/frontend/assets/css/iframe/styleguide/spacings.css +21 -0
  24. package/frontend/assets/css/iframe.css +410 -0
  25. package/frontend/assets/css/main/menu/config-switcher.css +49 -0
  26. package/frontend/assets/css/main/menu/config-switchers.css +67 -0
  27. package/frontend/assets/css/main/menu/goto.css +24 -0
  28. package/frontend/assets/css/main/menu/nav.css +113 -0
  29. package/frontend/assets/css/main/menu/search.css +64 -0
  30. package/frontend/assets/css/main/menu/title.css +40 -0
  31. package/frontend/assets/css/main/menu.css +114 -0
  32. package/frontend/assets/css/main/reset.css +217 -0
  33. package/frontend/assets/css/main.css +71 -0
  34. package/frontend/assets/css/shared.css +34 -0
  35. package/frontend/assets/css/tokens.css +112 -0
  36. package/frontend/assets/favicon.ico +0 -0
  37. package/frontend/assets/js/_accordion-tabs.js +403 -0
  38. package/frontend/assets/js/_goto.js +63 -0
  39. package/frontend/assets/js/_iframe-links.js +19 -0
  40. package/frontend/assets/js/_is-triggered.js +15 -0
  41. package/frontend/assets/js/_main.js +379 -0
  42. package/frontend/assets/js/_mock-data.js +13 -0
  43. package/frontend/assets/js/_prism.js +1098 -0
  44. package/frontend/assets/js/_search.js +190 -0
  45. package/frontend/assets/js/_socket.js +9 -0
  46. package/frontend/assets/js/config-switcher/development-mode.js +49 -0
  47. package/frontend/assets/js/config-switcher/index.js +63 -0
  48. package/frontend/assets/js/config-switcher/text-direction.js +30 -0
  49. package/frontend/assets/js/config-switcher/theme.js +87 -0
  50. package/frontend/assets/js/iframe.build.js +43 -0
  51. package/frontend/assets/js/iframe.js +52 -0
  52. package/frontend/assets/js/jsontree.js +979 -0
  53. package/frontend/assets/js/main.build.js +40 -0
  54. package/frontend/assets/js/main.js +42 -0
  55. package/frontend/assets/js/styleguide/color-converter.js +741 -0
  56. package/frontend/assets/js/styleguide/index.js +119 -0
  57. package/frontend/views/component_variation.twig.miyagi +57 -0
  58. package/frontend/views/design-tokens/colors.twig.miyagi +43 -0
  59. package/frontend/views/design-tokens/sizes.twig.miyagi +35 -0
  60. package/frontend/views/design-tokens/typography.twig.miyagi +38 -0
  61. package/frontend/views/iframe_component.twig.miyagi +141 -0
  62. package/frontend/views/iframe_component_variation.twig.miyagi +55 -0
  63. package/frontend/views/iframe_index.twig.miyagi +14 -0
  64. package/frontend/views/layouts/iframe_default.twig.miyagi +22 -0
  65. package/frontend/views/main.twig.miyagi +24 -0
  66. package/frontend/views/menu/config-switchers.twig.miyagi +83 -0
  67. package/frontend/views/menu/goto.twig.miyagi +9 -0
  68. package/frontend/views/menu/menu.twig.miyagi +21 -0
  69. package/frontend/views/menu/nav.twig.miyagi +95 -0
  70. package/frontend/views/menu/search.twig.miyagi +13 -0
  71. package/frontend/views/menu/title.twig.miyagi +24 -0
  72. package/index.js +3 -0
  73. package/lib/build/index.js +1020 -0
  74. package/lib/cli/app.js +38 -0
  75. package/lib/cli/component.js +56 -0
  76. package/lib/cli/index.js +5 -0
  77. package/lib/cli/lint.js +180 -0
  78. package/lib/config.js +74 -0
  79. package/lib/default-config.js +105 -0
  80. package/lib/generator/component.js +199 -0
  81. package/lib/generator/mocks.js +201 -0
  82. package/lib/helpers.js +184 -0
  83. package/lib/i18n/en.js +91 -0
  84. package/lib/i18n/index.js +17 -0
  85. package/lib/index.js +166 -0
  86. package/lib/init/args.js +55 -0
  87. package/lib/init/config.js +330 -0
  88. package/lib/init/engines.js +65 -0
  89. package/lib/init/index.js +102 -0
  90. package/lib/init/rendering.js +12 -0
  91. package/lib/init/router.js +249 -0
  92. package/lib/init/static.js +133 -0
  93. package/lib/init/twing/cache.js +34 -0
  94. package/lib/init/twing/functions.js +51 -0
  95. package/lib/init/views.js +19 -0
  96. package/lib/init/watcher.js +402 -0
  97. package/lib/logger.js +94 -0
  98. package/lib/mocks/get.js +111 -0
  99. package/lib/mocks/index.js +9 -0
  100. package/lib/mocks/resolve/ref.js +484 -0
  101. package/lib/mocks/resolve/tpl.js +246 -0
  102. package/lib/mocks/resolve.js +205 -0
  103. package/lib/render/helpers.js +51 -0
  104. package/lib/render/index.js +38 -0
  105. package/lib/render/views/iframe/component.docs.js +77 -0
  106. package/lib/render/views/iframe/component.js +338 -0
  107. package/lib/render/views/iframe/design-tokens/colors.js +52 -0
  108. package/lib/render/views/iframe/design-tokens/index.js +9 -0
  109. package/lib/render/views/iframe/design-tokens/sizes.js +49 -0
  110. package/lib/render/views/iframe/design-tokens/typography.js +52 -0
  111. package/lib/render/views/iframe/docs.js +68 -0
  112. package/lib/render/views/iframe/index.js +44 -0
  113. package/lib/render/views/iframe/variation.js +116 -0
  114. package/lib/render/views/iframe/variation.standalone.js +89 -0
  115. package/lib/render/views/main/component.docs.js +53 -0
  116. package/lib/render/views/main/component.js +74 -0
  117. package/lib/render/views/main/design-tokens.js +53 -0
  118. package/lib/render/views/main/docs.js +47 -0
  119. package/lib/render/views/main/index.js +46 -0
  120. package/lib/state/components.js +132 -0
  121. package/lib/state/css.js +50 -0
  122. package/lib/state/docs.js +111 -0
  123. package/lib/state/file-contents.js +207 -0
  124. package/lib/state/helpers.js +86 -0
  125. package/lib/state/index.js +56 -0
  126. package/lib/state/menu/index.js +275 -0
  127. package/lib/state/menu/structure.js +146 -0
  128. package/lib/state/partials.js +23 -0
  129. package/lib/state/source-tree.js +75 -0
  130. package/lib/styleguide/color-names.js +150 -0
  131. package/lib/styleguide/colors.js +135 -0
  132. package/lib/styleguide/helpers.js +37 -0
  133. package/lib/styleguide/index.js +17 -0
  134. package/lib/styleguide/media-queries.js +26 -0
  135. package/lib/styleguide/spacings.js +35 -0
  136. package/lib/styleguide/typography.js +61 -0
  137. package/lib/validator/mocks.js +105 -0
  138. package/package.json +117 -0
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Module for saving all relevant data
3
+ * @module state
4
+ */
5
+
6
+ import { getPartials } from "./partials.js";
7
+ import { getFileContents } from "./file-contents.js";
8
+ import getCSS from "./css.js";
9
+ import { getMenu } from "./menu/index.js";
10
+ import getComponents from "./components.js";
11
+ import { getSourceTree } from "./source-tree.js";
12
+
13
+ /**
14
+ * @param {object} methods
15
+ * @returns {Promise<object>}
16
+ */
17
+ export default async function setState(methods) {
18
+ if (!global.state) {
19
+ global.state = {
20
+ routes: [],
21
+ };
22
+ }
23
+
24
+ if (methods.sourceTree) {
25
+ global.state.routes = [];
26
+ global.state.sourceTree = getSourceTree();
27
+ }
28
+
29
+ if (methods.fileContents) {
30
+ if (typeof methods.fileContents === "object") {
31
+ global.state.fileContents = methods.fileContents;
32
+ } else {
33
+ global.state.fileContents = await getFileContents(
34
+ global.state.sourceTree,
35
+ );
36
+ }
37
+ }
38
+
39
+ if (methods.partials) {
40
+ global.state.partials = getPartials(global.state.sourceTree);
41
+ }
42
+
43
+ if (methods.menu) {
44
+ global.state.menu = getMenu(global.state.sourceTree);
45
+ global.state.components = getComponents(
46
+ global.state.menu,
47
+ global.config.isBuild,
48
+ );
49
+ }
50
+
51
+ if (methods.css) {
52
+ global.state.css = getCSS(global.state.fileContents);
53
+ }
54
+
55
+ return global.state;
56
+ }
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Module for creating a menu object
3
+ * @module stateMenu
4
+ */
5
+
6
+ import path from "path";
7
+ import getSourceStructure from "./structure.js";
8
+ import * as helpers from "../../helpers.js";
9
+ import { getMenu as getDocsMenu } from "../docs.js";
10
+
11
+ /**
12
+ * @param {object} directory - file tree object
13
+ * @returns {Array} file tree object of the component file in the given directory
14
+ */
15
+ function getComponentFiles(directory) {
16
+ return directory.children.filter((child) => {
17
+ const baseName =
18
+ global.config.files.templates.name === "<component>"
19
+ ? child.name.replace(`.${global.config.files.templates.extension}`, "")
20
+ : global.config.files.templates.name;
21
+
22
+ if (helpers.docFileIsIndexFile(child.path)) return true;
23
+
24
+ if (helpers.fileIsTemplateFile(child.name)) {
25
+ if (
26
+ global.config.files.templates.name === "<component>" &&
27
+ directory.name === baseName
28
+ )
29
+ return true;
30
+
31
+ if (global.config.files.templates.name === baseName) return true;
32
+ }
33
+
34
+ return false;
35
+ });
36
+ }
37
+
38
+ /**
39
+ * @param {object} directory - file tree object
40
+ * @returns {boolean} returns true if the given directory has a component file with the same name
41
+ */
42
+ function hasComponentFileWithCorrectNameAsChild(directory) {
43
+ return (
44
+ directory.children &&
45
+ directory.children.length &&
46
+ getComponentFiles(directory).length > 0
47
+ );
48
+ }
49
+
50
+ /**
51
+ * @param {object} directory - file tree object
52
+ * @returns {object} adapted file tree object
53
+ */
54
+ function getDataForLinkedDirectory(directory) {
55
+ const shortPath = helpers.getShortPathFromFullPath(directory.path);
56
+ const normalizedShortPath = helpers.normalizeString(shortPath);
57
+ const name = directory.name.replaceAll("-", " ");
58
+
59
+ return {
60
+ type: directory.type,
61
+ section: "components",
62
+ name,
63
+ fullPath: directory.path,
64
+ shortPath,
65
+ normalizedShortPath,
66
+ url: global.config.isBuild
67
+ ? `/component-${normalizedShortPath}-embedded.html`
68
+ : `/component?file=${shortPath}&embedded=true`,
69
+ variations:
70
+ directory.variations.map((variation) => {
71
+ const normalizedName = helpers.normalizeString(variation.name);
72
+
73
+ return {
74
+ ...variation,
75
+ normalizedName,
76
+ parentShortPath: shortPath,
77
+ url: global.config.isBuild
78
+ ? `component-${normalizedShortPath}-variation-${normalizedName}-embedded.html`
79
+ : `/component?file=${shortPath}&variation=${encodeURIComponent(
80
+ variation.name,
81
+ )}&embedded=true`,
82
+ };
83
+ }) || [],
84
+ index: directory.index,
85
+ id: normalizedShortPath,
86
+ };
87
+ }
88
+
89
+ /**
90
+ * @param {object} file
91
+ * @returns {object}
92
+ */
93
+ function getDataForDocumentationFile(file) {
94
+ const shortPath = helpers
95
+ .getShortPathFromFullPath(file.path)
96
+ .replace(".md", "");
97
+ const normalizedShortPath = helpers.normalizeString(shortPath);
98
+
99
+ return {
100
+ type: file.type,
101
+ name: path
102
+ .basename(file.name, ".md")
103
+ .replaceAll("-", " ")
104
+ .replaceAll("_", " "),
105
+ fullPath: file.path,
106
+ shortPath,
107
+ normalizedShortPath,
108
+ url: global.config.isBuild
109
+ ? `/component-${normalizedShortPath}-embedded.html`
110
+ : `/component?file=${shortPath}&embedded=true`,
111
+ index: file.index,
112
+ id: normalizedShortPath,
113
+ };
114
+ }
115
+
116
+ /**
117
+ * @param {object} directory - file tree object
118
+ * @returns {object} adapted file tree object
119
+ */
120
+ function getDataForDirectory(directory) {
121
+ const shortPath = path.relative(
122
+ path.join(process.cwd(), global.config.components.folder),
123
+ directory.path,
124
+ );
125
+
126
+ return {
127
+ type: directory.type,
128
+ name: directory.name.replaceAll("-", " "),
129
+ fullPath: directory.path,
130
+ shortPath,
131
+ index: directory.index,
132
+ id: helpers.normalizeString(shortPath),
133
+ };
134
+ }
135
+
136
+ /**
137
+ * @param {object} directory - file tree object
138
+ * @returns {object} adapted file tree object
139
+ */
140
+ function restructureDirectory(directory) {
141
+ let item;
142
+
143
+ if (hasComponentFileWithCorrectNameAsChild(directory)) {
144
+ item = getDataForLinkedDirectory(directory);
145
+ } else {
146
+ item = getDataForDirectory(directory);
147
+ }
148
+
149
+ return item;
150
+ }
151
+
152
+ /**
153
+ * @param {object} item - file tree object
154
+ * @returns {boolean} returns true if the given file tree object has children
155
+ */
156
+ function hasChildren(item) {
157
+ return item.children && item.children.length > 0;
158
+ }
159
+
160
+ /**
161
+ * @param {object} sourceTree
162
+ * @returns {object[]} array with adapted menu items
163
+ */
164
+ export const getMenu = function (sourceTree) {
165
+ const srcStructure = getSourceStructure();
166
+ const arr = [];
167
+ let componentsMenu;
168
+
169
+ (function restructure(structure, array) {
170
+ for (const item of structure) {
171
+ if (item.type === "directory") {
172
+ const restructured = restructureDirectory(item);
173
+
174
+ if (hasChildren(item)) {
175
+ restructured.children = [];
176
+ restructure(item.children, restructured.children);
177
+
178
+ if (restructured.children.length === 0) {
179
+ delete restructured.children;
180
+ }
181
+
182
+ if (restructured.children) {
183
+ restructured.children.sort(function (a, b) {
184
+ const nameA = a.name.toLowerCase();
185
+ const nameB = b.name.toLowerCase();
186
+
187
+ if (nameA < nameB) return -1;
188
+ if (nameA > nameB) return 1;
189
+
190
+ return 0;
191
+ });
192
+ }
193
+ }
194
+ array.push(restructured);
195
+ } else if (
196
+ helpers.fileIsDocumentationFile(item.path) &&
197
+ !item.path.endsWith("index.md") &&
198
+ !item.path.endsWith("README.md") &&
199
+ path.basename(item.path, ".md") !==
200
+ path.dirname(item.path).split("/")[
201
+ path.dirname(item.path).split("/").length - 1
202
+ ]
203
+ ) {
204
+ array.push(getDataForDocumentationFile(item));
205
+ }
206
+ }
207
+ })(srcStructure, arr);
208
+
209
+ if (arr.length > 0) {
210
+ componentsMenu = {
211
+ topLevel: true,
212
+ section: "components",
213
+ name: "components",
214
+ type: "directory",
215
+ shortPath: "components",
216
+ file: null,
217
+ children: arr,
218
+ id: "components",
219
+ };
220
+ }
221
+
222
+ const docsMenu = getDocsMenu(sourceTree.docs);
223
+ const designTokensMenu = getDesignTokensMenu();
224
+
225
+ if (!docsMenu && !designTokensMenu && componentsMenu)
226
+ return componentsMenu.children;
227
+
228
+ const menus = [];
229
+ if (designTokensMenu) menus.push(designTokensMenu);
230
+ if (componentsMenu) menus.push(componentsMenu);
231
+ if (docsMenu) menus.push(docsMenu);
232
+
233
+ return menus;
234
+ };
235
+
236
+ /**
237
+ * @returns {object}
238
+ */
239
+ function getDesignTokensMenu() {
240
+ if (global.config.assets.customProperties.files.length === 0) return null;
241
+
242
+ return {
243
+ topLevel: true,
244
+ name: "Design Tokens",
245
+ id: "design-tokens",
246
+ type: "directory",
247
+ shortPath: "design-tokens",
248
+ children: [
249
+ {
250
+ section: "design-tokens",
251
+ type: "file",
252
+ name: "colors",
253
+ url: global.config.isBuild
254
+ ? "iframe-design-tokens-colors.html"
255
+ : "/iframe/design-tokens/colors",
256
+ },
257
+ {
258
+ section: "design-tokens",
259
+ type: "file",
260
+ name: "sizes",
261
+ url: global.config.isBuild
262
+ ? "iframe-design-tokens-sizes.html"
263
+ : "/iframe/design-tokens/sizes",
264
+ },
265
+ {
266
+ section: "design-tokens",
267
+ type: "file",
268
+ name: "typography",
269
+ url: global.config.isBuild
270
+ ? "iframe-design-tokens-typography.html"
271
+ : "/iframe/design-tokens/typography",
272
+ },
273
+ ],
274
+ };
275
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Module for getting the structure for the menu
3
+ * @module stateMenuStructure
4
+ */
5
+
6
+ import config from "../../default-config.js";
7
+ import { t } from "../../i18n/index.js";
8
+ import log from "../../logger.js";
9
+ import * as helpers from "../../helpers.js";
10
+
11
+ /**
12
+ * @param {object} json - mock data object
13
+ * @param {string} fullPath - the path of the mock file
14
+ * @returns {Array} all valid variation objects
15
+ */
16
+ function getAllValidVariations(json, fullPath) {
17
+ let arr = [];
18
+
19
+ if (json) {
20
+ const variations = json.$variants;
21
+ const rootData = helpers.removeInternalKeys(json);
22
+
23
+ if (Object.keys(rootData).length > 0 && !json.$hidden) {
24
+ arr.push({
25
+ name: json.$name || config.defaultVariationName,
26
+ data: rootData,
27
+ });
28
+ }
29
+
30
+ if (variations) {
31
+ for (const [i, variation] of variations.entries()) {
32
+ const variationData = helpers.removeInternalKeys(variation);
33
+ if (variation.$name) {
34
+ arr.push({
35
+ name: variation.$name,
36
+ data: variationData,
37
+ });
38
+ } else if (fullPath) {
39
+ const shortPath = helpers.getShortPathFromFullPath(fullPath);
40
+ log(
41
+ "warn",
42
+ t("noNameSetForVariation")
43
+ .replace("{{i}}", i)
44
+ .replace("{{file}}", shortPath),
45
+ );
46
+ }
47
+ }
48
+ }
49
+ } else {
50
+ arr.push({
51
+ name: config.defaultVariationName,
52
+ data: {},
53
+ });
54
+ }
55
+
56
+ return arr;
57
+ }
58
+
59
+ /**
60
+ * @param {string} mockFilePath - mock file to get the data from
61
+ * @returns {object[]} all valid variations for the given mock file
62
+ */
63
+ function getData(mockFilePath) {
64
+ let result;
65
+
66
+ if (mockFilePath && global.state.fileContents[mockFilePath]) {
67
+ result = global.state.fileContents[mockFilePath];
68
+ }
69
+
70
+ return getAllValidVariations(result, mockFilePath);
71
+ }
72
+
73
+ /**
74
+ * @param {object} obj - file tree object
75
+ * @returns {Array} all variations for the mock file of the given file tree object
76
+ */
77
+ function getVariations(obj) {
78
+ const { mocks } = global.config.files;
79
+ const tplChild = obj.children.find(
80
+ (o) =>
81
+ o.name ===
82
+ `${helpers.getResolvedFileName(
83
+ global.config.files.templates.name,
84
+ obj.name,
85
+ )}.${global.config.files.templates.extension}`,
86
+ );
87
+ const jsonChild = obj.children.find((o) =>
88
+ [
89
+ `${mocks.name}.${mocks.extension[0]}`,
90
+ `${mocks.name}.${mocks.extension[1]}`,
91
+ ].includes(o.name),
92
+ );
93
+
94
+ if (tplChild) {
95
+ return getData(jsonChild ? jsonChild.path : null);
96
+ }
97
+
98
+ return [];
99
+ }
100
+
101
+ /**
102
+ * @param {object} obj - the source object to update
103
+ * @returns {object} the updated object
104
+ */
105
+ function updateSourceObject(obj) {
106
+ const o = { ...obj };
107
+
108
+ if (o.children) {
109
+ o.variations = getVariations(o);
110
+ o.children = o.children.map((child) => updateSourceObject(child));
111
+ }
112
+
113
+ return o;
114
+ }
115
+
116
+ /**
117
+ * Adds the given index to the given object and recursively calls this
118
+ * method for its children
119
+ * @param {object} obj - the object to which the index should be added
120
+ * @param {number} index - the index that should be added
121
+ * @returns {object} the updated object
122
+ */
123
+ function addIndices(obj, index) {
124
+ const o = { ...obj };
125
+ o.index = index;
126
+
127
+ if (o.children) {
128
+ o.children = o.children.map((child) => {
129
+ delete child.size;
130
+ return addIndices(child, child.type === "directory" ? index + 1 : index);
131
+ });
132
+ }
133
+
134
+ return o;
135
+ }
136
+
137
+ /**
138
+ * @returns {object}
139
+ */
140
+ export default function setMenuStructure() {
141
+ let result = updateSourceObject(global.state.sourceTree.components);
142
+
143
+ result = addIndices(result, -1);
144
+
145
+ return result && result.children ? result.children : [];
146
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Module for getting all partials
3
+ * @module statePartials
4
+ */
5
+
6
+ import * as helpers from "../helpers.js";
7
+
8
+ export const getPartials = function (tree) {
9
+ const partials = {};
10
+
11
+ (function getPartials(entry) {
12
+ if (
13
+ entry.type === "file" &&
14
+ entry.name.endsWith(`.${global.config.files.templates.extension}`)
15
+ ) {
16
+ partials[helpers.getShortPathFromFullPath(entry.path)] = entry.path;
17
+ } else if (entry.type === "directory") {
18
+ entry.children.forEach((item) => getPartials(item));
19
+ }
20
+ })(tree.components);
21
+
22
+ return partials;
23
+ };
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Module for getting a source tree of the project
3
+ * @module stateSourcetree
4
+ */
5
+
6
+ import dirTree from "directory-tree";
7
+ import path from "path";
8
+ import { t } from "../i18n/index.js";
9
+ import log from "../logger.js";
10
+ import * as helpers from "../helpers.js";
11
+
12
+ /**
13
+ * @returns {object} the source tree object
14
+ */
15
+ export const getSourceTree = function () {
16
+ const tree = {};
17
+ const { files } = global.config;
18
+ const sources = [];
19
+
20
+ if (global.config.components?.folder) {
21
+ sources.push({
22
+ type: "components",
23
+ dir: global.config.components.folder,
24
+ extensions: new RegExp(
25
+ `.(md|${files.css.extension}|${files.js.extension}|${
26
+ files.mocks.extension[0]
27
+ }|${files.mocks.extension[1]}|${
28
+ files.schema.extension
29
+ }|${helpers.getSingleFileExtension(files.templates.extension)})$`,
30
+ ),
31
+ configStr: "components.folder",
32
+ });
33
+ }
34
+
35
+ if (global.config.docs?.folder) {
36
+ sources.push({
37
+ type: "docs",
38
+ dir: global.config.docs.folder,
39
+ extensions: /\.md/,
40
+ configStr: "docs.folder",
41
+ });
42
+ }
43
+
44
+ sources.forEach(({ type, extensions, dir, configStr }) => {
45
+ if (dir) {
46
+ const exclude = [];
47
+
48
+ const { ignores = [] } = global.config[type];
49
+ for (const ignore of ignores) {
50
+ const escapedIgnore = ignore.replaceAll(/\\/g, "\\\\");
51
+ exclude.push(new RegExp(escapedIgnore.replaceAll(/\./g, "\\.")));
52
+ }
53
+
54
+ const subTree = dirTree(path.join(process.cwd(), dir), {
55
+ attributes: ["type"],
56
+ extensions,
57
+ exclude,
58
+ });
59
+
60
+ if (!subTree) {
61
+ log(
62
+ "warn",
63
+ t("srcFolderNotFound")
64
+ .replaceAll("{{directory}}", `./${dir}`)
65
+ .replaceAll("{{type}}", type)
66
+ .replaceAll("{{config}}", configStr),
67
+ );
68
+ }
69
+
70
+ tree[type] = subTree;
71
+ }
72
+ });
73
+
74
+ return tree || {};
75
+ };