Skip to content

Commit

Permalink
Refactor read/write logics
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore committed May 3, 2024
1 parent 1c8b26b commit 0e5d99b
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 54 deletions.
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ lint:
deno lint -q

add:
cd source && deno run --allow-env --allow-read --allow-write add.ts "$(anchor)" "$(name)" "$(website)"
deno run --allow-env --allow-read --allow-write source/add.ts

add-platform:
cd source && deno run --allow-env --allow-read --allow-write add-platform.ts "$(anchor)" "$(name)" "$(badge)" "$(hostnames)"
deno run --allow-env --allow-read --allow-write source/add-platform.ts

check:
cd source && deno run --allow-env --allow-read check.ts
deno run --allow-env --allow-read source/check.ts

fix:
cd source && deno run --allow-env --allow-read --allow-write check.ts --fix
deno run --allow-env --allow-read --allow-write source/check.ts --fix

build:
cd source && deno run --allow-env --allow-read --allow-write build.ts
deno run --allow-env --allow-read --allow-write source/build.ts

reset:
cd source && deno run --allow-env --allow-read --allow-write reset.ts
deno run --allow-env --allow-read --allow-write source/reset.ts

search:
cd source && deno run --allow-env --allow-read search.ts "$(anchor)" "$(name)"
deno run --allow-env --allow-read source/search.ts

summary:
cd source && deno run --allow-read summary.ts
deno run --allow-env --allow-read source/summary.ts

