Skip to content

Commit 367c035

Browse files
committed
reorganize plugin management code
1 parent 3711cd8 commit 367c035

File tree

5 files changed

+43
-62
lines changed

5 files changed

+43
-62
lines changed

api/src/unraid-api/cli/plugins/dependency.service.ts renamed to api/src/unraid-api/app/dependency.service.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { Injectable } from '@nestjs/common';
2-
import * as fs from 'fs/promises';
32
import * as path from 'path';
43

5-
import type { PackageJson } from 'type-fest';
64
import { execa } from 'execa';
75

86
import { fileExists } from '@app/core/utils/files/file-exists.js';
9-
import { getPackageJson, getPackageJsonPath } from '@app/environment.js';
7+
import { getPackageJsonPath } from '@app/environment.js';
108

119
@Injectable()
1210
export class DependencyService {
@@ -25,26 +23,6 @@ export class DependencyService {
2523
});
2624
}
2725

28-
/**
29-
* Installs plugins using npm.
30-
*
31-
* @param plugins - The plugins to install.
32-
* @returns The execa result of the npm command.
33-
*/
34-
installPlugins(...plugins: string[]) {
35-
return this.npm('i', '--save-peer', '--save-exact', ...plugins);
36-
}
37-
38-
/**
39-
* Uninstalls plugins using npm.
40-
*
41-
* @param plugins - The plugins to uninstall.
42-
* @returns The execa result of the npm command.
43-
*/
44-
uninstallPlugins(...plugins: string[]) {
45-
return this.npm('uninstall', ...plugins);
46-
}
47-
4826
/**
4927
* Installs dependencies for the api using npm.
5028
*

api/src/unraid-api/cli/cli.module.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Module } from '@nestjs/common';
22

3+
import { DependencyService } from '@app/unraid-api/app/dependency.service.js';
34
import { ApiKeyService } from '@app/unraid-api/auth/api-key.service.js';
45
import { SsoUserService } from '@app/unraid-api/auth/sso-user.service.js';
56
import { AddApiKeyQuestionSet } from '@app/unraid-api/cli/apikey/add-api-key.questions.js';
@@ -10,7 +11,12 @@ import { DeveloperCommand } from '@app/unraid-api/cli/developer/developer.comman
1011
import { DeveloperQuestions } from '@app/unraid-api/cli/developer/developer.questions.js';
1112
import { LogService } from '@app/unraid-api/cli/log.service.js';
1213
import { LogsCommand } from '@app/unraid-api/cli/logs.command.js';
13-
import { moduleResources, PluginCommandModule } from '@app/unraid-api/cli/plugins/plugin.cli.module.js';
14+
import {
15+
InstallPluginCommand,
16+
ListPluginCommand,
17+
PluginCommand,
18+
RemovePluginCommand,
19+
} from '@app/unraid-api/cli/plugins/plugin.command.js';
1420
import { PM2Service } from '@app/unraid-api/cli/pm2.service.js';
1521
import { ReportCommand } from '@app/unraid-api/cli/report.command.js';
1622
import { RestartCommand } from '@app/unraid-api/cli/restart.command.js';
@@ -30,26 +36,30 @@ import { ApiConfigModule } from '@app/unraid-api/config/api-config.module.js';
3036
import { LegacyConfigModule } from '@app/unraid-api/config/legacy-config.module.js';
3137
import { PluginCliModule } from '@app/unraid-api/plugin/plugin.module.js';
3238

33-
// cli - plugin add/remove
34-
// plugin generator
35-
3639
const DEFAULT_COMMANDS = [
3740
ApiKeyCommand,
3841
ConfigCommand,
3942
DeveloperCommand,
4043
LogsCommand,
4144
ReportCommand,
45+
VersionCommand,
46+
// Lifecycle commands
47+
SwitchEnvCommand,
4248
RestartCommand,
4349
StartCommand,
4450
StatusCommand,
4551
StopCommand,
46-
SwitchEnvCommand,
47-
VersionCommand,
52+
// SSO commands
4853
SSOCommand,
4954
ValidateTokenCommand,
5055
AddSSOUserCommand,
5156
RemoveSSOUserCommand,
5257
ListSSOUserCommand,
58+
// Plugin commands
59+
PluginCommand,
60+
ListPluginCommand,
61+
InstallPluginCommand,
62+
RemovePluginCommand,
5363
] as const;
5464

5565
const DEFAULT_PROVIDERS = [
@@ -62,10 +72,11 @@ const DEFAULT_PROVIDERS = [
6272
PM2Service,
6373
ApiKeyService,
6474
SsoUserService,
75+
DependencyService,
6576
] as const;
6677

6778
@Module({
6879
imports: [LegacyConfigModule, ApiConfigModule, PluginCliModule.register()],
69-
providers: [...DEFAULT_COMMANDS, ...DEFAULT_PROVIDERS, ...moduleResources],
80+
providers: [...DEFAULT_COMMANDS, ...DEFAULT_PROVIDERS],
7081
})
7182
export class CliModule {}

api/src/unraid-api/cli/plugins/plugin.cli.module.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

api/src/unraid-api/plugin/plugin-management.service.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ConfigService } from '@nestjs/config';
33

44
import { ApiConfig } from '@unraid/shared/services/api-config.js';
55

6-
import { DependencyService } from '@app/unraid-api/cli/plugins/dependency.service.js';
6+
import { DependencyService } from '@app/unraid-api/app/dependency.service.js';
77
import { persistApiConfig } from '@app/unraid-api/config/api-config.module.js';
88

99
@Injectable()
@@ -20,14 +20,14 @@ export class PluginManagementService {
2020
async addPlugin(...plugins: string[]) {
2121
const added = this.addPluginToConfig(...plugins);
2222
await this.persistConfig();
23-
await this.dependencyService.installPlugins(...added);
23+
await this.installPlugins(...added);
2424
await this.dependencyService.rebuildVendorArchive();
2525
}
2626

2727
async removePlugin(...plugins: string[]) {
2828
const removed = this.removePluginFromConfig(...plugins);
2929
await this.persistConfig();
30-
await this.dependencyService.uninstallPlugins(...removed);
30+
await this.uninstallPlugins(...removed);
3131
await this.dependencyService.rebuildVendorArchive();
3232
}
3333

@@ -66,6 +66,26 @@ export class PluginManagementService {
6666
return removed;
6767
}
6868

69+
/**
70+
* Installs plugins using npm.
71+
*
72+
* @param plugins - The plugins to install.
73+
* @returns The execa result of the npm command.
74+
*/
75+
private installPlugins(...plugins: string[]) {
76+
return this.dependencyService.npm('i', '--save-peer', '--save-exact', ...plugins);
77+
}
78+
79+
/**
80+
* Uninstalls plugins using npm.
81+
*
82+
* @param plugins - The plugins to uninstall.
83+
* @returns The execa result of the npm command.
84+
*/
85+
private uninstallPlugins(...plugins: string[]) {
86+
return this.dependencyService.npm('uninstall', ...plugins);
87+
}
88+
6989
/**------------------------------------------------------------------------
7090
* Bundled Plugins
7191
* Plugins that are not published to npm, but vendored as tarballs in the

api/src/unraid-api/plugin/plugin.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DynamicModule, Logger, Module } from '@nestjs/common';
22

3-
import { DependencyService } from '@app/unraid-api/cli/plugins/dependency.service.js';
3+
import { DependencyService } from '@app/unraid-api/app/dependency.service.js';
44
import { ResolversModule } from '@app/unraid-api/graph/resolvers/resolvers.module.js';
55
import { GlobalDepsModule } from '@app/unraid-api/plugin/global-deps.module.js';
66
import { PluginManagementService } from '@app/unraid-api/plugin/plugin-management.service.js';

0 commit comments

Comments
 (0)