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",
"make": "electron-forge make",
"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",
"tsc": "tsc -p tsconfig.json --noEmit"
"tsc": "tsc -p tsconfig.json --noEmit",
"check-links": "node tools/check-links.js"
},
"keywords": [],
"author": "Felix Rieseberg, felix@felixrieseberg.com",

View File

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

View File

@ -3,7 +3,7 @@ import * as path from "path";
export const CONSTANTS = {
IMAGE_PATH: path.join(__dirname, "../../images/windows95.img"),
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 = {

View File

@ -1,11 +1,11 @@
import { ipcMain, app } from 'electron';
import { ipcMain, app } from "electron";
import * as path from "path";
import { IPC_COMMANDS } from '../constants';
import { IPC_COMMANDS } from "../constants";
export function setupIpcListeners() {
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, () => {

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
import { ipcRenderer } from 'electron';
import { IPC_COMMANDS } from '../../constants';
import { ipcRenderer } from "electron";
import { IPC_COMMANDS } from "../../constants";
let _statePath = '';
let _statePath = "";
export async function getStatePath(): Promise<string> {
if (_statePath) {
@ -9,6 +9,5 @@ export async function getStatePath(): Promise<string> {
}
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()