default: lint check build
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"imports": {
"@std/fmt": "jsr:@std/fmt@^0.224.0"
"@std/fmt": "jsr:@std/fmt@^0.224.0",
"@std/path": "jsr:@std/path@^0.224.0"
}
}
165 changes: 164 additions & 1 deletion deno.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,137 @@
"version": "3",
"packages": {
"specifiers": {
"jsr:@std/assert@^0.224.0": "jsr:@std/assert@0.224.0",
"jsr:@std/fmt@^0.224.0": "jsr:@std/fmt@0.224.0",
"jsr:@std/path@^0.224.0": "jsr:@std/path@0.224.0",
"npm:@inquirer/input": "npm:@inquirer/input@2.1.6",
"npm:log-symbols": "npm:log-symbols@6.0.0"
},
"jsr": {
"@std/assert@0.224.0": {
"integrity": "8643233ec7aec38a940a8264a6e3eed9bfa44e7a71cc6b3c8874213ff401967f"
},
"@std/fmt@0.224.0": {
"integrity": "e20e9a2312a8b5393272c26191c0a68eda8d2c4b08b046bad1673148f1d69851"
},
"@std/path@0.224.0": {
"integrity": "55bca6361e5a6d158b9380e82d4981d82d338ec587de02951e2b7c3a24910ee6",
"dependencies": [
"jsr:@std/assert@^0.224.0"
]
}
},
"npm": {
"@inquirer/core@8.1.0": {
"integrity": "sha512-kfx0SU9nWgGe1f03ao/uXc85SFH1v2w3vQVH7QDGjKxdtJz+7vPitFtG++BTyJMYyYgH8MpXigutcXJeiQwVRw==",
"dependencies": {
"@inquirer/figures": "@inquirer/figures@1.0.1",
"@inquirer/type": "@inquirer/type@1.3.1",
"@types/mute-stream": "@types/mute-stream@0.0.4",
"@types/node": "@types/node@20.12.8",
"@types/wrap-ansi": "@types/wrap-ansi@3.0.0",
"ansi-escapes": "ansi-escapes@4.3.2",
"chalk": "chalk@4.1.2",
"cli-spinners": "cli-spinners@2.9.2",
"cli-width": "cli-width@4.1.0",
"mute-stream": "mute-stream@1.0.0",
"signal-exit": "signal-exit@4.1.0",
"strip-ansi": "strip-ansi@6.0.1",
"wrap-ansi": "wrap-ansi@6.2.0"
}
},
"@inquirer/figures@1.0.1": {
"integrity": "sha512-mtup3wVKia3ZwULPHcbs4Mor8Voi+iIXEWD7wCNbIO6lYR62oPCTQyrddi5OMYVXHzeCSoneZwJuS8sBvlEwDw==",
"dependencies": {}
},
"@inquirer/input@2.1.6": {
"integrity": "sha512-M8bUFOlcn/kQcVYskl4kkB6dYrHtymJJ1S4nSg/khXT3W3l71u2qhSzfo6PdBG3jUe6ILJZ0gUh4Kef2uJ5pxw==",
"dependencies": {
"@inquirer/core": "@inquirer/core@8.1.0",
"@inquirer/type": "@inquirer/type@1.3.1"
}
},
"@inquirer/type@1.3.1": {
"integrity": "sha512-Pe3PFccjPVJV1vtlfVvm9OnlbxqdnP5QcscFEFEnK5quChf1ufZtM0r8mR5ToWHMxZOh0s8o/qp9ANGRTo/DAw==",
"dependencies": {}
},
"@types/mute-stream@0.0.4": {
"integrity": "sha512-CPM9nzrCPPJHQNA9keH9CVkVI+WR5kMa+7XEs5jcGQ0VoAGnLv242w8lIVgwAEfmE4oufJRaTc9PNLQl0ioAow==",
"dependencies": {
"@types/node": "@types/node@18.16.19"
}
},
"@types/node@18.16.19": {
"integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==",
"dependencies": {}
},
"@types/node@20.12.8": {
"integrity": "sha512-NU0rJLJnshZWdE/097cdCBbyW1h4hEg0xpovcoAQYHl8dnEyp/NAOiE45pvc+Bd1Dt+2r94v2eGFpQJ4R7g+2w==",
"dependencies": {
"undici-types": "undici-types@5.26.5"
}
},
"@types/wrap-ansi@3.0.0": {
"integrity": "sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g==",
"dependencies": {}
},
"ansi-escapes@4.3.2": {
"integrity": "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==",
"dependencies": {
"type-fest": "type-fest@0.21.3"
}
},
"ansi-regex@5.0.1": {
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"dependencies": {}
},
"ansi-styles@4.3.0": {
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dependencies": {
"color-convert": "color-convert@2.0.1"
}
},
"chalk@4.1.2": {
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dependencies": {
"ansi-styles": "ansi-styles@4.3.0",
"supports-color": "supports-color@7.2.0"
}
},
"chalk@5.3.0": {
"integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==",
"dependencies": {}
},
"cli-spinners@2.9.2": {
"integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==",
"dependencies": {}
},
"cli-width@4.1.0": {
"integrity": "sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==",
"dependencies": {}
},
"color-convert@2.0.1": {
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dependencies": {
"color-name": "color-name@1.1.4"
}
},
"color-name@1.1.4": {
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dependencies": {}
},
"emoji-regex@8.0.0": {
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
"dependencies": {}
},
"has-flag@4.0.0": {
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dependencies": {}
},
"is-fullwidth-code-point@3.0.0": {
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
"dependencies": {}
},
"is-unicode-supported@1.3.0": {
"integrity": "sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==",
"dependencies": {}
Expand All @@ -25,6 +143,50 @@
"chalk": "chalk@5.3.0",
"is-unicode-supported": "is-unicode-supported@1.3.0"
}
},
"mute-stream@1.0.0": {
"integrity": "sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==",
"dependencies": {}
},
"signal-exit@4.1.0": {
"integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==",
"dependencies": {}
},
"string-width@4.2.3": {
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"dependencies": {
"emoji-regex": "emoji-regex@8.0.0",
"is-fullwidth-code-point": "is-fullwidth-code-point@3.0.0",
"strip-ansi": "strip-ansi@6.0.1"
}
},
"strip-ansi@6.0.1": {
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"dependencies": {
"ansi-regex": "ansi-regex@5.0.1"
}
},
"supports-color@7.2.0": {
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dependencies": {
"has-flag": "has-flag@4.0.0"
}
},
"type-fest@0.21.3": {
"integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==",
"dependencies": {}
},
"undici-types@5.26.5": {
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==",
"dependencies": {}
},
"wrap-ansi@6.2.0": {
"integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==",
"dependencies": {
"ansi-styles": "ansi-styles@4.3.0",
"string-width": "string-width@4.2.3",
"strip-ansi": "strip-ansi@6.0.1"
}
}
}
},
Expand All @@ -33,7 +195,8 @@
},
"workspace": {
"dependencies": [
"jsr:@std/fmt@^0.224.0"
"jsr:@std/fmt@^0.224.0",
"jsr:@std/path@^0.224.0"
]
}
}
17 changes: 8 additions & 9 deletions source/add-platform.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { bold, cyan } from "@std/fmt/colors";
import logSymbols from "npm:log-symbols";
import { GamesJson } from "./types.ts";
import { nameCompare } from "./utils.ts";
import input from "npm:@inquirer/input";
import { loadGamesJson, nameCompare, writeGamesJson } from "./utils.ts";

const gamesJson = await Deno.readTextFile("./games.json");
const games = JSON.parse(gamesJson) as GamesJson;

const [anchor, name, badge, hostnames] = Deno.args;
const games = await loadGamesJson();
const anchor = await input({ message: "anchor:" });
const name = await input({ message: "name:" });
const badge = await input({ message: "badge:" });
const hostnames = await input({ message: "hostnames:" });

