@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,52 @@
1
+ import config from "../../../../default-config.js";
2
+ import { getUserUiConfig, getThemeMode } from "../../../helpers.js";
3
+ import { getColors, getMediaQueries } from "../../../../styleguide/index.js";
4
+
5
+ /**
6
+ * @param {object} o
7
+ * @param {object} o.res
8
+ * @param {Function} [o.cb]
9
+ * @param {object} o.cookies
10
+ */
11
+ export default async function ({ res, cb, cookies }) {
12
+ const colors = global.state.css
13
+ ? getColors(
14
+ global.state.css,
15
+ global.config.assets.customProperties.prefixes.color,
16
+ )
17
+ : [];
18
+ const mediaQueries = global.state.css
19
+ ? getMediaQueries(global.state.css)
20
+ : [];
21
+ const themeMode = getThemeMode(cookies);
22
+
23
+ await res.render(
24
+ "design-tokens/colors.twig.miyagi",
25
+ {
26
+ additionalCssFiles: global.config.assets?.customProperties?.files || [],
27
+ colors:
28
+ colors.map(({ styles }) => styles.length).reduce((a, b) => a + b, 0) > 0
29
+ ? colors
30
+ : [],
31
+ isBuild: global.config.isBuild,
32
+ lang: global.config.ui.lang,
33
+ mediaQueries,
34
+ miyagiDev: !!process.env.MIYAGI_DEVELOPMENT,
35
+ projectName: config.projectName,
36
+ userUiConfig: getUserUiConfig(cookies),
37
+ theme: themeMode
38
+ ? Object.assign(global.config.ui.theme, { mode: themeMode })
39
+ : global.config.ui.theme,
40
+ uiTextDirection: global.config.ui.textDirection,
41
+ },
42
+ (html) => {
43
+ if (res.send) {
44
+ res.send(html);
45
+ }
46
+
47
+ if (cb) {
48
+ cb(null, html);
49
+ }
50
+ },
51
+ );
52
+ }
@@ -0,0 +1,9 @@
1
+ import colors from "./colors.js";
2
+ import sizes from "./sizes.js";
3
+ import typography from "./typography.js";
4
+
5
+ export default {
6
+ colors,
7
+ sizes,
8
+ typography,
9
+ };
@@ -0,0 +1,49 @@
1
+ import config from "../../../../default-config.js";
2
+ import { getUserUiConfig, getThemeMode } from "../../../helpers.js";
3
+ import { getSpacings, getMediaQueries } from "../../../../styleguide/index.js";
4
+
5
+ /**
6
+ * @param {object} o
7
+ * @param {object} o.res
8
+ * @param {Function} [o.cb]
9
+ * @param {object} o.cookies
10
+ */
11
+ export default async function ({ res, cb, cookies }) {
12
+ const spacings = global.state.css
13
+ ? getSpacings(
14
+ global.state.css,
15
+ global.config.assets.customProperties.prefixes.spacing,
16
+ )
17
+ : [];
18
+ const mediaQueries = global.state.css
19
+ ? getMediaQueries(global.state.css)
20
+ : [];
21
+ const themeMode = getThemeMode(cookies);
22
+
23
+ await res.render(
24
+ "design-tokens/sizes.twig.miyagi",
25
+ {
26
+ additionalCssFiles: global.config.assets?.customProperties?.files || [],
27
+ isBuild: global.config.isBuild,
28
+ lang: global.config.ui.lang,
29
+ mediaQueries,
30
+ miyagiDev: !!process.env.MIYAGI_DEVELOPMENT,
31
+ spacings: spacings.length > 0 ? spacings : null,
32
+ projectName: config.projectName,
33
+ userUiConfig: getUserUiConfig(cookies),
34
+ theme: themeMode
35
+ ? Object.assign(global.config.ui.theme, { mode: themeMode })
36
+ : global.config.ui.theme,
37
+ uiTextDirection: global.config.ui.textDirection,
38
+ },
39
+ (html) => {
40
+ if (res.send) {
41
+ res.send(html);
42
+ }
43
+
44
+ if (cb) {
45
+ cb(null, html);
46
+ }
47
+ },
48
+ );
49
+ }
@@ -0,0 +1,52 @@
1
+ import config from "../../../../default-config.js";
2
+ import { getUserUiConfig, getThemeMode } from "../../../helpers.js";
3
+ import {
4
+ getTypography,
5
+ getMediaQueries,
6
+ } from "../../../../styleguide/index.js";
7
+
8
+ /**
9
+ * @param {object} o
10
+ * @param {object} o.res
11
+ * @param {Function} [o.cb]
12
+ * @param {object} o.cookies
13
+ */
14
+ export default async function ({ res, cb, cookies }) {
15
+ const typography = global.state.css
16
+ ? getTypography(
17
+ global.state.css,
18
+ global.config.assets.customProperties.prefixes.typo,
19
+ )
20
+ : [];
21
+ const mediaQueries = global.state.css
22
+ ? getMediaQueries(global.state.css)
23
+ : [];
24
+ const themeMode = getThemeMode(cookies);
25
+
26
+ await res.render(
27
+ "design-tokens/typography.twig.miyagi",
28
+ {
29
+ additionalCssFiles: global.config.assets?.customProperties?.files || [],
30
+ isBuild: global.config.isBuild,
31
+ lang: global.config.ui.lang,
32
+ mediaQueries,
33
+ miyagiDev: !!process.env.MIYAGI_DEVELOPMENT,
34
+ typography: typography.length > 0 ? typography : null,
35
+ projectName: config.projectName,
36
+ userUiConfig: getUserUiConfig(cookies),
37
+ theme: themeMode
38
+ ? Object.assign(global.config.ui.theme, { mode: themeMode })
39
+ : global.config.ui.theme,
40
+ uiTextDirection: global.config.ui.textDirection,
41
+ },
42
+ (html) => {
43
+ if (res.send) {
44
+ res.send(html);
45
+ }
46
+
47
+ if (cb) {
48
+ cb(null, html);
49
+ }
50
+ },
51
+ );
52
+ }
@@ -0,0 +1,68 @@
1
+ import path from "path";
2
+ import config from "../../../default-config.js";
3
+ import { getUserUiConfig, getThemeMode } from "../../helpers.js";
4
+
5
+ /**
6
+ * @param {object} object - parameter object
7
+ * @param {object} object.res - the express response object
8
+ * @param {object} object.doc
9
+ * @param {Function} [object.cb] - callback function
10
+ * @param {object} [object.cookies]
11
+ */
12
+ export default async function renderIframeDocs({ res, doc, cb, cookies }) {
13
+ const fullPath = doc.paths.dir.full;
14
+ const shortPath = doc.paths.dir.short;
15
+ const componentDocumentation = global.state.fileContents[fullPath];
16
+ const componentName = getHeadlineFromFileName(shortPath);
17
+ const themeMode = getThemeMode(cookies);
18
+
19
+ await res.render(
20
+ "iframe_component.twig.miyagi",
21
+ {
22
+ lang: global.config.ui.lang,
23
+ miyagiDev: !!process.env.MIYAGI_DEVELOPMENT,
24
+ prod: process.env.NODE_ENV === "production",
25
+ projectName: config.projectName,
26
+ userProjectName: global.config.projectName,
27
+ isBuild: global.config.isBuild,
28
+ userUiConfig: getUserUiConfig(cookies),
29
+ theme: themeMode
30
+ ? Object.assign(global.config.ui.theme, { mode: themeMode })
31
+ : global.config.ui.theme,
32
+ documentation: componentDocumentation,
33
+ name: componentDocumentation?.includes("<h1") ? null : componentName,
34
+ uiTextDirection: global.config.ui.textDirection,
35
+ },
36
+ (html) => {
37
+ if (res.send) {
38
+ res.send(html);
39
+ }
40
+
41
+ if (cb) {
42
+ cb(null, html);
43
+ }
44
+ },
45
+ );
46
+ }
47
+
48
+ /**
49
+ * @param {string} file
50
+ * @returns {string}
51
+ */
52
+ function getHeadlineFromFileName(file) {
53
+ if (typeof file !== "string") return "";
54
+
55
+ let fileName = file;
56
+
57
+ if (fileName.startsWith("/")) {
58
+ fileName = fileName.slice(1);
59
+ }
60
+
61
+ if (file.endsWith("README.md") || file.endsWith("index.md")) {
62
+ fileName = path.dirname(fileName);
63
+ } else {
64
+ fileName = path.basename(fileName, ".md");
65
+ }
66
+
67
+ return fileName.replaceAll("-", " ");
68
+ }
@@ -0,0 +1,44 @@
1
+ import config from "../../../default-config.js";
2
+ import * as helpers from "../../../helpers.js";
3
+ import { getUserUiConfig, getThemeMode } from "../../helpers.js";
4
+
5
+ /**
6
+ * @param {object} object - parameter object
7
+ * @param {object} object.res - the express response object
8
+ * @param {Function} [object.cb] - callback function
9
+ * @param {object} [object.cookies]
10
+ * @returns {Promise}
11
+ */
12
+ export default async function renderIframeIndex({ res, cb, cookies }) {
13
+ const documentation =
14
+ global.state.fileContents[helpers.getFullPathFromShortPath("README.md")];
15
+
16
+ const themeMode = getThemeMode(cookies);
17
+
18
+ await res.render(
19
+ "iframe_index.twig.miyagi",
20
+ {
21
+ lang: global.config.ui.lang,
22
+ miyagiDev: !!process.env.MIYAGI_DEVELOPMENT,
23
+ prod: process.env.NODE_ENV === "production",
24
+ projectName: config.projectName,
25
+ userProjectName: global.config.projectName,
26
+ isBuild: global.config.isBuild,
27
+ userUiConfig: getUserUiConfig(cookies),
28
+ theme: themeMode
29
+ ? Object.assign(global.config.ui.theme, { mode: themeMode })
30
+ : global.config.ui.theme,
31
+ documentation,
32
+ uiTextDirection: global.config.ui.textDirection,
33
+ },
34
+ (html) => {
35
+ if (res.send) {
36
+ res.send(html);
37
+ }
38
+
39
+ if (cb) {
40
+ cb(null, html);
41
+ }
42
+ },
43
+ );
44
+ }
@@ -0,0 +1,116 @@
1
+ import path from "path";
2
+ import config from "../../../default-config.js";
3
+ import { t } from "../../../i18n/index.js";
4
+ import * as helpers from "../../../helpers.js";
5
+ import validateMocks from "../../../validator/mocks.js";
6
+ import { getUserUiConfig, getThemeMode } from "../../helpers.js";
7
+
8
+ /**
9
+ * @param {object} object - parameter object
10
+ * @param {object} [object.res] - the express response object
11
+ * @param {object} object.component
12
+ * @param {string} [object.variation] - the variation name
13
+ * @param {Function} [object.cb] - callback function
14
+ * @param {object} [object.cookies]
15
+ * @param {object} [object.data]
16
+ * @returns {Promise} gets resolved when the variation has been rendered
17
+ */
18
+ export default async function renderIframeVariation({
19
+ res,
20
+ component,
21
+ variation,
22
+ cb,
23
+ cookies,
24
+ data,
25
+ }) {
26
+ const rawComponentData = (data && data.raw) ?? null;
27
+ const componentData = (data && data.resolved) ?? null;
28
+ const themeMode = getThemeMode(cookies);
29
+
30
+ const validatedMocks = validateMocks(component, [
31
+ {
32
+ resolved: componentData,
33
+ name: variation,
34
+ },
35
+ ]);
36
+
37
+ let standaloneUrl;
38
+
39
+ if (global.config.isBuild) {
40
+ standaloneUrl = `component-${helpers.normalizeString(
41
+ path.dirname(component.paths.tpl.short),
42
+ )}-variation-${helpers.normalizeString(variation)}.html`;
43
+ } else {
44
+ standaloneUrl = `/component?file=${path.dirname(
45
+ component.paths.tpl.short,
46
+ )}&variation=${encodeURIComponent(variation)}`;
47
+ }
48
+
49
+ const mockValidation = validatedMocks
50
+ ? {
51
+ valid: validatedMocks.length === 0,
52
+ copy: t(
53
+ `validator.mocks.${validatedMocks.length === 0 ? "valid" : "invalid"}`,
54
+ ),
55
+ }
56
+ : null;
57
+ const fileContents = {
58
+ mocks: {
59
+ type: global.config.files.mocks.extension[0],
60
+ },
61
+ };
62
+
63
+ return new Promise((resolve, reject) => {
64
+ global.app.render(
65
+ component.paths.tpl.full,
66
+ componentData ?? {},
67
+ async (error, result) => {
68
+ if (error) {
69
+ if (global.config.isBuild) {
70
+ if (cb) {
71
+ cb(error);
72
+ }
73
+ } else {
74
+ reject(error);
75
+ }
76
+ } else if (res) {
77
+ await res.render(
78
+ "iframe_component_variation.twig.miyagi",
79
+ {
80
+ html: result,
81
+ standaloneUrl,
82
+ miyagiDev: !!process.env.MIYAGI_DEVELOPMENT,
83
+ prod: process.env.NODE_ENV === "production",
84
+ projectName: config.projectName,
85
+ isBuild: global.config.isBuild,
86
+ userUiConfig: getUserUiConfig(cookies),
87
+ theme: themeMode
88
+ ? Object.assign(global.config.ui.theme, { mode: themeMode })
89
+ : global.config.ui.theme,
90
+ mockData: JSON.stringify(rawComponentData),
91
+ mockDataResolved: JSON.stringify(componentData),
92
+ variation,
93
+ normalizedVariation: helpers.normalizeString(variation),
94
+ mockValidation,
95
+ mocks: fileContents.mocks,
96
+ uiTextDirection: global.config.ui.textDirection,
97
+ },
98
+ (html) => {
99
+ if (res.send) {
100
+ res.send(html);
101
+ }
102
+
103
+ if (cb) {
104
+ cb(null, html);
105
+ }
106
+ },
107
+ );
108
+
109
+ resolve();
110
+ } else {
111
+ resolve(result);
112
+ }
113
+ },
114
+ );
115
+ });
116
+ }
@@ -0,0 +1,89 @@
1
+ import path from "path";
2
+ import config from "../../../default-config.js";
3
+ import { getUserUiConfig } from "../../helpers.js";
4
+
5
+ /**
6
+ * @param {object} object - parameter object
7
+ * @param {object} [object.res] - the express response object
8
+ * @param {object} object.component
9
+ * @param {object} object.componentData
10
+ * @param {Function} [object.cb] - callback function
11
+ * @param {object} [object.cookies]
12
+ * @returns {Promise} gets resolved when the variation has been rendered
13
+ */
14
+ export default async function renderIframeVariationStandalone({
15
+ res,
16
+ component,
17
+ componentData,
18
+ cb,
19
+ cookies,
20
+ }) {
21
+ const directoryPath = component.paths.dir.short;
22
+
23
+ return new Promise((resolve, reject) => {
24
+ global.app.render(
25
+ component.paths.tpl.full,
26
+ componentData ?? {},
27
+ async (error, result) => {
28
+ if (error) {
29
+ if (global.config.isBuild) {
30
+ if (cb) {
31
+ cb(error);
32
+ }
33
+ } else {
34
+ reject(error);
35
+ }
36
+ } else if (res) {
37
+ const componentsEntry = global.state.components.find(
38
+ ({ shortPath }) => shortPath === directoryPath,
39
+ );
40
+
41
+ await res.render(
42
+ "component_variation.twig.miyagi",
43
+ {
44
+ html: result,
45
+ cssFiles: global.config.assets.css,
46
+ jsFilesHead: global.config.assets.js.filter(
47
+ (entry) => entry.position === "head" || !entry.position,
48
+ ),
49
+ jsFilesBody: global.config.assets.js.filter(
50
+ (entry) => entry.position === "body",
51
+ ),
52
+ assets: {
53
+ css: componentsEntry
54
+ ? componentsEntry.assets.css
55
+ ? path.join("/", componentsEntry.assets.css)
56
+ : false
57
+ : false,
58
+ js: componentsEntry
59
+ ? componentsEntry.assets.js
60
+ ? path.join("/", componentsEntry.assets.js)
61
+ : false
62
+ : false,
63
+ },
64
+ miyagiDev: !!process.env.MIYAGI_DEVELOPMENT,
65
+ prod: process.env.NODE_ENV === "production",
66
+ projectName: config.projectName,
67
+ isBuild: global.config.isBuild,
68
+ userUiConfig: getUserUiConfig(cookies),
69
+ componentLanguage: global.config.components.lang,
70
+ },
71
+ (html) => {
72
+ if (res.send) {
73
+ res.send(html);
74
+ }
75
+
76
+ if (cb) {
77
+ cb(null, html);
78
+ }
79
+ },
80
+ );
81
+
82
+ resolve();
83
+ } else {
84
+ resolve(result);
85
+ }
86
+ },
87
+ );
88
+ });
89
+ }
@@ -0,0 +1,53 @@
1
+ import config from "../../../default-config.js";
2
+ import { getUserUiConfig, getThemeMode } from "../../helpers.js";
3
+
4
+ /**
5
+ * @param {object} object - parameter object
6
+ * @param {object} object.res - the express response object
7
+ * @param {object} object.component
8
+ * @param {Function} [object.cb] - callback function
9
+ * @param {object} [object.cookies]
10
+ */
11
+ export default async function renderMainComponentDocs({
12
+ res,
13
+ component,
14
+ cb,
15
+ cookies,
16
+ }) {
17
+ const iframeSrc = component.route.embedded;
18
+ const themeMode = getThemeMode(cookies);
19
+
20
+ await res.render(
21
+ "main.twig.miyagi",
22
+ {
23
+ lang: global.config.ui.lang,
24
+ folders: global.state.menu,
25
+ components: global.state.components,
26
+ flatUrlPattern: global.config.isBuild
27
+ ? "/show-{{component}}.html"
28
+ : "/show?file={{component}}",
29
+ iframeSrc,
30
+ requestedComponent: component.paths.dir.short,
31
+ projectName: config.projectName,
32
+ userProjectName: global.config.projectName,
33
+ indexPath: global.config.indexPath.embedded,
34
+ miyagiDev: !!process.env.MIYAGI_DEVELOPMENT,
35
+ isBuild: global.config.isBuild,
36
+ userUiConfig: getUserUiConfig(cookies),
37
+ theme: themeMode
38
+ ? Object.assign(global.config.ui.theme, { mode: themeMode })
39
+ : global.config.ui.theme,
40
+ basePath: global.config.isBuild ? global.config.build.basePath : "/",
41
+ uiTextDirection: global.config.ui.textDirection,
42
+ },
43
+ (html) => {
44
+ if (res.send) {
45
+ res.send(html);
46
+ }
47
+
48
+ if (cb) {
49
+ cb(null, html);
50
+ }
51
+ },
52
+ );
53
+ }
@@ -0,0 +1,74 @@
1
+ import config from "../../../default-config.js";
2
+ import * as helpers from "../../../helpers.js";
3
+ import { getUserUiConfig, getThemeMode } from "../../helpers.js";
4
+
5
+ /**
6
+ * @param {object} object - parameter object
7
+ * @param {object} object.res - the express response object
8
+ * @param {object} object.component
9
+ * @param {string} [object.variation] - the variation name
10
+ * @param {Function} [object.cb] - callback function
11
+ * @param {object} [object.cookies]
12
+ */
13
+ export default async function renderMainComponent({
14
+ res,
15
+ component,
16
+ variation,
17
+ cb,
18
+ cookies,
19
+ }) {
20
+ let iframeSrc = component.route.default;
21
+ const themeMode = getThemeMode(cookies);
22
+
23
+ if (variation) {
24
+ if (global.config.isBuild) {
25
+ iframeSrc = iframeSrc.replace(
26
+ /\.html$/,
27
+ `-variation-${helpers.normalizeString(variation)}.html`,
28
+ );
29
+ } else {
30
+ iframeSrc += `&variation=${variation}`;
31
+ }
32
+ }
33
+
34
+ if (global.config.isBuild) {
35
+ iframeSrc = iframeSrc.replace(/\.html$/, "-embedded.html");
36
+ } else {
37
+ iframeSrc += "&embedded=true";
38
+ }
39
+
40
+ await res.render(
41
+ "main.twig.miyagi",
42
+ {
43
+ lang: global.config.ui.lang,
44
+ folders: global.state.menu,
45
+ components: global.state.components,
46
+ flatUrlPattern: global.config.isBuild
47
+ ? "/show-{{component}}.html"
48
+ : "/show?file={{component}}",
49
+ iframeSrc,
50
+ requestedComponent: component.paths.dir.short,
51
+ requestedVariation: variation,
52
+ projectName: config.projectName,
53
+ userProjectName: global.config.projectName,
54
+ indexPath: global.config.indexPath.embedded,
55
+ miyagiDev: !!process.env.MIYAGI_DEVELOPMENT,
56
+ isBuild: global.config.isBuild,
57
+ userUiConfig: getUserUiConfig(cookies),
58
+ theme: themeMode
59
+ ? Object.assign(global.config.ui.theme, { mode: themeMode })
60
+ : global.config.ui.theme,
61
+ basePath: global.config.isBuild ? global.config.build.basePath : "/",
62
+ uiTextDirection: global.config.ui.textDirection,
63
+ },
64
+ (html) => {
65
+ if (res.send) {
66
+ res.send(html);
67
+ }
68
+
69
+ if (cb) {
70
+ cb(null, html);
71
+ }
72
+ },
73
+ );
74
+ }
@@ -0,0 +1,53 @@
1
+ import config from "../../../default-config.js";
2
+ import { getUserUiConfig, getThemeMode } from "../../helpers.js";
3
+
4
+ /**
5
+ * @param {object} object - parameter object
6
+ * @param {object} object.res - the express response object
7
+ * @param {Function} [object.cb] - callback function
8
+ * @param {string} object.type
9
+ * @param {object} [object.cookies]
10
+ */
11
+ export default function renderMainDesignTokens({ res, cb, cookies, type }) {
12
+ if (!["colors", "sizes", "typography"].includes(type)) return;
13
+
14
+ const themeMode = getThemeMode(cookies);
15
+
16
+ res.render(
17
+ "main.twig.miyagi",
18
+ {
19
+ lang: global.config.ui.lang,
20
+ folders: global.state.menu,
21
+ components: global.state.components,
22
+ flatUrlPattern: global.config.isBuild
23
+ ? "/show-{{component}}.html"
24
+ : "/show?file={{component}}",
25
+ iframeSrc: global.config.isBuild
26
+ ? `/iframe-design-tokens-${type}.html`
27
+ : `/iframe/design-tokens/${type}`,
28
+ showAll: true,
29
+ projectName: config.projectName,
30
+ userProjectName: global.config.projectName,
31
+ indexPath: global.config.indexPath.embedded,
32
+ miyagiDev: !!process.env.MIYAGI_DEVELOPMENT,
33
+ isBuild: global.config.isBuild,
34
+ userUiConfig: getUserUiConfig(cookies),
35
+ theme: themeMode
36
+ ? Object.assign(global.config.ui.theme, { mode: themeMode })
37
+ : global.config.ui.theme,
38
+ basePath: global.config.isBuild ? global.config.build.basePath : "/",
39
+ uiTextDirection: global.config.ui.textDirection,
40
+ requestedComponent: "design-tokens",
41
+ requestedVariation: type,
42
+ },
43
+ (html) => {
44
+ if (res.send) {
45
+ res.send(html);
46
+ }
47
+
48
+ if (cb) {
49
+ cb(null, html);
50
+ }
51
+ },
52
+ );
53
+ }