Build with tsup, fix warnings and cleanup imports
This commit is contained in:
parent
5a094be82e
commit
5b904bda46
1873
package-lock.json
generated
1873
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,14 +4,15 @@
|
|||||||
"description": "YouTube, SoundCloud, Spotify, Deezer searching and streaming for discord.js bots",
|
"description": "YouTube, SoundCloud, Spotify, Deezer searching and streaming for discord.js bots",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
|
"module": "dist/index.mjs",
|
||||||
"directories": {
|
"directories": {
|
||||||
"example": "examples"
|
"example": "examples"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsup",
|
||||||
"build:check": "tsc --noEmit --incremental false",
|
"build:check": "tsc --noEmit --incremental false",
|
||||||
"pretty": "prettier --config .prettierrc \"play-dl/*.ts\" \"play-dl/*/*.ts\" \"play-dl/*/*/*.ts\" --write ",
|
"pretty": "prettier --config .prettierrc \"play-dl/*.ts\" \"play-dl/*/*.ts\" \"play-dl/*/*/*.ts\" --write ",
|
||||||
"prepublishOnly": "tsc --build --clean && tsc --build --verbose"
|
"prepublishOnly": "tsup"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -43,6 +44,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^16.9.4",
|
"@types/node": "^16.9.4",
|
||||||
"prettier": "^2.3.1",
|
"prettier": "^2.3.1",
|
||||||
|
"tsup": "^5.11.1",
|
||||||
"typedoc": "^0.22.9",
|
"typedoc": "^0.22.9",
|
||||||
"typedoc-plugin-missing-exports": "^0.22.4",
|
"typedoc-plugin-missing-exports": "^0.22.4",
|
||||||
"typescript": "^4.4.4",
|
"typescript": "^4.4.4",
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { URL } from 'url';
|
import { URL } from 'node:url';
|
||||||
import { request, request_resolve_redirect } from '../Request';
|
import { request, request_resolve_redirect } from '../Request';
|
||||||
import { DeezerAlbum, DeezerPlaylist, DeezerTrack } from './classes';
|
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 (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.');
|
if (metadata.length === 0) throw new Error('At least one type of metadata is required.');
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { IncomingMessage } from 'node:http';
|
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 { 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 { cookieHeaders, getCookies } from '../YouTube/utils/cookie';
|
||||||
import { getRandomUserAgent } from './useragent';
|
import { getRandomUserAgent } from './useragent';
|
||||||
|
|
||||||
@ -78,9 +78,9 @@ export function request(req_url: string, options: RequestOpts = { method: 'GET'
|
|||||||
const data: string[] = [];
|
const data: string[] = [];
|
||||||
let decoder: BrotliDecompress | Gunzip | Deflate | undefined = undefined;
|
let decoder: BrotliDecompress | Gunzip | Deflate | undefined = undefined;
|
||||||
const encoding = res.headers['content-encoding'];
|
const encoding = res.headers['content-encoding'];
|
||||||
if (encoding === 'gzip') decoder = zlib.createGunzip();
|
if (encoding === 'gzip') decoder = createGunzip();
|
||||||
else if (encoding === 'br') decoder = zlib.createBrotliDecompress();
|
else if (encoding === 'br') decoder = createBrotliDecompress();
|
||||||
else if (encoding === 'deflate') decoder = zlib.createDeflate();
|
else if (encoding === 'deflate') decoder = createDeflate();
|
||||||
|
|
||||||
if (decoder) {
|
if (decoder) {
|
||||||
res.pipe(decoder);
|
res.pipe(decoder);
|
||||||
@ -137,7 +137,7 @@ function https_getter(req_url: string, options: RequestOpts = {}): Promise<Incom
|
|||||||
method: options.method
|
method: options.method
|
||||||
};
|
};
|
||||||
|
|
||||||
const req = https.request(req_options, resolve);
|
const req = httpsRequest(req_options, resolve);
|
||||||
req.on('error', (err) => {
|
req.on('error', (err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import fs from 'node:fs';
|
import { existsSync, readFileSync } from 'node:fs';
|
||||||
import { StreamType } from '../YouTube/stream';
|
import { StreamType } from '../YouTube/stream';
|
||||||
import { request } from '../Request';
|
import { request } from '../Request';
|
||||||
import { SoundCloudPlaylist, SoundCloudTrack, SoundCloudTrackFormat, SoundCloudStream } from './classes';
|
import { SoundCloudPlaylist, SoundCloudTrack, SoundCloudTrackFormat, SoundCloudStream } from './classes';
|
||||||
let soundData: SoundDataOptions;
|
let soundData: SoundDataOptions;
|
||||||
if (fs.existsSync('.data/soundcloud.data')) {
|
if (existsSync('.data/soundcloud.data')) {
|
||||||
soundData = JSON.parse(fs.readFileSync('.data/soundcloud.data').toString());
|
soundData = JSON.parse(readFileSync('.data/soundcloud.data').toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SoundDataOptions {
|
interface SoundDataOptions {
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import { request } from '../Request';
|
import { request } from '../Request';
|
||||||
import { SpotifyAlbum, SpotifyPlaylist, SpotifyTrack } from './classes';
|
import { SpotifyAlbum, SpotifyPlaylist, SpotifyTrack } from './classes';
|
||||||
import fs from 'node:fs';
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
||||||
|
|
||||||
let spotifyData: SpotifyDataOptions;
|
let spotifyData: SpotifyDataOptions;
|
||||||
if (fs.existsSync('.data/spotify.data')) {
|
if (existsSync('.data/spotify.data')) {
|
||||||
spotifyData = JSON.parse(fs.readFileSync('.data/spotify.data').toString());
|
spotifyData = JSON.parse(readFileSync('.data/spotify.data').toString());
|
||||||
spotifyData.file = true;
|
spotifyData.file = true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -132,7 +132,7 @@ export async function SpotifyAuthorize(data: SpotifyDataOptions, file: boolean):
|
|||||||
token_type: resp_json.token_type,
|
token_type: resp_json.token_type,
|
||||||
market: data.market
|
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 {
|
else {
|
||||||
console.log(`Client ID : ${spotifyData.client_id}`);
|
console.log(`Client ID : ${spotifyData.client_id}`);
|
||||||
console.log(`Client Secret : ${spotifyData.client_secret}`);
|
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.expires_in = Number(resp_json.expires_in);
|
||||||
spotifyData.expiry = Date.now() + (resp_json.expires_in - 1) * 1000;
|
spotifyData.expiry = Date.now() + (resp_json.expires_in - 1) * 1000;
|
||||||
spotifyData.token_type = resp_json.token_type;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import fs from 'node:fs';
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
||||||
|
|
||||||
let youtubeData: youtubeDataOptions;
|
let youtubeData: youtubeDataOptions;
|
||||||
if (fs.existsSync('.data/youtube.data')) {
|
if (existsSync('.data/youtube.data')) {
|
||||||
youtubeData = JSON.parse(fs.readFileSync('.data/youtube.data').toString());
|
youtubeData = JSON.parse(readFileSync('.data/youtube.data').toString());
|
||||||
youtubeData.file = true;
|
youtubeData.file = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ export function setCookie(key: string, value: string): boolean {
|
|||||||
|
|
||||||
export function uploadCookie() {
|
export function uploadCookie() {
|
||||||
if (youtubeData.cookie && youtubeData.file)
|
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 }) {
|
export function setCookieToken(options: { cookie: string }) {
|
||||||
|
|||||||
@ -60,8 +60,8 @@ interface SearchOptions {
|
|||||||
fuzzy?: boolean;
|
fuzzy?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
import readline from 'node:readline';
|
import { createInterface } from 'node:readline';
|
||||||
import fs from 'node:fs';
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
||||||
import {
|
import {
|
||||||
sp_validate,
|
sp_validate,
|
||||||
yt_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.
|
* Just run the above command and you will get a interface asking some questions.
|
||||||
*/
|
*/
|
||||||
export function authorization(): void {
|
export function authorization(): void {
|
||||||
const ask = readline.createInterface({
|
const ask = createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout
|
output: process.stdout
|
||||||
});
|
});
|
||||||
@ -346,7 +346,7 @@ export function authorization(): void {
|
|||||||
)} \n`
|
)} \n`
|
||||||
);
|
);
|
||||||
ask.question('Paste the url which you just copied : ', async (url) => {
|
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 = {
|
const spotifyData = {
|
||||||
client_id,
|
client_id,
|
||||||
client_secret,
|
client_secret,
|
||||||
@ -375,11 +375,11 @@ export function authorization(): void {
|
|||||||
ask.close();
|
ask.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!fs.existsSync('.data')) fs.mkdirSync('.data');
|
if (!existsSync('.data')) mkdirSync('.data');
|
||||||
console.log('Validating your client ID, hold on...');
|
console.log('Validating your client ID, hold on...');
|
||||||
if (await check_id(client_id)) {
|
if (await check_id(client_id)) {
|
||||||
console.log('Client ID has been validated successfully.');
|
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.");
|
} else console.log("That doesn't look like a valid client ID. Retry with a correct client ID.");
|
||||||
ask.close();
|
ask.close();
|
||||||
});
|
});
|
||||||
@ -395,7 +395,7 @@ export function authorization(): void {
|
|||||||
ask.close();
|
ask.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!fs.existsSync('.data')) fs.mkdirSync('.data');
|
if (!existsSync('.data')) mkdirSync('.data');
|
||||||
console.log('Cookies has been added successfully.');
|
console.log('Cookies has been added successfully.');
|
||||||
let cookie: Object = {};
|
let cookie: Object = {};
|
||||||
cook.split(';').forEach((x) => {
|
cook.split(';').forEach((x) => {
|
||||||
@ -405,7 +405,7 @@ export function authorization(): void {
|
|||||||
const value = arr.join('=').trim();
|
const value = arr.join('=').trim();
|
||||||
Object.assign(cookie, { [key]: value });
|
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();
|
ask.close();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -13,7 +13,6 @@
|
|||||||
"declaration": true,
|
"declaration": true,
|
||||||
"declarationMap": true,
|
"declarationMap": true,
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"incremental": true,
|
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"resolveJsonModule": true
|
"resolveJsonModule": true
|
||||||
|
|||||||
16
tsup.config.json
Normal file
16
tsup.config.json
Normal 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
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user