2021-08-31 23:37:56 +02:00
|
|
|
import * as fs from 'fs-extra';
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2021-08-31 23:37:56 +02:00
|
|
|
export async function readJsonFile(manifestPath: string, defaultValue: any = null): Promise<any> {
|
|
|
|
if (!(await fs.pathExists(manifestPath))) {
|
|
|
|
if (defaultValue === null) throw new Error(`No such file: ${manifestPath}`);
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const content = await fs.readFile(manifestPath, 'utf8');
|
|
|
|
return JSON.parse(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
function stripOffPackageOrg(name: string): string {
|
|
|
|
const n = name.split('/');
|
|
|
|
if (n[0][0] === '@') n.splice(0, 1);
|
|
|
|
return n.join('/');
|
|
|
|
}
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2021-08-31 23:37:56 +02:00
|
|
|
export function isJoplinPluginPackage(pack: any): boolean {
|
|
|
|
if (!pack.keywords || !pack.keywords.includes('joplin-plugin')) return false;
|
|
|
|
if (stripOffPackageOrg(pack.name).indexOf('joplin-plugin') !== 0) return false;
|
|
|
|
return true;
|
|
|
|
}
|