@schalkneethling/miyagi-core 4.4.2 → 4.4.3

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 (115) hide show
  1. package/README.md +7 -2
  2. package/api/app.js +16 -16
  3. package/api/index.js +263 -262
  4. package/bin/miyagi.js +1 -1
  5. package/dist/css/iframe.css +6 -30
  6. package/frontend/assets/css/iframe/accordion-tabs.css +39 -39
  7. package/frontend/assets/css/iframe/jsontree.js.css +149 -149
  8. package/frontend/assets/css/iframe/prism.css +45 -45
  9. package/frontend/assets/css/iframe/styleguide/colors.css +27 -27
  10. package/frontend/assets/css/iframe/styleguide/fonts.css +23 -23
  11. package/frontend/assets/css/iframe/styleguide/index.css +58 -58
  12. package/frontend/assets/css/iframe/styleguide/spacings.css +10 -10
  13. package/frontend/assets/css/iframe.css +191 -191
  14. package/frontend/assets/css/main/menu/config-switcher.css +21 -21
  15. package/frontend/assets/css/main/menu/config-switchers.css +34 -34
  16. package/frontend/assets/css/main/menu/goto.css +16 -16
  17. package/frontend/assets/css/main/menu/nav.css +49 -49
  18. package/frontend/assets/css/main/menu/search.css +34 -34
  19. package/frontend/assets/css/main/menu/title.css +18 -18
  20. package/frontend/assets/css/main/menu.css +89 -89
  21. package/frontend/assets/css/main/reset.css +47 -47
  22. package/frontend/assets/css/main.css +41 -41
  23. package/frontend/assets/css/shared.css +16 -16
  24. package/frontend/assets/css/tokens.css +108 -107
  25. package/frontend/assets/js/_accordion-tabs.js +392 -392
  26. package/frontend/assets/js/_goto.js +59 -59
  27. package/frontend/assets/js/_iframe-links.js +14 -14
  28. package/frontend/assets/js/_is-triggered.js +3 -3
  29. package/frontend/assets/js/_main.js +369 -369
  30. package/frontend/assets/js/_mock-data.js +8 -8
  31. package/frontend/assets/js/_prism.js +1082 -1081
  32. package/frontend/assets/js/_search.js +186 -186
  33. package/frontend/assets/js/_socket.js +44 -44
  34. package/frontend/assets/js/config-switcher/development-mode.js +38 -38
  35. package/frontend/assets/js/config-switcher/index.js +55 -55
  36. package/frontend/assets/js/config-switcher/text-direction.js +22 -22
  37. package/frontend/assets/js/config-switcher/theme.js +68 -68
  38. package/frontend/assets/js/iframe.build.js +25 -25
  39. package/frontend/assets/js/iframe.js +38 -38
  40. package/frontend/assets/js/jsontree.js +979 -976
  41. package/frontend/assets/js/main.build.js +29 -29
  42. package/frontend/assets/js/main.js +31 -31
  43. package/frontend/assets/js/styleguide/color-converter.js +652 -652
  44. package/frontend/assets/js/styleguide/index.js +100 -100
  45. package/lib/build/index.js +1014 -1020
  46. package/lib/cli/app.js +16 -16
  47. package/lib/cli/component.js +50 -50
  48. package/lib/cli/doctor.js +130 -121
  49. package/lib/cli/drupal-assets.js +163 -157
  50. package/lib/cli/lint.js +196 -196
  51. package/lib/cli/run.js +150 -146
  52. package/lib/config.js +86 -86
  53. package/lib/constants/lint-log-levels.js +6 -6
  54. package/lib/drupal/load-assets-config.js +59 -60
  55. package/lib/drupal/resolve-library-assets.js +132 -141
  56. package/lib/errors.js +20 -20
  57. package/lib/generator/component.js +124 -124
  58. package/lib/generator/mocks.js +156 -156
  59. package/lib/helpers.js +68 -68
  60. package/lib/i18n/en.js +93 -93
  61. package/lib/i18n/index.js +8 -8
  62. package/lib/index.js +13 -13
  63. package/lib/init/args.js +153 -153
  64. package/lib/init/config.js +452 -438
  65. package/lib/init/engines.js +41 -41
  66. package/lib/init/index.js +83 -83
  67. package/lib/init/rendering.js +3 -3
  68. package/lib/init/static.js +90 -90
  69. package/lib/init/twing/cache.js +27 -27
  70. package/lib/init/twing/functions.js +37 -37
  71. package/lib/init/views.js +5 -5
  72. package/lib/logger.js +72 -72
  73. package/lib/mocks/get.js +88 -88
  74. package/lib/mocks/index.js +2 -2
  75. package/lib/mocks/resolve/ref.js +447 -447
  76. package/lib/mocks/resolve/tpl.js +218 -218
  77. package/lib/mocks/resolve.js +154 -154
  78. package/lib/render/helpers/resolve-assets.js +29 -39
  79. package/lib/render/helpers.js +27 -27
  80. package/lib/render/index.js +18 -18
  81. package/lib/render/views/iframe/component.docs.js +50 -50
  82. package/lib/render/views/iframe/component.js +249 -248
  83. package/lib/render/views/iframe/design-tokens/colors.js +38 -38
  84. package/lib/render/views/iframe/design-tokens/index.js +3 -3
  85. package/lib/render/views/iframe/design-tokens/sizes.js +35 -35
  86. package/lib/render/views/iframe/design-tokens/typography.js +37 -37
  87. package/lib/render/views/iframe/docs.js +42 -42
  88. package/lib/render/views/iframe/index.js +28 -28
  89. package/lib/render/views/iframe/variation.js +89 -89
  90. package/lib/render/views/iframe/variation.standalone.js +69 -68
  91. package/lib/render/views/main/component.docs.js +38 -38
  92. package/lib/render/views/main/component.js +55 -55
  93. package/lib/render/views/main/design-tokens.js +38 -38
  94. package/lib/render/views/main/docs.js +33 -33
  95. package/lib/render/views/main/index.js +33 -33
  96. package/lib/state/components.js +99 -99
  97. package/lib/state/css.js +33 -33
  98. package/lib/state/docs.js +72 -72
  99. package/lib/state/file-contents.js +154 -154
  100. package/lib/state/helpers.js +53 -53
  101. package/lib/state/index.js +39 -39
  102. package/lib/state/menu/index.js +202 -202
  103. package/lib/state/menu/structure.js +84 -84
  104. package/lib/state/partials.js +12 -12
  105. package/lib/state/source-tree.js +51 -51
  106. package/lib/styleguide/color-names.js +148 -148
  107. package/lib/styleguide/colors.js +113 -113
  108. package/lib/styleguide/helpers.js +33 -33
  109. package/lib/styleguide/index.js +4 -4
  110. package/lib/styleguide/media-queries.js +18 -18
  111. package/lib/styleguide/spacings.js +22 -22
  112. package/lib/styleguide/typography.js +46 -46
  113. package/lib/validator/mocks.js +110 -83
  114. package/lib/validator/schemas.js +236 -227
  115. package/package.json +118 -117
