fix: Sort out Ring enum typing issues

This commit is contained in:
Jarosław Marek
2021-05-04 20:24:20 +12:00
parent 622da055c7
commit 15feb9bc58
14 changed files with 138 additions and 75 deletions

View File

@@ -1,35 +1,58 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isMobileViewport = exports.translate = exports.getItemPageNames = exports.assetUrl = exports.rings = exports.quadrants = exports.radarNameShort = exports.radarName = void 0;
exports.assetUrl = exports.isMobileViewport = exports.showEmptyRings = exports.getItemPageNames = exports.chartConfig = exports.quadrantsMap = exports.homepageContent = exports.radarNameShort = exports.radarName = void 0;
const model_1 = require("./model");
exports.radarName = process.env.RADAR_NAME || 'AOE Technology Radar';
exports.radarNameShort = exports.radarName;
exports.quadrants = [
'languages-and-frameworks',
'methods-and-patterns',
'platforms-and-aoe-services',
'tools',
];
exports.rings = [
'all',
'adopt',
'trial',
'assess',
'hold'
];
// todo: fix
function assetUrl(file) {
return process.env.PUBLIC_URL + '/' + file;
// return `/techradar/assets/${file}`
}
exports.assetUrl = assetUrl;
exports.getItemPageNames = (items) => items.map(item => `${item.quadrant}/${item.name}`);
const messages = {
'languages-and-frameworks': 'Languages & Frameworks',
'methods-and-patterns': 'Methods & Patterns',
'platforms-and-aoe-services': 'Platforms and Operations',
'tools': 'Tools',
exports.homepageContent = model_1.HomepageOption.both; // by defaul show both versions so that people can choose which one they like more (or keep both)
// Quadrants positions start from the top left and go clockwise
exports.quadrantsMap = new Map([
['languages-and-frameworks', {
id: 'languages-and-frameworks',
displayName: 'Languages & Frameworks',
colour: '#84BFA4',
txtColour: '#444444',
position: 1,
description: "We've placed development languages (such as Scala or Golang) here, as well as more low-level development frameworks (such as Play or Symfony), which are useful for implementing custom software of all kinds."
}],
['methods-and-patterns', {
id: 'methods-and-patterns',
displayName: 'Methods & Patterns',
colour: '#248EA6',
txtColour: 'white',
position: 2,
description: 'Here we put information on methods and patterns concerning development, continuous x, testing, organization, architecture, etc.'
}],
['platforms-and-aoe-services', {
id: 'platforms-and-aoe-services',
displayName: 'Platforms and Operations',
colour: '#F25244',
txtColour: '#444444',
position: 3,
description: 'Here we include infrastructure platforms and services. We also use this category to communicate news about AOE services that we want all AOE teams to be aware of.'
}],
['tools', {
id: 'tools',
displayName: 'Tools',
colour: '#F2A25C',
txtColour: 'white',
position: 4,
description: 'Here we put different software tools - from small helpers to bigger software projects'
}]
]);
exports.chartConfig = {
size: 800,
scale: [-16, 16],
blipSize: 12,
ringsAttributes: [
{ radius: 8, arcWidth: 6 },
{ radius: 11, arcWidth: 4 },
{ radius: 14, arcWidth: 2 },
{ radius: 16, arcWidth: 2 }
]
};
exports.translate = (key) => (messages[key] || '-');
exports.getItemPageNames = (items) => items.map(item => `${item.quadrant}/${item.name}`);
exports.showEmptyRings = false;
function isMobileViewport() {
// return false for server side rendering
if (typeof window == 'undefined')
@@ -38,3 +61,8 @@ function isMobileViewport() {
return width < 1200;
}
exports.isMobileViewport = isMobileViewport;
function assetUrl(file) {
return process.env.PUBLIC_URL + '/' + file;
// return `/techradar/assets/${file}`
}
exports.assetUrl = assetUrl;

View File

@@ -1,6 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFirstLetter = exports.groupByFirstLetter = exports.groupByQuadrants = exports.featuredOnly = void 0;
exports.getFirstLetter = exports.groupByFirstLetter = exports.groupByQuadrants = exports.featuredOnly = exports.FlagType = exports.Ring = exports.HomepageOption = void 0;
var HomepageOption;
(function (HomepageOption) {
HomepageOption[HomepageOption["chart"] = 0] = "chart";
HomepageOption[HomepageOption["columns"] = 1] = "columns";
HomepageOption[HomepageOption["both"] = 2] = "both";
})(HomepageOption = exports.HomepageOption || (exports.HomepageOption = {}));
var Ring;
(function (Ring) {
Ring[Ring["all"] = 0] = "all";
Ring[Ring["adopt"] = 1] = "adopt";
Ring[Ring["trial"] = 2] = "trial";
Ring[Ring["assess"] = 3] = "assess";
Ring[Ring["hold"] = 4] = "hold";
})(Ring = exports.Ring || (exports.Ring = {}));
var FlagType;
(function (FlagType) {
FlagType["new"] = "new";
FlagType["changed"] = "changed";
FlagType["default"] = "default";
})(FlagType = exports.FlagType || (exports.FlagType = {}));
exports.featuredOnly = (items) => items.filter(item => item.featured);
exports.groupByQuadrants = (items) => items.reduce((quadrants, item) => (Object.assign(Object.assign({}, quadrants), { [item.quadrant]: addItemToQuadrant(quadrants[item.quadrant], item) })), {});
exports.groupByFirstLetter = (items) => {

2
bin/tasks/create-static.js Normal file → Executable file
View File

@@ -19,7 +19,7 @@ const config_1 = require("../src/config");
const radar = yield radar_1.createRadar();
fs_1.copyFileSync('build/index.html', 'build/overview.html');
fs_1.copyFileSync('build/index.html', 'build/help-and-about-tech-radar.html');
config_1.quadrants.forEach(quadrant => {
[...config_1.quadrantsMap.keys()].forEach(quadrant => {
fs_1.copyFileSync('build/index.html', 'build/' + quadrant + '.html');
fs_1.mkdirSync('build/' + quadrant);
});

View File

@@ -20,6 +20,7 @@ const marked_1 = __importDefault(require("marked"));
const highlight_js_1 = __importDefault(require("highlight.js"));
const config_1 = require("../src/config");
const file_1 = require("./file");
const model_1 = require("../src/model");
marked_1.default.setOptions({
highlight: code => highlight_js_1.default.highlightAuto(code).value,
});
@@ -35,11 +36,17 @@ exports.createRadar = () => __awaiter(void 0, void 0, void 0, function* () {
};
});
const checkAttributes = (fileName, attributes) => {
if (attributes.ring && !config_1.rings.includes(attributes.ring)) {
throw new Error(`Error: ${fileName} has an illegal value for 'ring' - must be one of ${config_1.rings}`);
const validRings = [];
for (var ring in model_1.Ring) {
if (isNaN(Number(ring))) {
validRings.push(ring);
}
}
if (attributes.quadrant && !config_1.quadrants.includes(attributes.quadrant)) {
throw new Error(`Error: ${fileName} has an illegal value for 'quadrant' - must be one of ${config_1.quadrants}`);
if (attributes.ring && !validRings.includes(attributes.ring)) {
throw new Error(`Error: ${fileName} has an illegal value for 'ring' - must be one of ${validRings}`);
}
if (attributes.quadrant && !config_1.quadrantsMap.has(attributes.quadrant)) {
throw new Error(`Error: ${fileName} has an illegal value for 'quadrant' - must be one of ${config_1.quadrantsMap.keys()}`);
}
if (!attributes.quadrant || attributes.quadrant === '') {
// throw new Error(`Error: ${fileName} has no 'quadrant' set`);
@@ -47,7 +54,9 @@ const checkAttributes = (fileName, attributes) => {
if (!attributes.title || attributes.title === '') {
attributes.title = path_1.default.basename(fileName);
}
return attributes;
return Object.assign(Object.assign({}, attributes), {
// Convert string representation of the ring into enum value
ring: model_1.Ring[attributes.ring] });
};
const createRevisionsFromFiles = (fileNames) => Promise.all(fileNames.map(fileName => {
return new Promise((resolve, reject) => {
@@ -94,12 +103,12 @@ const ignoreEmptyRevisionBody = (revision, item) => {
return revision.body;
};
const addRevisionToItem = (item = {
flag: 'default',
flag: model_1.FlagType.default,
featured: true,
revisions: [],
name: '',
title: '',
ring: 'trial',
ring: model_1.Ring.trial,
quadrant: '',
body: '',
info: '',
@@ -119,10 +128,10 @@ const isNewItem = (item, allReleases) => item.revisions.length === 1 && isInLast
const hasItemChanged = (item, allReleases) => item.revisions.length > 1 && isInLastRelease(item, allReleases);
const getItemFlag = (item, allReleases) => {
if (isNewItem(item, allReleases)) {
return 'new';
return model_1.FlagType.new;
}
if (hasItemChanged(item, allReleases)) {
return 'changed';
return model_1.FlagType.changed;
}
return 'default';
return model_1.FlagType.default;
};