@madgex/fert 5.0.0 → 5.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/README.md CHANGED
@@ -91,7 +91,7 @@ e.g.
91
91
 
92
92
  ```js
93
93
  module.exports = {
94
- name: 'jobseekers-frontend',
94
+ serviceName: 'jobseekers-frontend',
95
95
  entry: './src/index.js',
96
96
  externalAssets: {
97
97
  links: [],
@@ -9,13 +9,10 @@ const { validateLocalConfigs } = require('../utils/configs.js');
9
9
 
10
10
  module.exports = async (options = {}) => {
11
11
  const fertConfig = await resolveConfig(options);
12
- await validateLocalConfigs(
13
- {
14
- workingDir: fertConfig.rootDir,
15
- clientPropertyId: fertConfig.clientPropertyId,
16
- },
17
- { throwable: true }
18
- );
12
+ await validateLocalConfigs({
13
+ workingDir: fertConfig.rootDir,
14
+ clientPropertyId: fertConfig.clientPropertyId,
15
+ });
19
16
 
20
17
  if (!options.only) {
21
18
  await rimraf(path.resolve(fertConfig.workingDir, 'dist'));
@@ -24,7 +24,11 @@ module.exports = async (options = {}) => {
24
24
  )}\n`
25
25
  );
26
26
 
27
- await validateLocalConfigs(fertConfig);
27
+ await validateLocalConfigs({
28
+ workingDir: fertConfig.rootDir,
29
+ clientPropertyId: fertConfig.clientPropertyId,
30
+ throwable: false,
31
+ });
28
32
  await buildTokens(fertConfig);
29
33
 
30
34
  const fertConfigDir = await findFertConfigDir();
