chore: init

This commit is contained in:
HerozDotExe 2025-09-28 13:12:46 +02:00
commit acb41dd4bf
18 changed files with 3056 additions and 0 deletions

12
.editorconfig Normal file
View file

@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false

144
.gitignore vendored Normal file
View file

@ -0,0 +1,144 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# 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
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.*
!.env.example
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
.output
# Gatsby files
.cache/
# 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
.cache
# Sveltekit cache directory
.svelte-kit/
# vitepress build output
**/.vitepress/dist
# vitepress cache directory
**/.vitepress/cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# Firebase cache directory
.firebase/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v3
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
# Vite files
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
.vite/
# Test temp folder
tests/temp

21
LICENCE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Virgile DORIER
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# node-launcher-kit
A node.js library to install and launch minecraft with or without modloaders.

17
eslint.config.js Normal file
View file

@ -0,0 +1,17 @@
import js from "@eslint/js";
import globals from "globals";
import tseslint from "typescript-eslint";
import { defineConfig } from "eslint/config";
import eslintConfigPrettier from "eslint-config-prettier/flat";
export default defineConfig([
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
plugins: { js },
extends: ["js/recommended"],
languageOptions: { globals: globals.node },
},
tseslint.configs.recommended,
eslintConfigPrettier,
{ ignores: ["dist", "node_modules"] },
]);

37
package.json Normal file
View file

@ -0,0 +1,37 @@
{
"name": "nlk",
"version": "0.1.0",
"description": "Node Launcher Kit",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"scripts": {
"build": "tsup",
"test": "tsup && vitest --run"
},
"keywords": [],
"author": "HerozDotExe",
"license": "MIT",
"packageManager": "pnpm@10.17.1",
"devDependencies": {
"@eslint/js": "^9.36.0",
"@types/node": "^24.5.2",
"eslint": "^9.36.0",
"eslint-config-prettier": "^10.1.8",
"globals": "^16.4.0",
"prettier": "3.6.2",
"tsup": "^8.5.0",
"typescript-eslint": "^8.44.1",
"vitest": "^3.2.4"
},
"dependencies": {
"p-limit": "^7.1.1",
"p-queue": "^8.1.1"
}
}

2503
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load diff

2
pnpm-workspace.yaml Normal file
View file

@ -0,0 +1,2 @@
onlyBuiltDependencies:
- esbuild

1
src/core/index.ts Normal file
View file

@ -0,0 +1 @@
export * as java from "./java"

50
src/core/java.ts Normal file
View file

@ -0,0 +1,50 @@
import path from "path";
import { DownloadPool, fetchJson } from "../utils/fetch";
import fs from "fs/promises";
import {
FilesList,
JavaRuntimesManifests,
PoolFile,
RuntimeComponent,
RuntimeOS,
} from "../utils/types";
export async function install(
os: RuntimeOS,
component: RuntimeComponent,
destination: string,
signal?: AbortController,
) {
const javaRuntimesManifests = await fetchJson<JavaRuntimesManifests>(
"https://launchermeta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json",
);
const javaRuntimeManifest = (
await fetchJson<FilesList>(
javaRuntimesManifests[os][component][0].manifest.url,
)
).files;
const files: PoolFile[] = [];
for (const key in javaRuntimeManifest) {
if (Object.prototype.hasOwnProperty.call(javaRuntimeManifest, key)) {
const element = javaRuntimeManifest[key];
if (element.type === "file") {
files.push({
url: element.downloads.raw.url,
path: path.join(destination, key),
});
} else if (element.type === "directory") {
await fs.mkdir(path.join(destination, key));
}
}
}
const dPool = new DownloadPool(files, 5);
await dPool.run();
if (process.platform !== "win32") {
await fs.chmod(path.join(destination, "bin/java"), 0o777);
}
}

1
src/index.ts Normal file
View file

@ -0,0 +1 @@
export * as core from "./core";

100
src/utils/fetch.ts Normal file
View file

@ -0,0 +1,100 @@
import fs from "fs";
import { pipeline } from "stream/promises";
import { PoolFile } from "./types";
import { Task } from "./task";
export async function fetchJson<T>(url: string): Promise<T> {
return await (await fetch(url)).json();
}
export async function downloadFile(
file: { url: string; path: string },
signal: AbortSignal,
) {
try {
const res = await fetch(file.url, { signal });
if (!res.ok)
throw new Error(
`Failed to download ${file.url}: ${res.status} ${res.statusText}`,
);
await pipeline(res.body, fs.createWriteStream(file.path), { signal });
} catch (error) {
if (error.name !== "AbortError") throw error;
return;
}
}
// export class DownloadPool {
// files: PoolFiles;
// concurrency: number;
// controller: AbortController;
// queue?: pQueue;
// done: number;
// total: number;
// progressCallback: (done: number, total: number) => void;
// constructor(
// files: PoolFiles,
// concurrentDownloads = 5,
// ) {
// this.files = files;
// this.concurrency = concurrentDownloads;
// this.controller = new AbortController();
// this.queue = new pQueue({ concurrency: this.concurrency });
// this.done = 0;
// this.total = files.length;
// }
// async run() {
// try {
// for (const file of this.files) {
// this.queue.add(async () => {
// await downloadFile(file, this.controller.signal);
// });
// }
// } catch (error) {
// if (error.name !== "AbortError") throw error;
// return;
// }
// this.queue.on("completed", () => {
// this.done++;
// this.progressCallback(this.done, this.total);
// });
// await this.queue.onIdle();
// }
// cancel() {
// this.queue.clear();
// this.controller.abort();
// }
// }
export class DownloadPool extends Task<PoolFile> {
files: PoolFile[];
constructor(files: PoolFile[], concurrency: number) {
super(concurrency);
this.files = files;
this.total = files.length;
}
async run() {
await this._run(downloadFile, this.files);
}
}
// export class AssetsDownloader extends DownloadPool {
// assets: PoolFile[];
// constructor(assets: PoolFile[], concurrency: number) {
// super(assets, concurrency);
// this.assets = assets;
// }
// async run() {
// await this._run(downloadAssets, this.assets);
// }
// }

