@madgex/fert 1.4.1 → 1.5.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.
@@ -1,6 +1,6 @@
1
1
  const Path = require('path');
2
2
  const fs = require('fs/promises');
3
- const { log } = require('../../utils');
3
+ const { log } = require('../../utils/logging');
4
4
 
5
5
  module.exports = async function buildExternalAssets(fertConfig) {
6
6
  const { externalAssets, workingDir } = fertConfig;
@@ -5,7 +5,8 @@ const {
5
5
  registerTransforms,
6
6
  } = require('@madgex/design-system/tasks/registerTransforms');
7
7
  const colorTransforms = require('@madgex/design-system/tasks/colorTransforms');
8
- const { ensureTrailingSlash, log, exists } = require('../../utils');
8
+ const { ensureTrailingSlash, exists } = require('../../utils');
9
+ const { log } = require('../../utils/logging');
9
10
  const { TMP_DIR } = require('../../../constants');
10
11
 
11
12
  const dsTokensPath = Path.dirname(
@@ -3,7 +3,7 @@ const _ = require('lodash');
3
3
  const vite = require('vite');
4
4
  const updateBuildWithBundledDsCSS = require('./bundle-ds-css');
5
5
  const buildExternalAssets = require('./build-external-assets');
6
- const { log } = require('../../utils');
6
+ const { log } = require('../../utils/logging');
7
7
 
8
8
  module.exports = async (fertConfig, options = {}) => {
9
9
  let dynamicOptions = {};
@@ -17,7 +17,7 @@ module.exports = async (fertConfig, options = {}) => {
17
17
 
18
18
  dynamicOptions = {
19
19
  root: path.resolve(fertConfig.workingDir),
20
- base: '/_/jobseekers-frontend/',
20
+ base: '/_/jobseekers-frontend/assets/',
21
21
  build: {
22
22
  cssCodeSplit: false, // important: to get a single, style.css file output
23
23
  outDir: path.resolve(fertConfig.workingDir, 'dist'),
@@ -1,6 +1,7 @@
1
1
  const path = require('path');
2
2
  const { rimraf } = require('rimraf');
3
- const { resolveConfig, log } = require('../utils');
3
+ const { resolveConfig } = require('../utils');
4
+ const { log } = require('../utils/logging');
4
5
  const bundleEntry = require('./build-tasks/bundle-entry');
5
6
  const buildCssFromTokens = require('./build-tasks/build-tokens');
6
7
  const buildExternalAssets = require('./build-tasks/build-external-assets');
@@ -2,7 +2,8 @@ const path = require('path');
2
2
  const chalk = require('chalk');
3
3
  const open = require('open');
4
4
  const chokidar = require('chokidar');
5
- const { resolveConfig, log } = require('../utils/index.js');
5
+ const { resolveConfig } = require('../utils/index.js');
6
+ const { log } = require('../utils/logging.js');
6
7
  const { devServer } = require('../../server');
7
8
  const { buildTokens, buildExternalAssets } = require('./build.js');
8
9
  const {
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
  const Hoek = require('@hapi/hoek');
4
- const { log } = require('../../utils');
4
+ const { log } = require('../../utils/logging');
5
5
  const axios = require('axios');
6
6
  const FormData = require('form-data');
7
7
  const ora = require('ora');
@@ -1,7 +1,8 @@
1
1
  const path = require('path');
2
2
  const Hoek = require('@hapi/hoek');
3
3
  const chalk = require('chalk');
4
- const { resolveConfig, log } = require('../utils');
4
+ const { resolveConfig } = require('../utils');
5
+ const { log } = require('../utils/logging');
5
6
  const getAwsParam = require('./publish-tasks/get-aws-parameter');
6
7
  const AssetStoreUploader = require('./publish-tasks/asset-store-uploader');
7
8
  const {
@@ -1,22 +1,33 @@
1
1
  // Fetch provides support for node 16 and lower
2
- const fetch = require('node-fetch-commonjs');
2
+ const axios = require('axios');
3
+ const { log } = require('../utils/logging');
3
4
  const storage = require('node-persist');
4
5
  const dayjs = require('dayjs');
5
6
  const duration = require('dayjs/plugin/duration');
6
7
  const { PROPERTY_ID_API, TMP_DIR } = require('../../constants');
8
+ const chalk = require('chalk');
7
9
 
8
10
  dayjs.extend(duration);
9
11
 
10
12
  exports.doCpidLookup = async (clientPropertyId) => {
11
13
  const API_URL = new URL(clientPropertyId, PROPERTY_ID_API).toString();
12
14
 
13
- const res = await fetch(API_URL);
14
-
15
- if (!res.ok) {
16
- throw Error(`Unable to lookup CPID [${clientPropertyId}]`);
17
- }
18
-
19
- const { data: results } = await res.json();
15
+ const results = await axios
16
+ .get(API_URL, { timeout: 5000 })
17
+ .then((res) => {
18
+ return res.data.data;
19
+ })
20
+ .catch((error) => {
21
+ log.error(
22
+ `Unable to lookup CPID [${chalk.yellow(
23
+ clientPropertyId
24
+ )}] from ${chalk.cyan(API_URL)}: ${chalk.redBright(error.message)}\n`
25
+ );
26
+
27
+ throw Error(error.message);
28
+ });
29
+
30
+ // const { data: results } = await res.json();
20
31
  const { brandName, parentId: parentCpid } = results;
21
32
 
22
33
  return {
@@ -33,10 +44,10 @@ exports.cpidLookup = async (clientPropertyId) => {
33
44
  ttl: dayjs.duration(1, 'week').asMilliseconds(),
34
45
  });
35
46
 
36
- const value = await storage.getItem(clientPropertyId);
47
+ const cache = await storage.getItem(clientPropertyId);
37
48
 
38
- if (value) {
39
- return value;
49
+ if (cache) {
50
+ return cache;
40
51
  }
41
52
 
42
53
  const result = await this.doCpidLookup(clientPropertyId);
@@ -3,8 +3,6 @@ const fs = require('fs');
3
3
  const fsp = require('fs/promises');
4
4
  const { VERSION } = require('../../constants');
5
5
  const chalk = require('chalk');
6
- const debug = require('debug');
7
- const debugLog = debug('fert');
8
6
  const uuidValidator = require('uuid-validate');
9
7
  const Hoek = require('@hapi/hoek');
10
8
  const { cpidLookup } = require('./cpid-lookup');
@@ -14,21 +12,6 @@ exports.printBanner = () => {
14
12
  console.log(chalk`\n{green.bold Fert} v${VERSION}\n`);
15
13
  };
16
14
 
17
- exports.log = {
18
- info: (...args) => {
19
- console.log(...args);
20
- },
21
- success: (...args) => {
22
- console.log(chalk.green.bold('✔'), ...args);
23
- },
24
- error: (...args) => {
25
- console.log(chalk.red.bold('✖'), ...args);
26
- },
27
- debug: (...args) => {
28
- debugLog(...args);
29
- },
30
- };
31
-
32
15
  exports.resolveConfig = async (root, options = {}) => {
33
16
  const defaults = {
34
17
  clientPropertyId: null,
@@ -0,0 +1,18 @@
1
+ const debug = require('debug');
2
+ const debugLog = debug('fert');
3
+ const chalk = require('chalk');
4
+
5
+ exports.log = {
6
+ info: (...args) => {
7
+ console.log(...args);
8
+ },
9
+ success: (...args) => {
10
+ console.log(chalk.green.bold('✔'), ...args);
11
+ },
12
+ error: (...args) => {
13
+ console.log(chalk.red.bold('✖'), ...args);
14
+ },
15
+ debug: (...args) => {
16
+ debugLog(...args);
17
+ },
18
+ };
package/constants.js CHANGED
@@ -14,6 +14,7 @@ module.exports = {
14
14
  AWS_REGION: 'eu-west-1',
15
15
  PROPERTY_ID_API:
16
16
  'https://property-identification-api.cs.madgexhosting.net/properties/',
17
+ ASSETS_API_URL: 'https://asset-store.job.madgexhosting.net',
17
18
  BRAND_JSON_FILENAME: 'brand.json',
18
19
  FERT_CONFIG_FILENAME: 'fert.config.js',
19
20
  ASSET_STORE_API: 'https://asset-store-api.{env}.madgexhosting.net/',
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@madgex/fert",
3
- "version": "1.4.1",
3
+ "version": "1.5.3",
4
4
  "description": "Tool to help build the V6 branding",
5
5
  "bin": {
6
6
  "fert": "./bin/cli.js"
7
7
  },
8
8
  "scripts": {
9
9
  "lint": "eslint .",
10
+ "format": "prettier --write .",
10
11
  "lint-staged": "lint-staged",
11
12
  "semantic-release": "semantic-release",
12
13
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -27,11 +28,11 @@
27
28
  "@hapi/hapi": "^21.3.2",
28
29
  "@hapi/hoek": "^11.0.2",
29
30
  "@hapi/inert": "^7.1.0",
30
- "@hapi/vision": "^7.0.2",
31
+ "@hapi/vision": "^7.0.3",
31
32
  "@hapipal/toys": "^4.0.0",
32
33
  "@madgex/design-system": "*",
33
34
  "@private/header-footer-podlet-server": "github:wiley/madgex-header-footer-podlet",
34
- "axios": "^1.4.0",
35
+ "axios": "^1.5.0",
35
36
  "cac": "^6.7.14",
36
37
  "chalk": "4.1.2",
37
38
  "chokidar": "^3.5.3",
@@ -39,31 +40,30 @@
39
40
  "debug": "^4.3.4",
40
41
  "form-data": "^4.0.0",
41
42
  "lodash": "^4.17.21",
42
- "node-fetch-commonjs": "^3.3.1",
43
43
  "node-persist": "^3.1.3",
44
44
  "nunjucks": "^3.2.4",
45
45
  "open": "8.4.2",
46
46
  "ora": "5.4.1",
47
47
  "prompts": "^2.4.2",
48
48
  "rimraf": "^5.0.1",
49
- "sass": "^1.64.1",
49
+ "sass": "^1.66.1",
50
50
  "simple-update-notifier": "^2.0.0",
51
51
  "style-dictionary": "^3.8.0",
52
52
  "uuid-validate": "^0.0.3",
53
- "vite": "^4.4.7",
53
+ "vite": "^4.4.9",
54
54
  "vite-plugin-static-copy": "^0.17.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@commitlint/cli": "^17.6.7",
58
- "@commitlint/config-conventional": "^17.6.7",
58
+ "@commitlint/config-conventional": "^17.7.0",
59
59
  "commitizen": "^4.3.0",
60
60
  "cz-conventional-changelog": "^3.3.0",
61
- "eslint": "^8.45.0",
62
- "eslint-config-prettier": "^8.8.0",
61
+ "eslint": "^8.49.0",
62
+ "eslint-config-prettier": "^9.0.0",
63
63
  "eslint-plugin-prettier": "^5.0.0",
64
64
  "husky": "^8.0.3",
65
- "lint-staged": "^13.2.3",
66
- "prettier": "^3.0.0",
65
+ "lint-staged": "^14.0.1",
66
+ "prettier": "^3.0.3",
67
67
  "semantic-release": "^21.1.1"
68
68
  },
69
69
  "peerDependencies": {
package/server/index.js CHANGED
@@ -1,9 +1,14 @@
1
1
  const Hapi = require('@hapi/hapi');
2
2
  const Toys = require('@hapipal/toys');
3
3
  const path = require('path');
4
- const { log } = require('../bin/utils');
4
+ const { log } = require('../bin/utils/logging');
5
5
  const podletServer = require('@private/header-footer-podlet-server');
6
- const { VERSION, DEFAULT_DEV_PORT } = require('../constants');
6
+ const {
7
+ VERSION,
8
+ DEFAULT_DEV_PORT,
9
+ PROPERTY_ID_API,
10
+ ASSETS_API_URL,
11
+ } = require('../constants');
7
12
 
8
13
  exports.devServer = async ({ start, fertConfig = {} } = {}) => {
9
14
  const server = Hapi.server({
@@ -33,6 +38,8 @@ exports.devServer = async ({ start, fertConfig = {} } = {}) => {
33
38
  isFert: true,
34
39
  isProd: false,
35
40
  templatePath: [path.resolve(fertConfig.workingDir, 'templates')],
41
+ clientPropertiesApi: PROPERTY_ID_API,
42
+ assetsApiUrl: ASSETS_API_URL,
36
43
  },
37
44
  routes: { prefix: '/_podlet' },
38
45
  });
@@ -5,6 +5,7 @@ module.exports = {
5
5
  path: '/{page*}',
6
6
  handler: async (request, h) => {
7
7
  const { page } = request.params;
8
+ const fertConfig = request.server.fertConfig();
8
9
 
9
10
  // we'll pass over the headers as ModHeader may be used but
10
11
  // remove the browsers 'accept-encoding' header otherwise
@@ -17,16 +18,11 @@ module.exports = {
17
18
  method: request.method,
18
19
  headers: filteredHeaders,
19
20
  auth: request.auth.isAuthenticated ? request.auth : null,
21
+ app: {
22
+ clientPropertyId: fertConfig.clientPropertyId,
23
+ },
20
24
  });
21
25
 
22
- if (podletResponse.statusCode === 200) {
23
- try {
24
- podletResponse.result = JSON.parse(podletResponse.result);
25
- } catch (err) {
26
- console.error('Unable to parse podlet response', err);
27
- }
28
- }
29
-
30
26
  return h.view(page, {
31
27
  auth: request.auth,
32
28
  podletResponse,
@@ -50,9 +50,9 @@
50
50
  <script type="text/javascript">
51
51
  document.onreadystatechange = () => {
52
52
  if (document.readyState === "interactive") {
53
- const body = document.querySelector('body');
53
+ const html = document.querySelector('html');
54
54
  const leaderboardContainer = document.querySelector('#ad-leaderboard');
55
- body.classList.add('js');
55
+ html.classList.add('js');
56
56
  if (leaderboardContainer) {
57
57
  const ad = document.createElement("div");
58
58
  ad.setAttribute("style", "width:728px;height:90px;background-color:#f0f8ff;border:1px solid #14f;padding:20px;text-align:center;");