fix: resolve all issues in npm run check (#70)

Co-authored-by: Ax333l <main@axelen.xyz>
This commit is contained in:
afn 2023-02-27 16:16:56 -05:00 committed by GitHub
parent 8720546722
commit 458cf9bcc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 114 additions and 96 deletions

12
src/app.d.ts vendored
View File

@ -9,3 +9,15 @@ declare namespace App {
// interface Session {} // interface Session {}
// interface Stuff {} // interface Stuff {}
} }
declare module "*&picture" {
/**
* actual types
* taken from https://github.com/JonasKruckenberg/imagetools/issues/160#issuecomment-1009292026
* - code https://github.com/JonasKruckenberg/imagetools/blob/main/packages/core/src/output-formats.ts
* - docs https://github.com/JonasKruckenberg/imagetools/blob/main/docs/guide/getting-started.md#metadata
*/
const out;
export default out;
}

View File

@ -20,7 +20,7 @@ function makeStore(): Readable<RouterEvent> {
}); });
} else { } else {
// On client. // On client.
let current = new URL(location); let current = new URL(location.href);
// Return store that responds to navigation events. // Return store that responds to navigation events.
// The `navigating` store immediately "pushes" `null`. // The `navigating` store immediately "pushes" `null`.

View File

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { queries } from '$data/api'; import { queries } from '$data/api';
import { friendlyName } from '$lib/utils'; import { friendlyName } from '$util/friendlyName';
import { createQuery } from '@tanstack/svelte-query'; import { createQuery } from '@tanstack/svelte-query';
import Query from '$lib/components/Query.svelte'; import Query from '$lib/components/Query.svelte';

View File

@ -1,7 +1,4 @@
<script> <script>
import { fly } from 'svelte/transition';
import { quintOut } from 'svelte/easing';
import Button from '$lib/components/Button.svelte'; import Button from '$lib/components/Button.svelte';
</script> </script>
@ -51,10 +48,6 @@
padding-bottom: 0; padding-bottom: 0;
} }
h4 {
font-size: clamp(1rem, 1.2rem, 1.5rem);
}
br { br {
content: ' '; content: ' ';
} }

View File

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { queries } from '$data/api'; import { queries } from '$data/api';
import { dev_log } from '$lib/utils'; import { dev_log } from '$util/dev';
import RouterEvents from '$data/RouterEvents'; import RouterEvents from '$data/RouterEvents';
import { useQueryClient } from '@tanstack/svelte-query'; import { useQueryClient } from '@tanstack/svelte-query';

View File

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { horizontalSlide } from '$lib/utils'; import { horizontalSlide } from '$util/horizontalSlide';
import { fade } from 'svelte/transition'; import { fade } from 'svelte/transition';
import { expoOut } from 'svelte/easing'; import { expoOut } from 'svelte/easing';

View File