53
src/utils/task.ts Normal file
View file

@ -0,0 +1,53 @@
import pQueue from "p-queue";
export class Task<T> {
controller: AbortController;
concurrency: number;
queue?: pQueue;
done: number;
total: number;
progressCallback: (done: number, total: number) => void;
constructor(concurrency: number) {
this.controller = new AbortController();
this.concurrency = concurrency;
this.queue = new pQueue({ concurrency: this.concurrency });
this.done = 0;
this.total = 0;
}
async _run(
f: (element: unknown, signal: AbortSignal) => Promise<void>,
data: T[],
) {
try {
for (const element of data) {
this.queue.add(async () => {
await f(element, this.controller.signal);
});
}
} catch (error) {
if (error.name !== "AbortError") throw error;
return;
}
this.queue.on("completed", () => {
this.done++;
this.progressCallback(this.done, this.total);
});
await this.queue.onIdle();
}
cancel() {
this.queue.clear();
this.controller.abort();
}
}
// const t = new Task<{ url: string; path: string }>(5);
// class DownloadPool<T> extends Task<T> {}
// const dp = new DownloadPool<{ url: string; path: string }>(5);

62
src/utils/types.ts Normal file
View file

@ -0,0 +1,62 @@
export type RuntimeComponent =
| "java-runtime-alpha"
| "java-runtime-beta"
| "java-runtime-delta"
| "java-runtime-gamma"
| "java-runtime-gamma-snapsht"
| "jre-legacy"
| "minecraft-java-exe";
export type RuntimeOS =
| "gamecore"
| "linux"
| "linux-i386"
| "mac-os"
| "mac-os-arm64"
| "windows-arm64"
| "windows-x64"
| "windows-x86";
type File = {
sha1: string;
size: number;
url: string;
};
type PerOSRuntimes = {
[key in RuntimeComponent]: [
{
availability: {
group: number;
progress: number;
};
manifest: File;
version: {
name: string;
released: string;
};
},
];
};
export type JavaRuntimesManifests = {
[key in RuntimeOS]: PerOSRuntimes;
};
type FileType = "file" | "directory" | "link";
export type FilesList = {
files: {
[key: string]: {
target?: string;
downloads?: {
lzma: File;
raw: File;
};
executable?: boolean;
type: FileType;
};
};
}
export type PoolFile = { url: string; path: string };

3
test.cjs Normal file
View file

@ -0,0 +1,3 @@
const {core} = require(".")
core.java.install("linux", "java-runtime-beta", "/home/heroz/Dev/nlk/tests/temp/java")

30
tests/java.test.ts Normal file
View file

@ -0,0 +1,30 @@
import { expect, test } from "vitest";
import * as nlk from "../dist/index.js";
import path from "path";
import fs from "fs/promises";
const javaPath = path.join(import.meta.dirname, "temp/java");
await fs.rm(javaPath, { recursive: true });
await fs.mkdir(javaPath, { recursive: true });
async function exists(path: string) {
try {
await fs.access(path, fs.constants.F_OK);
return true;
} catch {
return false;
}
}
test("install java-runtime-beta for linux correctly", {timeout: 10000}, async () => {
await nlk.core.java.install("linux", "java-runtime-beta", javaPath);
expect(
await fs.readFile(path.join(javaPath, "release"), { encoding: "utf-8" }),
"check release file"
).toBe(`JAVA_VERSION="17.0.15"
MODULES="java.base java.compiler java.datatransfer java.xml java.prefs java.desktop java.instrument java.logging java.management java.security.sasl java.naming java.rmi java.management.rmi java.net.http java.scripting java.security.jgss java.transaction.xa java.sql java.sql.rowset java.xml.crypto java.se java.smartcardio jdk.accessibility jdk.internal.jvmstat jdk.attach jdk.charsets jdk.compiler jdk.crypto.ec jdk.crypto.cryptoki jdk.dynalink jdk.internal.ed jdk.editpad jdk.hotspot.agent jdk.httpserver jdk.incubator.foreign jdk.incubator.vector jdk.internal.le jdk.internal.opt jdk.internal.vm.ci jdk.internal.vm.compiler jdk.internal.vm.compiler.management jdk.jartool jdk.javadoc jdk.jcmd jdk.management jdk.management.agent jdk.jconsole jdk.jdeps jdk.jdwp.agent jdk.jdi jdk.jfr jdk.jlink jdk.jpackage jdk.jshell jdk.jsobject jdk.jstatd jdk.localedata jdk.management.jfr jdk.naming.dns jdk.naming.rmi jdk.net jdk.nio.mapmode jdk.random jdk.sctp jdk.security.auth jdk.security.jgss jdk.unsupported jdk.unsupported.desktop jdk.xml.dom jdk.zipfs"
`);
expect(await exists(path.join(javaPath, "bin/java")), "bin/java exists").toBe(true);
});

9
tsconfig.json Normal file
View file

@ -0,0 +1,9 @@
{
"compilerOptions": {
"resolveJsonModule": true,
"module": "esnext",
"target": "esnext",
"moduleResolution": "bundler",
"noEmit": true,
}
}

8
tsup.config.js Normal file
View file

@ -0,0 +1,8 @@
import { defineConfig } from "tsup";
export default defineConfig({
entry: ["src/index.ts"],
target: "node22",
format: ["cjs", "esm"],
dts: true,
});