Skip to content

Commit b1fb4f8

Browse files
committed
Rework cta validations
1 parent a509211 commit b1fb4f8

File tree

12 files changed

+312
-136
lines changed

12 files changed

+312
-136
lines changed

config/build.conf.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ const MANPAGE_NAME = 'mongosh.1.gz'
7575
*/
7676
const PACKAGE_VARIANT = process.env.PACKAGE_VARIANT;
7777

78+
const CTA_CONFIG = require(path.join(ROOT, 'config', 'cta-config.json'));
79+
80+
const CTA_CONFIG_SCHEMA = require(path.join(ROOT, 'config', 'cta-config.schema.json'));
81+
7882
/**
7983
* Export the configuration for the build.
8084
*/
@@ -194,4 +198,6 @@ module.exports = {
194198
downloadPath: path.resolve(TMP_DIR, 'manpage'),
195199
fileName: MANPAGE_NAME,
196200
},
201+
ctaConfig: CTA_CONFIG,
202+
ctaConfigSchema: CTA_CONFIG_SCHEMA,
197203
};

config/cta-config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$schema": "./cta-config.schema.json"
3+
}

config/cta-config.schema.json

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"$id": "https://mongodb.com/schemas/mongosh/cta-config",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"title": "CTAConfig",
5+
"type": "object",
6+
"properties": {
7+
"*": {
8+
"$ref": "#/definitions/GreetingCTADetails",
9+
"description": "The default CTA for all versions that don't have an explicit one defined."
10+
},
11+
"$schema": {
12+
"type": "string"
13+
}
14+
},
15+
"patternProperties": {
16+
"^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$": {
17+
"$ref": "#/definitions/GreetingCTADetails",
18+
"description": "The CTA for a specific version.",
19+
"$comment": "The property name must be a valid semver string."
20+
}
21+
},
22+
"additionalProperties": false,
23+
"definitions": {
24+
"GreetingCTADetails": {
25+
"type": "object",
26+
"additionalProperties": false,
27+
"properties": {
28+
"chunks": {
29+
"description": "The chunks that make up the CTA. They will be combined sequentially with no additional spacing added.",
30+
"items": {
31+
"properties": {
32+
"style": {
33+
"description": "The style to apply to the text. It must match the values from clr.ts/StyleDefinition.",
34+
"enum": [
35+
"reset",
36+
"bold",
37+
"italic",
38+
"underline",
39+
"fontDefault",
40+
"font2",
41+
"font3",
42+
"font4",
43+
"font5",
44+
"font6",
45+
"imageNegative",
46+
"imagePositive",
47+
"black",
48+
"red",
49+
"green",
50+
"yellow",
51+
"blue",
52+
"magenta",
53+
"cyan",
54+
"white",
55+
"grey",
56+
"gray",
57+
"bg-black",
58+
"bg-red",
59+
"bg-green",
60+
"bg-yellow",
61+
"bg-blue",
62+
"bg-magenta",
63+
"bg-cyan",
64+
"bg-white",
65+
"bg-grey",
66+
"bg-gray",
67+
"mongosh:warning",
68+
"mongosh:error",
69+
"mongosh:section-header",
70+
"mongosh:uri",
71+
"mongosh:filename",
72+
"mongosh:additional-error-info"
73+
],
74+
"type": "string"
75+
},
76+
"text": {
77+
"type": "string",
78+
"description": "The text in the chunk."
79+
}
80+
},
81+
"type": "object",
82+
"required": [
83+
"text"
84+
]
85+
},
86+
"type": "array"
87+
}
88+
},
89+
"required": [
90+
"chunks"
91+
]
92+
}
93+
}
94+
}

config/cta.conf.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/build/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"@mongodb-js/monorepo-tools": "^1.1.16",
7171
"@mongodb-js/signing-utils": "^0.3.7",
7272
"@octokit/rest": "^17.9.0",
73+
"ajv": "^8.17.1",
7374
"aws-sdk": "^2.674.0",
7475
"boxednode": "^2.4.3",
7576
"command-exists": "^1.2.9",

packages/build/src/config/config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Schema } from 'ajv';
12
import type { PackageInformationProvider } from '../packaging/package';
23
import type { PackageVariant } from './build-variant';
34

@@ -7,6 +8,18 @@ interface ManPageConfig {
78
fileName: string;
89
}
910

11+
// TODO: this is duplicated in update-notification-manager.ts
12+
export interface GreetingCTADetails {
13+
chunks: {
14+
text: string;
15+
style?: string; // TODO: this is actually clr.ts/StyleDefinition
16+
}[];
17+
}
18+
19+
export type CTAConfig = {
20+
[version: string | '*']: GreetingCTADetails;
21+
};
22+
1023
/**
1124
* Defines the configuration interface for the build system.
1225
*/
@@ -47,4 +60,6 @@ export interface Config {
4760
manpage?: ManPageConfig;
4861
isDryRun?: boolean;
4962
useAuxiliaryPackagesOnly?: boolean;
63+
ctaConfig: CTAConfig;
64+
ctaConfigSchema: Schema;
5065
}

0 commit comments

Comments
 (0)