some cleanup
This commit is contained in:
parent
3b04a27f0e
commit
7bdd922b51
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@squeebot/core",
|
||||
"version": "3.1.1",
|
||||
"version": "3.2.0",
|
||||
"description": "Squeebot v3 core for the execution environment",
|
||||
"main": "lib/index.js",
|
||||
"module": "lib/",
|
||||
|
@ -95,13 +95,8 @@ export class ChannelManager {
|
||||
}
|
||||
}
|
||||
|
||||
public getChannelByName(name: string): IChannel | null {
|
||||
for (const chan of this.channels) {
|
||||
if (chan.name === name) {
|
||||
return chan;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
public getChannelByName(name: string): IChannel | undefined {
|
||||
return this.channels.find(c => c.name === name);
|
||||
}
|
||||
|
||||
public addChannel(chan: IChannel): IChannel {
|
||||
|
@ -11,7 +11,7 @@ import { NPMExecutor } from '../npm/executor';
|
||||
|
||||
import { logger } from '../core/logger';
|
||||
|
||||
export function requireNoCache(file: string): object | null {
|
||||
export function requireNoCache(file: string): object | undefined {
|
||||
const fullPath = path.resolve(file);
|
||||
const mod = require(fullPath);
|
||||
if (require.cache && require.cache[fullPath]) {
|
||||
@ -34,28 +34,19 @@ export class PluginManager {
|
||||
this.addEvents();
|
||||
}
|
||||
|
||||
public getAvailableByName(name: string): IPluginManifest | null {
|
||||
for (const pl of this.availablePlugins) {
|
||||
if (pl.name === name) {
|
||||
return pl;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
public getAvailableByName(name: string): IPluginManifest | undefined {
|
||||
return this.availablePlugins.find(p => p.name === name);
|
||||
}
|
||||
|
||||
public getLoadedByName(name: string): IPlugin | null {
|
||||
public getLoadedByName(name: string): IPlugin | undefined {
|
||||
if (this.plugins.has(name)) {
|
||||
return this.plugins.get(name) as IPlugin;
|
||||
}
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
public getLoaded(): IPlugin[] {
|
||||
const list = [];
|
||||
for (const pl of this.plugins.values()) {
|
||||
list.push(pl);
|
||||
}
|
||||
return list;
|
||||
return Array.from(this.plugins.values());
|
||||
}
|
||||
|
||||
public addAvailable(manifest: IPluginManifest | IPluginManifest[]): boolean {
|
||||
|
@ -17,25 +17,14 @@ export class RepositoryManager {
|
||||
|
||||
constructor(private env: IEnvironment, private plugins: PluginManager) {}
|
||||
|
||||
public repoProvidesPlugin(repo: IRepository, mf: IPluginManifest): IRepoPluginDef | null {
|
||||
for (const plugin of repo.plugins) {
|
||||
if (plugin.name === mf.name && mf.repository === repo.name) {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
public repoProvidesPlugin(repo: IRepository, mf: IPluginManifest): IRepoPluginDef | undefined {
|
||||
return repo.plugins.find(plugin => plugin.name === mf.name && repo.name === mf.repository);
|
||||
}
|
||||
|
||||
public findRepoForPlugin(pname: string): IRepository | null {
|
||||
for (const [name, repo] of this.repositories) {
|
||||
for (const plugin of repo.plugins) {
|
||||
if (plugin.name === pname) {
|
||||
return repo;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
public findRepoForPlugin(pname: string): IRepository | undefined {
|
||||
return Array.from(this.repositories.values()).find(repo =>
|
||||
repo.plugins.find(plugin => plugin.name === pname) !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
public getRepoByName(name: string): IRepository | undefined {
|
||||
@ -43,11 +32,7 @@ export class RepositoryManager {
|
||||
}
|
||||
|
||||
public getAll(): IRepository[] {
|
||||
const list = [];
|
||||
for (const irep of this.repositories.values()) {
|
||||
list.push(irep);
|
||||
}
|
||||
return list;
|
||||
return Array.from(this.repositories.values());
|
||||
}
|
||||
|
||||
public async installPlugin(name: string): Promise<IPluginManifest> {
|
||||
@ -192,18 +177,13 @@ export class RepositoryManager {
|
||||
|
||||
// Checking for version differences in the plugins
|
||||
// Get locally installed plugins
|
||||
const needsUpdates: IPluginManifest[] = [];
|
||||
for (const avail of this.plugins.availablePlugins) {
|
||||
return this.plugins.availablePlugins.filter(avail => {
|
||||
const repoPlugin = this.repoProvidesPlugin(oprep, avail);
|
||||
if (repoPlugin) {
|
||||
if (semver.gt(repoPlugin.version, avail.version)) {
|
||||
// Plugin needs update
|
||||
needsUpdates.push(avail);
|
||||
}
|
||||
if (!repoPlugin) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return needsUpdates;
|
||||
return semver.gt(repoPlugin.version, avail.version);
|
||||
});
|
||||
}
|
||||
|
||||
public async updateRepository(repo: IRepository): Promise<IRepository> {
|
||||
|
@ -8,7 +8,7 @@ export interface IProcessData {
|
||||
}
|
||||
|
||||
export async function spawnProcess(execp: string, args: any[], env: IEnvironment): Promise<IProcessData> {
|
||||
return new Promise((resolve, reject): void => {
|
||||
return new Promise((resolve): void => {
|
||||
const process = spawn(execp, args, { cwd: env.path });
|
||||
const stdout: string[] = [];
|
||||
const stderr: string[] = [];
|
||||
@ -29,8 +29,8 @@ export async function spawnProcess(execp: string, args: any[], env: IEnvironment
|
||||
}
|
||||
|
||||
export async function execProcess(execp: string, env: IEnvironment): Promise<IProcessData> {
|
||||
return new Promise((resolve, reject): void => {
|
||||
const cprog = exec(execp, (error: any, stdout: any, stderr: any): void => resolve({
|
||||
return new Promise((resolve): void => {
|
||||
exec(execp, (error: any, stdout: any, stderr: any): void => resolve({
|
||||
code: error.code, stderr, stdout,
|
||||
}));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user