Skip to content

Instantly share code, notes, and snippets.

@myoun
Last active February 8, 2023 14:44
Show Gist options
  • Save myoun/a357d9b3ee5484fde8ceca2dd70cb8a0 to your computer and use it in GitHub Desktop.
Save myoun/a357d9b3ee5484fde8ceca2dd70cb8a0 to your computer and use it in GitHub Desktop.
easily create minecraft project
node_modules
.debug
package-lock.json

Create Minecraft Project

#!/usr/bin/env node
import fetch from "node-fetch";
import prompts from "prompts";
import { promises as fs, createWriteStream } from "fs";
const createPaperProject = async (projectName) => {
const getPaperVersions = async () => {
const url = "https://papermc.io/api/v2/projects/paper";
const versionResponse = await fetch(url);
const versionJson = await versionResponse.json();
return Array.from(versionJson.versions).reverse()
};
const paperVersion = (await prompts({
type : "select",
name : "version",
message : "Choose the version of PaperMC",
choices : (await getPaperVersions()).map((v) => ({ title : v, value : v }))
})).version;
const dir = await fs.readdir("./");
if (!dir.includes(".debug")) {
await fs.mkdir('.debug');
}
const build = (await (await fetch(`https://papermc.io/api/v2/projects/paper/versions/${paperVersion}`)).json()).builds.at(-1);
const downloadName = await (await fetch(`https://papermc.io/api/v2/projects/paper/versions/${paperVersion}/builds/${build}`)).json().then((r) => r.downloads.application.name);
const downloadResponse = await fetch(`https://papermc.io/api/v2/projects/paper/versions/${paperVersion}/builds/${build}/downloads/${downloadName}`);
const stream = createWriteStream(`.debug/${downloadName}`);
downloadResponse.body.pipe(stream);
await fs.writeFile(".debug/eula.txt", "eula=true");
}
(async() => {
const projects = { papermc : createPaperProject, };
const questions = [
{
type : 'text',
name : 'project_name',
message: 'What is your project name?'
},
{
type : 'select',
name : 'project_type',
message : 'Select the type of your minecraft project',
choices: [
{ title : 'PaperMC', value : 'papermc' }
]
}
]
const resuslt = await prompts(questions);
const projectType = resuslt.project_type;
await projects[projectType](resuslt.project_name);
})();
{
"name": "create-minecraft-app",
"version": "1.0.0",
"description": "simple minecraft project initializer",
"bin": "./index.js",
"repository": {
"type": "git",
"url": "git+https://gist.github.com/a357d9b3ee5484fde8ceca2dd70cb8a0.git"
},
"author": "myoun",
"license": "MIT",
"bugs": {
"url": "https://gist.github.com/a357d9b3ee5484fde8ceca2dd70cb8a0"
},
"homepage": "https://gist.github.com/a357d9b3ee5484fde8ceca2dd70cb8a0",
"dependencies": {
"node-fetch": "^3.3.0",
"prompts": "^2.4.2"
},
"type": "module"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment