Skip to content

Commit

Permalink
eod
Browse files Browse the repository at this point in the history
  • Loading branch information
bitBeater committed Mar 5, 2024
1 parent 6544cde commit 80fd6d9
Show file tree
Hide file tree
Showing 15 changed files with 670 additions and 53 deletions.
76 changes: 46 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,70 @@ ensuring you're always up-to-date with the latest release from `piston-meta.moja

## Installation

[Include detailed steps on how to install this script, along with any prerequisites needed.]
To install the Minecraft Server Launcher, please visit the GitHub releases section of our repository and download the `misela` binary. Ensure you have the necessary permissions to execute the file.

For more detailed instructions and prerequisites, refer to our [Installation Guide](#installation-guide).

## Usage

- **View Launcher Version**
The `misela` tool provides various commands for managing your Minecraft servers:

- **Launch the latest installed Minecraft server**

```sh
./minecraft_server_launcher [-v | --version]
```
~~~sh
misela run
~~~

- **Launch the lastest installed mincreaft server**
```sh
./minecraft_server_launcher
```
- **Start a Specific Server Version**
```sh
./minecraft_server_launcher <version>
```

~~~sh
misela run <version>
~~~

- **List Installed Servers**

```sh
./minecraft_server_launcher [-l | --list]
```
~~~sh
misela list
~~~

- **List Available Servers for download**

```sh
./minecraft_server_launcher [-la | --list-available]
```
~~~sh
misela list-available
~~~

- **Start a Specific Server Version**
```sh
./minecraft_server_launcher <version>
```
- **Install a Server**
```sh
./minecraft_server_launcher [i | install] <version> <optional: version to copy worlds and configs from>
```
- **Install the Latest or a Specific Server Version**

~~~sh
misela install [install_version] [migration_version]
~~~

- **Migrate Worlds and Configs Between Versions**

~~~sh
misela migrate [version_from] [version_to]
~~~

- **Display Current Configuration**

~~~sh
misela info
~~~

For a complete list of commands and options, run:

~~~sh
misela --help
~~~

## Additional Information

The script uses this endpoint to retrieve the latest game version: `https://piston-meta.mojang.com/mc/game/version_manifest_v2.json`
The script interacts with Mojang's official metadata endpoint at `https://piston-meta.mojang.com/mc/game/version_manifest_v2.json` to retrieve the latest game versions.

## Contributing

Contributions are welcome! Please feel free to submit pull requests, suggest features, or report issues. For major changes, please open an issue first to
discuss what you would like to change.
We welcome contributions! If you'd like to improve the Minecraft Server Launcher, please submit pull requests, suggest features, or report issues. For significant changes, open an issue first to discuss what you would like to change.

## License

This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details.
This project is licensed under the GNU General Public License v3.0. See the [LICENSE](LICENSE) file for more details.
44 changes: 23 additions & 21 deletions assets/defaults/config.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
{
"serverInstallationDir": "~/.local/bin/minecraft-server",
"versionManifestV2Url": "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json",
"launchArgs": {
"default": {
"javaArgs": [
"-Xms4G",
"-Xmx8G",
"-XX:+UseG1GC",
"-XX:+ParallelRefProcEnabled",
"-XX:MaxGCPauseMillis=200",
"-XX:+UseLargePages",
"-XX:+AlwaysPreTouch",
"-XX:+UseStringDeduplication",
"-XX:+DisableExplicitGC",
"-XX:+UnlockExperimentalVMOptions",
"-XX:+OptimizeStringConcat"
],
"serverArgs": ["--nogui"]
}
}
}
"serverInstallationDir": "/home/alex/.local/bin/minecraft-server",
"versionManifestV2Url": "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json",
"launchArgs": {
"default": {
"javaArgs": [
"-Xms4G",
"-Xmx8G",
"-XX:+UseG1GC",
"-XX:+ParallelRefProcEnabled",
"-XX:MaxGCPauseMillis=200",
"-XX:+UseLargePages",
"-XX:+AlwaysPreTouch",
"-XX:+UseStringDeduplication",
"-XX:+DisableExplicitGC",
"-XX:+UnlockExperimentalVMOptions",
"-XX:+OptimizeStringConcat"
],
"serverArgs": [
"--nogui"
]
}
}
}
8 changes: 8 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env -S deno run -A

import { build } from './utils/build.ts';

/**
* script to check code quality and consistency
*/
build();
4 changes: 3 additions & 1 deletion scripts/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
* script to check code quality and consistency
*/
import { checkCodeQuality } from './utils/check.ts';
import { repositoryCheck } from './utils/repo_check.ts';

checkCodeQuality()
checkCodeQuality();
repositoryCheck();
12 changes: 12 additions & 0 deletions scripts/release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env -S deno run -A
import { appInfo } from 'utils/app_info.ts';
import { logger } from 'utils/logger.ts';
import { build } from './utils/build.ts';
import { doRelease } from './utils/release.ts';
import { doTag } from './utils/tag.ts';

await doTag();
await build();
await doRelease();

