more align with template implementation
This commit is contained in:
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
* text=auto eol=lf
|
||||
76
.github/workflows/node.yaml
vendored
Normal file
76
.github/workflows/node.yaml
vendored
Normal file
@@ -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
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -2,7 +2,8 @@ node_modules/
|
||||
package-lock.json
|
||||
.DS_Store
|
||||
/pkg
|
||||
/pkg.tgz
|
||||
/*.tgz
|
||||
/dist
|
||||
DEBUG-*
|
||||
/.yarn
|
||||
/.yarn
|
||||
/.vscode
|
||||
|
||||
2
LICENSE
2
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
|
||||
|
||||
@@ -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.
|
||||
|
||||
10
package.json
10
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"
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
40
src/main.ts
40
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<ModuleConfig> {
|
||||
super(internal)
|
||||
}
|
||||
|
||||
getConfigFields(): SomeCompanionConfigField[] {
|
||||
return GetConfigFields()
|
||||
}
|
||||
|
||||
async destroy(): Promise<void> {
|
||||
this.log('info', 'destroy ' + this.id)
|
||||
if (this.config.startTimerPoller) {
|
||||
this.stopTimeEntryPoller()
|
||||
}
|
||||
|
||||
clearInterval(this.currentTimerUpdaterIntervalId)
|
||||
}
|
||||
|
||||
async init(config: ModuleConfig): Promise<void> {
|
||||
this.log('info', '--- init toggltrack ' + this.id + ' ---')
|
||||
|
||||
@@ -76,6 +63,19 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
||||
}
|
||||
}
|
||||
|
||||
// When module gets deleted
|
||||
async destroy(): Promise<void> {
|
||||
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<void> {
|
||||
this.log('debug', 'config updated')
|
||||
|
||||
@@ -123,6 +123,11 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
||||
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<ModuleConfig> {
|
||||
updateActions(): void {
|
||||
UpdateActions(this)
|
||||
}
|
||||
|
||||
updateFeedbacks(): void {
|
||||
UpdateFeedbacks(this)
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
export default [
|
||||
import type { CompanionStaticUpgradeScript } from '@companion-module/base'
|
||||
import type { ModuleConfig } from './config.js'
|
||||
|
||||
export const UpgradeScripts: CompanionStaticUpgradeScript<ModuleConfig>[] = [
|
||||
/*
|
||||
* Place your upgrade scripts here
|
||||
* Remember that once it has been added it cannot be removed!
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["node_modules/**"],
|
||||
"compilerOptions": {
|
||||
"types": ["jest", "node"]
|
||||
"types": ["node" /* , "jest" ] // uncomment this if using jest */]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user