@madgex/fert 1.7.2 → 2.0.1
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/commands/build-tasks/build-tokens-v5.js +98 -0
- package/bin/commands/build-tasks/build-tokens.js +6 -13
- package/bin/commands/build-tasks/bundle-ds-css.js +1 -1
- package/bin/commands/build.js +2 -0
- package/package.json +3 -2
- package/repo-templates/template-basic/src/css/styles.scss +0 -1
- package/repo-templates/template-bigworkbag/src/css/styles.scss +0 -1
- package/server/plugins/hapi-vite.js +0 -10
- package/server/routes/public.js +7 -0
- package/server/templates/furniture.njk +2 -9
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const StyleDictionaryPackage = require('style-dictionary');
|
|
2
|
+
const Path = require('path');
|
|
3
|
+
const fs = require('fs/promises');
|
|
4
|
+
const {
|
|
5
|
+
registerTransforms,
|
|
6
|
+
} = require('@madgex/design-system-v5/tasks/registerTransforms');
|
|
7
|
+
const colorTransforms = require('@madgex/design-system-v5/tasks/colorTransforms');
|
|
8
|
+
const { ensureTrailingSlash, exists } = require('../../utils');
|
|
9
|
+
const { log } = require('../../utils/logging');
|
|
10
|
+
const { TMP_DIR } = require('../../../constants');
|
|
11
|
+
|
|
12
|
+
const dsTokensPath = Path.dirname(
|
|
13
|
+
require.resolve('@madgex/design-system-v5/src/tokens/_config.js')
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// eslint-disable-next-line no-unused-vars
|
|
17
|
+
const createTempBrandFile = async (dir = './') => {
|
|
18
|
+
// Generate unique name to bust style dict cache
|
|
19
|
+
const timestamp = Date.now();
|
|
20
|
+
const tmpBrandFile = Path.join(TMP_DIR, `/fert/brand-${timestamp}-v5.json`);
|
|
21
|
+
const dirPath = Path.dirname(tmpBrandFile);
|
|
22
|
+
|
|
23
|
+
if (!(await exists(dirPath))) {
|
|
24
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return tmpBrandFile;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Style Dictionary is noisy and annoying, this suppresses its output
|
|
31
|
+
async function runSilently(fn) {
|
|
32
|
+
const originalLog = console.log;
|
|
33
|
+
console.log = () => {};
|
|
34
|
+
await fn();
|
|
35
|
+
console.log = originalLog;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = async function buildCssFromTokensV5(srcTokensPath, buildPath) {
|
|
39
|
+
srcTokensPath = ensureTrailingSlash(Path.resolve(srcTokensPath));
|
|
40
|
+
buildPath = ensureTrailingSlash(Path.resolve(buildPath));
|
|
41
|
+
|
|
42
|
+
const brandFile = Path.join(srcTokensPath, 'brand.json');
|
|
43
|
+
|
|
44
|
+
if (!(await exists(buildPath))) {
|
|
45
|
+
await fs.mkdir(buildPath, { recursive: true });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Fetch the file so we can transform the colours in style dictionary
|
|
49
|
+
const brandObj = JSON.parse(
|
|
50
|
+
await fs.readFile(brandFile, { encoding: 'utf8' })
|
|
51
|
+
);
|
|
52
|
+
const tmpBrandFile = await createTempBrandFile(srcTokensPath);
|
|
53
|
+
|
|
54
|
+
await fs.writeFile(
|
|
55
|
+
Path.join(tmpBrandFile),
|
|
56
|
+
JSON.stringify(colorTransforms(brandObj))
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
// TODO - Investigate whether we can retrieve from DS instead of redefining
|
|
60
|
+
// e.g. const { registerTransforms } = require('@madgex/design-system/tasks/registerTransforms');
|
|
61
|
+
const transforms = [
|
|
62
|
+
'attribute/cti',
|
|
63
|
+
'name/cti/kebab',
|
|
64
|
+
'color/css',
|
|
65
|
+
'css/rawData',
|
|
66
|
+
];
|
|
67
|
+
const prefix = 'mds';
|
|
68
|
+
|
|
69
|
+
// TODO - Investigate whether we can retrieve from DS instead of redefining
|
|
70
|
+
const styleDictionaryConfig = {
|
|
71
|
+
include: [Path.join(dsTokensPath, '*.json')],
|
|
72
|
+
source: [tmpBrandFile],
|
|
73
|
+
platforms: {
|
|
74
|
+
'scss-variables': {
|
|
75
|
+
transforms,
|
|
76
|
+
prefix,
|
|
77
|
+
buildPath: Path.join(buildPath, 'scss/'),
|
|
78
|
+
files: [
|
|
79
|
+
{
|
|
80
|
+
destination: 'index.scss',
|
|
81
|
+
format: 'scss/map-deep',
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Use StyleDictionary to build a tokens SCSS file
|
|
89
|
+
const StyleDictionary = StyleDictionaryPackage.extend(styleDictionaryConfig);
|
|
90
|
+
|
|
91
|
+
await registerTransforms(StyleDictionary);
|
|
92
|
+
await runSilently(StyleDictionary.buildAllPlatforms.bind(StyleDictionary));
|
|
93
|
+
|
|
94
|
+
// clean-up temp SD file
|
|
95
|
+
await fs.unlink(tmpBrandFile);
|
|
96
|
+
|
|
97
|
+
log.success('Token build complete (SCSS).');
|
|
98
|
+
};
|
|
@@ -63,6 +63,7 @@ module.exports = async function buildCssFromTokens(srcTokensPath, buildPath) {
|
|
|
63
63
|
'name/cti/kebab',
|
|
64
64
|
'color/css',
|
|
65
65
|
'css/rawData',
|
|
66
|
+
'custom/pxToRem',
|
|
66
67
|
];
|
|
67
68
|
const prefix = 'mds';
|
|
68
69
|
|
|
@@ -71,17 +72,6 @@ module.exports = async function buildCssFromTokens(srcTokensPath, buildPath) {
|
|
|
71
72
|
include: [Path.join(dsTokensPath, '*.json')],
|
|
72
73
|
source: [tmpBrandFile],
|
|
73
74
|
platforms: {
|
|
74
|
-
'scss-variables': {
|
|
75
|
-
transforms,
|
|
76
|
-
prefix,
|
|
77
|
-
buildPath: Path.join(buildPath, 'scss/'),
|
|
78
|
-
files: [
|
|
79
|
-
{
|
|
80
|
-
destination: 'index.scss',
|
|
81
|
-
format: 'scss/map-deep',
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
},
|
|
85
75
|
'css-variables': {
|
|
86
76
|
transforms,
|
|
87
77
|
prefix,
|
|
@@ -90,6 +80,7 @@ module.exports = async function buildCssFromTokens(srcTokensPath, buildPath) {
|
|
|
90
80
|
{
|
|
91
81
|
destination: `variables.css`,
|
|
92
82
|
format: 'css/variables',
|
|
83
|
+
filter: 'removePrivate',
|
|
93
84
|
},
|
|
94
85
|
],
|
|
95
86
|
},
|
|
@@ -101,6 +92,7 @@ module.exports = async function buildCssFromTokens(srcTokensPath, buildPath) {
|
|
|
101
92
|
{
|
|
102
93
|
destination: `variables.json`,
|
|
103
94
|
format: 'json/nested',
|
|
95
|
+
filter: 'removePrivate',
|
|
104
96
|
},
|
|
105
97
|
],
|
|
106
98
|
},
|
|
@@ -110,11 +102,12 @@ module.exports = async function buildCssFromTokens(srcTokensPath, buildPath) {
|
|
|
110
102
|
// Use StyleDictionary to build a tokens SCSS file
|
|
111
103
|
const StyleDictionary = StyleDictionaryPackage.extend(styleDictionaryConfig);
|
|
112
104
|
|
|
113
|
-
|
|
105
|
+
const tokenBaseFontSize = brandObj?.font?.size?.base; // will default to 16px if undefined
|
|
106
|
+
await registerTransforms(StyleDictionary, tokenBaseFontSize);
|
|
114
107
|
await runSilently(StyleDictionary.buildAllPlatforms.bind(StyleDictionary));
|
|
115
108
|
|
|
116
109
|
// clean-up temp SD file
|
|
117
110
|
await fs.unlink(tmpBrandFile);
|
|
118
111
|
|
|
119
|
-
log.success('Token build complete.');
|
|
112
|
+
log.success('Token build complete (CSS & JSON).');
|
|
120
113
|
};
|
|
@@ -25,7 +25,7 @@ module.exports = async (viteConfig) => {
|
|
|
25
25
|
scss: {
|
|
26
26
|
additionalData: `
|
|
27
27
|
@import "../../public/tokens/scss/index.scss";
|
|
28
|
-
@import "@madgex/design-system/src/scss/import.scss";
|
|
28
|
+
@import "@madgex/design-system-v5/src/scss/import.scss";
|
|
29
29
|
`, // all scss processed files gets this injected at the top
|
|
30
30
|
},
|
|
31
31
|
},
|
package/bin/commands/build.js
CHANGED
|
@@ -4,6 +4,7 @@ const { resolveConfig } = require('../utils');
|
|
|
4
4
|
const { log } = require('../utils/logging');
|
|
5
5
|
const bundleEntry = require('./build-tasks/bundle-entry');
|
|
6
6
|
const buildCssFromTokens = require('./build-tasks/build-tokens');
|
|
7
|
+
const buildCssFromTokensV5 = require('./build-tasks/build-tokens-v5');
|
|
7
8
|
const buildExternalAssets = require('./build-tasks/build-external-assets');
|
|
8
9
|
|
|
9
10
|
module.exports = async (root, options = {}) => {
|
|
@@ -37,6 +38,7 @@ exports.buildTokens = async (fertConfig, options = {}) => {
|
|
|
37
38
|
const tokenDist = path.join(workingDir, `/public/tokens/`);
|
|
38
39
|
|
|
39
40
|
buildCssFromTokens(workingDir, tokenDist);
|
|
41
|
+
buildCssFromTokensV5(workingDir, tokenDist);
|
|
40
42
|
};
|
|
41
43
|
|
|
42
44
|
exports.bundleEntry = bundleEntry;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@madgex/fert",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Tool to help build the V6 branding",
|
|
5
5
|
"bin": {
|
|
6
6
|
"fert": "./bin/cli.js"
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"@hapi/inert": "^7.1.0",
|
|
31
31
|
"@hapi/vision": "^7.0.3",
|
|
32
32
|
"@hapipal/toys": "^4.0.0",
|
|
33
|
-
"@madgex/design-system": "^
|
|
33
|
+
"@madgex/design-system": "^6.1.2",
|
|
34
|
+
"@madgex/design-system-v5": "npm:@madgex/design-system@^5.0.0",
|
|
34
35
|
"@private/header-footer-podlet-server": "github:wiley/madgex-header-footer-podlet",
|
|
35
36
|
"axios": "^1.6.2",
|
|
36
37
|
"cac": "^6.7.14",
|
|
@@ -33,16 +33,6 @@ module.exports = {
|
|
|
33
33
|
input: options.entry,
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
|
-
css: {
|
|
37
|
-
preprocessorOptions: {
|
|
38
|
-
scss: {
|
|
39
|
-
additionalData: `
|
|
40
|
-
@import "../../public/tokens/scss/index.scss";
|
|
41
|
-
@import "@madgex/design-system/src/scss/import.scss";
|
|
42
|
-
`, // all scss processed files gets this injected at the top
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
36
|
});
|
|
47
37
|
|
|
48
38
|
await server.app.viteServer.listen();
|
package/server/routes/public.js
CHANGED
|
@@ -4,20 +4,18 @@
|
|
|
4
4
|
<meta charset="utf-8"/>
|
|
5
5
|
<title>{{ title | default('Frontend Rollout Tool') }}</title>
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
7
|
-
|
|
7
|
+
<link rel="stylesheet" href="/public/tokens/css-vars/variables.css">
|
|
8
|
+
<link rel="stylesheet" href="/design-system.css">
|
|
8
9
|
{%- for link in fertConfig.externalAssets.links %}
|
|
9
10
|
<link {%- for key, value in link %} {{ key }}="{{ value }}" {%- endfor %}/>
|
|
10
11
|
{%- endfor -%}
|
|
11
|
-
|
|
12
12
|
{%- for script in fertConfig.externalAssets.scripts %}
|
|
13
13
|
<script {%- for key, value in script %} {{ key }}="{{ value }}" {%- endfor %}></script>
|
|
14
14
|
{%- endfor -%}
|
|
15
|
-
|
|
16
15
|
</head>
|
|
17
16
|
<body {%- if auth.isAuthenticated %} class="is-signed-in" {% endif %}>
|
|
18
17
|
<section class="layout">
|
|
19
18
|
<div id="site-container" class="mds-site-container">
|
|
20
|
-
|
|
21
19
|
{%- if podletResponse.statusCode === 200 -%}
|
|
22
20
|
{{ podletResponse.result.headerHtml | safe }}
|
|
23
21
|
{%- else -%}
|
|
@@ -26,26 +24,21 @@
|
|
|
26
24
|
<pre>{{ podletResponse.result | dump(2) | safe }}</pre>
|
|
27
25
|
</div>
|
|
28
26
|
{%- endif %}
|
|
29
|
-
|
|
30
27
|
<main class="mds-main mds-padding-top-b5" role="main" id="main">
|
|
31
28
|
<div class="mds-wrapper">
|
|
32
29
|
{% block main %}Page does not override main block{% endblock %}
|
|
33
30
|
</div>
|
|
34
31
|
</main>
|
|
35
|
-
|
|
36
32
|
{% if podletResponse.statusCode === 200 -%}
|
|
37
33
|
{{ podletResponse.result.footerHtml | safe }}
|
|
38
34
|
{%- endif %}
|
|
39
|
-
|
|
40
35
|
</div>
|
|
41
36
|
</section>
|
|
42
|
-
|
|
43
37
|
{% if isFertDevelopment %}
|
|
44
38
|
<!-- development only - vite client/HMR & fert entry script -->
|
|
45
39
|
{{ viteClientScript | safe }}
|
|
46
40
|
{{ fertEntryScript | safe }}
|
|
47
41
|
{%- endif %}
|
|
48
|
-
|
|
49
42
|
{# Adding leaderboard placeholder to help with styling #}
|
|
50
43
|
<script type="text/javascript">
|
|
51
44
|
document.onreadystatechange = () => {
|