build: Add a check-links tool

This commit is contained in:
Felix Rieseberg 2021-01-04 09:54:20 -08:00
parent 9dc1e422ff
commit 238b07b7dd
9 changed files with 65 additions and 29 deletions

View file

@ -9,9 +9,10 @@
"package": "electron-forge package", "package": "electron-forge package",
"make": "electron-forge make", "make": "electron-forge make",
"publish": "electron-forge publish", "publish": "electron-forge publish",
"lint": "prettier --write src/**/*.{ts,tsx}", "lint": "prettier --write src/**/*.{ts,tsx} && npm run check-links",
"less": "node ./tools/lessc.js", "less": "node ./tools/lessc.js",
"tsc": "tsc -p tsconfig.json --noEmit" "tsc": "tsc -p tsconfig.json --noEmit",
"check-links": "node tools/check-links.js"
}, },
"keywords": [], "keywords": [],
"author": "Felix Rieseberg, felix@felixrieseberg.com", "author": "Felix Rieseberg, felix@felixrieseberg.com",

View file

@ -16,19 +16,17 @@ export async function clearStorageData() {
return; return;
} }
await session.defaultSession.clearStorageData( await session.defaultSession.clearStorageData({
{ storages: [
storages: [ "appcache",
"appcache", "cookies",
"cookies", "filesystem",
"filesystem", "indexdb",
"indexdb", "localstorage",
"localstorage", "shadercache",
"shadercache", "websql",
"websql", "serviceworkers",
"serviceworkers", ],
], quotas: ["temporary", "persistent", "syncable"],
quotas: ["temporary", "persistent", "syncable"], });
}
);
} }

View file

@ -3,7 +3,7 @@ import * as path from "path";
export const CONSTANTS = { export const CONSTANTS = {
IMAGE_PATH: path.join(__dirname, "../../images/windows95.img"), IMAGE_PATH: path.join(__dirname, "../../images/windows95.img"),
IMAGE_DEFAULT_SIZE: 1073741824, // 1GB IMAGE_DEFAULT_SIZE: 1073741824, // 1GB
DEFAULT_STATE_PATH: path.join(__dirname, "../../images/default-state.bin") DEFAULT_STATE_PATH: path.join(__dirname, "../../images/default-state.bin"),
}; };
export const IPC_COMMANDS = { export const IPC_COMMANDS = {

View file

@ -1,11 +1,11 @@
import { ipcMain, app } from 'electron'; import { ipcMain, app } from "electron";
import * as path from "path"; import * as path from "path";
import { IPC_COMMANDS } from '../constants'; import { IPC_COMMANDS } from "../constants";
export function setupIpcListeners() { export function setupIpcListeners() {
ipcMain.handle(IPC_COMMANDS.GET_STATE_PATH, () => { ipcMain.handle(IPC_COMMANDS.GET_STATE_PATH, () => {
return path.join(app.getPath("userData"), "state-v2.bin") return path.join(app.getPath("userData"), "state-v2.bin");
}); });
ipcMain.handle(IPC_COMMANDS.APP_QUIT, () => { ipcMain.handle(IPC_COMMANDS.APP_QUIT, () => {

View file

@ -6,7 +6,7 @@ import { shouldQuit } from "./squirrel";
import { setupUpdates } from "./update"; import { setupUpdates } from "./update";
import { getOrCreateWindow } from "./windows"; import { getOrCreateWindow } from "./windows";
import { setupMenu } from "./menu"; import { setupMenu } from "./menu";
import { setupIpcListeners } from './ipc'; import { setupIpcListeners } from "./ipc";
/** /**
* Handle the app's "ready" event. This is essentially * Handle the app's "ready" event. This is essentially

View file

@ -1,7 +1,7 @@
import * as React from "react"; import * as React from "react";
import * as fs from "fs-extra"; import * as fs from "fs-extra";
import { getStatePath } from './utils/get-state-path'; import { getStatePath } from "./utils/get-state-path";
interface CardSettingsProps { interface CardSettingsProps {
bootFromScratch: () => void; bootFromScratch: () => void;

View file

@ -10,7 +10,7 @@ import { StartMenu } from "./start-menu";
import { CardSettings } from "./card-settings"; import { CardSettings } from "./card-settings";
import { EmulatorInfo } from "./emulator-info"; import { EmulatorInfo } from "./emulator-info";
import { CardDrive } from "./card-drive"; import { CardDrive } from "./card-drive";
import { getStatePath } from './utils/get-state-path'; import { getStatePath } from "./utils/get-state-path";
export interface EmulatorState { export interface EmulatorState {
currentUiCard: string; currentUiCard: string;

View file

@ -1,7 +1,7 @@
import { ipcRenderer } from 'electron'; import { ipcRenderer } from "electron";
import { IPC_COMMANDS } from '../../constants'; import { IPC_COMMANDS } from "../../constants";
let _statePath = ''; let _statePath = "";
export async function getStatePath(): Promise<string> { export async function getStatePath(): Promise<string> {
if (_statePath) { if (_statePath) {
@ -9,6 +9,5 @@ export async function getStatePath(): Promise<string> {
} }
const statePath = await ipcRenderer.invoke(IPC_COMMANDS.GET_STATE_PATH); const statePath = await ipcRenderer.invoke(IPC_COMMANDS.GET_STATE_PATH);
return _statePath = statePath; return (_statePath = statePath);
} }

38
tools/check-links.js Normal file
View file

@ -0,0 +1,38 @@
const fs = require('fs/promises')
const path = require('path')
const fetch = require('node-fetch')
const LINK_RGX = /(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?/g;
async function main() {
const readmePath = path.join(__dirname, '../README.md')
const readme = await fs.readFile(readmePath, 'utf-8')
const links = readme.match(LINK_RGX)
let failed = false
for (const link of links) {
try {
const response = await fetch(link, { method: 'HEAD' })
if (!response.ok) {
// If we're inside GitHub's release asset server, we just ran into AWS not allowing
// HEAD requests, which is different from a 404.
if (!response.url.startsWith('https://github-production-release-asset')) {
throw new Error (`HTTP Error Response: ${response.status} ${response.statusText}`)
}
}
console.log(`${link}`);
} catch (error) {
failed = true
console.log(`${link}\n${error}`)
}
}
if (failed) {
process.exit(-1);
}
}
main()