package/lib/cli/app.js CHANGED
@@ -16,23 +16,23 @@ import setViews from "../init/views.js";
16
16
  * @returns {Promise<object>}
17
17
  */
18
18
  export default async function init(mergedConfig) {
19
- global.app = express();
20
- global.config = mergedConfig;
21
- global.app.set("view cache", false);
22
- global.app.set("cache", false);
19
+ global.app = express();
20
+ global.config = mergedConfig;
21
+ global.app.set("view cache", false);
22
+ global.app.set("cache", false);
23
23
 
24
- await setEngines();
25
- await setState({
26
- sourceTree: true,
27
- menu: true,
28
- partials: true,
29
- fileContents: true,
30
- css: true,
31
- });
24
+ await setEngines();
25
+ await setState({
26
+ sourceTree: true,
27
+ menu: true,
28
+ partials: true,
29
+ fileContents: true,
30
+ css: true,
31
+ });
32
32
 
33
- setStatic();
34
- setRouter();
35
- setViews();
33
+ setStatic();
34
+ setRouter();
35
+ setViews();
36
36
 
37
- return global.app;
37
+ return global.app;
38
38
  }
@@ -9,43 +9,43 @@ import { EXIT_CODES } from "../errors.js";
9
9
  * @returns {Promise<object>}
