core: add `hydrooj uninstall` command

pull/461/head
undefined 2 years ago
parent d21ae767dd
commit bd1034eff8

@ -175,6 +175,23 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
lastUpdate: Date.now(),
}));
});
cli.command('uninstall [package]').action(async (name) => {
if (!name) {
cli.outputHelp();
return;
}
if (yarnVersion !== 1) throw new Error('Yarn 1 is required.');
const addonDir = path.join(hydroPath, 'addons');
fs.ensureDirSync(addonDir);
const plugins = fs.readdirSync(addonDir);
if (!plugins.includes(name)) {
throw new Error(`Plugin ${name} not found or not installed with \`hydrooj install\`.`);
}
const newAddonPath = path.join(addonDir, name);
child.execSync(`hydrooj addon remove '${newAddonPath}'`, { stdio: 'inherit' });
fs.removeSync(newAddonPath);
console.log(`Successfully uninstalled ${name}.`);
});
cli.help();
cli.parse();
if (!cli.matchedCommand) {

@ -126,6 +126,36 @@ Set.intersection = function Intersection<T>(A: Set<T> | Array<T> = [], B: Set<T>
return intersection;
};
export function sleep(timeout: number) {
return new Promise((resolve) => {
setTimeout(() => resolve(true), timeout);
});
}
function deepen(modifyString: (source: string) => string) {
function modifyObject<T>(source: T): T {
if (typeof source !== 'object' || !source) return source;
if (Array.isArray(source)) return source.map(modifyObject) as any;
const result = {} as T;
for (const key in source) {
result[modifyString(key)] = modifyObject(source[key]);
}
return result;
}
return function t<T>(source: T): T {
if (typeof source === 'string') return modifyString(source) as any;
return modifyObject(source);
};
}
export function noop() { }
export const camelCase = deepen((source) => source.replace(/[_-][a-z]/g, (str) => str.slice(1).toUpperCase()));
export const paramCase = deepen((source) => source.replace(/_/g, '-').replace(/(?<!^)[A-Z]/g, (str) => `-${str.toLowerCase()}`));
export const snakeCase = deepen((source) => source.replace(/-/g, '_').replace(/(?<!^)[A-Z]/g, (str) => `_${str.toLowerCase()}`));
const TIME_RE = /^([0-9]+(?:\.[0-9]*)?)([mu]?)s?$/i;
const TIME_UNITS = { '': 1000, m: 1, u: 0.001 };
const MEMORY_RE = /^([0-9]+(?:\.[0-9]*)?)([kmg])b?$/i;

@ -105,35 +105,6 @@ export function bufferToStream(buffer: Buffer): NodeJS.ReadableStream {
return stream;
}
export function sleep(timeout: number) {
return new Promise((resolve) => {
setTimeout(() => resolve(true), timeout);
});
}
function deepen(modifyString: (source: string) => string) {
function modifyObject<T>(source: T): T {
if (typeof source !== 'object' || !source) return source;
if (Array.isArray(source)) return source.map(modifyObject) as any;
const result = {} as T;
for (const key in source) {
result[modifyString(key)] = modifyObject(source[key]);
}
return result;
}
return function t<T>(source: T): T {
if (typeof source === 'string') return modifyString(source) as any;
return modifyObject(source);
};
}
export function noop() { }
export const camelCase = deepen((source) => source.replace(/[_-][a-z]/g, (str) => str.slice(1).toUpperCase()));
export const paramCase = deepen((source) => source.replace(/_/g, '-').replace(/(?<!^)[A-Z]/g, (str) => `-${str.toLowerCase()}`));
export const snakeCase = deepen((source) => source.replace(/-/g, '_').replace(/(?<!^)[A-Z]/g, (str) => `_${str.toLowerCase()}`));
export namespace Time {
export const second = 1000;
export const minute = second * 60;

Loading…
Cancel
Save