From 0a327b247c80a437a067e8064d6ffb18866ad240 Mon Sep 17 00:00:00 2001 From: Matthias Kesler Date: Wed, 29 Oct 2025 17:39:14 +0100 Subject: [PATCH] more align with template implementation --- .gitattributes | 1 + .github/workflows/node.yaml | 76 +++++++++++++++++++++++++++++++++++++ .gitignore | 5 ++- LICENSE | 2 +- README.md | 8 ++++ package.json | 10 ++--- src/actions.ts | 2 +- src/main.ts | 40 ++++++++++--------- src/presets.ts | 2 +- src/upgrades.ts | 5 ++- src/variables.ts | 2 +- tsconfig.build.json | 2 +- tsconfig.json | 2 +- 13 files changed, 126 insertions(+), 31 deletions(-) create mode 100644 .gitattributes create mode 100644 .github/workflows/node.yaml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/workflows/node.yaml b/.github/workflows/node.yaml new file mode 100644 index 0000000..3cb6491 --- /dev/null +++ b/.github/workflows/node.yaml @@ -0,0 +1,76 @@ +name: Node CI + +on: + push: + branches: + - '**' + tags: + - 'v[0-9]+.[0-9]+.[0-9]+*' + pull_request: + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js 22.x + # This should match the version of Node.js you have defined in the manifest.json runtime field + uses: actions/setup-node@v4 + with: + node-version: 22.x + - name: Prepare Environment + run: | + corepack enable + - name: Prepare Environment (For template repository) + # Only run this step if the repository is a template repository + # If you are using this in a module, you can remove this step + if: ${{ contains(github.repository, 'companion-module-template-') }} + run: | + # Perform an install to generate the lockfile + yarn install + env: + CI: false + - name: Prepare module + run: | + yarn install + env: + CI: true + - name: Build and check types + run: | + yarn build + env: + CI: true + - name: Run lint + run: | + yarn lint + env: + CI: true + + # Uncomment this to enable running unit tests + # test: + # name: Test + # runs-on: ubuntu-latest + # timeout-minutes: 15 + + # steps: + # - uses: actions/checkout@v4 + # - name: Use Node.js 22.x + # uses: actions/setup-node@v4 + # with: + # node-version: 22.x + # - name: Prepare Environment + # run: | + # corepack enable + # yarn install + # env: + # CI: true + # - name: Run tests + # run: | + # yarn test + # env: + # CI: true + # - name: Send coverage + # uses: codecov/codecov-action@v5 diff --git a/.gitignore b/.gitignore index 94ff50b..5e6dce8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ node_modules/ package-lock.json .DS_Store /pkg -/pkg.tgz +/*.tgz /dist DEBUG-* -/.yarn \ No newline at end of file +/.yarn +/.vscode diff --git a/LICENSE b/LICENSE index a73aa11..0f6be20 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Bitfocus AS - Open Source +Copyright (c) 2022 Bitfocus AS - Open Source Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 8134341..03043d5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # companion-module-toggl-track See [HELP.md](./companion/HELP.md) and [LICENSE](./LICENSE) + +## Getting started + +Executing a `yarn` command should perform all necessary steps to develop the module, if it does not then follow the steps below. + +The module can be built once with `yarn build`. This should be enough to get the module to be loadable by companion. + +While developing the module, by using `yarn dev` the compiler will be run in watch mode to recompile the files on change. diff --git a/package.json b/package.json index e63c19e..aa04639 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,15 @@ "scripts": { "postinstall": "husky", "format": "prettier -w .", - "package": "yarn run build && companion-module-build", - "build": "rimraf dist && yarn run build:main", + "package": "run build && companion-module-build", + "build": "rimraf dist && run build:main", "build:main": "tsc -p tsconfig.build.json", "dev": "tsc -p tsconfig.build.json --watch", "lint:raw": "eslint", - "lint": "yarn run lint:raw .", + "lint": "run lint:raw .", "test": "echo \"Error: no test specified\" && exit 1" }, + "license": "MIT", "repository": { "type": "git", "url": "git+https://github.com/bitfocus/companion-module-toggl-track.git" @@ -22,7 +23,6 @@ "node": "^22.14", "yarn": "^4" }, - "license": "MIT", "dependencies": { "@companion-module/base": "~1.13.4", "toggl-track": "https://github.com/krombel/toggl-track#v0.8.0-2" @@ -48,5 +48,5 @@ "yarn lint:raw --fix" ] }, - "packageManager": "yarn@4.9.1" + "packageManager": "yarn@4.10.2" } diff --git a/src/actions.ts b/src/actions.ts index 253ce2d..a6fdfe7 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -1,6 +1,6 @@ import { TogglTrack } from './main.js' -export default function (self: TogglTrack): void { +export function UpdateActions(self: TogglTrack): void { self.setActionDefinitions({ startNewTimer: { name: 'Start New Timer', diff --git a/src/main.ts b/src/main.ts index 4d7ea0f..0071527 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,10 +3,10 @@ import { InstanceBase, runEntrypoint, InstanceStatus, SomeCompanionConfigField } from '@companion-module/base' import { GetConfigFields, type ModuleConfig } from './config.js' -import UpdateActions from './actions.js' -import UpdatePresets from './presets.js' -import UpdateVariableDefinitions from './variables.js' -import UpgradeScripts from './upgrades.js' +import { UpdatePresets } from './presets.js' +import { UpdateVariableDefinitions } from './variables.js' +import { UpgradeScripts } from './upgrades.js' +import { UpdateActions } from './actions.js' import { UpdateFeedbacks } from './feedbacks.js' import { Toggl, ITimeEntry, IWorkspaceProject, IClient, isRatelimitError } from 'toggl-track' import { togglGetWorkspaces } from './toggl-extend.js' @@ -30,19 +30,6 @@ export class TogglTrack extends InstanceBase { super(internal) } - getConfigFields(): SomeCompanionConfigField[] { - return GetConfigFields() - } - - async destroy(): Promise { - this.log('info', 'destroy ' + this.id) - if (this.config.startTimerPoller) { - this.stopTimeEntryPoller() - } - - clearInterval(this.currentTimerUpdaterIntervalId) - } - async init(config: ModuleConfig): Promise { this.log('info', '--- init toggltrack ' + this.id + ' ---') @@ -76,6 +63,19 @@ export class TogglTrack extends InstanceBase { } } + // When module gets deleted + async destroy(): Promise { + this.log('debug', 'destroy ' + this.id) + if (this.config.startTimerPoller) { + this.stopTimeEntryPoller() + } + + clearInterval(this.currentTimerUpdaterIntervalId) + if (this.config.startTogglWebsocket && this.stream) { + await this.stream.destroy() + } + } + async configUpdated(config: ModuleConfig): Promise { this.log('debug', 'config updated') @@ -123,6 +123,11 @@ export class TogglTrack extends InstanceBase { this.updateStatus(InstanceStatus.Ok) } } + + getConfigFields(): SomeCompanionConfigField[] { + return GetConfigFields() + } + updateVariables(): void { this.log('error', 'updateVariables not implemented') //throw new Error('Method not implemented.') @@ -130,6 +135,7 @@ export class TogglTrack extends InstanceBase { updateActions(): void { UpdateActions(this) } + updateFeedbacks(): void { UpdateFeedbacks(this) } diff --git a/src/presets.ts b/src/presets.ts index 381bfa5..0439a98 100644 --- a/src/presets.ts +++ b/src/presets.ts @@ -1,7 +1,7 @@ import { combineRgb } from '@companion-module/base' import { TogglTrack } from './main.js' -export default function (self: TogglTrack): void { +export function UpdatePresets(self: TogglTrack): void { self.setPresetDefinitions({ Start: { type: 'button', diff --git a/src/upgrades.ts b/src/upgrades.ts index 006a02f..080154f 100644 --- a/src/upgrades.ts +++ b/src/upgrades.ts @@ -1,4 +1,7 @@ -export default [ +import type { CompanionStaticUpgradeScript } from '@companion-module/base' +import type { ModuleConfig } from './config.js' + +export const UpgradeScripts: CompanionStaticUpgradeScript[] = [ /* * Place your upgrade scripts here * Remember that once it has been added it cannot be removed! diff --git a/src/variables.ts b/src/variables.ts index 3d88c24..716e102 100644 --- a/src/variables.ts +++ b/src/variables.ts @@ -1,6 +1,6 @@ import { TogglTrack } from './main.js' -export default function (self: TogglTrack): void { +export function UpdateVariableDefinitions(self: TogglTrack): void { self.setVariableDefinitions([ { name: 'Workspace', diff --git a/tsconfig.build.json b/tsconfig.build.json index df61900..844460f 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,5 +1,5 @@ { - "extends": "@companion-module/tools/tsconfig/node18/recommended", + "extends": "@companion-module/tools/tsconfig/node22/recommended", "include": ["src/**/*.ts"], "exclude": ["node_modules/**", "src/**/*spec.ts", "src/**/__tests__/*", "src/**/__mocks__/*"], "compilerOptions": { diff --git a/tsconfig.json b/tsconfig.json index d733551..8c2ffac 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,6 @@ "include": ["src/**/*.ts"], "exclude": ["node_modules/**"], "compilerOptions": { - "types": ["jest", "node"] + "types": ["node" /* , "jest" ] // uncomment this if using jest */] } }