Skip to content

Commit

Permalink
feat: esm
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Apr 15, 2022
1 parent 3003f48 commit 0b4d7e3
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 101 deletions.
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
},
"homepage": "https://github.com/bitfocus/companion-satellite#readme",
"main": "dist/electron.js",
"type": "module",
"license": "MIT",
"private": true,
"scripts": {
"prepare": "husky install",
"dev": "yarn ts-node src/main.ts",
"dev": "yarn ts-node-esm src/main.ts",
"dev-electron": "yarn build:main && electron dist/electron.js",
"dist:prepare:sharp": "cd node_modules/sharp && rimraf vendor && node install/libvips && node install/dll-copy",
"electron-rebuild": "yarn dist:prepare:sharp && electron-builder install-app-deps",
Expand All @@ -43,7 +44,7 @@
"electron-notarize": "^1.2.1",
"rimraf": "^3.0.2",
"standard-version": "^9.3.2",
"ts-node": "^9.1.1",
"ts-node": "^10.7.0",
"typescript": "~4.5",
"zx": "^6.1.0"
},
Expand All @@ -58,9 +59,9 @@
"electron-prompt": "^1.7.0",
"electron-store": "^8.0.1",
"eventemitter3": "^4.0.7",
"exit-hook": "^2.2.1",
"exit-hook": "^3.0.0",
"infinitton-idisplay": "^1.1.2",
"meow": "^9.0.0",
"meow": "^10.1.2",
"node-hid": "github:julusian/node-hid#v2.1.2-1",
"sharp": "^0.30.3",
"tslib": "^2.3.1",
Expand Down Expand Up @@ -126,14 +127,14 @@
"target": "tar.gz",
"artifactName": "companion-satellite-${arch}.tar.gz",
"extraFiles": [
{
"from": "./node_modules/sharp/vendor/${env.VIPS_VENDOR}/lib",
"to": ".",
"filter": [
"libvips*.so.*"
]
}
]
{
"from": "./node_modules/sharp/vendor/${env.VIPS_VENDOR}/lib",
"to": ".",
"filter": [
"libvips*.so.*"
]
}
]
},
"files": [
"**/*",
Expand Down
10 changes: 3 additions & 7 deletions src/cards.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import * as path from 'path'
import { promisify } from 'util'
import { readFile } from 'fs'
import * as sharp from 'sharp'

const readFileP = promisify(readFile)
import { readFile } from 'fs/promises'
import sharp from 'sharp'

export class CardGenerator {
private iconImage: Buffer | undefined

async loadIcon(): Promise<Buffer> {
if (!this.iconImage) {
const rawData = await readFileP(path.join(__dirname, '../assets/icon.png'))
const rawData = await readFile(new URL('../assets/icon.png', import.meta.url))
this.iconImage = rawData
}

Expand Down
8 changes: 4 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventEmitter } from 'eventemitter3'
import EE3 from 'eventemitter3'
import { Socket } from 'net'
import { DeviceDrawProps, DeviceRegisterProps } from './device-types/api'
import { DEFAULT_PORT } from './lib'
import { DeviceDrawProps, DeviceRegisterProps } from './device-types/api.js'
import { DEFAULT_PORT } from './lib.js'

const PING_UNACKED_LIMIT = 5 // Arbitrary number
const PING_INTERVAL = 100
Expand Down Expand Up @@ -53,7 +53,7 @@ export type CompanionSatelliteClientEvents = {
clearDeck: [{ deviceId: string }]
}

export class CompanionSatelliteClient extends EventEmitter<CompanionSatelliteClientEvents> {
export class CompanionSatelliteClient extends EE3.EventEmitter<CompanionSatelliteClientEvents> {
private readonly debug: boolean
private socket: Socket | undefined

Expand Down
2 changes: 1 addition & 1 deletion src/device-types/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CompanionSatelliteClient } from '../client'
import { CompanionSatelliteClient } from '../client.js'

export type DeviceId = string

Expand Down
8 changes: 4 additions & 4 deletions src/device-types/infinitton.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CompanionSatelliteClient } from '../client'
import { CardGenerator } from '../cards'
import { DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api'
import Infinitton = require('infinitton-idisplay')
import { CompanionSatelliteClient } from '../client.js'
import { CardGenerator } from '../cards.js'
import { DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api.js'
import Infinitton from 'infinitton-idisplay'

export class InfinittonWrapper implements WrappedDevice {
readonly #cardGenerator: CardGenerator
Expand Down
10 changes: 5 additions & 5 deletions src/device-types/streamdeck.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { StreamDeck } from '@elgato-stream-deck/node'
import sharp = require('sharp')
import { CompanionSatelliteClient } from '../client'
import { CardGenerator } from '../cards'
import { ImageWriteQueue } from '../writeQueue'
import { DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api'
import sharp from 'sharp'
import { CompanionSatelliteClient } from '../client.js'
import { CardGenerator } from '../cards.js'
import { ImageWriteQueue } from '../writeQueue.js'
import { DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api.js'

export class StreamDeckWrapper implements WrappedDevice {
readonly #cardGenerator: CardGenerator
Expand Down
4 changes: 2 additions & 2 deletions src/device-types/xencelabs-quick-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
XencelabsQuickKeysDisplayOrientation,
WheelEvent,
} from '@xencelabs-quick-keys/node'
import { CompanionSatelliteClient } from '../client'
import { WrappedDevice, DeviceRegisterProps, DeviceDrawProps } from './api'
import { CompanionSatelliteClient } from '../client.js'
import { WrappedDevice, DeviceRegisterProps, DeviceDrawProps } from './api.js'

function keyToCompanion(k: number): number | null {
if (k >= 0 && k < 4) return k + 1
Expand Down
14 changes: 7 additions & 7 deletions src/devices.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { CompanionSatelliteClient } from './client'
import { CompanionSatelliteClient } from './client.js'
import { getStreamDeckDeviceInfo, openStreamDeck, StreamDeck } from '@elgato-stream-deck/node'
import { usb } from 'usb'
import { CardGenerator } from './cards'
import { CardGenerator } from './cards.js'
import { XencelabsQuickKeysManagerInstance, XencelabsQuickKeys } from '@xencelabs-quick-keys/node'
import { DeviceId, WrappedDevice } from './device-types/api'
import { StreamDeckWrapper } from './device-types/streamdeck'
import { QuickKeysWrapper } from './device-types/xencelabs-quick-keys'
import Infinitton = require('infinitton-idisplay')
import { InfinittonWrapper } from './device-types/infinitton'
import { DeviceId, WrappedDevice } from './device-types/api.js'
import { StreamDeckWrapper } from './device-types/streamdeck.js'
import { QuickKeysWrapper } from './device-types/xencelabs-quick-keys.js'
import Infinitton from 'infinitton-idisplay'
import { InfinittonWrapper } from './device-types/infinitton.js'
import * as HID from 'node-hid'

export class DeviceManager {
Expand Down
14 changes: 8 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import exitHook = require('exit-hook')
import * as meow from 'meow'
import { CompanionSatelliteClient } from './client'
import { DeviceManager } from './devices'
import { DEFAULT_PORT } from './lib'
import exitHook from 'exit-hook'
import meow from 'meow'
import { CompanionSatelliteClient } from './client.js'
import { DeviceManager } from './devices.js'
import { DEFAULT_PORT } from './lib.js'

const cli = meow(
`
Expand All @@ -13,7 +13,9 @@ const cli = meow(
$ companion-satellite 192.168.1.100
$ companion-satellite 192.168.1.100 16622
`,
{}
{
importMeta: import.meta,
}
)

if (cli.input.length === 0) {
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"{{PACKAGE-NAME}}": ["./src/index.ts"]
},
"types": ["node"],
"skipLibCheck": true
"skipLibCheck": true,
"module": "ES2020",
"allowSyntheticDefaultImports": true
}
}
Loading

0 comments on commit 0b4d7e3

Please sign in to comment.