Update plugins

This commit is contained in:
Gregory Schier
2025-01-20 13:07:04 -08:00
parent 26cce077bb
commit d142966d0c
16 changed files with 855 additions and 504 deletions

View File

@@ -1,6 +1,16 @@
import { Context, Environment } from '@yaakapp/api';
import { Environment, PluginDefinition } from '@yaakapp/api';
export function pluginHookImport(_ctx: Context, contents: string) {
export const plugin: PluginDefinition = {
importer: {
name: 'Yaak',
description: 'Yaak official format',
onImport(_ctx, args) {
return migrateImport(args.text) as any;
},
},
};
export function migrateImport(contents: string) {
let parsed;
try {
parsed = JSON.parse(contents);

View File

@@ -1,19 +1,15 @@
import { Context } from '@yaakapp/api';
import { describe, expect, test } from 'vitest';
import { pluginHookImport } from '../src';
const ctx = {} as Context;
import { migrateImport } from '../src';
describe('importer-yaak', () => {
test('Skips invalid imports', () => {
expect(pluginHookImport(ctx, 'not JSON')).toBeUndefined();
expect(pluginHookImport(ctx, '[]')).toBeUndefined();
expect(pluginHookImport(ctx, JSON.stringify({ resources: {} }))).toBeUndefined();
expect(migrateImport('not JSON')).toBeUndefined();
expect(migrateImport('[]')).toBeUndefined();
expect(migrateImport(JSON.stringify({ resources: {} }))).toBeUndefined();
});
test('converts schema 1 to 2', () => {
const imported = pluginHookImport(
ctx,
const imported = migrateImport(
JSON.stringify({
yaakSchema: 1,
resources: {
@@ -31,8 +27,7 @@ describe('importer-yaak', () => {
);
});
test('converts schema 2 to 3', () => {
const imported = pluginHookImport(
ctx,
const imported = migrateImport(
JSON.stringify({
yaakSchema: 2,
resources: {