10
10
  */
11
11
  export default async function createComponentViaCli(cliParams) {
12
- const commands = [cliParams.component].filter(Boolean);
12
+ const commands = [cliParams.component].filter(Boolean);
13
13
 
14
- if (commands.length === 0) {
15
- const message = t("generator.noComponentNameDefined");
16
- log("error", message);
17
- return {
18
- success: false,
19
- code: EXIT_CODES.CLI_USAGE_ERROR,
20
- shouldExit: true,
21
- message,
22
- };
23
- }
14
+ if (commands.length === 0) {
15
+ const message = t("generator.noComponentNameDefined");
16
+ log("error", message);
17
+ return {
18
+ success: false,
19
+ code: EXIT_CODES.CLI_USAGE_ERROR,
20
+ shouldExit: true,
21
+ message,
22
+ };
23
+ }
24
24
 
25
- const [component] = commands;
26
- const fileTypes = getFileTypesFromCliArgs(
27
- cliParams,
28
- Object.values(appConfig.defaultUserConfig.files).map((file) => file.abbr),
29
- );
25
+ const [component] = commands;
26
+ const fileTypes = getFileTypesFromCliArgs(
27
+ cliParams,
28
+ Object.values(appConfig.defaultUserConfig.files).map((file) => file.abbr),
29
+ );
30
30
 
31
- try {
32
- const result = await generateComponent({ component, fileTypes });
33
- log("success", result);
34
- return {
35
- success: true,
36
- code: EXIT_CODES.SUCCESS,
37
- shouldExit: true,
38
- message: result,
39
- };
40
- } catch (message) {
41
- log("error", message);
42
- return {
43
- success: false,
44
- code: EXIT_CODES.GENERAL_ERROR,
45
- shouldExit: true,
46
- message: String(message),
47
- };
48
- }
31
+ try {
32
+ const result = await generateComponent({ component, fileTypes });
33
+ log("success", result);
34
+ return {
35
+ success: true,
36
+ code: EXIT_CODES.SUCCESS,
37
+ shouldExit: true,
38
+ message: result,
39
+ };
40
+ } catch (message) {
41
+ log("error", message);
42
+ return {
43
+ success: false,
44
+ code: EXIT_CODES.GENERAL_ERROR,
45
+ shouldExit: true,
46
+ message: String(message),
47
+ };
48
+ }
49
49
  }
50
50
 
51
51
  /**
@@ -55,20 +55,20 @@ export default async function createComponentViaCli(cliParams) {
55
55
  * @returns {Array} all file paths that should be created
56
56
  */
57
57
  function getFileTypesFromCliArgs(args, fileTypes) {
58
- if (args) {
59
- if (args.skip) {
60
- const files = [];
61
- for (const fileType of fileTypes) {
62
- if (!args.skip.includes(fileType)) {
63
- files.push(fileType);
64
- }
65
- }
66
- return files;
67
- }
68
- if (args.only) {
69
- return args.only;
70
- }
71
- return fileTypes;
72
- }
73
- return fileTypes;
58
+ if (args) {
59
+ if (args.skip) {
60
+ const files = [];
61
+ for (const fileType of fileTypes) {
62
+ if (!args.skip.includes(fileType)) {
63
+ files.push(fileType);
64
+ }
65
+ }
66
+ return files;
67
+ }
68
+ if (args.only) {
69
+ return args.only;
70
+ }
71
+ return fileTypes;
72
+ }
73
+ return fileTypes;
74
74
  }
package/lib/cli/doctor.js CHANGED
@@ -10,102 +10,111 @@ const CONFIG_FILES = [".miyagi.js", ".miyagi.mjs"];
10
10
  * @returns {Promise<object>}
11
11
  */
