npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ci-minecraft-forge-server-test

v1.4.0

Published

Minecraft Forge server testing for CI

Downloads

6

Readme

ci-minecraft-forge-server-test

Tool for testing Minecraft Forge servers as part of testing on CI servers.

This handles installing Minecraft Forge, copy/download mods, starting the server, running commands and stopping the server again.

How to

This is only a library and will need to be executed by other code (See example code below), as different projects will have different requirements for the server testing.

To run the code on a Jenkins CI server, simply add sh 'npm install' and sh 'npm start' as a step in your Jenkinsfile. Tip: You can archive the log file as a post action.

Example Jenkinsfile

pipeline {
  agent any
  options {
    timeout(time: 30, unit: 'MINUTES')
  }
  tools {
    jdk 'jdk_8u144'
    nodejs 'node_8.4.0'
  }
  stages {
    stage('Prepare') {
      steps {
        sh 'chmod +x gradlew'
        sh './gradlew setupCiWorkspace clean'
      }
    }
    stage('Build') {
      steps {
        sh './gradlew build jar'
      }
    }
    stage('Run Server Test') {
      steps {
        dir('serverTest') {
          sh 'npm update'
          sh 'npm start'
        }
      }
      post {
        always {
          archiveArtifacts 'run/logs/fml-server-latest.log'
        }
      }
    }
    stage('Archive') {
      steps {
        archiveArtifacts 'build/libs/*.jar'
        fingerprint 'build/libs/*.jar'
      }
    }
  }
}

Example code

The following is an example code that use this library.

import { readFile } from 'fs';
import { join, resolve as pathResolve } from 'path';
import { exit } from 'process';

import { CIMinecraftForgeServerTest } from 'ci-minecraft-forge-server-test';

const buildLibsDirectory = pathResolve('..', 'build', 'libs');
const serverDirectory = pathResolve('..', 'run');

// Minecraft and Forge versions
let minecraftVersion = null;
let forgeVersion = null;
// Path to mod .jar file
let modFilepath = null;

// Get the Minecraft, Forge and mod versions from build.gradle
function getVersions() {
    return new Promise((resolve, reject) => {
        readFile(pathResolve('..', 'build.gradle'), 'UTF-8', (err, data) => {
            if (err != null) {
                reject(err);
                return;
            }

            let modVersion = null;

            data
                .split('\n')
                .forEach((line, i) => {
                    if (line.startsWith('def')) {
                        const varName = line.split(' ')[1];
                        const varValue = line.split('\'')[1];

                        if (varName === 'mcVersion') {
                            minecraftVersion = varValue;
                        } else if (varName === 'forgeVersion') {
                            forgeVersion = varValue;
                        } else if (varName === 'modVersion') {
                            modVersion = varValue;
                        }
                    }
                });

            if (minecraftVersion == null || forgeVersion == null) {
                reject('Could not find Minecraft and/or Forge version');
                return;
            }

            if (modVersion == null) {
                reject('Could not find mod version');
                return;
            }

            modFilepath = join(buildLibsDirectory, `ModName-mc${minecraftVersion}-${modVersion}.jar`);
            resolve();
        });
    });
}

// Create instance of ci-minecraft-forge-server-test
const tester = new CIMinecraftForgeServerTest();
getVersions()
    .then(() => {
        tester
            .setVersions(minecraftVersion, forgeVersion) // Set versions
            //.acceptEULA()                              // Accept Minecraft's EULA (commented out to prevent blindingly accepting by copy/paste)
            .useServerProperties()                       // Use ci-minecraft-forge-server-test's server.properties file
            .setServerDirectory(serverDirectory)         // Set the directory for the server
            .addLocalMod(modFilepath)                    // Add the mod
            .addCommand('forge tps');                    // Add command to run

        return tester.installForge()                     // Install Forge
            .then(() => tester.runServer());             // Run the server
    })
    .catch(err => {
        console.error(err);
        exit(1);
    });

For this to work, the minecraft/forge/mod versions must be defined in the build.gradle file.

def mcVersion = '1.12'
def forgeVersion = '14.21.1.2387'
def modVersion = '1.0.0'

When the server is started it executes forge tps before executing stop (automaticly done by the library).