@madgex/fert 2.2.1 → 3.0.0

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.
@@ -1,7 +1,6 @@
1
1
  const path = require('node:path');
2
2
  const _ = require('lodash');
3
3
  const vite = require('vite');
4
- const updateBuildWithBundledDsCSS = require('./bundle-ds-css');
5
4
  const buildExternalAssets = require('./build-external-assets');
6
5
  const { log } = require('../../utils/logging');
7
6
 
@@ -34,9 +33,6 @@ module.exports = async (fertConfig, options = {}) => {
34
33
 
35
34
  await vite.build(viteConfig);
36
35
 
37
- // second build - this time with the DS included in the CSS bundle
38
- await updateBuildWithBundledDsCSS(viteConfig);
39
-
40
36
  await buildExternalAssets(fertConfig);
41
37
 
42
38
  log.success('Assets built.');
@@ -4,7 +4,6 @@ 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');
8
7
  const buildExternalAssets = require('./build-tasks/build-external-assets');
9
8
 
10
9
  module.exports = async (root, options = {}) => {
@@ -38,7 +37,6 @@ exports.buildTokens = async (fertConfig, options = {}) => {
38
37
  const tokenDist = path.join(workingDir, `/public/tokens/`);
39
38
 
40
39
  buildCssFromTokens(workingDir, tokenDist);
41
- buildCssFromTokensV5(workingDir, tokenDist);
42
40
  };
43
41
 
44
42
  exports.bundleEntry = bundleEntry;
@@ -4,7 +4,7 @@ const {
4
4
  } = require('@aws-sdk/client-cloudfront');
5
5
  const { persistentCacheWithTtl } = require('./persistent-cache-with-ttl');
6
6
  const assert = require('node:assert');
7
- const { ONE_WEEK } = require('../../constants');
7
+ const { ONE_WEEK, AWS_REGION } = require('../../constants');
8
8
  const { log } = require('../utils/logging');
9
9
 
10
10
  const cache = new persistentCacheWithTtl('cf-distribution-cache', {
@@ -12,7 +12,7 @@ const cache = new persistentCacheWithTtl('cf-distribution-cache', {
12
12
  });
13
13
 
14
14
  exports.doGetAllCloudFrontDistributions = async () => {
15
- const cloudfront = new CloudFrontClient();
15
+ const cloudfront = new CloudFrontClient({ region: AWS_REGION });
16
16
  const distributions = [];
17
17
 
18
18
  let Marker = '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madgex/fert",
3
- "version": "2.2.1",
3
+ "version": "3.0.0",
4
4
  "description": "Tool to help build the V6 branding",
5
5
  "bin": {
6
6
  "fert": "./bin/cli.js"
@@ -32,7 +32,6 @@
32
32
  "@hapi/vision": "^7.0.3",
33
33
  "@hapipal/toys": "^4.0.0",
34
34
  "@madgex/design-system": "^6.1.4",
35
- "@madgex/design-system-v5": "npm:@madgex/design-system@^5.0.0",
36
35
  "@private/header-footer-podlet-server": "github:wiley/madgex-header-footer-podlet",
37
36
  "axios": "^1.6.2",
38
37
  "cac": "^6.7.14",
@@ -30,7 +30,10 @@ module.exports = [
30
30
  method: 'get',
31
31
  path: '/design-system.css',
32
32
  handler: {
33
- file: require.resolve('@madgex/design-system/index.css'),
33
+ file: {
34
+ path: require.resolve('@madgex/design-system/index.css'),
35
+ confine: false, // allow access outside of the fert project (helpful during dev)
36
+ },
34
37
  },
35
38
  },
36
39
  ];
@@ -1,98 +0,0 @@
1
- const Path = require('node:path');
2
- const fs = require('node:fs/promises');
3
- const StyleDictionaryPackage = require('style-dictionary');
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
- };
@@ -1,74 +0,0 @@
1
- const path = require('node:path');
2
- const fsp = require('node:fs/promises');
3
- const _ = require('lodash');
4
- const vite = require('vite');
5
- const chalk = require('chalk');
6
-
7
- // TODO: delete me when DS is driven by CSS Custom Ppoperties
8
-
9
- module.exports = async (viteConfig) => {
10
- const dsBundledViteConfig = { ...viteConfig };
11
-
12
- // create ds-bundled vite build in-memory
13
- _.merge(dsBundledViteConfig, {
14
- logLevel: 'silent',
15
- build: {
16
- write: false,
17
- rollupOptions: {
18
- output: {
19
- assetFileNames: 'assets/[name]-ds-[hash].[ext]',
20
- },
21
- },
22
- },
23
- css: {
24
- preprocessorOptions: {
25
- scss: {
26
- additionalData: `
27
- @import "../../public/tokens/scss/index.scss";
28
- @import "@madgex/design-system-v5/src/scss/import.scss";
29
- `, // all scss processed files gets this injected at the top
30
- },
31
- },
32
- },
33
- });
34
-
35
- const dsBuild = await vite.build(dsBundledViteConfig);
36
- const { output: files } = Array.isArray(dsBuild) ? dsBuild[0] : dsBuild;
37
-
38
- // write just the CSS file to disk
39
- for (const file of files) {
40
- if (file.name !== 'style.css') {
41
- continue;
42
- }
43
- const cssFileContent = file.source;
44
- await fsp.writeFile(
45
- path.resolve('dist', file.fileName),
46
- cssFileContent,
47
- 'utf8'
48
- );
49
-
50
- // read the manifest.json
51
- const manifestPath = path.resolve('dist', 'manifest.json');
52
- const manifestStr = await fsp.readFile(manifestPath);
53
- const manifest = JSON.parse(manifestStr);
54
-
55
- // add entry to manifest.json
56
- const dsEntryName = file.name
57
- .split('.')
58
- .map((part, i) => (i === 0 ? `${part}-ds` : part))
59
- .join('.');
60
- manifest[dsEntryName] = { ...manifest[file.name] };
61
- manifest[dsEntryName].file = file.fileName;
62
-
63
- // write new manifest
64
- await fsp.writeFile(
65
- manifestPath,
66
- JSON.stringify(manifest, null, 2),
67
- 'utf8'
68
- );
69
-
70
- console.log(
71
- `\nUpdated build & manifest with DS-bundled CSS file: ${chalk.magenta(file.fileName)}\n` // prettier-ignore
72
- );
73
- }
74
- };