From 80692b1a190c1cfcaa7b884821624c571272b296 Mon Sep 17 00:00:00 2001 From: korigamik-hypr Date: Thu, 15 Feb 2024 03:10:33 +0530 Subject: [PATCH] Update package.json and add release workflow --- .github/workflows/release.yml | 22 +++++++ README.md | 35 +++++++---- package.json | 8 +-- src/cli/main.ts | 113 ++++++++++++++++------------------ 4 files changed, 102 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e4f2eec --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,22 @@ +name: Publish Package to npmjs + +on: + push: + tags: + - '*' + + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # Setup .npmrc file to publish to npm + - uses: actions/setup-node@v3 + with: + node-version: "20.x" + registry-url: "https://registry.npmjs.org" + - run: npm ci + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/README.md b/README.md index cbe7ac7..a1de289 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,46 @@ -# osu!play +

+
+ osu!play +
-Listen to your favourite [osu!lazer](https://lazer.ppy.sh) beatmaps as a spotify playlist from the terminal +[![NPM version](https://img.shields.io/npm/v/osu-play.svg?style=flat)](https://npmjs.org/package/osu-play) +[![Downloads](https://badgen.net/npm/dt/osu-play)](https://www.npmjs.com/package/osu-play) +[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) + +

+ +> Listen to your favourite [osu!lazer](https://lazer.ppy.sh) beatmaps as a +> spotify playlist from the terminal ## Installation ### Requirements - [Node.js](https://nodejs.org/en/) (v18 or higher) -- [osu!lazer](https://lazer.ppy.sh/home/download) with some beatmaps to listen to 😉 +- [osu!lazer](https://lazer.ppy.sh/home/download) with some beatmaps to listen + to 😉 - That's it! ### Quick start - Try out the latest release without installing anything: -```sh -npx osu-play # using npm -pnpm dlx osu-play # using pnpm -``` + ```sh + npx osu-play # using npm + pnpm dlx osu-play # using pnpm + ``` - Install the latest release globally: -```sh -npm i -g osu-play # using npm -pnpm i -g osu-play # using pnpm -``` + ```sh + npm i -g osu-play # using npm + pnpm i -g osu-play # using pnpm + ``` ## Usage The `osu-play` command can be used with the following options: + ```sh ➜ korigamik git:(main) ✗ osu-play --help Play music from your osu!lazer beatmaps from the terminal @@ -55,4 +67,3 @@ import { lazer } from "osu-play"; const realm = getLazerDB(); ``` - diff --git a/package.json b/package.json index ec1d999..c45e670 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "osu-play", - "version": "1.0.6", + "version": "1.0.7", "description": "Play music from your osu!lazer beatmaps from the terminal.", "type": "module", "main": "bin/osu-play.js", @@ -31,11 +31,11 @@ "devDependencies": { "@types/node": "^20.8.9", "@types/prompts": "^2.4.7", - "tsup": "^7.2.0", + "tsup": "^8.0.2", "typescript": "^5.2.2" }, "dependencies": { - "@types/yargs": "^17.0.29", + "@types/yargs": "^17.0.32", "prompts": "^2.4.2", "realm": "^12.2.1", "yargs": "^17.7.2" @@ -53,4 +53,4 @@ "url": "https://github.com/KorigamiK/osu-play" }, "bugs": "https://github.com/KorigamiK/osu-play/issues" -} +} \ No newline at end of file diff --git a/src/cli/main.ts b/src/cli/main.ts index 40ad628..2d6d6c8 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -1,6 +1,5 @@ import path from "node:path"; import { existsSync, writeFileSync } from "node:fs"; -import { execFileSync } from "node:child_process"; import Realm from "realm"; import prompts from "prompts"; @@ -10,45 +9,49 @@ import { getLazerDB, getNamedFileHash, hashedFilePath } from "../realm/mod.js"; import yargs from "yargs/yargs"; import { hideBin } from "yargs/helpers"; +import util from "node:util"; +import { execFile } from "node:child_process"; + +const execFilePromise = util.promisify(execFile); export function getArgs() { const argv = yargs(hideBin(process.argv)) .usage("Play music from your osu!lazer beatmaps from the terminal\nUsage: $0 [options]") .options({ - reload: { - type: "boolean", - default: false, - alias: "r", - describe: "Reload lazer database", - }, - exportPlaylist: { - type: "string", - describe: "Export playlist to a file", - }, - osuDataDir: { - type: "string", - default: path.join(getDataDir() || ".", "osu"), - alias: "d", - describe: "Osu!lazer data directory", - }, - configDir: { - type: "string", - default: path.join(getConfigDir() || ".", "osu-play"), - alias: "c", - describe: "Config directory", - }, - loop: { - type: "boolean", - default: false, - alias: "l", - describe: "Loop the playlist on end", - }, - help: { - type: "boolean", - alias: "h", - describe: "Show help", - } - }).argv; + reload: { + type: "boolean", + default: false, + alias: "r", + describe: "Reload lazer database", + }, + exportPlaylist: { + type: "string", + describe: "Export playlist to a file", + }, + osuDataDir: { + type: "string", + default: path.join(getDataDir() || ".", "osu"), + alias: "d", + describe: "Osu!lazer data directory", + }, + configDir: { + type: "string", + default: path.join(getConfigDir() || ".", "osu-play"), + alias: "c", + describe: "Config directory", + }, + loop: { + type: "boolean", + default: false, + alias: "l", + describe: "Loop the playlist on end", + }, + help: { + type: "boolean", + alias: "h", + describe: "Show help", + } + }).argv; return argv; } @@ -65,7 +68,7 @@ export async function main() { } if (argv.osuDataDir !== getDataDir()) { - console.log(`[INFO] Using osu!lazer data directory: ${argv.osuDataDir}`); + console.log(`[INFO] Using osu!lazer data directory: ${ argv.osuDataDir }`); } const realmDBPath = getRealmDBPath(argv.configDir, { reload, osuDataDir }); @@ -76,14 +79,12 @@ export async function main() { } const currentSchema = Realm.schemaVersion(realmDBPath); - console.log(`currentSchema: ${currentSchema}`); + console.log(`currentSchema: ${ currentSchema }`); Realm.flags.ALLOW_CLEAR_TEST_STATE = true; const realm: Realm = await getLazerDB(realmDBPath); - console.log(`realm.isClosed: ${realm.isClosed}`); - const beatmapSets = realm.objects(BeatmapSet); const songSet = new Set(); @@ -101,22 +102,21 @@ export async function main() { songSet.add(hash); const meta = beatmap.Metadata; const path = hashedFilePath(hash); - const title = `${meta.Title} : ${meta.Artist} - ${meta.TitleUnicode} : ${meta.ArtistUnicode}`; + const title = `${ meta.Title } : ${ meta.Artist } - ${ meta.TitleUnicode } : ${ meta.ArtistUnicode }`; uniqueBeatmaps.push({ title, path }); } } - console.log(`beatmap songs: ${beatmapSets.length}`); + console.log(`beatmap songs: ${ beatmapSets.length }`); if (argv.exportPlaylist) { - console.log(`[INFO] Exporting playlist to ${argv.exportPlaylist}`); + console.log(`[INFO] Exporting playlist to ${ argv.exportPlaylist }`); const playlist = uniqueBeatmaps.map((mp) => mp.path).join("\n"); writeFileSync(argv.exportPlaylist, playlist); - console.log(`[INFO] Done. Use something like \`mpv --playlist=${argv.exportPlaylist}\` to play the playlist`); + console.log(`[INFO] Done. Use something like \`mpv --playlist=${ argv.exportPlaylist }\` to play the playlist`); return; } - // Get the map index from the user let selectedBeatmap: number = ( await prompts({ type: "autocomplete", @@ -128,22 +128,18 @@ export async function main() { })), }) ).beatmap; + console.log(`Selected: ${ selectedBeatmap }`); - for (let i = selectedBeatmap; i < uniqueBeatmaps.length; ++i) { + let i = selectedBeatmap + + for (; i < uniqueBeatmaps.length; ++i) { const beatmap = uniqueBeatmaps[i]; - console.log(`Map : ${beatmap.title}`); + console.log(`Map : ${ beatmap.title }`); if (beatmap.path && existsSync(beatmap.path)) { - // Open file using exo-open. - console.log(`File exists: ${beatmap.path}`); - console.log(`Playing ${beatmap.title}`); - try { - execFileSync("exo-open", [beatmap.path]); - } catch (err) { - console.log(`Error: ${err}`); - break; - } + console.log(`Playing ${ beatmap.title }`); + await execFilePromise('exo-open', [beatmap.path]); } else { - console.log(`File does not exist: ${beatmap.path}`); + console.log(`File does not exist: ${ beatmap.path }`); } if (i < uniqueBeatmaps.length - 1) { // Wait 1 second between @@ -151,13 +147,10 @@ export async function main() { } else if (argv.loop) { console.log('[INFO] Looping playlist'); i = 0; - } else { + } else { console.log('[INFO] Done. Use --loop to loop the playlist'); } } realm.close(); - console.log(`realm.isClosed: ${realm.isClosed}`); - - // Realm.clearTestState(); }