@madgex/fert 2.1.0 → 2.2.2
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
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const simpleGit = require('simple-git');
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
const Hoek = require('@hapi/hoek');
|
|
4
|
+
const dedent = require('dedent');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Validates client property ID found in the fert config against the git url and the package name.
|
|
8
|
+
* All three should match. Mismatched CPIDs can lead to destructive publication.
|
|
9
|
+
*
|
|
10
|
+
* @function validateCpId
|
|
11
|
+
*
|
|
12
|
+
* @async
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} fertConfig an object containing client branding configuration.
|
|
15
|
+
*
|
|
16
|
+
* @returns {Boolean} Returns true if the CPIDs found in the fert config, git url, and package.json are the same
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
exports.cpIdMatchesGitRemote = async (fertConfig, workingDir) => {
|
|
21
|
+
// Validate that the working directory is a git repository
|
|
22
|
+
const simpleGitOptions = {
|
|
23
|
+
baseDir: fertConfig.workingDir,
|
|
24
|
+
};
|
|
25
|
+
const git = simpleGit(simpleGitOptions);
|
|
26
|
+
Hoek.assert(await git.checkIsRepo(), `${workingDir} is not a git repository`);
|
|
27
|
+
|
|
28
|
+
// Validate that the CPID in the fert config matches the CPID in the git remote URL
|
|
29
|
+
try {
|
|
30
|
+
const remoteUrl = await git.listRemote(['--get-url']);
|
|
31
|
+
const parts = remoteUrl.split('/');
|
|
32
|
+
const repo = parts[parts.length - 1].trim();
|
|
33
|
+
const remoteUrlCpid = repo.split('madgex-')[1].trim().replace('.git', '');
|
|
34
|
+
|
|
35
|
+
if (remoteUrlCpid == fertConfig.clientPropertyId) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Big ugly console message for high visibility.
|
|
40
|
+
console.log(
|
|
41
|
+
dedent`
|
|
42
|
+
${chalk.bgRed.bold(
|
|
43
|
+
'💀 💀 💀 Client Property IDs do not match! 💀 💀 💀 '
|
|
44
|
+
)}
|
|
45
|
+
${chalk.red('CPID from fert.config.js:')} ${fertConfig.clientPropertyId}
|
|
46
|
+
${chalk.red('CPID from Git remote URL:')} ${remoteUrlCpid}
|
|
47
|
+
${chalk.bgYellow.bold(
|
|
48
|
+
'🤓 Please ensure that the Client Property Id from the fert.config.js and the git remote match 🧐 '
|
|
49
|
+
)}\n
|
|
50
|
+
`
|
|
51
|
+
);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.log(error);
|
|
54
|
+
console.log(chalk.red('CPID could not be validated'));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return false;
|
|
58
|
+
};
|
package/bin/utils/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const chalk = require('chalk');
|
|
|
5
5
|
const uuidValidator = require('uuid-validate');
|
|
6
6
|
const Hoek = require('@hapi/hoek');
|
|
7
7
|
const { cpidLookup } = require('./cpid-lookup');
|
|
8
|
+
const { cpIdMatchesGitRemote } = require('./cpid-matches-git-remote');
|
|
8
9
|
const { resolveExternalAssets } = require('./resolve-external-assets');
|
|
9
10
|
const { log } = require('./logging');
|
|
10
11
|
const { CONFIG_API } = require('../../constants');
|
|
@@ -41,17 +42,32 @@ exports.resolveConfig = async (root, options = {}) => {
|
|
|
41
42
|
};
|
|
42
43
|
|
|
43
44
|
const workingDir = root ? path.resolve(root) : path.resolve(process.cwd());
|
|
45
|
+
|
|
44
46
|
const fertConfig = Hoek.applyToDefaults(
|
|
45
47
|
defaults,
|
|
46
48
|
this.loadConfigFromFile(workingDir)
|
|
47
49
|
);
|
|
48
|
-
const client = await cpidLookup(fertConfig.clientPropertyId, options);
|
|
49
50
|
|
|
51
|
+
// Check Fert cpid is valid
|
|
50
52
|
Hoek.assert(
|
|
51
53
|
uuidValidator(fertConfig.clientPropertyId),
|
|
52
54
|
`Invalid clientPropertyId specified in fert.config.js: ${fertConfig.clientPropertyId}`
|
|
53
55
|
);
|
|
54
56
|
|
|
57
|
+
// Check Fert cpid matches git's remote
|
|
58
|
+
|
|
59
|
+
const fertCpidMatchesGitRemote = await cpIdMatchesGitRemote(
|
|
60
|
+
fertConfig,
|
|
61
|
+
workingDir
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
Hoek.assert(
|
|
65
|
+
fertCpidMatchesGitRemote,
|
|
66
|
+
`CPID mismatch, please correct before retrying: ${fertConfig.clientPropertyId}`
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const client = await cpidLookup(fertConfig.clientPropertyId);
|
|
70
|
+
|
|
55
71
|
fertConfig.externalAssets = resolveExternalAssets(fertConfig.externalAssets);
|
|
56
72
|
|
|
57
73
|
fertConfig.config = await exports.getConfig(fertConfig.clientPropertyId, [
|
|
@@ -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.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Tool to help build the V6 branding",
|
|
5
5
|
"bin": {
|
|
6
6
|
"fert": "./bin/cli.js"
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"chokidar": "^3.5.3",
|
|
41
41
|
"dayjs": "^1.11.10",
|
|
42
42
|
"debug": "^4.3.4",
|
|
43
|
+
"dedent": "^1.5.3",
|
|
43
44
|
"flat-cache": "^4.0.0",
|
|
44
45
|
"form-data": "^4.0.0",
|
|
45
46
|
"lodash": "^4.17.21",
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"prompts": "^2.4.2",
|
|
50
51
|
"rimraf": "^5.0.5",
|
|
51
52
|
"sass": "^1.69.5",
|
|
53
|
+
"simple-git": "^3.24.0",
|
|
52
54
|
"simple-update-notifier": "^2.0.0",
|
|
53
55
|
"style-dictionary": "3.9.0",
|
|
54
56
|
"uuid-validate": "^0.0.3",
|