Skip to content

Commit 947f84c

Browse files
committed
refactor: Implement UpdaterRegistry and move to dedicated directory
- Introduced `UpdaterRegistry` for dynamic discovery and instantiation of updaters. - Moved `UpdaterRegistry` to `src/registry` for better organization. - Renamed `Updater` interface to `IUpdater` for consistent naming conventions. - Updated `UpdaterService`, `index.ts`, and all updater implementations to use the new registry and interface.
1 parent 205da4f commit 947f84c

12 files changed

Lines changed: 53 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes for each version of the Ambient Music extension.
44

55
---
66

7+
## v0.7.2 2025 08 24
8+
9+
- refactor: Moved `UpdaterRegistry` to `src/registry` for better organization and updated all relevant imports.
10+
711
## v0.7.1 2025 08 24
812

913
- refactor: Encapsulate Git operations in a GitService
@@ -19,6 +23,7 @@ All notable changes for each version of the Ambient Music extension.
1923
- Modify `UpdaterService` to use the `target_platform` if provided, otherwise fall back to existing detection logic.
2024
- Update `index.ts` to read and pass `target_platform` to `UpdaterService`.
2125
- Implement conditional Git tag creation based on the `git_tag` input from `action.yml`.
26+
- build: Updated `dist/index.js` after centralizing action configuration.
2227

2328
## v0.7.0 2025 08 24
2429

src/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
PythonUpdater,
88
RustUpdater,
99
} from './updaters';
10+
import { UpdaterRegistry } from './registry';
1011
import { PlatformDetectionError, VersionBumpError } from './errors';
1112
import { RELEASE_TYPE, TARGET_PLATFORM, GIT_TAG } from './config';
1213
import * as core from '@actions/core';
@@ -16,15 +17,15 @@ async function run() {
1617
const releaseType = RELEASE_TYPE;
1718
const targetPlatform = TARGET_PLATFORM;
1819

19-
const updaters = [
20-
new NodeUpdater(),
21-
new PythonUpdater(),
22-
new RustUpdater(),
23-
new GoUpdater(),
24-
new DockerUpdater(),
25-
new PHPUpdater(),
26-
];
27-
const updaterService = new UpdaterService(updaters);
20+
const updaterRegistry = new UpdaterRegistry();
21+
updaterRegistry.registerUpdater(new NodeUpdater());
22+
updaterRegistry.registerUpdater(new PythonUpdater());
23+
updaterRegistry.registerUpdater(new RustUpdater());
24+
updaterRegistry.registerUpdater(new GoUpdater());
25+
updaterRegistry.registerUpdater(new DockerUpdater());
26+
updaterRegistry.registerUpdater(new PHPUpdater());
27+
28+
const updaterService = new UpdaterService(updaterRegistry);
2829
const gitService = new GitService();
2930

3031
const platform = updaterService.getPlatform(targetPlatform);

src/interface/updaterInterface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ReleaseType } from 'semver';
22

3-
export interface Updater {
3+
export interface UpdaterInterface {
44
/** Name of the platform/language */
55
platform: string;
66

src/registry/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './updaterRegistry';

src/registry/updaterRegistry.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { UpdaterInterface as IUpdater } from '../interface';
2+
3+
export class UpdaterRegistry {
4+
private updaters: Map<string, IUpdater> = new Map();
5+
6+
registerUpdater(updater: IUpdater): void {
7+
this.updaters.set(updater.platform, updater);
8+
}
9+
10+
getUpdater(platform: string): IUpdater | undefined {
11+
return this.updaters.get(platform);
12+
}
13+
14+
getAllUpdaters(): IUpdater[] {
15+
return Array.from(this.updaters.values());
16+
}
17+
}

src/services/updaterService.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import semver from 'semver';
2-
import { Updater } from '../interface';
32
import { PlatformDetectionError, VersionBumpError } from '../errors';
3+
import { UpdaterRegistry } from '../registry/updaterRegistry';
44

55
export class UpdaterService {
6-
private updaters: Updater[];
6+
private updaterRegistry: UpdaterRegistry;
77

8-
constructor(updaters: Updater[]) {
9-
this.updaters = updaters;
8+
constructor(updaterRegistry: UpdaterRegistry) {
9+
this.updaterRegistry = updaterRegistry;
1010
}
1111

1212
getPlatform(targetPlatform?: string): string {
1313
if (targetPlatform) {
14-
const updater = this.updaters.find((u) => u.platform === targetPlatform);
14+
const updater = this.updaterRegistry.getUpdater(targetPlatform);
1515
if (!updater) {
1616
throw new PlatformDetectionError(
1717
`Specified platform "${targetPlatform}" is not supported.`,
@@ -20,7 +20,7 @@ export class UpdaterService {
2020
return updater.platform;
2121
}
2222

23-
const detectedUpdater = this.updaters.find((u) => u.canHandle());
23+
const detectedUpdater = this.updaterRegistry.getAllUpdaters().find((u) => u.canHandle());
2424
if (!detectedUpdater) {
2525
throw new PlatformDetectionError(
2626
'Could not detect platform. Please specify target_platform input if auto-detection fails.',
@@ -30,7 +30,7 @@ export class UpdaterService {
3030
}
3131

3232
updateVersion(platform: string, releaseType: semver.ReleaseType): string {
33-
const updater = this.updaters.find((u) => u.platform === platform);
33+
const updater = this.updaterRegistry.getUpdater(platform);
3434
if (!updater) {
3535
throw new VersionBumpError(`No updater found for platform: ${platform}`);
3636
}

src/updaters/dockerUpdater.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ReleaseType } from 'semver';
2-
import { Updater } from '../interface';
2+
import { UpdaterInterface } from '../interface';
33
import { calculateNextVersion, ManifestParser } from '../utils';
44

5-
export class DockerUpdater implements Updater {
5+
export class DockerUpdater implements UpdaterInterface {
66
platform = 'docker';
77
private manifestPath: string | null = null;
88

src/updaters/goUpdater.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ReleaseType } from 'semver';
2-
import { Updater } from '../interface';
2+
import { UpdaterInterface } from '../interface';
33
import { calculateNextVersion, ManifestParser } from '../utils';
44

5-
export class GoUpdater implements Updater {
5+
export class GoUpdater implements UpdaterInterface {
66
platform = 'go';
77
private manifestPath: string | null = null;
88

src/updaters/nodeUpdater.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ReleaseType } from 'semver';
2-
import { Updater } from '../interface';
2+
import { UpdaterInterface } from '../interface';
33
import { calculateNextVersion, ManifestParser } from '../utils';
44

5-
export class NodeUpdater implements Updater {
5+
export class NodeUpdater implements UpdaterInterface {
66
platform = 'node';
77
private manifestPath: string | null = null;
88

src/updaters/phpUpdater.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ReleaseType } from 'semver';
2-
import { Updater } from '../interface';
2+
import { UpdaterInterface } from '../interface';
33
import { calculateNextVersion, ManifestParser } from '../utils';
44

5-
export class PHPUpdater implements Updater {
5+
export class PHPUpdater implements UpdaterInterface {
66
platform = 'php';
77
private manifestPath: string | null = null;
88

0 commit comments

Comments
 (0)