fix(core): update

This commit is contained in:
2019-09-03 19:58:08 +02:00
parent dd5e1a978d
commit 44d30fc4d6
4 changed files with 104 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
import * as plugins from './smartdaemon.plugins';
import { SmartDaemonTemplateManager } from './smartdaemon.classes.templatemanager';
import { SmartDaemonService } from './smartdaemon.classes.service';
import { SmartDaemonService, SmartDaemonServiceConstructorOptions } from './smartdaemon.classes.service';
import { SmartDaemonSystemdManager } from './smartdaemon.classes.systemdmanager';
@@ -17,19 +17,23 @@ export class SmartDaemon {
this.systemdManager = new SmartDaemonSystemdManager(this);
}
public async addService(nameArg: string, commandArg: string, workingDirectoryArg?: string): Promise<SmartDaemonService> {
/**
* adds a service
* @param nameArg
* @param commandArg
* @param workingDirectoryArg
*/
public async addService(optionsArg: SmartDaemonServiceConstructorOptions): Promise<SmartDaemonService> {
let serviceToAdd: SmartDaemonService;
const existingService = this.serviceMap.find(serviceArg => {
return serviceArg.name === nameArg;
return serviceArg.name === optionsArg.name;
});
if (!existingService) {
serviceToAdd = await SmartDaemonService.createFromOptions(this, {
command: commandArg,
name: nameArg,
workingDir: workingDirectoryArg
})
serviceToAdd = await SmartDaemonService.createFromOptions(this, optionsArg);
} else {
serviceToAdd = existingService;
Object.assign(serviceToAdd, optionsArg);
await serviceToAdd.save();
}
return serviceToAdd;
};