Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions bin/gen-list.mts
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { exit } from 'node:process';
import type { ValidateFunction } from 'ajv';
import type { TaskList, TaskTier } from '@/types.js';
import ajv from '@/util/ajv.mjs';
import fmt from '@/util/formatter.mjs';

const [listName, tierString] = process.argv.slice(2);
const listTiers = tierString.split(',');

// type "casting" is required here for type guards to work
const validateTier = ajv.getSchema(
'http://osrs-taskman.com/task-tier.schema.json'
) as ValidateFunction<TaskTier>;

const listData: TaskList = {};
for (const tier of listTiers) {
const tierData = JSON.parse((await readFile(`./tiers/${tier}.json`)).toString());
if (!validateTier(tierData)) {
console.error(`Unable to locate JSON file for tier ${tier}`);
exit(1);
}
const tierData: TaskTier = JSON.parse((await readFile(`./tiers/${tier}.json`)).toString());

listData[tierData.name] = tierData.tasks;
}
Expand Down
13 changes: 1 addition & 12 deletions bin/validate-links.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { hash } from 'node:crypto';
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { basename } from 'node:path';
import { exit } from 'node:process';
import type { ValidateFunction } from 'ajv';
import { Glob } from 'glob';
import type { TaskTier } from '@/types.js';
import ajv from '@/util/ajv.mjs';

const CACHE_DIR = './.cache/links';
const IMAGE_CONTENT_TYPE_REGEX = /^image\/(png|gif)/;
Expand All @@ -32,11 +30,6 @@ async function validateLink(link: string, contentTypeRegex: RegExp): Promise<boo
return true;
}

// type "casting" is required here for type guards to work
const validateTier = ajv.getSchema(
'http://osrs-taskman.com/task-tier.schema.json'
) as ValidateFunction<TaskTier>;

// create cache directory if needed
await mkdir(CACHE_DIR, { recursive: true });

Expand All @@ -54,11 +47,7 @@ const imageLinks = new Set<string>();

const tierWalker = new Glob('./tiers/*.json', {});
for await (const tierFile of tierWalker) {
const tierData = JSON.parse((await readFile(tierFile)).toString());
if (!validateTier(tierData)) {
console.error(`File ${tierFile} does not match schema`);
exit(1);
}
const tierData: TaskTier = JSON.parse((await readFile(tierFile)).toString());

for (const task of tierData.tasks) {
wikiLinks.add(task.wikiLink);
Expand Down
8 changes: 2 additions & 6 deletions bin/validate-schema.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import type { TaskList, TaskTier } from '@/types.js';
import ajv from '@/util/ajv.mjs';

// type "casting" is required here for type guards to work
const validateTier = ajv.getSchema(
'http://osrs-taskman.com/task-tier.schema.json'
) as ValidateFunction<TaskTier>;
const validateList = ajv.getSchema(
'http://osrs-taskman.com/task-list.schema.json'
) as ValidateFunction<TaskList>;
const validateTier = ajv.getSchema('task-tier.schema.json') as ValidateFunction<TaskTier>;
const validateList = ajv.getSchema('task-list.schema.json') as ValidateFunction<TaskList>;

const allErrors = new Map<string, DefinedError[]>();

Expand Down
8 changes: 4 additions & 4 deletions schema/root.schema.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"$id": "http://osrs-taskman.com/root.schema.json",
"$id": "root.schema.json",
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"definitions": {
"task": {
"$ref": "task.schema.json#"
"$ref": "task.schema.json"
},
"task-tier": {
"$ref": "task-tier.schema.json#"
"$ref": "task-tier.schema.json"
},
"task-list": {
"$ref": "task-list.schema.json#"
"$ref": "task-list.schema.json"
}
}
}
4 changes: 2 additions & 2 deletions schema/task-list.schema.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"$id": "http://osrs-taskman.com/task-list.schema.json",
"$id": "task-list.schema.json",
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"$ref": "task.schema.json#"
"$ref": "task.schema.json"
}
}
}
4 changes: 2 additions & 2 deletions schema/task-tier.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$id": "http://osrs-taskman.com/task-tier.schema.json",
"$id": "task-tier.schema.json",
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"required": ["name", "tasks"],
Expand All @@ -12,7 +12,7 @@
"tasks": {
"type": "array",
"items": {
"$ref": "task.schema.json#"
"$ref": "task.schema.json"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion schema/task.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$id": "http://osrs-taskman.com/task.schema.json",
"$id": "task.schema.json",
"$schema": "http://json-schema.org/draft-07/schema",
"definitions": {
"diary-region": {
Expand Down
Loading