Skip to content

Commit 0e2c654

Browse files
Initial commit
0 parents  commit 0e2c654

20 files changed

+396
-0
lines changed

Diff for: .github/workflows/companion-module-checks.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Companion Module Checks
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
check:
8+
name: Check module
9+
10+
if: ${{ !contains(github.repository, 'companion-module-template-') }}
11+
12+
permissions:
13+
packages: read
14+
15+
uses: bitfocus/actions/.github/workflows/module-checks.yaml@main
16+
# with:
17+
# upload-artifact: true # uncomment this to upload the built package as an artifact to this workflow that you can download and share with others
18+

Diff for: .github/workflows/node.yaml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Node CI
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
tags:
8+
- 'v[0-9]+.[0-9]+.[0-9]+*'
9+
pull_request:
10+
11+
jobs:
12+
lint:
13+
name: Lint
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 15
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Use Node.js 22.x
20+
# This should match the version of Node.js you have defined in the manifest.json runtime field
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 22.x
24+
- name: Prepare Environment
25+
run: |
26+
corepack enable
27+
- name: Prepare Environment (For template repository)
28+
# Only run this step if the repository is a template repository
29+
# If you are using this in a module, you can remove this step
30+
if: ${{ contains(github.repository, 'companion-module-template-') }}
31+
run: |
32+
# Perform an install to generate the lockfile
33+
yarn install
34+
env:
35+
CI: false
36+
- name: Prepare module
37+
run: |
38+
yarn install
39+
env:
40+
CI: true
41+
- name: Build and check types
42+
run: |
43+
yarn build
44+
env:
45+
CI: true
46+
- name: Run lint
47+
run: |
48+
yarn lint
49+
env:
50+
CI: true
51+
52+
# Uncomment this to enable running unit tests
53+
# test:
54+
# name: Test
55+
# runs-on: ubuntu-latest
56+
# timeout-minutes: 15
57+
58+
# steps:
59+
# - uses: actions/checkout@v4
60+
# - name: Use Node.js 22.x
61+
# uses: actions/setup-node@v4
62+
# with:
63+
# node-version: 22.x
64+
# - name: Prepare Environment
65+
# run: |
66+
# corepack enable
67+
# yarn install
68+
# env:
69+
# CI: true
70+
# - name: Run tests
71+
# run: |
72+
# yarn test
73+
# env:
74+
# CI: true
75+
# - name: Send coverage
76+
# uses: codecov/codecov-action@v5

Diff for: .gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules/
2+
package-lock.json
3+
/pkg
4+
/pkg.tgz
5+
/dist
6+
DEBUG-*
7+
/.yarn

Diff for: .husky/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lint-staged

Diff for: .prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package.json
2+
/LICENSE.md

Diff for: .yarnrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Bitfocus AS - Open Source
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# companion-module-[replace with module name]
2+
3+
See [HELP.md](./companion/HELP.md) and [LICENSE](./LICENSE)
4+
5+
## Getting started
6+
7+
Executing a `yarn` command should perform all necessary steps to develop the module, if it does not then follow the steps below.
8+
9+
The module can be built once with `yarn build`. This should be enough to get the module to be loadable by companion.
10+
11+
While developing the module, by using `yarn dev` the compiler will be run in watch mode to recompile the files on change.

Diff for: companion/HELP.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Your module
2+
3+
Write some help for your users here!

Diff for: companion/manifest.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"id": "your-module-name",
3+
"name": "your-module-name",
4+
"shortname": "module-shortname",
5+
"description": "A short one line description of your module",
6+
"version": "0.0.0",
7+
"license": "MIT",
8+
"repository": "git+https://github.com/bitfocus/companion-module-your-module-name.git",
9+
"bugs": "https://github.com/bitfocus/companion-module-your-module-name/issues",
10+
"maintainers": [
11+
{
12+
"name": "Your name",
13+
"email": "Your email"
14+
}
15+
],
16+
"runtime": {
17+
"type": "node22",
18+
"api": "nodejs-ipc",
19+
"apiVersion": "0.0.0",
20+
"entrypoint": "../dist/main.js"
21+
},
22+
"legacyIds": [],
23+
"manufacturer": "Your company",
24+
"products": ["Your product"],
25+
"keywords": []
26+
}

Diff for: eslint.config.mjs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { generateEslintConfig } from '@companion-module/tools/eslint/config.mjs'
2+
3+
export default generateEslintConfig({
4+
enableTypescript: true,
5+
})

Diff for: package.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "your-module-name",
3+
"version": "0.1.0",
4+
"main": "dist/main.js",
5+
"type": "module",
6+
"scripts": {
7+
"postinstall": "husky",
8+
"format": "prettier -w .",
9+
"package": "run build && companion-module-build",
10+
"build": "rimraf dist && run build:main",
11+
"build:main": "tsc -p tsconfig.build.json",
12+
"dev": "tsc -p tsconfig.build.json --watch",
13+
"lint:raw": "eslint",
14+
"lint": "run lint:raw ."
15+
},
16+
"license": "MIT",
17+
"repository": {
18+
"type": "git",
19+
"url": "git+https://github.com/bitfocus/companion-module-your-module-name.git"
20+
},
21+
"dependencies": {
22+
"@companion-module/base": "~1.11.2"
23+
},
24+
"devDependencies": {
25+
"@companion-module/tools": "^2.1.1",
26+
"@types/node": "^22.10.2",
27+
"eslint": "^9.17.0",
28+
"husky": "^9.1.7",
29+
"lint-staged": "^15.2.11",
30+
"prettier": "^3.4.2",
31+
"rimraf": "^6.0.1",
32+
"typescript": "~5.5.4",
33+
"typescript-eslint": "^8.18.1"
34+
},
35+
"prettier": "@companion-module/tools/.prettierrc.json",
36+
"lint-staged": {
37+
"*.{css,json,md,scss}": [
38+
"prettier --write"
39+
],
40+
"*.{ts,tsx,js,jsx}": [
41+
"yarn lint:raw --fix"
42+
]
43+
},
44+
"packageManager": "[email protected]"
45+
}

