Skip to content

Commit

Permalink
Use tsup more for building and sourcemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
PapiOphidian committed Nov 17, 2023
1 parent 9f4cdac commit b0e4e38
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 52 deletions.
2 changes: 1 addition & 1 deletion packages/buttons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc -p .",
"build": "tsup && node ../../scripts/fixup-dts.js",
"lint": "eslint . --ext .ts"
},
"author": "PapiOphidian",
Expand Down
56 changes: 29 additions & 27 deletions packages/buttons/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,34 @@ const randomString = Math.random().toString(36).substring(7)
let idSequence = 0
const bcAcceptableTypes = [2, 3, 5, 6, 7, 8] as const

class BetterComponent {
public callback: ((interaction: APIMessageComponentInteraction, component: BetterComponent) => unknown) | null = null
public id: string = BetterComponent.#nextID
public component: APIButtonComponentWithCustomId | APISelectMenuComponent

public constructor(
public info: Omit<APIButtonComponentWithCustomId | APISelectMenuComponent, "custom_id">,
extraEncodedInfo: Record<string, any>
) {
components.set(this.id, this)
this.component = { custom_id: encoding.encode({ mid: this.id, ...(extraEncodedInfo || {}) }), ...this.info } as BetterComponent["component"]
}

static get #nextID(): string {
return `menu-${randomString}-${idSequence++}`
}

public setCallback(fn: (interaction: APIMessageComponentInteraction, component: BetterComponent) => unknown): this {
this.callback = fn
return this
}

public destroy(): this {
components.delete(this.id)
return this
}
}

const cc = {
setHandlers(router: (button: APIMessageComponentInteractionData, user: APIUser) => string, info: {
[route: string]: (button: APIMessageComponentInteractionData, user: APIUser) => unknown
Expand All @@ -43,33 +71,7 @@ const cc = {
if (handlers[route]) handlers[route](interaction.data, interaction.user ? interaction.user : interaction.member!.user)
},

BetterComponent: class BetterComponent {
public callback: ((interaction: APIMessageComponentInteraction, component: BetterComponent) => unknown) | null = null
public id: string = BetterComponent.#nextID
public component: APIButtonComponentWithCustomId | APISelectMenuComponent

public constructor(
public info: Omit<APIButtonComponentWithCustomId | APISelectMenuComponent, "custom_id">,
extraEncodedInfo: Record<string, any>
) {
components.set(this.id, this)
this.component = { custom_id: encoding.encode({ mid: this.id, ...(extraEncodedInfo || {}) }), ...this.info } as BetterComponent["component"]
}

static get #nextID(): string {
return `menu-${randomString}-${idSequence++}`
}

public setCallback(fn: (interaction: APIMessageComponentInteraction, component: BetterComponent) => unknown): this {
this.callback = fn
return this
}

public destroy(): this {
components.delete(this.id)
return this
}
}
BetterComponent
}

export = cc
3 changes: 2 additions & 1 deletion packages/buttons/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"compilerOptions": {
"outDir": "./dist",
"sourceMap": false,
"declaration": true
"declaration": true,
"incremental": false
}
}
16 changes: 16 additions & 0 deletions packages/buttons/tsup.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"clean": false,
"dts": true,
"entryPoints": [
"src/index.ts"
],
"format": [
"cjs"
],
"minify": true,
"skipNodeModulesBundle": true,
"sourcemap": true,
"target": "es2022",
"splitting": false,
"keepNames": true
}
2 changes: 1 addition & 1 deletion packages/commands/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc -p .",
"build": "tsup",
"lint": "eslint . --ext .ts"
},
"author": "PapiOphidian",
Expand Down
3 changes: 2 additions & 1 deletion packages/commands/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"outDir": "./dist",
"sourceMap": false,
"declaration": true
"declaration": true,
"incremental": false
}
}
16 changes: 16 additions & 0 deletions packages/commands/tsup.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"clean": false,
"dts": true,
"entryPoints": [
"src/index.ts"
],
"format": [
"cjs"
],
"minify": true,
"skipNodeModulesBundle": true,
"sourcemap": true,
"target": "es2022",
"splitting": false,
"keepNames": true
}
2 changes: 1 addition & 1 deletion packages/encoding/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc -p .",
"build": "tsup",
"lint": "eslint . --ext .ts"
},
"author": "PapiOphidian",
Expand Down
3 changes: 2 additions & 1 deletion packages/encoding/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"compilerOptions": {
"outDir": "./dist",
"sourceMap": false,
"declaration": true
"declaration": true,
"incremental": false
}
}
16 changes: 16 additions & 0 deletions packages/encoding/tsup.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"clean": false,
"dts": true,
"entryPoints": [
"src/index.ts"
],
"format": [
"cjs"
],
"minify": true,
"skipNodeModulesBundle": true,
"sourcemap": true,
"target": "es2022",
"splitting": false,
"keepNames": true
}
21 changes: 12 additions & 9 deletions packages/runtime-website-client/src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import type { UnpackArray } from "../../shared-types/index"
// From HTML
const serverTimeDiff = _serverTimeDiff