logger.info(`✅ ${appInfo.version} RELEASED! 🚀🍾🎉🎇!!! Good Luck...`);
12 changes: 12 additions & 0 deletions scripts/set_build_env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//TODO: loock if thsi code is used, if not delete

/**
* This script is a simple workaround for ecmascript module import mechanism, that loads and evaluates modules in a top-down manner,
* which means it first loads and evaluates all import statements before executing the rest of the code in a module.
*
* Since the project relies on the deno's ".env" feature to determine the runing environment, with a default value of 'development'.
*
* take a look at utils/paths.ts
*/

Deno.env.set('DENO_ENV', 'production');
33 changes: 33 additions & 0 deletions scripts/set_up_test_env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env -S deno run -A

//TODO: loock if this code is used, if not delete

import { log } from 'iggs-utils';
import { defaultConfig } from 'utils/config.ts';
import { writeFileAndDir } from 'utils/fs.ts';
import { logger } from 'utils/logger.ts';
import { DEFAULT_SERVER_PROPERTIES_PATH, SYS_CONFIG_FILE_PATH, USR_CONFIG_FILE_PATH } from 'utils/paths.ts';
import { FAKE_SERVER_VERSION_MANIFEST_V2_URL } from './../tests/test_utils/fake_api_server.ts';

// Deno.env.set('DENO_ENV', 'development');
logger.logLevel = log.LogLevel.TRACE;

/**
* error: NotFound: No such file or directory (os error 2): open '/home/<user>/.development/minecraft-server-launcher/usr/share/minecraft-server-launcher/server.properties'
* const defaultServerPropertiesFile = Deno.openSync(DEFAULT_SERVER_PROPERTIES_PATH);
*/
writeFileAndDir(DEFAULT_SERVER_PROPERTIES_PATH, '#Minecraft server properties');

/**
* error: NotFound: No such file or directory (os error 2): readfile '/home/<user>/.development/minecraft-server-launcher/etc/minecraft-server-launcher/config.json'
* sysConf = Deno.readFileSync(SYS_CONFIG_FILE_PATH);
*/
writeFileAndDir(SYS_CONFIG_FILE_PATH, JSON.stringify(defaultConfig, undefined, 4));

//----------------------------------------------------------------------------------------------------------------------
// setting tests config file

const testConfig = { ...defaultConfig };
testConfig.versionManifestV2Url = FAKE_SERVER_VERSION_MANIFEST_V2_URL;

writeFileAndDir(USR_CONFIG_FILE_PATH, JSON.stringify(testConfig, undefined, 4));
158 changes: 158 additions & 0 deletions scripts/utils/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// const denoEnvFilePath = join(import.meta.dirname, 'set_build_env.ts');

/** ./set_build_env.ts it needs to be evaluated befor everething so should be at top*/
// import(join(import.meta.dirname, 'set_build_env.ts'));
import 'https://deno.land/x/dotenv@v3.2.2/load.ts';
import { join, resolve } from 'std/path/mod.ts';

if (Deno.env.get('DENO_ENV') !== 'production') {
logger.warn(`DENO_ENV is set to: "${Deno.env.get('DENO_ENV')}".\tIf you need to change it to "production", edit the .env file, in the root project directory`);
askToContinue();
}

import { log } from 'iggs-utils';
import { defaultConfig } from 'utils/config.ts';
import { copyFileRecursive, silentRemove, writeFileAndDir } from 'utils/fs.ts';
import { logger } from 'utils/logger.ts';
import { DEFAULT_SERVER_PROPERTIES_PATH, SYS_CONFIG_FILE_PATH, USR_CONFIG_FILE_PATH } from 'utils/paths.ts';
import { appInfo } from '../../src/utils/app_info.ts';
import { askToContinue, exe, RELEASE_ASSETS_DIR } from './utils.ts';

// setting application logger level. '-s' (silent) is used to shut down logger.
logger.logLevel = Deno.args.includes('-s') ? log.LogLevel.OFF : log.LogLevel.TRACE;
logger.prefix = `[MK_DEB_PKG]`;

/**
* Interface representing the structure of a Debian package's control file.
*/
interface DebianControlFile {
/** The unique identifier name of the package. */
Package: string;

/** The version of the package, following the Debian versioning scheme. */
Version: string;

/** The section to which the package belongs, such as 'utils', 'net', etc. */
Section?: string;

/** The priority of the package, indicating its importance. */
Priority?: 'required' | 'important' | 'standard' | 'optional' | 'extra';

/** The architecture for which the package is built, like 'amd64', 'i386'. */
Architecture: string;

/** Packages that must be installed for this package to work. */
Depends?: string;

/** Packages that are recommended for enhanced functionality. */
Recommends?: string;

/** Packages that are suggested but not necessary. */
Suggests?: string;

/** Indicates that the package enhances the functionality of other packages. */
Enhances?: string;

/** Packages that are required to be configured before this package is unpacked. */
PreDepends?: string;

/** Lists packages that are incompatible with this package. */
Breaks?: string;

/** Lists packages that cannot be installed alongside this package. */
Conflicts?: string;

/** Indicates that this package replaces other packages. */
Replaces?: string;

/** Declares that this package provides the functionality of another package. */
Provides?: string;

/** The disk space required by the package in kilobytes. */
'Installed-Size'?: number;

/** The name and email of the person or team responsible for the package. */
Maintainer: string;

/** A brief description of the package. */
Description: string;

/** URL of the homepage for the software or package. */
Homepage?: string;

/** Indicates the source packages used to build this package. */
'Built-Using'?: string;
}