@ -7,17 +7,29 @@
</script> </script>
<button on:click> <button on:click>
<svelte:element {#if href}
this={href ? 'a' : 'div'} <a
{href} {href}
{target} {target}
class={type} {...$$restProps}
> class={type}
{#if icon} >
<img src="../icons/{icon}.svg" alt={icon} /> {#if icon}
{/if} <img src="../icons/{icon}.svg" alt={icon} />
<slot /> {/if}
</svelte:element> <slot />
</a>
{:else}
<div
{...$$restProps}
class={type}
>
{#if icon}
<img src="../icons/{icon}.svg" alt={icon} />
{/if}
<slot />
</div>
{/if}
</button> </button>
<style> <style>

View File

@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
// See: https://github.com/JonasKruckenberg/imagetools/blob/main/docs/directives.md#picture // See: https://github.com/JonasKruckenberg/imagetools/blob/main/docs/directives.md#picture
export let data; import type { Picture } from 'vite-imagetools';
export let data: Picture;
export let alt: string; export let alt: string;
</script> </script>

View File

@ -13,10 +13,10 @@
{#if status == 404} {#if status == 404}
<p>This page received a cease and desist letter from a multi-billion dollar tech company.</p> <p>This page received a cease and desist letter from a multi-billion dollar tech company.</p>
<br /> <br />
<Navigation href="/" is_selected={() => true}>Home</Navigation> <Navigation href="/">Home</Navigation>
{:else} {:else}
<p> <p>
{$page.error.message} {$page.error?.message}
</p> </p>
{/if} {/if}
</section> </section>

View File

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { friendlyName } from '$lib/utils'; import { friendlyName } from '$util/friendlyName';
import { slide, fade } from 'svelte/transition'; import { slide } from 'svelte/transition';
import { quintOut } from 'svelte/easing'; import { quintOut } from 'svelte/easing';
import type { Contributor } from '$lib/types'; import type { Contributor } from '$lib/types';
import ContributorButton from './ContributorPerson.svelte'; import ContributorButton from './ContributorPerson.svelte';

View File

@ -1,4 +1,4 @@
import type { PageServerLoad } from './$types'; import type { LayoutServerLoad } from './$types';
import { index_content } from './documentation.server'; import { index_content } from './documentation.server';
@ -7,4 +7,4 @@ import { index_content } from './documentation.server';
// If you can no longer prerender the docs, then you are going to have to move the load functions here to a prerendered server route like before and fetch them here. // If you can no longer prerender the docs, then you are going to have to move the load functions here to a prerendered server route like before and fetch them here.
export const prerender = true; export const prerender = true;
export const load: PageServerLoad = () => ({ tree: index_content() }); export const load: LayoutServerLoad = () => ({ tree: index_content() });

View File

@ -1,13 +1,10 @@
<script lang="ts"> <script lang="ts">
import type { PageData } from './$types'; import type { LayoutData } from './$types';
import DocsNavTree from './DocsNavTree.svelte'; import DocsNavTree from './DocsNavTree.svelte';
import { fly } from 'svelte/transition';
import { quintOut } from 'svelte/easing';
import Footer from '$layout/Footer.svelte'; import Footer from '$layout/Footer.svelte';
export let data: PageData; export let data: LayoutData;
</script> </script>
<section id="doc-section-main"> <section id="doc-section-main">

View File

@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { is_tree } from './documentation.shared'; import { is_tree, assert_is_info_node } from './documentation.shared';
import type { DocsTree } from './documentation.shared'; import type { DocsTree } from './documentation.shared';
import DocsNavNode from './DocsNavNode.svelte'; import DocsNavNode from './DocsNavNode.svelte';
@ -25,7 +25,7 @@
<!-- Recursion here is fine. We are not dealing with a tree the size of a linux root file system. --> <!-- Recursion here is fine. We are not dealing with a tree the size of a linux root file system. -->
<svelte:self tree={node} nested={nested + 1} /> <svelte:self tree={node} nested={nested + 1} />
{:else} {:else}
<DocsNavNode info={node} /> <DocsNavNode info={assert_is_info_node(node)} />
{/if} {/if}
{/each} {/each}
</ul> </ul>

View File

@ -1,12 +1,12 @@
import { is_tree } from './documentation.shared'; import { is_tree } from './documentation.shared';
import type { Document, DocsTree, DocsTreeNode, DocumentInfo } from './documentation.shared'; import type { Document, DocsTree, DocsTreeNode, DocumentInfo } from './documentation.shared';
import { browser, building } from '$app/environment'; import { browser } from '$app/environment';
import fs, { existsSync as exists } from 'fs'; import fs, { existsSync as exists } from 'fs';
import path from 'path'; import path from 'path';
import { parse as parse_md } from 'marked'; import { marked } from 'marked';
import AsciiDocProcessor from 'asciidoctor'; import AsciiDocProcessor from 'asciidoctor';
// This file does not work in a browser. // This file does not work in a browser.
@ -18,7 +18,7 @@ if (browser) {
const supported_formats: Map<string, (markup: string) => Document> = new Map(); const supported_formats: Map<string, (markup: string) => Document> = new Map();
supported_formats.set('md', (markup) => { supported_formats.set('md', (markup: string) => {
let lines = markup.split('\n'); let lines = markup.split('\n');
// Get and remove the first line. // Get and remove the first line.
@ -27,13 +27,13 @@ supported_formats.set('md', (markup) => {
const title = first_line.substring(2); const title = first_line.substring(2);
// Convert the rest to html // Convert the rest to html
const content = parse_md(lines.join('\n')); const content = marked(lines.join('\n'));
return { title, content }; return { title, content };
}); });
const asciidoctor = AsciiDocProcessor(); const asciidoctor = AsciiDocProcessor();
const adoc_fn = (markup) => { const adoc_fn = (markup: string) => {
// Get first line. // Get first line.
const first_line = markup.split('\n')[0]; const first_line = markup.split('\n')[0];
// Remove `= `. // Remove `= `.
@ -41,7 +41,7 @@ const adoc_fn = (markup) => {
// Convert it to html. Unlike markdown, we do not need to remove the first title heading. // Convert it to html. Unlike markdown, we do not need to remove the first title heading.
// NOTE: Maybe consider change the safe mode value. // NOTE: Maybe consider change the safe mode value.
const content = asciidoctor.convert(markup, { doctype: 'book' }); const content = asciidoctor.convert(markup, { doctype: 'book' }) as string;
return { title, content }; return { title, content };
}; };
@ -51,13 +51,7 @@ supported_formats.set('asciidoc', adoc_fn);
const supported_filetypes = [...supported_formats.keys()]; const supported_filetypes = [...supported_formats.keys()];
let docs_folder = process.env.REVANCED_DOCS_FOLDER; let docs_folder = process.env.REVANCED_DOCS_FOLDER ?? 'testing-docs';
if (docs_folder === undefined) {
if (building) {
console.warn('Using testing docs in production build');
}
docs_folder = 'testing-docs';
}
const ignored_items = ['assets']; const ignored_items = ['assets'];
@ -74,10 +68,10 @@ function get_ext(fname: string) {
function get_slug_of_node(node: DocsTreeNode): string { function get_slug_of_node(node: DocsTreeNode): string {
if (is_tree(node)) { if (is_tree(node)) {
return node.index.slug; return (node as DocsTree).index.slug;
} }
return node.slug; return (node as DocumentInfo).slug;
} }
/// Important functions /// Important functions
@ -95,8 +89,8 @@ export function get(slug: string): Document | null {
return null; return null;
} }
let full_path, let full_path: string,
ext, ext: string,
found = false; found = false;
// We are looking for the file `${target}.(any_supported_extension)`. Try to find it. // We are looking for the file `${target}.(any_supported_extension)`. Try to find it.
for (const item of fs.readdirSync(dir)) { for (const item of fs.readdirSync(dir)) {
@ -122,7 +116,7 @@ export function get(slug: string): Document | null {
} }
// Process the file and return. // Process the file and return.
return supported_formats.get(ext)(fs.readFileSync(full_path, 'utf-8')); return supported_formats.get(ext!!)!!(fs.readFileSync(full_path!!, 'utf-8'));
} }
// Get file information // Get file information
@ -139,7 +133,7 @@ function process_file(fname: string): DocumentInfo {
} }
const slug = parts.join('/'); const slug = parts.join('/');
const title = get(slug).title; const title = get(slug)!!.title;
return { slug, title }; return { slug, title };
} }
@ -147,7 +141,7 @@ function process_file(fname: string): DocumentInfo {
// Returns a document tree. // Returns a document tree.
function process_folder(dir: string): DocsTree | null { function process_folder(dir: string): DocsTree | null {
let tree: DocsTree = { let tree: DocsTree = {
index: null, index: null as any,
nodes: [] nodes: []
}; };
@ -184,7 +178,7 @@ function process_folder(dir: string): DocsTree | null {
} }
if (is_index_file) { if (is_index_file) {
tree.index = node; tree.index = node as DocumentInfo;
} else { } else {
tree.nodes.push(node); tree.nodes.push(node);
} }

View File

@ -1,22 +1,22 @@
/// Types /// Types
export interface Document { export interface Document {
title: string; title: string;
// HTML // HTML
content: string; content: string;
} }
export interface DocumentInfo { export interface DocumentInfo {
title: string; title: string;
slug: string; slug: string;
} }
// A tree representing the `docs` folder. // A tree representing the `docs` folder.
export interface DocsTree { export interface DocsTree {
// index.whatever // index.whatever
index: DocumentInfo; index: DocumentInfo;
// Everything except index.whatever // Everything except index.whatever
nodes: DocsTreeNode[]; nodes: DocsTreeNode[];
} }
export type DocsTreeNode = DocsTree | DocumentInfo; export type DocsTreeNode = DocsTree | DocumentInfo;
@ -24,5 +24,12 @@ export type DocsTreeNode = DocsTree | DocumentInfo;
/// Functions /// Functions
export function is_tree(node: DocsTreeNode) { export function is_tree(node: DocsTreeNode) {
return node.hasOwnProperty('nodes'); return Object.prototype.hasOwnProperty.call(node, 'nodes');
}
export function assert_is_info_node(v: DocsTreeNode) {
if (is_tree(v)) {
throw new Error('Value is not an info node.');
}
return v as DocumentInfo;
} }

View File

@ -23,7 +23,7 @@
<p>Patch your favourite apps, right on your device.</p> <p>Patch your favourite apps, right on your device.</p>
<div class="buttons"> <div class="buttons">
<Query {query} let:data> <Query {query} let:data>
<Button kind="primary" icon="download" href={data.assets[0].url} target="_blank"> <Button kind="primary" icon="download" href={data.assets[0].url} download>
{data.version} {data.version}
</Button> </Button>
</Query> </Query>

View File

@ -2,7 +2,7 @@
import { slide, fade } from 'svelte/transition'; import { slide, fade } from 'svelte/transition';
import { quintOut } from 'svelte/easing'; import { quintOut } from 'svelte/easing';
import type { Patch } from '$lib/types'; import type { Patch } from '$lib/types';
import { friendlyName } from '$lib/utils'; import { friendlyName } from '$util/friendlyName';
export let patch: Patch; export let patch: Patch;
const hasPatchOptions = !!patch.options.length; const hasPatchOptions = !!patch.options.length;
@ -26,7 +26,7 @@
</div> </div>
<h5>{patch.description}</h5> <h5>{patch.description}</h5>
<ul class="info-container"> <ul class="info-container">
{#each patch.compatiblePackages as pkg, i} {#each patch.compatiblePackages as pkg}
<a <a
href="https://play.google.com/store/apps/details?id={pkg.name}" href="https://play.google.com/store/apps/details?id={pkg.name}"
target="_blank" target="_blank"

View File

@ -25,7 +25,7 @@
let searchTerm: string; let searchTerm: string;
let searchTermFiltered: string; let searchTermFiltered: string;
let timeout: any = null; let timeout: ReturnType<typeof setTimeout>;
let mobilePackages = false; let mobilePackages = false;
function checkCompatibility(patch: Patch, pkg: string) { function checkCompatibility(patch: Patch, pkg: string) {

8
src/util/dev.ts Normal file
View File

@ -0,0 +1,8 @@
import { dev } from '$app/environment';
// console.log, but only if in dev environment.
export function dev_log(part: string, ...args: any[]) {
if (dev) {
console.log(`[${part}]:`, ...args);
}
}

14
src/util/friendlyName.ts Normal file
View File

@ -0,0 +1,14 @@
export function friendlyName(text: string): string {
return text
.replace(/-/g, ' ')
.replace(/revanced\/revanced/g, '')
.replace(/revanced/g, 'ReVanced')
.replace(/\bcli\b/g, 'CLI')
.replace(/api/g, 'API')
.replace(/microg/g, 'MicroG')
.replace(/hdr/g, 'HDR')
.replace(/sponsorblock/g, 'SponsorBlock')
.replace(/tiktok/g, 'TikTok')
.replace(/vr/g, 'VR')
.replace(/(?:^|\s)\S/g, (x: string) => x.toUpperCase());
}

View File

@ -1,28 +1,6 @@
import { dev } from '$app/environment'; // @ts-nocheck
import { cubicOut } from 'svelte/easing'; import { cubicOut } from 'svelte/easing';
// console.log, but only if in dev environment.
export function dev_log(part: string, ...args) {
if (dev) {
console.log(`[${part}]:`, ...args);
}
}
export function friendlyName(text: string): string {
return text
.replace(/-/g, ' ')
.replace(/revanced\/revanced/g, '')
.replace(/revanced/g, 'ReVanced')
.replace(/\bcli\b/g, 'CLI')
.replace(/api/g, 'API')
.replace(/microg/g, 'MicroG')
.replace(/hdr/g, 'HDR')
.replace(/sponsorblock/g, 'SponsorBlock')
.replace(/tiktok/g, 'TikTok')
.replace(/vr/g, 'VR')
.replace(/(?:^|\s)\S/g, (x: string) => x.toUpperCase());
}
// stolen from https://svelte.dev/repl/6d5239f09b0b4dc6aafeb70606a0fe94?version=3.46.4 // stolen from https://svelte.dev/repl/6d5239f09b0b4dc6aafeb70606a0fe94?version=3.46.4
// please add this svelte thanks ily <3 // please add this svelte thanks ily <3
export function horizontalSlide( export function horizontalSlide(

View File

@ -16,7 +16,8 @@
"$lib": ["src/lib"], "$lib": ["src/lib"],
"$lib/*": ["./src/lib/*"], "$lib/*": ["./src/lib/*"],
"$layout/*": ["./src/layout/*"], "$layout/*": ["./src/layout/*"],
"$images/*": ["./images/*"] "$images/*": ["./images/*"],
"$util/*": ["./src/util/*"]
} }
} }
} }

View File

@ -10,7 +10,8 @@ const config = {
alias: { alias: {
$images: path.resolve('./images'), $images: path.resolve('./images'),
$data: path.resolve('./src/data'), $data: path.resolve('./src/data'),
$layout: path.resolve('./src/layout') $layout: path.resolve('./src/layout'),
$util: path.resolve('./src/util')
} }
} }
}; };