type WebQueueMembers = ReturnType<WebQueue["toJSON"]>["members"]
type WebTrackJSON = ReturnType<WebTrack["toObject"]>

export class ElemJS<E extends HTMLElement = HTMLElement> {
public parent: ElemJS<HTMLElement>
public children: Array<ElemJS<HTMLElement>> = []
Expand Down Expand Up @@ -132,7 +135,7 @@ export class Queue<E extends HTMLElement = HTMLElement> extends ElemJS<E> {
super(container)
}

public addItem(data: ReturnType<WebTrack["toObject"]>, position?: number): void {
public addItem(data: WebTrackJSON, position?: number): void {
const shouldAnimate = this.addingCount < this.animateMax
const e = new QueueItem(data, this)
if (shouldAnimate) {
Expand Down Expand Up @@ -180,12 +183,12 @@ export class QueueItem<Q extends Queue> extends ElemJS<HTMLDivElement> {
length: ejs`div.song-length` as ElemJS<HTMLDivElement>,
controls: ejs`div.song-management` as ElemJS<HTMLDivElement>
}
public data: ReturnType<WebTrack["toObject"]> = {} as ReturnType<WebTrack["toObject"]>
public data: WebTrackJSON = {} as WebTrackJSON
public shifting = false

declare public parent: Q

public constructor(data: ReturnType<WebTrack["toObject"]>, public queue: Q) {
public constructor(data: WebTrackJSON, public queue: Q) {
super("div")
this.class("queue-item")

Expand All @@ -197,7 +200,7 @@ export class QueueItem<Q extends Queue> extends ElemJS<HTMLDivElement> {
this.updateData(data)
}

public updateData(data: ReturnType<WebTrack["toObject"]>): void {
public updateData(data: WebTrackJSON): void {
Object.assign(this.data, data)
this.render()
this.preloadThumbnail()
Expand Down Expand Up @@ -362,7 +365,7 @@ class AttributeButton extends ElemJS<HTMLImageElement> {
}

export class Player<E extends HTMLElement> extends ElemJS<E> {
public track: ReturnType<WebTrack["toObject"]> | null = null
public track: WebTrackJSON | null = null
public thumbnailDisplayHeight = 94
public attributes = {
loop: false
Expand All @@ -388,13 +391,13 @@ export class Player<E extends HTMLElement> extends ElemJS<E> {
this.render()
}

public setTrack(track: ReturnType<WebTrack["toObject"]> | null): void {
public setTrack(track: WebTrackJSON | null): void {
this.trackSet = true
this.track = track
this.render()
}

public updateData(data: ReturnType<WebTrack["toObject"]>): void {
public updateData(data: WebTrackJSON): void {
this.trackSet = true
Object.assign(this.track!, data)
this.render()
Expand Down Expand Up @@ -650,7 +653,7 @@ export class VoiceInfo<E extends HTMLElement> extends ElemJS<E> {
this.render()
}

public setMembers(members: ReturnType<WebQueue["toJSON"]>["members"]): void {
public setMembers(members: WebQueueMembers): void {
members.forEach(member => {
if (!this.memberStore.has(member.id)) {
this.memberStore.set(member.id, new VoiceMember(member))
Expand Down Expand Up @@ -712,7 +715,7 @@ export class VoiceMember extends ElemJS<HTMLDivElement> {
public isNew = true
public leaving = false

public constructor(public props: UnpackArray<ReturnType<WebQueue["toJSON"]>["members"]>) {
public constructor(public props: UnpackArray<WebQueueMembers>) {
super("div")
}

Expand Down
13 changes: 8 additions & 5 deletions packages/runtime-website-client/src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import { ListenManager } from "./wrappers/ListenManager.js"
import type { Queue as WebQueue } from "../../runtime-website/src/music/queue.js"
import type { Track as WebTrack } from "../../runtime-website/src/music/tracktypes.js"

type WebQueueJSON = ReturnType<WebQueue["toJSON"]>
type WebTrackJSON = ReturnType<WebTrack["toObject"]>

export class Session {
public state: ReturnType<WebQueue["toJSON"]> | null = null
public state: WebQueueJSON | null = null
public player: Player<HTMLElement> = new Player(q("#player-container")!, this)
public queue: Queue<HTMLElement> = new Queue(q("#queue-container")!, this)
public voiceInfo: VoiceInfo<HTMLElement> = new VoiceInfo(q("#voice-info")!)
Expand Down Expand Up @@ -72,7 +75,7 @@ export class Session {
this.sideControls.render()
}

public updateState(data: { d: ReturnType<WebQueue["toJSON"]> }): void {
public updateState(data: { d: WebQueueJSON }): void {
const oldState = this.state
this.state = data.d || null
if (this.state === null) {
Expand All @@ -97,7 +100,7 @@ export class Session {
this.listenersUpdate(data)
}

public listenersUpdate(data: { d: ReturnType<WebQueue["toJSON"]> }): void {
public listenersUpdate(data: { d: WebQueueJSON }): void {
if (data && this.state) {
this.state.members = data.d.members
this.voiceInfo.setMembers(this.state.members)
Expand All @@ -106,7 +109,7 @@ export class Session {
}
}

public trackAdd(data: { d: { position: number; track: ReturnType<WebTrack["toObject"]> } }): void {
public trackAdd(data: { d: { position: number; track: WebTrackJSON } }): void {
if (!this.state) return
this.state.tracks.splice(data.d.position, 0, data.d.track)
if (this.state.tracks.length == 1) {
Expand Down Expand Up @@ -138,7 +141,7 @@ export class Session {
this.listenManager.next(this.state.tracks[0])
}

public trackUpdate(data: { d: { index: number; track: ReturnType<WebTrack["toObject"]> } }): void {
public trackUpdate(data: { d: { index: number; track: WebTrackJSON } }): void {
if (!this.state) return
const track = data.d.track
const index = data.d.index
Expand Down
10 changes: 6 additions & 4 deletions packages/runtime-website-client/src/wrappers/ListenManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@ import { SoundCloudWrapper } from "./SoundCloudWrapper.js"

import type { Track as WebTrack } from "../../../runtime-website/src/music/tracktypes"

type WebTrackJSON = ReturnType<WebTrack["toObject"]>

export class ListenManager {
public currentWrapper: Wrapper | null = null
public wrappers = { soundCloudWrapper: new SoundCloudWrapper() }
public enabled = false

public boot(track: ReturnType<WebTrack["toObject"]>, timeGetter: () => number): void {
public boot(track: WebTrackJSON, timeGetter: () => number): void {
this.enabled = true
this._selectWrapper(track)
if (!this.currentWrapper) return
this.currentWrapper.load(track)
this.currentWrapper.seekAndPlay(timeGetter, track.length * 1000)
}

public load(track: ReturnType<WebTrack["toObject"]>): void {
public load(track: WebTrackJSON): void {
if (!this.enabled) return
this.stop()
this._selectWrapper(track)
if (!this.currentWrapper) return
this.currentWrapper.load(track)
}

public async next(track: ReturnType<WebTrack["toObject"]>): Promise<void> {
public async next(track: WebTrackJSON): Promise<void> {
if (!this.enabled) return
console.log("next: calling stop")
if (this.currentWrapper) await this.currentWrapper.stop()
Expand Down Expand Up @@ -55,7 +57,7 @@ export class ListenManager {
this.currentWrapper = null
}

private _selectWrapper(track: ReturnType<WebTrack["toObject"]>): void {
private _selectWrapper(track: WebTrackJSON): void {
if (track.source === "soundcloud") this.currentWrapper = this.wrappers.soundCloudWrapper
else this.currentWrapper = null
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sql/tsup.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"minify": true,
"skipNodeModulesBundle": true,
"sourcemap": false,
"sourcemap": true,
"target": "es2022",
"splitting": false,
"keepNames": true
Expand Down

0 comments on commit b0e4e38

Please sign in to comment.