style: run prettier on pre-commit hook

This commit is contained in:
Stefan Rotsch
2023-06-01 16:43:09 +02:00
committed by Stefan Rotsch
parent b82d5a9da9
commit 9948712690
15 changed files with 50 additions and 45 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run lint && npm run build:scripts && git add dist_scripts
npm run lint && npm rum prettier && npm run build:scripts && git add dist_scripts

View File

@@ -41,8 +41,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs_1 = require("fs");
var xml_sitemap_1 = __importDefault(require("xml-sitemap"));
var jsdom_1 = require("jsdom");
var xml_sitemap_1 = __importDefault(require("xml-sitemap"));
var config_1 = require("../src/config");
var radar_1 = require("./generateJson/radar");
// Do this as the first thing so that any code reading it knows the right env.

View File

@@ -89,10 +89,10 @@ var fs_extra_1 = require("fs-extra");
var highlight_js_1 = __importDefault(require("highlight.js"));
var marked_1 = require("marked");
var path = __importStar(require("path"));
var config_1 = require("../../src/config");
var model_1 = require("../../src/model");
var paths_1 = require("../paths");
var file_1 = require("./file");
var config_1 = require("../../src/config");
marked_1.marked.setOptions({
highlight: function (code) { return highlight_js_1.default.highlightAuto(code).value; },
});
@@ -200,7 +200,7 @@ var addRevisionToItem = function (item, revision) {
body: "",
info: "",
angleFraction: Math.random(),
radiusFraction: Math.random()
radiusFraction: Math.random(),
}; }
var newItem = __assign(__assign(__assign({}, item), revision), { body: ignoreEmptyRevisionBody(revision, item) });
if (revisionCreatesNewHistoryEntry(revision, item)) {

View File

@@ -17,7 +17,7 @@ function isMobileViewport() {
return width < 1200;
}
exports.isMobileViewport = isMobileViewport;
exports.publicUrl = (process.env.PUBLIC_URL || "").replace(/\/$/, '') + "/";
exports.publicUrl = (process.env.PUBLIC_URL || "").replace(/\/$/, "") + "/";
function assetUrl(file) {
return exports.publicUrl + file;
}

View File

@@ -92,9 +92,11 @@ var filteredOnly = function (items, tags) {
};
exports.filteredOnly = filteredOnly;
var getTags = function (items) {
var tags = items.reduce(function (acc, item) {
var tags = items
.reduce(function (acc, item) {
return !item.tags ? acc : acc.concat(item.tags);
}, []).sort();
}, [])
.sort();
return Array.from(new Set(tags));
};
exports.getTags = getTags;

View File

@@ -20,7 +20,8 @@
"build:scripts": "tsc --project tsconfig.scripts.json",
"test": "react-scripts test --watchAll=false",
"ts:check": "tsc --noEmit",
"lint": "npm run ts:check && eslint src/**/*.tsx"
"lint": "npm run ts:check && eslint src/**/*.tsx",
"prettier": "prettier --write '{scripts,src}/**/*.{ts,tsx}'"
},
"dependencies": {
"@apideck/better-ajv-errors": "0.3.6",

View File

@@ -6,8 +6,8 @@ import {
readFileSync,
writeFileSync,
} from "fs";
import { JSDOM } from "jsdom";
import XmlSitemap from "xml-sitemap";
import { JSDOM } from 'jsdom';
import { publicUrl } from "../src/config";
import { createRadar } from "./generateJson/radar";
@@ -44,43 +44,42 @@ const createStaticFiles = async () => {
const sitemapOptions = {
lastmod: "now",
changefreq: "weekly",
}
};
sitemap.add(`${publicUrl}index.html`, sitemapOptions);
radar.items.forEach((item) => {
const targetPath = `build/${item.quadrant}/${item.name}.html`
copyFileSync(
"build/index.html",
targetPath
);
const targetPath = `build/${item.quadrant}/${item.name}.html`;
copyFileSync("build/index.html", targetPath);
JSDOM.fromFile(targetPath).then(dom => {
JSDOM.fromFile(targetPath).then((dom) => {
const document = dom.window.document;
const rootEl = document.getElementById("root")
const rootEl = document.getElementById("root");
if (rootEl) {
const textNode = document.createElement("div")
const textNode = document.createElement("div");
const bodyFragment = JSDOM.fragment(item.body);
textNode.appendChild(bodyFragment)
textNode.appendChild(bodyFragment);
const headlineNode = document.createElement("h1")
const headlineNode = document.createElement("h1");
const titleText = document.createTextNode(item.title);
headlineNode.appendChild(titleText)
headlineNode.appendChild(titleText);
rootEl.appendChild(headlineNode)
rootEl.appendChild(textNode)
rootEl.appendChild(headlineNode);
rootEl.appendChild(textNode);
} else {
console.warn('Element with ID "root" not found. Static site content will be empty.')
console.warn(
'Element with ID "root" not found. Static site content will be empty.'
);
}
writeFileSync(
targetPath,
dom.serialize()
);
writeFileSync(targetPath, dom.serialize());
});
sitemap.add(`${publicUrl}${item.quadrant}/${item.name}.html`, sitemapOptions);
sitemap.add(
`${publicUrl}${item.quadrant}/${item.name}.html`,
sitemapOptions
);
});
writeFileSync("build/sitemap.xml", sitemap.xml);

View File

@@ -5,6 +5,7 @@ import highlight from "highlight.js";
import { marked } from "marked";
import * as path from "path";
import { ConfigData, publicUrl } from "../../src/config";
import {
FlagType,
Item,
@@ -15,8 +16,6 @@ import {
import { appBuild } from "../paths";
import { getAllMarkdownFiles, radarPath } from "./file";
import { ConfigData, publicUrl } from "../../src/config";
marked.setOptions({
highlight: (code: any) => highlight.highlightAuto(code).value,
});
@@ -147,7 +146,7 @@ const addRevisionToItem = (
body: "",
info: "",
angleFraction: Math.random(),
radiusFraction: Math.random()
radiusFraction: Math.random(),
},
revision: Revision
): Item => {

2
scripts/types.d.ts vendored
View File

@@ -1 +1 @@
declare module 'xml-sitemap';
declare module "xml-sitemap";

View File

@@ -26,7 +26,8 @@ function generateCoordinates(
ringPadding = 0.7;
// radian between 0 and 90 degrees
const randomDegree = ((0.1 + (blip.angleFraction || Math.random()) * .8) * 90 * pi) / 180;
const randomDegree =
((0.1 + (blip.angleFraction || Math.random()) * 0.8) * 90 * pi) / 180;
// random distance from the centre of the radar, but within given ring. Also, with some "padding" so the points don't touch ring borders.
const radius = pointBetween(
previousRingRadius + ringPadding,

View File

@@ -7,7 +7,7 @@ import { QuadrantConfig } from "../../model";
const arcAngel = [
[(3 * Math.PI) / 2, (4 * Math.PI) / 2],
[0, Math.PI / 2],
[Math.PI, Math.PI * 3 / 2],
[Math.PI, (Math.PI * 3) / 2],
[Math.PI / 2, Math.PI],
];

View File

@@ -76,8 +76,8 @@ const RadarChart: React.FC<{
</g>
{Object.values(config.quadrantsMap).map((value, index) => {
console.log(value)
return null
console.log(value);
return null;
})}
{Object.values(config.quadrantsMap).map((value, index) => (
<QuadrantRings

View File

@@ -1,8 +1,8 @@
import { render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { item as testItem } from "./testData";
import Item from "./Item";
import { item as testItem } from "./testData";
describe("Item", () => {
it("Should render the item", () => {

View File

@@ -38,7 +38,8 @@ export function isMobileViewport() {
return width < 1200;
}
export const publicUrl = (process.env.PUBLIC_URL || "").replace(/\/$/, '') + "/";
export const publicUrl =
(process.env.PUBLIC_URL || "").replace(/\/$/, "") + "/";
export function assetUrl(file: string) {
return publicUrl + file;

View File

@@ -125,17 +125,19 @@ export const filteredOnly = (items: Item[], tags: Tag[] | string) => {
}
if (Array.isArray(tags)) {
return tags.every(tag => itemTags.includes(tag));
return tags.every((tag) => itemTags.includes(tag));
}
return itemTags.includes(tags);
});
}
};
export const getTags = (items: Item[]): Tag[] => {
const tags: Tag[] = items.reduce((acc: Tag[], item: Item) => {
const tags: Tag[] = items
.reduce((acc: Tag[], item: Item) => {
return !item.tags ? acc : acc.concat(item.tags);
}, []).sort();
}, [])
.sort();
return Array.from(new Set(tags));
};