const LINUXx64_BIN_PATH = join(resolve('dist'), 'bin', 'linux', 'x64', appInfo.name);
const WINx64_BIN_PATH = join(RELEASE_ASSETS_DIR, `${appInfo.name + appInfo.version}_x86_64-win.exe`);

export async function mkDebPkg() {
linuxBuild();
const { DEB_PKG_PATH, PKG_ROOT } = mkDebPkgStructure();
exe('dpkg-deb', '--build', PKG_ROOT, DEB_PKG_PATH);

logger.info(`🐧 creatted linux deb pkg in ${DEB_PKG_PATH}`);

// cleaning up the debian package directory
// silentRemove(DEB_PKG_DIR, { recursive: true });
}

function mkDebPkgStructure(): { DEB_PKG_PATH; PKG_ROOT } {
const controlFile: DebianControlFile = {
Package: appInfo.name,
Version: appInfo.version,
Architecture: 'amd64',
Maintainer: appInfo.maintainer,
Description: appInfo.description,
Homepage: appInfo.homepage,
};

const controlFileContent = Object.entries(controlFile).reduce((prev, [key, value]) => `${prev}${key}: ${value}\n`, '');

logger.debug(`creating debian package`, '\n', controlFileContent);

// generating deb package directories
const ASSETS_DIR = resolve('assets');
// const DEFAULT_CONFIG_FILE_PATH = resolve(ASSETS_DIR, 'defaults', CONFIG_FILE_NAME);
const DEFAULT_DEFAULT_SERVER_PROPERTIES_PATH = resolve(ASSETS_DIR, 'defaults', 'server.properties');

const DEB_PKG_DIR = resolve('dist', 'deb_package');
const PKG_ROOT = resolve(DEB_PKG_DIR, appInfo.name);
const PKG_BIN_PATH = join(PKG_ROOT, 'usr', 'bin', 'misela');
const PKG_CONTROL_FILE_PATH = join(PKG_ROOT, 'DEBIAN', 'control');
const PKG_DOC_PATH = join(PKG_ROOT, 'usr', 'share', 'doc', appInfo.name, 'README.md');
const PKG_SYS_CONFIG_FILE_PATH = join(PKG_ROOT, SYS_CONFIG_FILE_PATH);
const PKG_USR_CONFIG_FILE_PATH = join(PKG_ROOT, USR_CONFIG_FILE_PATH);
const PKG_DEFAULT_SERVER_PROPERTIES_PATH = join(PKG_ROOT, DEFAULT_SERVER_PROPERTIES_PATH);
const DEB_PKG_PATH = resolve(RELEASE_ASSETS_DIR, `${appInfo.name}_${appInfo.version}_linux_amd64.deb`);

// cleaning: if for some reason a debian package directory already exists, remove it
silentRemove(DEB_PKG_DIR, { recursive: true });
writeFileAndDir(PKG_CONTROL_FILE_PATH, controlFileContent);
copyFileRecursive(LINUXx64_BIN_PATH, PKG_BIN_PATH);
copyFileRecursive('./README.md', PKG_DOC_PATH);
copyFileRecursive(DEFAULT_DEFAULT_SERVER_PROPERTIES_PATH, PKG_DEFAULT_SERVER_PROPERTIES_PATH);
writeFileAndDir(PKG_SYS_CONFIG_FILE_PATH, JSON.stringify(defaultConfig, null, 4));
writeFileAndDir(PKG_USR_CONFIG_FILE_PATH, JSON.stringify(defaultConfig, null, 4));

return { DEB_PKG_PATH, PKG_ROOT };
}

export async function linuxBuild() {
exe('deno', 'compile', '--target=x86_64-unknown-linux-gnu', '-A', '--output=' + LINUXx64_BIN_PATH, './src/main.ts');
logger.info(`🐧 creatted linux bin in ${LINUXx64_BIN_PATH}`);
}

export function winBuild() {
exe('deno', 'compile', '--unstable', '--target=x86_64-pc-windows-msvc', '-A', '--output=' + WINx64_BIN_PATH, './src/main.ts');
logger.info(`🪟 creatted windows executable in ${WINx64_BIN_PATH}`);
}

export async function build(): Promise<void> {
silentRemove(RELEASE_ASSETS_DIR, { recursive: true });
Deno.mkdirSync(RELEASE_ASSETS_DIR, { recursive: true });

mkDebPkg();
winBuild();
}
Loading

0 comments on commit 80fd6d9

Please sign in to comment.