if (!(anchor && name && badge && hostnames)) {
console.error(
Expand All @@ -33,10 +34,8 @@ const platform = {
};

games.platforms.push(platform);

games.platforms.sort(nameCompare());

const jsonFile = JSON.stringify(games, null, 2);
await Deno.writeTextFile("./games.json", jsonFile + "\n");
await writeGamesJson(games);
console.log(logSymbols.success, `${name} added.`);
console.log(platform);
21 changes: 12 additions & 9 deletions source/add.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { bold, cyan, green } from "@std/fmt/colors";
import logSymbols from "npm:log-symbols";
import { GamesJson } from "./types.ts";
import { nameCompare, websiteChecks } from "./utils.ts";
import input from "npm:@inquirer/input";
import {
loadGamesJson,
nameCompare,
websiteChecks,
writeGamesJson,
} from "./utils.ts";

const gamesJson = await Deno.readTextFile("./games.json");
const games = JSON.parse(gamesJson) as GamesJson;

let [anchor, name, website] = Deno.args;
const games = await loadGamesJson();
const anchor = await input({ message: "anchor:" });
const name = await input({ message: "name:" });
let website = await input({ message: "website:" });

if (!(anchor && name && website)) {
console.error(
Expand Down Expand Up @@ -60,11 +65,9 @@ const game = {
};

foundPlatform.gameList.push(game);

foundPlatform.gameList.sort(nameCompare());

const jsonFile = JSON.stringify(games, null, 2);
await Deno.writeTextFile("./games.json", jsonFile + "\n");
await writeGamesJson(games);
console.log(
logSymbols.success,
`${green(bold(name))} added to ${cyan(bold(foundPlatform.name))}.`,
Expand Down
8 changes: 3 additions & 5 deletions source/build.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import logSymbols from "npm:log-symbols";
import { GamesJson } from "./types.ts";
import { nameCompare } from "./utils.ts";
import { loadGamesJson, nameCompare, writeReadme } from "./utils.ts";

const gamesJson = await Deno.readTextFile("./games.json");
const games = JSON.parse(gamesJson) as GamesJson;
const games = await loadGamesJson();

const titleSection = `<h1 align="center">GAMES</h1>
`;
Expand Down Expand Up @@ -77,5 +75,5 @@ const relatedSection = games.related.length > 0
const markdownContent = titleSection + badgesSection + descriptionSection +
ciSection + gamesSection + relatedSection;

await Deno.writeTextFile("../README.md", markdownContent);
await writeReadme(markdownContent);
console.log(logSymbols.success, "Compiled successfully.");
16 changes: 10 additions & 6 deletions source/check.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import logSymbols from "npm:log-symbols";
import { Game, Platform } from "./types.ts";
import { nameChecks, nameCompare, websiteChecks } from "./utils.ts";

const gamesJson = await Deno.readTextFile("./games.json");
const games = JSON.parse(gamesJson);
import {
loadGamesJson,
nameChecks,
nameCompare,
websiteChecks,
writeGamesJson,
} from "./utils.ts";

const games = await loadGamesJson();
const withFix = Deno.args.includes("--fix");

const checkWebsite = () => {
Expand Down Expand Up @@ -49,8 +54,7 @@ checkPlatformOrder();
checkGamesOrder();

if (withFix) {
const jsonFile = JSON.stringify(games, null, 2);
await Deno.writeTextFile("./games.json", jsonFile + "\n");
await writeGamesJson(games);
}

console.log(logSymbols.success, "Validation passed.");
8 changes: 3 additions & 5 deletions source/reset.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import logSymbols from "npm:log-symbols";
import { GamesJson } from "./types.ts";
import { loadGamesJson, writeGamesJson } from "./utils.ts";

const gamesJson = await Deno.readTextFile("./games.json");
const games = JSON.parse(gamesJson) as GamesJson;
const games = await loadGamesJson();

games.platforms.forEach((platform) => {
platform.hostnames = [];
Expand All @@ -11,6 +10,5 @@ games.platforms.forEach((platform) => {

games.related = [];

const jsonFile = JSON.stringify(games, null, 2);
await Deno.writeTextFile("./games.json", jsonFile + "\n");
await writeGamesJson(games);
console.log(logSymbols.success, "Reset to default done.");
11 changes: 5 additions & 6 deletions source/search.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { GamesJson } from "./types.ts";
import { fuzzyMatched } from "./utils.ts";
import input from "npm:@inquirer/input";
import { fuzzyMatched, loadGamesJson } from "./utils.ts";

const gamesJson = await Deno.readTextFile("./games.json");
const games = JSON.parse(gamesJson) as GamesJson;

const [anchor, name] = Deno.args;
const games = await loadGamesJson();
const anchor = await input({ message: "author:" });
const name = await input({ message: "name:" });

const matchedGames = [];

Expand Down

0 comments on commit 0e5d99b

Please sign in to comment.