style: run prettier on pre-commit hook
This commit is contained in:
committed by
Stefan Rotsch
parent
b82d5a9da9
commit
9948712690
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
. "$(dirname "$0")/_/husky.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
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
var fs_1 = require("fs");
|
var fs_1 = require("fs");
|
||||||
var xml_sitemap_1 = __importDefault(require("xml-sitemap"));
|
|
||||||
var jsdom_1 = require("jsdom");
|
var jsdom_1 = require("jsdom");
|
||||||
|
var xml_sitemap_1 = __importDefault(require("xml-sitemap"));
|
||||||
var config_1 = require("../src/config");
|
var config_1 = require("../src/config");
|
||||||
var radar_1 = require("./generateJson/radar");
|
var radar_1 = require("./generateJson/radar");
|
||||||
// Do this as the first thing so that any code reading it knows the right env.
|
// Do this as the first thing so that any code reading it knows the right env.
|
||||||
|
|||||||
@@ -89,10 +89,10 @@ var fs_extra_1 = require("fs-extra");
|
|||||||
var highlight_js_1 = __importDefault(require("highlight.js"));
|
var highlight_js_1 = __importDefault(require("highlight.js"));
|
||||||
var marked_1 = require("marked");
|
var marked_1 = require("marked");
|
||||||
var path = __importStar(require("path"));
|
var path = __importStar(require("path"));
|
||||||
|
var config_1 = require("../../src/config");
|
||||||
var model_1 = require("../../src/model");
|
var model_1 = require("../../src/model");
|
||||||
var paths_1 = require("../paths");
|
var paths_1 = require("../paths");
|
||||||
var file_1 = require("./file");
|
var file_1 = require("./file");
|
||||||
var config_1 = require("../../src/config");
|
|
||||||
marked_1.marked.setOptions({
|
marked_1.marked.setOptions({
|
||||||
highlight: function (code) { return highlight_js_1.default.highlightAuto(code).value; },
|
highlight: function (code) { return highlight_js_1.default.highlightAuto(code).value; },
|
||||||
});
|
});
|
||||||
@@ -200,7 +200,7 @@ var addRevisionToItem = function (item, revision) {
|
|||||||
body: "",
|
body: "",
|
||||||
info: "",
|
info: "",
|
||||||
angleFraction: Math.random(),
|
angleFraction: Math.random(),
|
||||||
radiusFraction: Math.random()
|
radiusFraction: Math.random(),
|
||||||
}; }
|
}; }
|
||||||
var newItem = __assign(__assign(__assign({}, item), revision), { body: ignoreEmptyRevisionBody(revision, item) });
|
var newItem = __assign(__assign(__assign({}, item), revision), { body: ignoreEmptyRevisionBody(revision, item) });
|
||||||
if (revisionCreatesNewHistoryEntry(revision, item)) {
|
if (revisionCreatesNewHistoryEntry(revision, item)) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ function isMobileViewport() {
|
|||||||
return width < 1200;
|
return width < 1200;
|
||||||
}
|
}
|
||||||
exports.isMobileViewport = isMobileViewport;
|
exports.isMobileViewport = isMobileViewport;
|
||||||
exports.publicUrl = (process.env.PUBLIC_URL || "").replace(/\/$/, '') + "/";
|
exports.publicUrl = (process.env.PUBLIC_URL || "").replace(/\/$/, "") + "/";
|
||||||
function assetUrl(file) {
|
function assetUrl(file) {
|
||||||
return exports.publicUrl + file;
|
return exports.publicUrl + file;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,9 +92,11 @@ var filteredOnly = function (items, tags) {
|
|||||||
};
|
};
|
||||||
exports.filteredOnly = filteredOnly;
|
exports.filteredOnly = filteredOnly;
|
||||||
var getTags = function (items) {
|
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);
|
return !item.tags ? acc : acc.concat(item.tags);
|
||||||
}, []).sort();
|
}, [])
|
||||||
|
.sort();
|
||||||
return Array.from(new Set(tags));
|
return Array.from(new Set(tags));
|
||||||
};
|
};
|
||||||
exports.getTags = getTags;
|
exports.getTags = getTags;
|
||||||
|
|||||||
@@ -20,7 +20,8 @@
|
|||||||
"build:scripts": "tsc --project tsconfig.scripts.json",
|
"build:scripts": "tsc --project tsconfig.scripts.json",
|
||||||
"test": "react-scripts test --watchAll=false",
|
"test": "react-scripts test --watchAll=false",
|
||||||
"ts:check": "tsc --noEmit",
|
"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": {
|
"dependencies": {
|
||||||
"@apideck/better-ajv-errors": "0.3.6",
|
"@apideck/better-ajv-errors": "0.3.6",
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import {
|
|||||||
readFileSync,
|
readFileSync,
|
||||||
writeFileSync,
|
writeFileSync,
|
||||||
} from "fs";
|
} from "fs";
|
||||||
|
import { JSDOM } from "jsdom";
|
||||||
import XmlSitemap from "xml-sitemap";
|
import XmlSitemap from "xml-sitemap";
|
||||||
import { JSDOM } from 'jsdom';
|
|
||||||
|
|
||||||
import { publicUrl } from "../src/config";
|
import { publicUrl } from "../src/config";
|
||||||
import { createRadar } from "./generateJson/radar";
|
import { createRadar } from "./generateJson/radar";
|
||||||
@@ -44,43 +44,42 @@ const createStaticFiles = async () => {
|
|||||||
const sitemapOptions = {
|
const sitemapOptions = {
|
||||||
lastmod: "now",
|
lastmod: "now",
|
||||||
changefreq: "weekly",
|
changefreq: "weekly",
|
||||||
}
|
};
|
||||||
|
|
||||||
sitemap.add(`${publicUrl}index.html`, sitemapOptions);
|
sitemap.add(`${publicUrl}index.html`, sitemapOptions);
|
||||||
|
|
||||||
radar.items.forEach((item) => {
|
radar.items.forEach((item) => {
|
||||||
const targetPath = `build/${item.quadrant}/${item.name}.html`
|
const targetPath = `build/${item.quadrant}/${item.name}.html`;
|
||||||
copyFileSync(
|
copyFileSync("build/index.html", targetPath);
|
||||||
"build/index.html",
|
|
||||||
targetPath
|
|
||||||
);
|
|
||||||
|
|
||||||
JSDOM.fromFile(targetPath).then(dom => {
|
JSDOM.fromFile(targetPath).then((dom) => {
|
||||||
const document = dom.window.document;
|
const document = dom.window.document;
|
||||||
const rootEl = document.getElementById("root")
|
const rootEl = document.getElementById("root");
|
||||||
|
|
||||||
if (rootEl) {
|
if (rootEl) {
|
||||||
const textNode = document.createElement("div")
|
const textNode = document.createElement("div");
|
||||||
const bodyFragment = JSDOM.fragment(item.body);
|
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);
|
const titleText = document.createTextNode(item.title);
|
||||||
headlineNode.appendChild(titleText)
|
headlineNode.appendChild(titleText);
|
||||||
|
|
||||||
rootEl.appendChild(headlineNode)
|
rootEl.appendChild(headlineNode);
|
||||||
rootEl.appendChild(textNode)
|
rootEl.appendChild(textNode);
|
||||||
} else {
|
} 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(
|
writeFileSync(targetPath, dom.serialize());
|
||||||
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);
|
writeFileSync("build/sitemap.xml", sitemap.xml);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import highlight from "highlight.js";
|
|||||||
import { marked } from "marked";
|
import { marked } from "marked";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
|
||||||
|
import { ConfigData, publicUrl } from "../../src/config";
|
||||||
import {
|
import {
|
||||||
FlagType,
|
FlagType,
|
||||||
Item,
|
Item,
|
||||||
@@ -15,8 +16,6 @@ import {
|
|||||||
import { appBuild } from "../paths";
|
import { appBuild } from "../paths";
|
||||||
import { getAllMarkdownFiles, radarPath } from "./file";
|
import { getAllMarkdownFiles, radarPath } from "./file";
|
||||||
|
|
||||||
import { ConfigData, publicUrl } from "../../src/config";
|
|
||||||
|
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
highlight: (code: any) => highlight.highlightAuto(code).value,
|
highlight: (code: any) => highlight.highlightAuto(code).value,
|
||||||
});
|
});
|
||||||
@@ -147,7 +146,7 @@ const addRevisionToItem = (
|
|||||||
body: "",
|
body: "",
|
||||||
info: "",
|
info: "",
|
||||||
angleFraction: Math.random(),
|
angleFraction: Math.random(),
|
||||||
radiusFraction: Math.random()
|
radiusFraction: Math.random(),
|
||||||
},
|
},
|
||||||
revision: Revision
|
revision: Revision
|
||||||
): Item => {
|
): Item => {
|
||||||
|
|||||||
2
scripts/types.d.ts
vendored
2
scripts/types.d.ts
vendored
@@ -1 +1 @@
|
|||||||
declare module 'xml-sitemap';
|
declare module "xml-sitemap";
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ function generateCoordinates(
|
|||||||
ringPadding = 0.7;
|
ringPadding = 0.7;
|
||||||
|
|
||||||
// radian between 0 and 90 degrees
|
// 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.
|
// 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(
|
const radius = pointBetween(
|
||||||
previousRingRadius + ringPadding,
|
previousRingRadius + ringPadding,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { QuadrantConfig } from "../../model";
|
|||||||
const arcAngel = [
|
const arcAngel = [
|
||||||
[(3 * Math.PI) / 2, (4 * Math.PI) / 2],
|
[(3 * Math.PI) / 2, (4 * Math.PI) / 2],
|
||||||
[0, Math.PI / 2],
|
[0, Math.PI / 2],
|
||||||
[Math.PI, Math.PI * 3 / 2],
|
[Math.PI, (Math.PI * 3) / 2],
|
||||||
[Math.PI / 2, Math.PI],
|
[Math.PI / 2, Math.PI],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ const RadarChart: React.FC<{
|
|||||||
</g>
|
</g>
|
||||||
|
|
||||||
{Object.values(config.quadrantsMap).map((value, index) => {
|
{Object.values(config.quadrantsMap).map((value, index) => {
|
||||||
console.log(value)
|
console.log(value);
|
||||||
return null
|
return null;
|
||||||
})}
|
})}
|
||||||
{Object.values(config.quadrantsMap).map((value, index) => (
|
{Object.values(config.quadrantsMap).map((value, index) => (
|
||||||
<QuadrantRings
|
<QuadrantRings
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { render, screen } from "@testing-library/react";
|
import { render, screen } from "@testing-library/react";
|
||||||
import { MemoryRouter } from "react-router-dom";
|
import { MemoryRouter } from "react-router-dom";
|
||||||
|
|
||||||
import { item as testItem } from "./testData";
|
|
||||||
import Item from "./Item";
|
import Item from "./Item";
|
||||||
|
import { item as testItem } from "./testData";
|
||||||
|
|
||||||
describe("Item", () => {
|
describe("Item", () => {
|
||||||
it("Should render the item", () => {
|
it("Should render the item", () => {
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ export function isMobileViewport() {
|
|||||||
return width < 1200;
|
return width < 1200;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const publicUrl = (process.env.PUBLIC_URL || "").replace(/\/$/, '') + "/";
|
export const publicUrl =
|
||||||
|
(process.env.PUBLIC_URL || "").replace(/\/$/, "") + "/";
|
||||||
|
|
||||||
export function assetUrl(file: string) {
|
export function assetUrl(file: string) {
|
||||||
return publicUrl + file;
|
return publicUrl + file;
|
||||||
|
|||||||
10
src/model.ts
10
src/model.ts
@@ -125,17 +125,19 @@ export const filteredOnly = (items: Item[], tags: Tag[] | string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(tags)) {
|
if (Array.isArray(tags)) {
|
||||||
return tags.every(tag => itemTags.includes(tag));
|
return tags.every((tag) => itemTags.includes(tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemTags.includes(tags);
|
return itemTags.includes(tags);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export const getTags = (items: Item[]): Tag[] => {
|
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);
|
return !item.tags ? acc : acc.concat(item.tags);
|
||||||
}, []).sort();
|
}, [])
|
||||||
|
.sort();
|
||||||
|
|
||||||
return Array.from(new Set(tags));
|
return Array.from(new Set(tags));
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user