12
12
  export default async function doctor() {
13
- let success = true;
14
-
15
- if (checkNodeVersion()) {
16
- log("success", `Node.js ${process.versions.node} satisfies ${pkgJson.engines.node}.`);
17
- } else {
18
- success = false;
19
- log(
20
- "error",
21
- `Node.js ${process.versions.node} does not satisfy ${pkgJson.engines.node}.`,
22
- );
23
- }
24
-
25
- const configResult = await loadUserConfig();
26
-
27
- if (!configResult.userFileName) {
28
- success = false;
29
- log(
30
- "error",
31
- "No miyagi config found. Create .miyagi.js or .miyagi.mjs in your project root.",
32
- );
33
- return {
34
- success,
35
- code: EXIT_CODES.CONFIG_ERROR,
36
- shouldExit: true,
37
- };
38
- }
39
-
40
- if (configResult.error) {
41
- success = false;
42
- log(
43
- "error",
44
- `Could not parse ${configResult.userFileName}. Check its syntax and exports.`,
45
- );
46
- log("error", configResult.error.message, configResult.error);
47
- return {
48
- success,
49
- code: EXIT_CODES.CONFIG_ERROR,
50
- shouldExit: true,
51
- };
52
- }
53
-
54
- log("success", `Loaded config from ${configResult.userFileName}.`);
55
-
56
- const config = configResult.config || {};
57
-
58
- if (typeof config.engine?.render === "function") {
59
- log("success", "engine.render is defined.");
60
- } else {
61
- success = false;
62
- log("error", "engine.render is missing.");
63
- }
64
-
65
- if (config.components?.folder || config.docs?.folder) {
66
- log("success", "At least one source folder is configured.");
67
- } else {
68
- success = false;
69
- log(
70
- "error",
71
- "Set at least one of components.folder or docs.folder in your miyagi config.",
72
- );
73
- }
74
-
75
- if (config.components?.folder) {
76
- if (await pathExists(config.components.folder)) {
77
- log("success", `components.folder exists: ${config.components.folder}`);
78
- } else {
79
- success = false;
80
- log("error", `components.folder does not exist: ${config.components.folder}`);
81
- }
82
- }
83
-
84
- if (config.docs?.folder) {
85
- if (await pathExists(config.docs.folder)) {
86
- log("success", `docs.folder exists: ${config.docs.folder}`);
87
- } else {
88
- success = false;
89
- log("error", `docs.folder does not exist: ${config.docs.folder}`);
90
- }
91
- }
92
-
93
- log(success ? "success" : "error", success ? "Doctor checks passed." : "Doctor found issues.");
94
-
95
- return {
96
- success,
97
- code: success ? EXIT_CODES.SUCCESS : EXIT_CODES.CONFIG_ERROR,
98
- shouldExit: true,
99
- };
13
+ let success = true;
14
+
15
+ if (checkNodeVersion()) {
16
+ log(
17
+ "success",
18
+ `Node.js ${process.versions.node} satisfies ${pkgJson.engines.node}.`,
19
+ );
20
+ } else {
21
+ success = false;
22
+ log(
23
+ "error",
24
+ `Node.js ${process.versions.node} does not satisfy ${pkgJson.engines.node}.`,
25
+ );
26
+ }
27
+
28
+ const configResult = await loadUserConfig();
29
+
30
+ if (!configResult.userFileName) {
31
+ success = false;
32
+ log(
33
+ "error",
34
+ "No miyagi config found. Create .miyagi.js or .miyagi.mjs in your project root.",
35
+ );
36
+ return {
37
+ success,
38
+ code: EXIT_CODES.CONFIG_ERROR,
39
+ shouldExit: true,
40
+ };
41
+ }
42
+
43
+ if (configResult.error) {
44
+ success = false;
45
+ log(
46
+ "error",
47
+ `Could not parse ${configResult.userFileName}. Check its syntax and exports.`,
48
+ );
49
+ log("error", configResult.error.message, configResult.error);
50
+ return {
51
+ success,
52
+ code: EXIT_CODES.CONFIG_ERROR,
53
+ shouldExit: true,
54
+ };
55
+ }
56
+
57
+ log("success", `Loaded config from ${configResult.userFileName}.`);
58
+
59
+ const config = configResult.config || {};
60
+
61
+ if (typeof config.engine?.render === "function") {
62
+ log("success", "engine.render is defined.");
63
+ } else {
64
+ success = false;
65
+ log("error", "engine.render is missing.");
66
+ }
67
+
68
+ if (config.components?.folder || config.docs?.folder) {
69
+ log("success", "At least one source folder is configured.");
70
+ } else {
71
+ success = false;
72
+ log(
73
+ "error",
74
+ "Set at least one of components.folder or docs.folder in your miyagi config.",
75
+ );
76
+ }
77
+
78
+ if (config.components?.folder) {
79
+ if (await pathExists(config.components.folder)) {
80
+ log("success", `components.folder exists: ${config.components.folder}`);
81
+ } else {
82
+ success = false;
83
+ log(
84
+ "error",
85
+ `components.folder does not exist: ${config.components.folder}`,
86
+ );
87
+ }
88
+ }
89
+
90
+ if (config.docs?.folder) {
91
+ if (await pathExists(config.docs.folder)) {
92
+ log("success", `docs.folder exists: ${config.docs.folder}`);
93
+ } else {
94
+ success = false;
95
+ log("error", `docs.folder does not exist: ${config.docs.folder}`);
96
+ }
97
+ }
98
+
99
+ log(
100
+ success ? "success" : "error",
101
+ success ? "Doctor checks passed." : "Doctor found issues.",
102
+ );
103
+
104
+ return {
105
+ success,
106
+ code: success ? EXIT_CODES.SUCCESS : EXIT_CODES.CONFIG_ERROR,
107
+ shouldExit: true,
108
+ };
100
109
  }
