From 6544cdef91b7fdfee766c1975646b9d7198273db Mon Sep 17 00:00:00 2001 From: alexrr2iggs Date: Tue, 5 Mar 2024 09:43:55 +0100 Subject: [PATCH] eod --- .vscode/launch.json | 3 - .vscode/tasks.json | 1 - assets/defaults/config.json | 38 ++--- config.json | 38 ++--- deno.jsonc | 27 +-- scripts/check.ts | 36 +--- scripts/generate_test_files.ts | 2 +- scripts/mk_deb_pkg.ts | 3 - scripts/mk_deb_pkg_mod.ts | 124 -------------- scripts/mk_tag.ts | 117 ------------- scripts/set_build_env.ts | 9 - scripts/set_up_test_env.ts | 29 ---- scripts/utils.ts | 291 --------------------------------- src/cli/info.ts | 13 +- src/main.ts | 7 +- src/utils/package_info.ts | 8 - src/utils/paths.ts | 12 +- 17 files changed, 77 insertions(+), 681 deletions(-) delete mode 100755 scripts/mk_deb_pkg.ts delete mode 100755 scripts/mk_deb_pkg_mod.ts delete mode 100755 scripts/mk_tag.ts delete mode 100644 scripts/set_build_env.ts delete mode 100755 scripts/set_up_test_env.ts delete mode 100644 scripts/utils.ts delete mode 100644 src/utils/package_info.ts diff --git a/.vscode/launch.json b/.vscode/launch.json index c4336fb..6095ee4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,7 +13,6 @@ "runtimeExecutable": "/home/alex/.deno/bin/deno", "runtimeArgs": [ "run", - "--unstable", "--config", "deno.jsonc", "--inspect-wait", @@ -34,7 +33,6 @@ "runtimeExecutable": "/home/alex/.deno/bin/deno", "runtimeArgs": [ "run", - "--unstable", "--config", "deno.jsonc", "--inspect-wait", @@ -54,7 +52,6 @@ "runtimeExecutable": "/home/alex/.deno/bin/deno", "runtimeArgs": [ "test", - "--unstable", "--config", "${workspaceFolder}/deno.jsonc", "--inspect-wait", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index cd1aef9..61c3cc2 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,7 +6,6 @@ "console": "integratedTerminal", "command": "run", "args": [ - "--unstable", "-A", "${file}" ], diff --git a/assets/defaults/config.json b/assets/defaults/config.json index 1eeed92..29fdcdb 100644 --- a/assets/defaults/config.json +++ b/assets/defaults/config.json @@ -1,22 +1,22 @@ { - "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": "~/.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"] } + } } diff --git a/config.json b/config.json index 1d909ab..9211845 100644 --- a/config.json +++ b/config.json @@ -1,22 +1,22 @@ { - "serverInstallationDir": "~/.local/bin/minecraft-server", - "versionManifestV2Url": "http://127.0.0.1:8765/version_manifest_v2", - "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": "~/.local/bin/minecraft-server", + "versionManifestV2Url": "http://127.0.0.1:8765/version_manifest_v2", + "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"] } + } } diff --git a/deno.jsonc b/deno.jsonc index fa4b845..215c3dd 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -1,20 +1,21 @@ { "imports": { - "std/": "https://deno.land/std@0.208.0/", + "@std/fs": "jsr:@std/fs@^0.218.2", + "cli/": "./src/cli/", "cliffy/": "https://deno.land/x/cliffy@v1.0.0-rc.3/", "data/": "./src/data/", - "cli/": "./src/cli/", - "utils/": "./src/utils/", - "types/": "./src/types/", - "services/": "./src/services/", "errors/": "./src/errors/", - "semver": "https://deno.land/x/semver@v1.4.1/mod.ts", - "progress": "https://deno.land/x/progress@v1.4.0/mod.ts", "iggs-utils": "npm:iggs-utils@1.2.16", - "testing-utils": "./tests/utils.ts" + "progress": "https://deno.land/x/progress@v1.4.0/mod.ts", + "semver": "https://deno.land/x/semver@v1.4.1/mod.ts", + "services/": "./src/services/", + "std/": "https://deno.land/std@0.208.0/", + "testing-utils": "./tests/utils.ts", + "types/": "./src/types/", + "utils/": "./src/utils/" }, "tasks": { - "test": "clear && ./scripts/set_up_test_env.ts && cd ./tests && deno test -A --allow-env --unstable --trace-ops", + "test": "./scripts/set_up_test_env.ts && cd ./tests && deno test -A --allow-env --unstable --trace-ops", "check": "deno run --allow-read --allow-write scripts/check.ts", "gtests": "deno run -A --allow-env scripts/generate_test_files.ts", "compile": "deno compile -A --target='x86_64-unknown-linux-gnu' --output='dist/minecraft-server-launcher' ./src/main.ts" @@ -26,7 +27,11 @@ "fmt": { "semiColons": true, "singleQuote": true, - "lineWidth": 160, - "indentWidth": 1 + "lineWidth": 500, + "indentWidth": 1, + "include": ["./src", "./tests", "./scripts"] + }, + "lint": { + "include": ["./src", "./tests"] } } diff --git a/scripts/check.ts b/scripts/check.ts index 1d8039b..802d8b9 100755 --- a/scripts/check.ts +++ b/scripts/check.ts @@ -2,38 +2,6 @@ /** * script to check code quality and consistency */ -import { getEmptyFiles, getSkipTestSrcs, getsMissingTestSrcs, SRC_DIR, TESTS_DIR } from './utils.ts'; +import { checkCodeQuality } from './utils/check.ts'; -let exitCode = 0; - -// check if there are src files with the @skip-test comment -const skipTestSrcFiles = getSkipTestSrcs(); -if (skipTestSrcFiles.length > 0) { - for (const srcFile of skipTestSrcFiles) { - console.log(`%c[SKIP TEST] %c${srcFile}`, 'color: orange', 'color: yellow'); - } -} - -// check if there are src files WITHOUT TEST files -const srcFilesWithoutTestFile = getsMissingTestSrcs(); -if (srcFilesWithoutTestFile.length > 0) { - for (const srcFile of srcFilesWithoutTestFile) { - console.log(`%c[WITHOUT TEST] %c${srcFile}`, 'color: red', 'color: #ff4900'); - } - exitCode = 1; -} - -// check if there are EMPTY TS FILES, in src or test -const emptyTsFiles = [...getEmptyFiles(SRC_DIR, 'ts'), ...getEmptyFiles(TESTS_DIR, 'test.ts')]; -if (emptyTsFiles.length > 0) { - for (const tsFile of emptyTsFiles) { - console.log(`%c[EMPTY TS FILE] %c${tsFile}`, 'color: red', 'color: gray'); - } - exitCode = 1; -} - -if (exitCode === 0) { - console.log(`%c[CHECK PASS]`, 'color: green'); -} else { - Deno.exit(exitCode); -} +checkCodeQuality() \ No newline at end of file diff --git a/scripts/generate_test_files.ts b/scripts/generate_test_files.ts index 403b007..9878afb 100755 --- a/scripts/generate_test_files.ts +++ b/scripts/generate_test_files.ts @@ -1,7 +1,7 @@ #!/usr/bin/env -S deno run -A /** script to generate an empty .test.ts file for each .ts file that doesnt have one*/ import { writeFileAndDir } from 'utils/fs.ts'; -import { getSkipTestSrcs, sourceFilePathToTestFilePath } from './utils.ts'; +import { getSkipTestSrcs, sourceFilePathToTestFilePath } from './utils/utils.ts'; const skipTestSrcFiles = getSkipTestSrcs(); diff --git a/scripts/mk_deb_pkg.ts b/scripts/mk_deb_pkg.ts deleted file mode 100755 index e4596c3..0000000 --- a/scripts/mk_deb_pkg.ts +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env --allow-run -import { mkDebPkg } from './mk_deb_pkg_mod.ts'; -await mkDebPkg(); diff --git a/scripts/mk_deb_pkg_mod.ts b/scripts/mk_deb_pkg_mod.ts deleted file mode 100755 index f1bce4c..0000000 --- a/scripts/mk_deb_pkg_mod.ts +++ /dev/null @@ -1,124 +0,0 @@ -/** ./set_build_env.ts it needs to be evaluated befor everething so should be at top*/ -import './set_build_env.ts'; - -import { log } from 'iggs-utils'; -import { join, resolve } from 'std/path/mod.ts'; -import { defaultConfig } from 'utils/config.ts'; -import { copyFileRecursive, silentRemove, writeFileAndDir } from 'utils/fs.ts'; -import { logger } from 'utils/logger.ts'; -import { CONFIG_FILE_NAME, DEFAULT_SERVER_PROPERTIES_PATH, SYS_CONFIG_FILE_PATH } from 'utils/paths.ts'; -import { pkgInfo } from '../src/utils/package_info.ts'; -import { exe } 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; -} - -export async function mkDebPkg(): Promise { - const controlFile: DebianControlFile = { - Package: pkgInfo.name, - Version: pkgInfo.version, - Architecture: 'amd64', - Maintainer: pkgInfo.maintainer, - Description: pkgInfo.description, - Homepage: pkgInfo.homepage, - }; - - const controlFileContent = Object.entries(controlFile) - .reduce((prev, [key, value]) => `${prev}${key}: ${value}\n`, ''); - - logger.debug(`creating debian package`, '\n', controlFileContent); - - const LINUXx64_BIN_PATH = join(resolve('dist'), 'bin', 'linux', 'x64', pkgInfo.name); - exe('deno', 'compile', '--unstable', '--target=x86_64-unknown-linux-gnu', '-A', '--output=' + LINUXx64_BIN_PATH, './src/main.ts'); - - // 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 PKG_DIR = resolve('dist', 'deb_package'); - const PKG_ROOT = resolve(PKG_DIR, pkgInfo.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', pkgInfo.name, 'README.md'); - const PKG_SYS_CONFIG_FILE_PATH = join(PKG_ROOT, SYS_CONFIG_FILE_PATH); - const PKG_DEFAULT_SERVER_PROPERTIES_PATH = join(PKG_ROOT, DEFAULT_SERVER_PROPERTIES_PATH); - const DEB_PKG_PATH = resolve('dist', `${pkgInfo.name}_${pkgInfo.version}_linux_amd64.deb`); - - silentRemove(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_CONFIG_FILE_PATH, PKG_SYS_CONFIG_FILE_PATH); - copyFileRecursive(DEFAULT_DEFAULT_SERVER_PROPERTIES_PATH, PKG_DEFAULT_SERVER_PROPERTIES_PATH); - writeFileAndDir(PKG_DEFAULT_SERVER_PROPERTIES_PATH, JSON.stringify(defaultConfig, null, 4)); - - exe('dpkg-deb', '--build', PKG_ROOT, DEB_PKG_PATH); - - console.log('%csuccessfully created deb package!!! πŸΎπŸŽ‰πŸŽ‡', 'color:green'); - - return DEB_PKG_PATH; -} diff --git a/scripts/mk_tag.ts b/scripts/mk_tag.ts deleted file mode 100755 index cd4bdd8..0000000 --- a/scripts/mk_tag.ts +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env -S deno run -A -import { log } from 'iggs-utils'; -import { logger } from 'utils/logger.ts'; -import { pkgInfo } from 'utils/package_info.ts'; -import { mkDebPkg } from './mk_deb_pkg_mod.ts'; -import { exe } from './utils.ts'; - -export interface GhRelease { - url: string; - assets_url: string; - upload_url: string; - html_url: string; - id: number; - author: Author; - node_id: string; - tag_name: string; - target_commitish: string; - name: string; - draft: boolean; - prerelease: boolean; - created_at: string; - published_at: string; - assets: object[]; - tarball_url: string; - zipball_url: string; - body: string; - reactions: Reactions; - mentions_count: number; -} - -export interface Author { - login: string; - id: number; - node_id: string; - avatar_url: string; - gravatar_id: string; - url: string; - html_url: string; - followers_url: string; - following_url: string; - gists_url: string; - starred_url: string; - subscriptions_url: string; - organizations_url: string; - repos_url: string; - events_url: string; - received_events_url: string; - type: string; - site_admin: boolean; -} - -export interface Reactions { - url: string; - total_count: number; - '+1': number; - '-1': number; - laugh: number; - hooray: number; - confused: number; - heart: number; - rocket: number; - eyes: number; -} - -logger.logLevel = log.LogLevel.TRACE; -logger.prefix = `[MK_TAG]`; - -// lint -logger.info('linting...'); -exe('deno', 'lint'); - -// format -logger.info('formatting...'); -exe('deno', 'fmt'); - -// do code checks -logger.info('checking...'); -exe('./scripts/check.ts'); - -// run tests -logger.info('testing...'); -exe('deno', 'task', 'test'); - -// check if tag exists -logger.info(`checking if Tag ${pkgInfo.version} exists...`); -await checkIfTagExists(); - -// build deb package -logger.info('building deb package...'); -const LINUX_BIN_PATH = await mkDebPkg(); - -// commit changes -logger.info('committing changes...'); -exe('git', 'commit', '-m', `tag ${pkgInfo.version}`); - -// tag the commit with the current version -logger.info(`tagging ${pkgInfo.version}...`); -exe('git', 'tag', pkgInfo.version); - -// push the tag -logger.info('pushing tag...'); -exe('git', 'push', 'origin', pkgInfo.version); - -//Upload deb backage as release assets -logger.info(`uploading ${LINUX_BIN_PATH} asset...`); -exe('gh', 'release', 'create', pkgInfo.version, LINUX_BIN_PATH); - -console.log('%csuccessfully togged!!! πŸΎπŸŽ‰πŸŽ‡', 'color:green'); - -async function checkIfTagExists() { - const tags: GhRelease[] = await fetch('https://api.github.com/repos/alexrr2iggs/minecraft_server_updater/releases').then((r) => r.json()); - const tagAlreadyExists = tags?.find((t: GhRelease) => t?.tag_name === pkgInfo.version); - if (tagAlreadyExists) { - console.warn(`Tag ${pkgInfo.version} already exists\nsee ${tagAlreadyExists.html_url}`); - Deno.exit(1); - } -} diff --git a/scripts/set_build_env.ts b/scripts/set_build_env.ts deleted file mode 100644 index 0ecba92..0000000 --- a/scripts/set_build_env.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * 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', 'compile_production'); diff --git a/scripts/set_up_test_env.ts b/scripts/set_up_test_env.ts deleted file mode 100755 index 82597f0..0000000 --- a/scripts/set_up_test_env.ts +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env -S deno run -A -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//.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//.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)); diff --git a/scripts/utils.ts b/scripts/utils.ts deleted file mode 100644 index ac1fb82..0000000 --- a/scripts/utils.ts +++ /dev/null @@ -1,291 +0,0 @@ -import { existsSync } from 'std/fs/exists.ts'; -import { WalkEntry, WalkOptions, walkSync } from 'std/fs/walk.ts'; -import { resolve } from 'std/path/resolve.ts'; - -export const PROJ_ROOT = resolve(new URL(import.meta.url).pathname, '..', '..'); -export const SRC_DIR = resolve(PROJ_ROOT, 'src'); -export const TESTS_DIR = resolve(PROJ_ROOT, 'tests'); -const TS_FILE_EXT_REX = /\.ts$/; -const SKIP_TEST_COMMENT_REX = /\/\/\s*@skip-test/gm; - -/* -import { getEmptyTsFiles, getSkipTestSrcFiles, getSrcFilesThatShouldHaveTestFile } from './utils.ts'; -const srcFilesWithoutTestFile = getSrcFilesThatShouldHaveTestFile(); -const emptyTsFiles = getEmptyTsFiles(); -const skipTestSrcFiles = getSkipTestSrcFiles(); - -let exitCode = 0; - -// check if there are src files with the @skip-test comment -if (skipTestSrcFiles.length > 0) { - for (const srcFile of skipTestSrcFiles) { - console.log(`%c[SKIP TEST] %c${srcFile}`, 'color: orange', 'color: yellow'); - } -} - -// check if there are src files WITHOUT TEST files -if (srcFilesWithoutTestFile.length > 0) { - for (const srcFile of srcFilesWithoutTestFile) { - console.log(`%c[WITHOUT TEST] %c${srcFile}`, 'color: red', 'color: yellow'); - } - exitCode = 1; -} - -// check if there are EMPTY TS FILES, in src or test -if (emptyTsFiles.length > 0) { - for (const tsFile of emptyTsFiles) { - console.log(`%c[EMPTY TS FILE] %c${tsFile}`, 'color: red', 'color: gray'); - } - exitCode = 1; -} - -if (exitCode === 0) { - console.log(`%c[CHECK PASS]`, 'color: green'); -} else { - Deno.exit(exitCode); -} - -*/ - -/** - - #!/usr/bin/env -S deno run -A -// script to generate an empty .test.ts file for each .ts file that doesnt have one -import { writeFileAndDir } from 'utils/fs.ts'; -import { getSkipTestSrcFiles, getSrcFilesThatShouldHaveTestFile, sourceFilePathToTestFilePath } from './utils.ts'; - -const skipTestSrcFiles = getSkipTestSrcFiles(); - -if (skipTestSrcFiles.length > 0) { - for (const srcFile of skipTestSrcFiles) { - console.log(`%c[SKIP TEST] %c${srcFile}`, 'color: orange', 'color: yellow'); - } -} - -for (const sourceFilePath of getSrcFilesThatShouldHaveTestFile()) { - const testFilePath = sourceFilePathToTestFilePath(sourceFilePath); - - console.log(`%c[GENERATE TEST] %c${testFilePath}`, 'color: green', 'color: yellow'); - writeFileAndDir(testFilePath, ''); -} - - */ - -/** -import './set_build_env.ts'; - -import { log } from 'iggs-utils'; -import { join, resolve } from 'std/path/mod.ts'; -import { defaultConfig } from 'utils/config.ts'; -import { copyFileRecursive, silentRemove, writeFileAndDir } from 'utils/fs.ts'; -import { logger } from 'utils/logger.ts'; -import { CONFIG_FILE_NAME, DEFAULT_SERVER_PROPERTIES_PATH, SYS_CONFIG_FILE_PATH } from 'utils/paths.ts'; -import { pkgInfo } from '../src/utils/package_info.ts'; -import { exe, LINUX_BIN_PATH } from './utils.ts'; -export async function mkDebPkg(): Promise { - exe('deno', ['compile', '--unstable', '--target=x86_64-unknown-linux-gnu', '-A', '--output=' + LINUX_BIN_PATH, './src/main.ts']); - - const controlFile: DebianControlFile = { - Package: pkgInfo.name, - Version: pkgInfo.version, - Architecture: 'amd64', - Maintainer: pkgInfo.maintainer, - Description: pkgInfo.description, - Homepage: pkgInfo.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 PKG_DIR = resolve('dist', 'deb_package'); - const PKG_ROOT = resolve(PKG_DIR, pkgInfo.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', pkgInfo.name, 'README.md'); - const PKG_SYS_CONFIG_FILE_PATH = join(PKG_ROOT, SYS_CONFIG_FILE_PATH); - const PKG_DEFAULT_SERVER_PROPERTIES_PATH = join(PKG_ROOT, DEFAULT_SERVER_PROPERTIES_PATH); - - const DEB_PKG_PATH = resolve('dist', `${pkgInfo.name}_${pkgInfo.version}_linux_amd64.deb`); - - silentRemove(PKG_DIR, { recursive: true }); - writeFileAndDir(PKG_CONTROL_FILE_PATH, controlFileContent); - copyFileRecursive(LINUX_BIN_PATH, PKG_BIN_PATH); - copyFileRecursive('./README.md', PKG_DOC_PATH); - copyFileRecursive(DEFAULT_CONFIG_FILE_PATH, PKG_SYS_CONFIG_FILE_PATH); - writeFileAndDir(PKG_DEFAULT_SERVER_PROPERTIES_PATH, JSON.stringify(defaultConfig, null, 4)); - - logger.debug('creating', DEB_PKG_PATH); - await new Deno.Command('dpkg-deb', { - args: ['--build', PKG_ROOT, DEB_PKG_PATH], - stderr: 'inherit', - stdin: 'inherit', - stdout: 'inherit', - }).output(); - - logger.debug('successfully created deb package'); - - return DEB_PKG_PATH; -} - - * - */ - -/** - * import { log } from 'iggs-utils'; -import { logger } from 'utils/logger.ts'; -import { pkgInfo } from 'utils/package_info.ts'; -import { mkDebPkg } from './mk_deb_pkg_mod.ts'; -import { exe } from './utils.ts'; - * // lint -logger.info('linting...'); -exe('deno', ['lint']); - -// format -logger.info('formatting...'); -exe('deno', ['fmt']); - -// do code checks -logger.info('checking...'); -exe('./scripts/check.ts'); - -// run tests -logger.info('testing...'); -exe('deno', ['task', 'test']); - -// check if tag exists -logger.info(`checking if Tag ${pkgInfo.version} exists...`); -await checkIfTagExists(); - -// build deb package -logger.info('building deb package...'); -const LINUX_BIN_PATH = await mkDebPkg(); - -// commit changes -logger.info('committing changes...'); -exe('git', ['commit', '-m', `tag ${pkgInfo.version}`]); - -// tag the commit with the current version -logger.info(`tagging ${pkgInfo.version}...`); -exe('git', ['tag', pkgInfo.version]); - -// push the tag -logger.info('pushing tag...'); -exe('git', ['push', 'origin', pkgInfo.version]); - -//Upload deb backage as release assets -logger.info(`uploading ${LINUX_BIN_PATH} asset...`); -exe('gh', ['release', 'create', pkgInfo.version, LINUX_BIN_PATH]); - -async function checkIfTagExists() { - const tags: GhRelease[] = await fetch('https://api.github.com/repos/alexrr2iggs/minecraft_server_updater/releases').then((r) => r.json()); - const tagAlreadyExists = tags?.find((t: GhRelease) => t?.tag_name === pkgInfo.version); - if (tagAlreadyExists) { - console.warn(`Tag ${pkgInfo.version} already exists\nsee ${tagAlreadyExists.html_url}`); - Deno.exit(1); - } -} - - */ - -export function exe(command: string, ...args: string[]): Deno.CommandOutput { - const cmd = new Deno.Command(command, { - args, - stderr: 'inherit', - stdin: 'inherit', - stdout: 'inherit', - }); - const cmdOutput = cmd.outputSync(); - - if (cmdOutput.code !== 0) { - Deno.exit(cmdOutput.code); - } - return cmdOutput; -} - -export function getEmptyFiles(dir: string | URL, ...exts: string[]): string[] { - const walkOptions: WalkOptions = { - exts, - includeDirs: false, - }; - - const files: IterableIterator = walkSync(dir, walkOptions); - const emptyFiles: string[] = []; - - for (const tsFile of files) { - if (isEmptyFile(tsFile.path)) { - emptyFiles.push(tsFile.path); - } - } - - return emptyFiles; -} - -// export function getSkipTestSrcFiles(): string[] { -// const srcTsFiles = walkSync(SRC_DIR, { exts: ['ts'], includeDirs: false }); - -// const skipTestFiles: string[] = []; -// for (const srcTsFile of srcTsFiles) { -// const srcTxt = Deno.readTextFileSync(srcTsFile.path); -// if (srcTxt.match(SKIP_TEST_COMMENT_REX)) { -// skipTestFiles.push(srcTsFile.path); -// } -// } - -// return skipTestFiles; -// } - -/** - * returns an array of string paths with the source files with the @skip-test comment - * @returns - */ -export function getSkipTestSrcs(): string[] { - const srcFiles = walkSync(SRC_DIR, { includeDirs: false, exts: ['ts'] }); - const skipTestSrcs = []; - - for (const srcFile of srcFiles) { - if (!hasSkipTestComment(srcFile.path)) { - skipTestSrcs.push(srcFile.path); - } - } - return skipTestSrcs; -} - -export function getsMissingTestSrcs(): string[] { - const srcFiles = walkSync(SRC_DIR, { includeDirs: false, exts: ['ts'] }); - const missingTestSrcs = []; - - for (const srcFile of srcFiles) { - if (!hasTest(srcFile.path) && !hasSkipTestComment(srcFile.path)) { - missingTestSrcs.push(srcFile.path); - } - } - - return missingTestSrcs; -} - -export function hasTest(srcTsFile: string): boolean { - return existsSync(sourceFilePathToTestFilePath(srcTsFile)); -} - -/** - * check if the src file has the @skip-test comment. - * @param srcTsFile - * @returns boolean - */ -export function hasSkipTestComment(srcTsFile: string): boolean { - return !!Deno.readTextFileSync(srcTsFile).match(SKIP_TEST_COMMENT_REX); -} - -export function sourceFilePathToTestFilePath(srcFile: string): string { - return resolve(srcFile).replace(SRC_DIR, TESTS_DIR).replace(TS_FILE_EXT_REX, '.test.ts'); -} - -export function isEmptyFile(path: string): boolean { - return Deno.statSync(path).size === 0; -} diff --git a/src/cli/info.ts b/src/cli/info.ts index 72eeceb..b14361f 100644 --- a/src/cli/info.ts +++ b/src/cli/info.ts @@ -1,13 +1,20 @@ import { getConf } from 'services/conf.ts'; +import { appInfo } from 'utils/app_info.ts'; +import { SYS_CONFIG_FILE_PATH, USR_CONFIG_FILE_PATH } from 'utils/paths.ts'; // @skip-test -export async function info(_options, ..._args: string[]) { +export function info(_options, ..._args: string[]) { + console.log('misela version:\t', appInfo.version); + console.log('Deno version:\t', Deno.version.deno); + console.log('usr configuration file:\t', USR_CONFIG_FILE_PATH); + console.log('sys configuration file:\t', SYS_CONFIG_FILE_PATH); + console.log('server Installation Dir:\t', getConf().serverInstallationDir); console.log('version Manifest V2 Url:\t', getConf().versionManifestV2Url); const launchArgs = getConf().launchArgs; for (const [k, launchArg] of Object.entries(launchArgs)) { - console.log(`ver ${k} server launch args:\t`, launchArg?.serverArgs?.join(' ')); - console.log(`ver ${k} java launch args:\t`, launchArg?.javaArgs?.join(' ')); + console.log(`${k} server launch args:\t`, launchArg?.serverArgs?.join(' ')); + console.log(`${k} java launch args:\t`, launchArg?.javaArgs?.join(' ')); } } diff --git a/src/main.ts b/src/main.ts index 80f414c..33439d4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,3 +1,4 @@ +import { appInfo } from 'utils/app_info.ts'; // @skip-test import { info } from 'cli/info.ts'; import { install } from 'cli/install.ts'; @@ -21,9 +22,9 @@ try { await new Command() // .default('run') - .name('minecraft_server_launcher') - .version('0.0.1') - .description('Minecraft Server Launcher') + .name(appInfo.name) + .version(appInfo.version) + .description(appInfo.description) .globalOption('-d, --debug', 'Enable debug output.') .globalAction(async (options) => { if (options.debug) { diff --git a/src/utils/package_info.ts b/src/utils/package_info.ts deleted file mode 100644 index 994da3d..0000000 --- a/src/utils/package_info.ts +++ /dev/null @@ -1,8 +0,0 @@ -// @skip-test -export const pkgInfo = { - name: 'minecraft-server-launcher', - version: '1.0.0', - description: 'A tool to install, update, migrate and launch Minecraft servers', - maintainer: 'https://github.com/alexrr2iggs', - homepage: 'https://github.com/alexrr2iggs/minecraft_server_launcher', -}; diff --git a/src/utils/paths.ts b/src/utils/paths.ts index 8002c26..17ef574 100644 --- a/src/utils/paths.ts +++ b/src/utils/paths.ts @@ -2,7 +2,7 @@ import 'https://deno.land/x/dotenv@v3.2.2/load.ts'; import { join } from 'std/path/join.ts'; import { resolve } from 'std/path/resolve.ts'; -import { pkgInfo } from 'utils/package_info.ts'; +import { appInfo } from './app_info.ts'; /** * Is in development mode? @@ -13,17 +13,17 @@ const IS_DEV = Deno.env.get('DENO_ENV') === 'development'; /** * Directory for storing app data during development. * This ensures that isn't required special permissions to write to the directory and it's isolated from system directories. */ -const DEV_ROOT_DIR = resolve(getOsUserHomeDir(), '.development', pkgInfo.name); +const DEV_ROOT_DIR = resolve(getOsUserHomeDir(), '.development', appInfo.name); export const CONFIG_FILE_NAME = 'config.json'; export const JAR_SERVER_FILE_NAME = 'server.jar'; export const SERVER_PROPERTIES_FILE_NAME = 'server.properties'; export const MINECRAFT_SERVER_DIR_NAME = 'minecraft-server'; -export const SHARED_DATA_DIR = _mkPath(getOsSharedDataDir(), pkgInfo.name); -export const SYS_CONFIG_FILE_PATH = _mkPath(getOsSysConfDir(), pkgInfo.name, CONFIG_FILE_NAME); -export const USR_CONFIG_FILE_PATH = _mkPath(getOsUsrConfDir(), pkgInfo.name, CONFIG_FILE_NAME); -export const DEFAULT_SERVER_PROPERTIES_PATH = _mkPath(getOsSharedDataDir(), pkgInfo.name, SERVER_PROPERTIES_FILE_NAME); +export const SHARED_DATA_DIR = _mkPath(getOsSharedDataDir(), appInfo.name); +export const SYS_CONFIG_FILE_PATH = _mkPath(getOsSysConfDir(), appInfo.name, CONFIG_FILE_NAME); +export const USR_CONFIG_FILE_PATH = _mkPath(getOsUsrConfDir(), appInfo.name, CONFIG_FILE_NAME); +export const DEFAULT_SERVER_PROPERTIES_PATH = _mkPath(getOsSharedDataDir(), appInfo.name, SERVER_PROPERTIES_FILE_NAME); export const SERVER_INSTALLATION_DIR = _mkPath(getOsUserBinDir(), MINECRAFT_SERVER_DIR_NAME); function _mkPath(...chunks: string[]) {