Diff for: src/actions.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { ModuleInstance } from './main.js'
2+
3+
export function UpdateActions(self: ModuleInstance): void {
4+
self.setActionDefinitions({
5+
sample_action: {
6+
name: 'My First Action',
7+
options: [
8+
{
9+
id: 'num',
10+
type: 'number',
11+
label: 'Test',
12+
default: 5,
13+
min: 0,
14+
max: 100,
15+
},
16+
],
17+
callback: async (event) => {
18+
console.log('Hello world!', event.options.num)
19+
},
20+
},
21+
})
22+
}

Diff for: src/config.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Regex, type SomeCompanionConfigField } from '@companion-module/base'
2+
3+
export interface ModuleConfig {
4+
host: string
5+
port: number
6+
}
7+
8+
export function GetConfigFields(): SomeCompanionConfigField[] {
9+
return [
10+
{
11+
type: 'textinput',
12+
id: 'host',
13+
label: 'Target IP',
14+
width: 8,
15+
regex: Regex.IP,
16+
},
17+
{
18+
type: 'number',
19+
id: 'port',
20+
label: 'Target Port',
21+
width: 4,
22+
min: 1,
23+
max: 65535,
24+
default: 8000,
25+
},
26+
]
27+
}

Diff for: src/feedbacks.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { combineRgb } from '@companion-module/base'
2+
import type { ModuleInstance } from './main.js'
3+
4+
export function UpdateFeedbacks(self: ModuleInstance): void {
5+
self.setFeedbackDefinitions({
6+
ChannelState: {
7+
name: 'Example Feedback',
8+
type: 'boolean',
9+
defaultStyle: {
10+
bgcolor: combineRgb(255, 0, 0),
11+
color: combineRgb(0, 0, 0),
12+
},
13+
options: [
14+
{
15+
id: 'num',
16+
type: 'number',
17+
label: 'Test',
18+
default: 5,
19+
min: 0,
20+
max: 10,
21+
},
22+
],
23+
callback: (feedback) => {
24+
console.log('Hello world!', feedback.options.num)
25+
if (Number(feedback.options.num) > 5) {
26+
return true
27+
} else {
28+
return false
29+
}
30+
},
31+
},
32+
})
33+
}

Diff for: src/main.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { InstanceBase, runEntrypoint, InstanceStatus, SomeCompanionConfigField } from '@companion-module/base'
2+
import { GetConfigFields, type ModuleConfig } from './config.js'
3+
import { UpdateVariableDefinitions } from './variables.js'
4+
import { UpgradeScripts } from './upgrades.js'
5+
import { UpdateActions } from './actions.js'
6+
import { UpdateFeedbacks } from './feedbacks.js'
7+
8+
export class ModuleInstance extends InstanceBase<ModuleConfig> {
9+
config!: ModuleConfig // Setup in init()
10+
11+
constructor(internal: unknown) {
12+
super(internal)
13+
}
14+
15+
async init(config: ModuleConfig): Promise<void> {
16+
this.config = config
17+
18+
this.updateStatus(InstanceStatus.Ok)
19+
20+
this.updateActions() // export actions
21+
this.updateFeedbacks() // export feedbacks
22+
this.updateVariableDefinitions() // export variable definitions
23+
}
24+
// When module gets deleted
25+
async destroy(): Promise<void> {
26+
this.log('debug', 'destroy')
27+
}
28+
29+
async configUpdated(config: ModuleConfig): Promise<void> {
30+
this.config = config
31+
}
32+
33+
// Return config fields for web config
34+
getConfigFields(): SomeCompanionConfigField[] {
35+
return GetConfigFields()
36+
}
37+
38+
updateActions(): void {
39+
UpdateActions(this)
40+
}
41+
42+
updateFeedbacks(): void {
43+
UpdateFeedbacks(this)
44+
}
45+
46+
updateVariableDefinitions(): void {
47+
UpdateVariableDefinitions(this)
48+
}
49+
}
50+
51+
runEntrypoint(ModuleInstance, UpgradeScripts)

Diff for: src/upgrades.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { CompanionStaticUpgradeScript } from '@companion-module/base'
2+
import type { ModuleConfig } from './config.js'
3+
4+
export const UpgradeScripts: CompanionStaticUpgradeScript<ModuleConfig>[] = [
5+
/*
6+
* Place your upgrade scripts here
7+
* Remember that once it has been added it cannot be removed!
8+
*/
9+
// function (context, props) {
10+
// return {
11+
// updatedConfig: null,
12+
// updatedActions: [],
13+
// updatedFeedbacks: [],
14+
// }
15+
// },
16+
]

Diff for: src/variables.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { ModuleInstance } from './main.js'
2+
3+
export function UpdateVariableDefinitions(self: ModuleInstance): void {
4+
self.setVariableDefinitions([
5+
{ variableId: 'variable1', name: 'My first variable' },
6+
{ variableId: 'variable2', name: 'My second variable' },
7+
{ variableId: 'variable3', name: 'Another variable' },
8+
])
9+
}

0 commit comments

Comments
 (0)