mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-11 03:26:58 +02:00
Update for standalone base environments
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Context } from '@yaakapp/api';
|
||||
import { Context, Environment } from '@yaakapp/api';
|
||||
|
||||
export function pluginHookImport(_ctx: Context, contents: string) {
|
||||
let parsed;
|
||||
@@ -23,6 +23,31 @@ export function pluginHookImport(_ctx: Context, contents: string) {
|
||||
delete parsed.resources['requests'];
|
||||
}
|
||||
|
||||
// Migrate v2 to v3
|
||||
for (const workspace of parsed.resources.workspaces ?? []) {
|
||||
if ('variables' in workspace) {
|
||||
// Create the base environment
|
||||
const baseEnvironment: Partial<Environment> = {
|
||||
id: `GENERATE_ID::base_env_${workspace['id']}`,
|
||||
name: 'Global Variables',
|
||||
variables: workspace.variables,
|
||||
workspaceId: workspace.id,
|
||||
};
|
||||
parsed.resources.environments = parsed.resources.environments ?? [];
|
||||
parsed.resources.environments.push(baseEnvironment);
|
||||
|
||||
// Delete variables key from workspace
|
||||
delete workspace.variables;
|
||||
|
||||
// Add environmentId to relevant environments
|
||||
for (const environment of parsed.resources.environments) {
|
||||
if (environment.workspaceId === workspace.id && environment.id !== baseEnvironment.id) {
|
||||
environment.environmentId = baseEnvironment.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { resources: parsed.resources }; // Should already be in the correct format
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user