101
110
 
102
111
  /**
103
112
  * @returns {boolean}
104
113
  */
105
114
  function checkNodeVersion() {
106
- const minimumMajor = Number(pkgJson.engines.node.match(/\d+/)?.[0] || 0);
107
- const currentMajor = Number(process.versions.node.split(".")[0]);
108
- return currentMajor >= minimumMajor;
115
+ const minimumMajor = Number(pkgJson.engines.node.match(/\d+/)?.[0] || 0);
116
+ const currentMajor = Number(process.versions.node.split(".")[0]);
117
+ return currentMajor >= minimumMajor;
109
118
  }
110
119
 
111
120
  /**
@@ -113,41 +122,41 @@ function checkNodeVersion() {
113
122
  * @returns {Promise<boolean>}
114
123
  */
115
124
  async function pathExists(relativePath) {
116
- try {
117
- await stat(path.resolve(process.cwd(), relativePath));
118
- return true;
119
- } catch {
120
- return false;
121
- }
125
+ try {
126
+ await stat(path.resolve(process.cwd(), relativePath));
127
+ return true;
128
+ } catch {
129
+ return false;
130
+ }
122
131
  }
123
132
 
124
133
  /**
125
134
  * @returns {Promise<object>}
126
135
  */
127
136
  async function loadUserConfig() {
128
- for (const fileName of CONFIG_FILES) {
129
- const fullPath = path.resolve(process.cwd(), fileName);
130
-
131
- if (!(await pathExists(fileName))) {
132
- continue;
133
- }
134
-
135
- try {
136
- const module = await import(`${fullPath}?time=${Date.now()}`);
137
- return {
138
- userFileName: fileName,
139
- config: module.default || {},
140
- };
141
- } catch (error) {
142
- return {
143
- userFileName: fileName,
144
- error: /** @type {Error} */ (error),
145
- };
146
- }
147
- }
148
-
149
- return {
150
- userFileName: null,
151
- config: null,
152
- };
137
+ for (const fileName of CONFIG_FILES) {
138
+ const fullPath = path.resolve(process.cwd(), fileName);
139
+
140
+ if (!(await pathExists(fileName))) {
141
+ continue;
142
+ }
143
+
144
+ try {
145
+ const module = await import(`${fullPath}?time=${Date.now()}`);
146
+ return {
147
+ userFileName: fileName,
148
+ config: module.default || {},
149
+ };
150
+ } catch (error) {
151
+ return {
152
+ userFileName: fileName,
153
+ error: /** @type {Error} */ (error),
154
+ };
155
+ }
156
+ }
157
+
158
+ return {
159
+ userFileName: null,
160
+ config: null,
161
+ };
153
162
  }