@madgex/fert 2.0.2 → 2.0.4

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,5 +1,5 @@
1
- const Path = require('path');
2
- const fs = require('fs/promises');
1
+ const Path = require('node:path');
2
+ const fs = require('node:fs/promises');
3
3
  const { log } = require('../../utils/logging');
4
4
 
5
5
  module.exports = async function buildExternalAssets(fertConfig) {
@@ -1,6 +1,6 @@
1
+ const Path = require('node:path');
2
+ const fs = require('node:fs/promises');
1
3
  const StyleDictionaryPackage = require('style-dictionary');
2
- const Path = require('path');
3
- const fs = require('fs/promises');
4
4
  const {
5
5
  registerTransforms,
6
6
  } = require('@madgex/design-system-v5/tasks/registerTransforms');
@@ -1,6 +1,6 @@
1
+ const Path = require('node:path');
2
+ const fs = require('node:fs/promises');
1
3
  const StyleDictionaryPackage = require('style-dictionary');
2
- const Path = require('path');
3
- const fs = require('fs/promises');
4
4
  const {
5
5
  registerTransforms,
6
6
  } = require('@madgex/design-system/tasks/registerTransforms');
@@ -102,7 +102,7 @@ module.exports = async function buildCssFromTokens(srcTokensPath, buildPath) {
102
102
  // Use StyleDictionary to build a tokens SCSS file
103
103
  const StyleDictionary = StyleDictionaryPackage.extend(styleDictionaryConfig);
104
104
 
105
- const tokenBaseFontSize = brandObj?.font?.size?.base; // will default to 16px if undefined
105
+ const tokenBaseFontSize = brandObj?.font?.size?.base?.value; // will default to 16px if undefined
106
106
  await registerTransforms(StyleDictionary, tokenBaseFontSize);
107
107
  await runSilently(StyleDictionary.buildAllPlatforms.bind(StyleDictionary));
108
108
 
@@ -1,4 +1,4 @@
1
- const path = require('path');
1
+ const path = require('node:path');
2
2
  const _ = require('lodash');
3
3
  const vite = require('vite');
4
4
  const updateBuildWithBundledDsCSS = require('./bundle-ds-css');
@@ -1,4 +1,4 @@
1
- const path = require('path');
1
+ const path = require('node:path');
2
2
  const { rimraf } = require('rimraf');
3
3
  const { resolveConfig } = require('../utils');
4
4
  const { log } = require('../utils/logging');
@@ -1,4 +1,4 @@
1
- const path = require('path');
1
+ const path = require('node:path');
2
2
  const chalk = require('chalk');
3
3
  const open = require('open');
4
4
  const chokidar = require('chokidar');
@@ -1,5 +1,5 @@
1
- const path = require('path');
2
- const fs = require('fs');
1
+ const path = require('node:path');
2
+ const fs = require('node:fs');
3
3
  const chalk = require('chalk');
4
4
  const prompts = require('prompts');
5
5
  const uuidValidator = require('uuid-validate');
@@ -1,5 +1,5 @@
1
- const fs = require('fs');
2
- const path = require('path');
1
+ const fs = require('node:fs');
2
+ const path = require('node:path');
3
3
  const Hoek = require('@hapi/hoek');
4
4
  const { log } = require('../../utils/logging');
5
5
  const axios = require('axios');
@@ -1,4 +1,4 @@
1
- const path = require('path');
1
+ const path = require('node:path');
2
2
  const Hoek = require('@hapi/hoek');
3
3
  const chalk = require('chalk');
4
4
  const { resolveConfig } = require('../utils');
@@ -38,7 +38,11 @@ module.exports = async (root, options) => {
38
38
  const apiKey = await getAwsParam(apiKeyParamPath);
39
39
 
40
40
  log.info(
41
- `Publishing ${chalk.cyan(localDir)} to ${chalk.green.bold(options.target)}`
41
+ `\nPublishing ${chalk.cyan(localDir)} to ${chalk.green.bold(
42
+ options.target
43
+ )} for ${chalk.green(fertConfig.client.brandName)} ${chalk.dim(
44
+ `(${fertConfig.clientPropertyId})`
45
+ )}\n`
42
46
  );
43
47
 
44
48
  // send to S3 using the Asset Store API
@@ -1,14 +1,25 @@
1
- // Fetch provides support for node 16 and lower
1
+ const path = require('node:path');
2
2
  const axios = require('axios');
3
3
  const { log } = require('../utils/logging');
4
- const storage = require('node-persist');
4
+ const { slug } = require('../utils/slug');
5
5
  const dayjs = require('dayjs');
6
6
  const duration = require('dayjs/plugin/duration');
7
- const { PROPERTY_ID_API, TMP_DIR } = require('../../constants');
7
+ const { PROPERTY_ID_API, TMP_DIR, VERSION } = require('../../constants');
8
8
  const chalk = require('chalk');
9
+ const flatCache = require('flat-cache');
10
+ const { diskCacheWithTtl } = require('./disk-cache-with-ttl');
9
11
 
10
12
  dayjs.extend(duration);
11
13
 
14
+ const flatCacheDoc = flatCache.load(
15
+ 'fert-cpid-cache',
16
+ path.resolve(`${TMP_DIR}/fert-cpid-cache-${slug(VERSION)}`)
17
+ );
18
+
19
+ const cache = new diskCacheWithTtl(flatCacheDoc, {
20
+ ttl: dayjs.duration(1, 'week').asMilliseconds(),
21
+ });
22
+
12
23
  exports.doCpidLookup = async (clientPropertyId) => {
13
24
  const API_URL = new URL(clientPropertyId, PROPERTY_ID_API).toString();
14
25
 
@@ -27,7 +38,6 @@ exports.doCpidLookup = async (clientPropertyId) => {
27
38
  throw Error(error.message);
28
39
  });
29
40
 
30
- // const { data: results } = await res.json();
31
41
  const { brandName, parentId: parentCpid } = results;
32
42
 
33
43
  return {
@@ -39,20 +49,15 @@ exports.doCpidLookup = async (clientPropertyId) => {
39
49
  };
40
50
 
41
51
  exports.cpidLookup = async (clientPropertyId) => {
42
- await storage.init({
43
- dir: `${TMP_DIR}/fert-cpid-cache`,
44
- ttl: dayjs.duration(1, 'week').asMilliseconds(),
45
- });
46
-
47
- const cache = await storage.getItem(clientPropertyId);
52
+ const value = cache.get(clientPropertyId);
48
53
 
49
- if (cache) {
50
- return cache;
54
+ if (value) {
55
+ return value;
51
56
  }
52
57
 
53
58
  const result = await this.doCpidLookup(clientPropertyId);
54
59
 
55
- await storage.updateItem(clientPropertyId, result);
60
+ cache.set(clientPropertyId, result);
56
61
 
57
62
  return result;
58
63
  };
@@ -0,0 +1,29 @@
1
+ class diskCacheWithTtl {
2
+ constructor(cache, options = { ttl: 0 }) {
3
+ this.cache = cache;
4
+ this.options = options;
5
+ }
6
+
7
+ set(key, value) {
8
+ this.cache.setKey(key, {
9
+ value,
10
+ expire: new Date().getTime() + this.options.ttl,
11
+ });
12
+
13
+ this.cache.save(true);
14
+ }
15
+
16
+ get(key) {
17
+ let cachedBlob = this.cache.getKey(key);
18
+
19
+ if (cachedBlob && new Date().getTime() > cachedBlob.expire) {
20
+ this.cache.removeKey(key);
21
+ cachedBlob = null;
22
+
23
+ this.cache.save(true);
24
+ }
25
+
26
+ return cachedBlob && cachedBlob.value;
27
+ }
28
+ }
29
+ exports.diskCacheWithTtl = diskCacheWithTtl;
@@ -1,15 +1,15 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
- const fsp = require('fs/promises');
1
+ const path = require('node:path');
2
+ const fs = require('node:fs');
4
3
  const { VERSION, SITE } = require('../../constants');
5
4
  const chalk = require('chalk');
6
5
  const uuidValidator = require('uuid-validate');
7
6
  const Hoek = require('@hapi/hoek');
8
7
  const { cpidLookup } = require('./cpid-lookup');
9
8
  const resolveExternalAssets = require('./resolve-external-assets');
9
+ const { log } = require('./logging');
10
10
 
11
11
  exports.printBanner = () => {
12
- console.log(chalk`\n{green.bold Fert} v${VERSION}\n`);
12
+ console.log(`\n${chalk.green.bold('Fert')} v${VERSION}`);
13
13
  };
14
14
 
15
15
  exports.resolveConfig = async (root, options = {}) => {
@@ -62,7 +62,7 @@ exports.loadConfigFromFile = (workingDir) => {
62
62
 
63
63
  return fertConfig;
64
64
  } catch (err) {
65
- this.log.error(
65
+ log.error(
66
66
  `Failed to load fert.config.js - ensure you're running fert on a branding repo & config exists.\n`
67
67
  );
68
68
 
@@ -78,7 +78,7 @@ exports.ensureTrailingSlash = (str) => {
78
78
 
79
79
  exports.exists = async (path) => {
80
80
  try {
81
- await fsp.access(path);
81
+ fs.access(path);
82
82
  return true;
83
83
  } catch {
84
84
  return false;
@@ -0,0 +1,6 @@
1
+ exports.slug = (txt) => {
2
+ return txt
3
+ .toLowerCase()
4
+ .replace(/\W+/g, '-')
5
+ .replace(/^-+|-+$/g, '');
6
+ };
package/constants.js CHANGED
@@ -1,6 +1,6 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const os = require('os');
1
+ const fs = require('node:fs');
2
+ const path = require('node:path');
3
+ const os = require('node:os');
4
4
 
5
5
  const { version: VERSION } = JSON.parse(
6
6
  fs.readFileSync(path.resolve(__dirname, './package.json')).toString()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madgex/fert",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Tool to help build the V6 branding",
5
5
  "bin": {
6
6
  "fert": "./bin/cli.js"
@@ -30,7 +30,7 @@
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": "^6.1.2",
33
+ "@madgex/design-system": "^6.1.4",
34
34
  "@madgex/design-system-v5": "npm:@madgex/design-system@^5.0.0",
35
35
  "@private/header-footer-podlet-server": "github:wiley/madgex-header-footer-podlet",
36
36
  "axios": "^1.6.2",
@@ -39,9 +39,9 @@
39
39
  "chokidar": "^3.5.3",
40
40
  "dayjs": "^1.11.10",
41
41
  "debug": "^4.3.4",
42
+ "flat-cache": "^4.0.0",
42
43
  "form-data": "^4.0.0",
43
44
  "lodash": "^4.17.21",
44
- "node-persist": "^3.1.3",
45
45
  "nunjucks": "^3.2.4",
46
46
  "open": "8.4.2",
47
47
  "ora": "5.4.1",
package/server/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const Hapi = require('@hapi/hapi');
2
2
  const Toys = require('@hapipal/toys');
3
- const path = require('path');
3
+ const path = require('node:path');
4
4
  const { log } = require('../bin/utils/logging');
5
5
  const podletServer = require('@private/header-footer-podlet-server');
6
6
  const {
@@ -1,5 +1,5 @@
1
1
  const Nunjucks = require('nunjucks');
2
- const path = require('path');
2
+ const path = require('node:path');
3
3
 
4
4
  module.exports = (server) => {
5
5
  const fertConfig = server.fertConfig();