Build with tsup, fix warnings and cleanup imports

This commit is contained in:
absidue 2021-12-13 17:54:18 +01:00
parent 5a094be82e
commit 5b904bda46
10 changed files with 1922 additions and 36 deletions

1873
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,14 +4,15 @@
"description": "YouTube, SoundCloud, Spotify, Deezer searching and streaming for discord.js bots",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"module": "dist/index.mjs",
"directories": {
"example": "examples"
},
"scripts": {
"build": "tsc",
"build": "tsup",
"build:check": "tsc --noEmit --incremental false",
"pretty": "prettier --config .prettierrc \"play-dl/*.ts\" \"play-dl/*/*.ts\" \"play-dl/*/*/*.ts\" --write ",
"prepublishOnly": "tsc --build --clean && tsc --build --verbose"
"prepublishOnly": "tsup"
},
"repository": {
"type": "git",
@ -43,6 +44,7 @@
"devDependencies": {
"@types/node": "^16.9.4",
"prettier": "^2.3.1",
"tsup": "^5.11.1",
"typedoc": "^0.22.9",
"typedoc-plugin-missing-exports": "^0.22.4",
"typescript": "^4.4.4",

View File

@ -1,4 +1,4 @@
import { URL } from 'url';
import { URL } from 'node:url';
import { request, request_resolve_redirect } from '../Request';
import { DeezerAlbum, DeezerPlaylist, DeezerTrack } from './classes';
@ -265,13 +265,13 @@ export async function dz_advanced_track_search(options: DeezerAdvancedSearchOpti
if (options.label) metadata.push(`label:"${encodeURIComponent(options.label)}"`);
if (Number(options.minDurationInSec) !== NaN) metadata.push(`dur_min:${options.minDurationInSec}`);
if (!isNaN(Number(options.minDurationInSec))) metadata.push(`dur_min:${options.minDurationInSec}`);
if (Number(options.maxDurationInSec) !== NaN) metadata.push(`dur_max:${options.maxDurationInSec}`);
if (!isNaN(Number(options.maxDurationInSec))) metadata.push(`dur_max:${options.maxDurationInSec}`);
if (Number(options.minBPM) !== NaN) metadata.push(`bpm_min:${options.minBPM}`);
if (!isNaN(Number(options.minBPM))) metadata.push(`bpm_min:${options.minBPM}`);
if (Number(options.maxBPM) !== NaN) metadata.push(`bpm_max:${options.maxBPM}`);
if (!isNaN(Number(options.maxBPM))) metadata.push(`bpm_max:${options.maxBPM}`);
if (metadata.length === 0) throw new Error('At least one type of metadata is required.');

View File

@ -1,7 +1,7 @@
import { IncomingMessage } from 'node:http';
import https, { RequestOptions } from 'node:https';
import { RequestOptions, request as httpsRequest } from 'node:https';
import { URL } from 'node:url';
import zlib, { BrotliDecompress, Deflate, Gunzip } from 'node:zlib';
import { BrotliDecompress, Deflate, Gunzip, createGunzip, createBrotliDecompress, createDeflate } from 'node:zlib';
import { cookieHeaders, getCookies } from '../YouTube/utils/cookie';
import { getRandomUserAgent } from './useragent';
@ -78,9 +78,9 @@ export function request(req_url: string, options: RequestOpts = { method: 'GET'
const data: string[] = [];
let decoder: BrotliDecompress | Gunzip | Deflate | undefined = undefined;
const encoding = res.headers['content-encoding'];
if (encoding === 'gzip') decoder = zlib.createGunzip();
else if (encoding === 'br') decoder = zlib.createBrotliDecompress();
else if (encoding === 'deflate') decoder = zlib.createDeflate();
if (encoding === 'gzip') decoder = createGunzip();
else if (encoding === 'br') decoder = createBrotliDecompress();
else if (encoding === 'deflate') decoder = createDeflate();
if (decoder) {
res.pipe(decoder);
@ -137,7 +137,7 @@ function https_getter(req_url: string, options: RequestOpts = {}): Promise<Incom
method: options.method
};
const req = https.request(req_options, resolve);
const req = httpsRequest(req_options, resolve);
req.on('error', (err) => {
reject(err);
});

View File

@ -1,10 +1,10 @@
import fs from 'node:fs';
import { existsSync, readFileSync } from 'node:fs';
import { StreamType } from '../YouTube/stream';
import { request } from '../Request';
import { SoundCloudPlaylist, SoundCloudTrack, SoundCloudTrackFormat, SoundCloudStream } from './classes';
let soundData: SoundDataOptions;
if (fs.existsSync('.data/soundcloud.data')) {
soundData = JSON.parse(fs.readFileSync('.data/soundcloud.data').toString());
if (existsSync('.data/soundcloud.data')) {
soundData = JSON.parse(readFileSync('.data/soundcloud.data').toString());
}
interface SoundDataOptions {

View File

@ -1,10 +1,10 @@
import { request } from '../Request';
import { SpotifyAlbum, SpotifyPlaylist, SpotifyTrack } from './classes';
import fs from 'node:fs';
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
let spotifyData: SpotifyDataOptions;
if (fs.existsSync('.data/spotify.data')) {
spotifyData = JSON.parse(fs.readFileSync('.data/spotify.data').toString());
if (existsSync('.data/spotify.data')) {
spotifyData = JSON.parse(readFileSync('.data/spotify.data').toString());
spotifyData.file = true;
}
/**
@ -132,7 +132,7 @@ export async function SpotifyAuthorize(data: SpotifyDataOptions, file: boolean):
token_type: resp_json.token_type,
market: data.market
};
if (file) fs.writeFileSync('.data/spotify.data', JSON.stringify(spotifyData, undefined, 4));
if (file) writeFileSync('.data/spotify.data', JSON.stringify(spotifyData, undefined, 4));
else {
console.log(`Client ID : ${spotifyData.client_id}`);
console.log(`Client Secret : ${spotifyData.client_secret}`);
@ -233,7 +233,7 @@ export async function refreshToken(): Promise<boolean> {
spotifyData.expires_in = Number(resp_json.expires_in);
spotifyData.expiry = Date.now() + (resp_json.expires_in - 1) * 1000;
spotifyData.token_type = resp_json.token_type;
if (spotifyData.file) fs.writeFileSync('.data/spotify.data', JSON.stringify(spotifyData, undefined, 4));
if (spotifyData.file) writeFileSync('.data/spotify.data', JSON.stringify(spotifyData, undefined, 4));
return true;
}

View File

@ -1,8 +1,8 @@
import fs from 'node:fs';
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
let youtubeData: youtubeDataOptions;
if (fs.existsSync('.data/youtube.data')) {
youtubeData = JSON.parse(fs.readFileSync('.data/youtube.data').toString());
if (existsSync('.data/youtube.data')) {
youtubeData = JSON.parse(readFileSync('.data/youtube.data').toString());
youtubeData.file = true;
}
@ -30,7 +30,7 @@ export function setCookie(key: string, value: string): boolean {
export function uploadCookie() {
if (youtubeData.cookie && youtubeData.file)
fs.writeFileSync('.data/youtube.data', JSON.stringify(youtubeData, undefined, 4));
writeFileSync('.data/youtube.data', JSON.stringify(youtubeData, undefined, 4));
}
export function setCookieToken(options: { cookie: string }) {

View File

@ -60,8 +60,8 @@ interface SearchOptions {
fuzzy?: boolean;
}
import readline from 'node:readline';
import fs from 'node:fs';
import { createInterface } from 'node:readline';
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
import {
sp_validate,
yt_validate,
@ -304,7 +304,7 @@ export async function validate(
* Just run the above command and you will get a interface asking some questions.
*/
export function authorization(): void {
const ask = readline.createInterface({
const ask = createInterface({
input: process.stdin,
output: process.stdout
});
@ -346,7 +346,7 @@ export function authorization(): void {
)} \n`
);
ask.question('Paste the url which you just copied : ', async (url) => {
if (!fs.existsSync('.data')) fs.mkdirSync('.data');
if (!existsSync('.data')) mkdirSync('.data');
const spotifyData = {
client_id,
client_secret,
@ -375,11 +375,11 @@ export function authorization(): void {
ask.close();
return;
}
if (!fs.existsSync('.data')) fs.mkdirSync('.data');
if (!existsSync('.data')) mkdirSync('.data');
console.log('Validating your client ID, hold on...');
if (await check_id(client_id)) {
console.log('Client ID has been validated successfully.');
fs.writeFileSync('.data/soundcloud.data', JSON.stringify({ client_id }, undefined, 4));
writeFileSync('.data/soundcloud.data', JSON.stringify({ client_id }, undefined, 4));
} else console.log("That doesn't look like a valid client ID. Retry with a correct client ID.");
ask.close();
});
@ -395,7 +395,7 @@ export function authorization(): void {
ask.close();
return;
}
if (!fs.existsSync('.data')) fs.mkdirSync('.data');
if (!existsSync('.data')) mkdirSync('.data');
console.log('Cookies has been added successfully.');
let cookie: Object = {};
cook.split(';').forEach((x) => {
@ -405,7 +405,7 @@ export function authorization(): void {
const value = arr.join('=').trim();
Object.assign(cookie, { [key]: value });
});
fs.writeFileSync('.data/youtube.data', JSON.stringify({ cookie }, undefined, 4));
writeFileSync('.data/youtube.data', JSON.stringify({ cookie }, undefined, 4));
ask.close();
});
} else {

View File

@ -13,7 +13,6 @@
"declaration": true,
"declarationMap": true,
"outDir": "dist",
"incremental": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true

16
tsup.config.json Normal file
View File

@ -0,0 +1,16 @@
{
"clean": true,
"dts": true,
"entryPoints": [
"play-dl/index.ts"
],
"format": [
"esm",
"cjs"
],
"minify": true,
"skipNodeModulesBundle": true,
"sourcemap": true,
"target": "es2021",
"splitting": false
}