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