@@ -32,7 +36,11 @@ module.exports = async (options = {}) => {
32
36
  // watch local configs - revalidate on change
33
37
  const configsPath = path.resolve(fertConfigDir, './config/*.json');
34
38
  chokidar.watch(configsPath, { ignoreInitial: true }).on('all', async () => {
35
- await validateLocalConfigs(fertConfig);
39
+ await validateLocalConfigs({
40
+ workingDir: fertConfig.rootDir,
41
+ clientPropertyId: fertConfig.clientPropertyId,
42
+ throwable: false,
43
+ });
36
44
  });
37
45
 
38
46
  // watch brand.json & fert.config.js - refresh on change
@@ -84,17 +84,16 @@ module.exports = async (options) => {
84
84
  }
85
85
  // validate & upload local configs to configuration API
86
86
  if (!options.dryRun) {
87
- await updateProjectConfigs(fertConfig, {
87
+ await updateProjectConfigs({
88
+ workingDir: fertConfig.rootDir,
89
+ clientPropertyId: fertConfig.clientPropertyId,
88
90
  environment: fertConfig.currBranch === 'master' ? 'production' : 'dev',
89
91
  });
90
92
  } else {
91
- await validateLocalConfigs(
92
- {
93
- workingDir: fertConfig.rootDir,
94
- clientPropertyId: fertConfig.clientPropertyId,
95
- },
96
- { throwable: true }
97
- );
93
+ await validateLocalConfigs({
94
+ workingDir: fertConfig.rootDir,
95
+ clientPropertyId: fertConfig.clientPropertyId,
96
+ });
98
97
  }
99
98
 
100
99
  log.success(
@@ -9,9 +9,10 @@ const { CONFIG_DIR } = require('../../constants');
9
9
  /**
10
10
  * Validates the local configuration files against the provided schema.
11
11
  *
12
- * @param {Object} fertConfig - The project config.
13
- * @param {Object} options - The options object.
14
- * @param {boolean} options.catch - Whether to catch validation errors or just log them.
12
+ * @param {Object} options - required, The options object.
13
+ * @param {string} options.workingDir - required, Working dir for configs - should usually be 'root' where fert.config.js is
14
+ * @param {string} options.clientPropertyId - required, clientPropertyId
15
+ * @param {boolean} options.throwable - default: true, Whether to throw validation errors or just log them.
15
16
  *
16
17
  * @returns {Promise<void>} - Returns a promise that resolves if all configurations are valid.
17
18
  * @throws {Error} - Throws an error if any configuration is invalid.
@@ -19,7 +20,7 @@ const { CONFIG_DIR } = require('../../constants');
19
20
  const validateLocalConfigs = async ({
20
21
  workingDir,
21
22
  clientPropertyId,
22
- throwable = false,
23
+ throwable = true,
23
24
  }) => {
24
25
  Hoek.assert(clientPropertyId, 'clientPropertyId is required');
25
26
  Hoek.assert(workingDir, 'workingDir is required');
@@ -97,6 +98,12 @@ const getConfigAPI = async ({
97
98
  return api;
98
99
  };
99
100
 
101
+ /**
102
+ * loading all configs from a directory (usually root /configs folder)
103
+ *
104
+ * @param {string} workingDir
105
+ * @returns {Promise<Object>} - Object map of configs loaded from files {filename:configJSON,...}
106
+ */
100
107
  const loadLocalConfigs = (workingDir) => {
101
108
  const dir = path.join(workingDir, CONFIG_DIR);
102
109
  const configs = {};
@@ -130,7 +137,10 @@ const loadLocalConfigs = (workingDir) => {
130
137
  /**
131
138
  * Handles the removal and setting of project configs in the Configuration API.
132
139
  *
133
- * @param {Object} fertConfig - The project config.
140
+ * @param {Object} options - required, The options object.
141
+ * @param {string} options.workingDir - required, Working dir for configs - should usually be 'root' where fert.config.js is
142
+ * @param {string} options.clientPropertyId - required, clientPropertyId
143
+ * @param {string} options.environment - default=production, clientPropertyId
134
144
  *
135
145
  * @returns {Promise<boolean>} - Returns a promise that resolves to true if the update is successful.
136
146
  */
@@ -140,6 +150,7 @@ const updateProjectConfigs = async ({
140
150
  environment = 'production',
141
151
  } = {}) => {
142
152
  Hoek.assert(clientPropertyId, 'clientPropertyId is required');
153
+ Hoek.assert(workingDir, 'workingDir is required');
143
154
 
144
155
  const dir = path.join(workingDir, CONFIG_DIR);
145
156
  let spinner;
@@ -151,10 +162,7 @@ const updateProjectConfigs = async ({
151
162
  }
152
163
 
153
164
  try {
154
- await validateLocalConfigs(
155
- { clientPropertyId, workingDir },
156
- { catch: false }
157
- );
165
+ await validateLocalConfigs({ clientPropertyId, workingDir });
158
166
  const api = await getConfigAPI({ clientPropertyId, environment });
159
167
  spinner = ora('Fetching local configs').start();
160
168
 
@@ -9,13 +9,14 @@ describe('configs', () => {
9
9
  it('logs debug message if config directory does not exist', async (t) => {
10
10
  const fsSpy = t.mock.method(fs, 'existsSync');
11
11
  const logSpy = t.mock.method(log, 'debug');
12
- const fertConfig = {
13
- workingDir: '/non/existent/dir',
14
- clientPropertyId: 'cpid',
15
- };
12
+ const workingDir = '/non/existent/dir';
13
+ const clientPropertyId = 'cpid';
16
14
  let calls;
17
15
 
18
- await validateLocalConfigs(fertConfig);
16
+ await validateLocalConfigs({
17
+ workingDir,
18
+ clientPropertyId,
19
+ });
19
20
 
20
21
  calls = fsSpy.mock.calls;
21
22
  assert.strictEqual(calls[0].arguments[0], '/non/existent/dir/config');
@@ -31,13 +32,14 @@ describe('configs', () => {
31
32
  it('logs debug message if config directory does not exist', async (t) => {
32
33
  const fsSpy = t.mock.method(fs, 'existsSync');
33
34
  const logSpy = t.mock.method(log, 'debug');
34
- const fertConfig = {
35
- workingDir: '/non/existent/dir',
36
- clientPropertyId: 'cpid',
37
- };
35
+ const workingDir = '/non/existent/dir';
36
+ const clientPropertyId = 'cpid';
38
37
  let calls;
39
38
 
40
- await updateProjectConfigs(fertConfig);
39
+ await updateProjectConfigs({
40
+ workingDir,
41
+ clientPropertyId,
42
+ });
41
43
 
42
44
  calls = fsSpy.mock.calls;
43
45
  assert.strictEqual(calls[0].arguments[0], '/non/existent/dir/config');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madgex/fert",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "Tool to help build the V6 branding",
5
5
  "bin": {
6
6
  "fert": "./bin/cli.js"
@@ -38,7 +38,6 @@
38
38
  "cac": "^6.7.14",
39
39
  "chalk": "4.1.2",
40
40
  "chokidar": "^3.5.3",
41
- "dayjs": "^1.11.13",
42
41
  "debug": "^4.4.0",
43
42
  "dedent": "^1.5.3",
44
43
  "find-up-simple": "^1.0.0",