Skip to content

Commit

Permalink
feat: the project
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHillcox committed Mar 25, 2024
0 parents commit 39c86f0
Show file tree
Hide file tree
Showing 14 changed files with 526 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GH_TOKEN=
CURSEFORGE_TOKEN=
31 changes: 31 additions & 0 deletions .github/workflows/meta-updater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
on:
push:
branches:
- master
schedule:
# Run every day at 00:00 UTC
- cron: '0 0 * * *'
# Allow manual running as well
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install
name: Install dependencies
- run: bun run index.ts
name: Update things
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }}
# Commit any changes back to the project
- run: git config --global user.email "[email protected]"
- run: git config --global user.name "Michael Hillcox"
- run: git add .
# Check if there are any changes to commit
- run: git diff --quiet --exit-code || git commit -m "Update things"
- run: git push
name: Push changes
175 changes: 175 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# nanite-meta

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run index.ts
```

This project was created using `bun init` in bun v1.0.19. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
Binary file added bun.lockb
Binary file not shown.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "nanite-meta",
"module": "index.ts",
"devDependencies": {
"bun-types": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"type": "module",
"dependencies": {
"@octokit/rest": "^20.0.2"
}
}
43 changes: 43 additions & 0 deletions src/fetchers/CurseDataFetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { CommonProvider } from "../types/EnrichedMetaSpec";
import { semverSortMinecraft } from "../utils";

const url = `https://api.curseforge.com/v1/`;

export async function getCurseProjectData(id: string): Promise<CommonProvider | null> {
const modRequest = await fetcher(`${url}mods/${id}`);

if (modRequest.status !== 200) {
console.log(`Failed to fetch Curse data for ${id} due to a status code of ${modRequest.status}`)
return null;
}

let modData: any = await modRequest.json();
if (!modData?.data?.slug) {
console.log(`No slug found for Curse project ${id}`);
return null;
}

modData = modData.data;

return {
title: modData.name,
description: modData.summary,
image: modData.logo?.url ?? null,
minecraftVersions: ([...new Set(modData.latestFilesIndexes.map((e: any) => e.gameVersion))] as string[])
.sort(semverSortMinecraft),
webUrl: modData.links?.websiteUrl ?? `https://www.curseforge.com/minecraft/mc-mods/${modData.slug}`,
updatedAt: modData.dateModified,
downloads: modData.downloadCount,
}
}

async function fetcher(request: string | URL | Request, init?: RequestInit): Promise<Response> {
return fetch(request, {
...init,
headers: {
...init?.headers,
'Accept':'application/json',
'x-api-key': process.env.CURSEFORGE_TOKEN ?? "",
},
});
}
28 changes: 28 additions & 0 deletions src/fetchers/ModrinthDataFetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { CommonProvider } from "../types/EnrichedMetaSpec";
import { semverSortMinecraft } from "../utils";

const modrinthApi = "https://api.modrinth.com/v2/";

export async function getModrinthData(id: string): Promise<CommonProvider | null> {
const request = await fetch(`${modrinthApi}project/${id}`);
if (request.status !== 200) {
console.log(`Failed to fetch Modrinth data for ${id} due to a status code of ${request.status}`)
return null;
}

const data: any = await request.json();
if (!data?.slug) {
console.log(`No slug found for Modrinth project ${id}`);
return null;
}

return {
title: data.title,
description: data.description,
image: data.icon_url,
minecraftVersions: data.game_versions.sort(semverSortMinecraft),
webUrl: `https://modrinth.com/mod/${data.slug}`,
updatedAt: data.updated,
downloads: data.downloads,
}
}
Loading

0 comments on commit 39c86f0

Please sign in to comment.