mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-23 18:01:21 +01:00
Logic for new Environment.base field
This commit is contained in:
20
package-lock.json
generated
20
package-lock.json
generated
@@ -9,7 +9,7 @@
|
||||
"plugins/*"
|
||||
],
|
||||
"dependencies": {
|
||||
"@yaakapp/api": "^0.5.0"
|
||||
"@yaakapp/api": "^0.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.7.4",
|
||||
@@ -999,9 +999,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@yaakapp/api": {
|
||||
"version": "0.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.5.0.tgz",
|
||||
"integrity": "sha512-M0PPLGWQft+eQOOJ7ubwvRm3LTYXjAWQ8nniiqV3TkRcwa5++PteIH0OHV2L3Pei8cRQA8S25AD+RajyvFC8XQ==",
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.5.1.tgz",
|
||||
"integrity": "sha512-0YFrrTJVjrnsSm9BTxSnz1pd1+Q52/CBV1QpTVtXPPqlSIwcvj7jMdwuDpSKy5G8xbaoVzTgBnW25RgKog/q7g==",
|
||||
"dependencies": {
|
||||
"@types/node": "^22.5.4"
|
||||
}
|
||||
@@ -1054,10 +1054,6 @@
|
||||
"resolved": "plugins/importer-yaak",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@yaakapp/template-function-file": {
|
||||
"resolved": "plugins/template-function-file",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@yaakapp/template-function-fs": {
|
||||
"resolved": "plugins/template-function-fs",
|
||||
"link": true
|
||||
@@ -7196,7 +7192,8 @@
|
||||
},
|
||||
"plugins/template-function-file": {
|
||||
"name": "@yaakapp/template-function-file",
|
||||
"version": "0.0.1"
|
||||
"version": "0.0.1",
|
||||
"extraneous": true
|
||||
},
|
||||
"plugins/template-function-fs": {
|
||||
"name": "@yaakapp/template-function-fs",
|
||||
@@ -7225,6 +7222,11 @@
|
||||
"devDependencies": {
|
||||
"@types/jsonpath": "^0.2.4"
|
||||
}
|
||||
},
|
||||
"plugins/template-function-secure": {
|
||||
"name": "@yaakapp/template-function-secure",
|
||||
"version": "0.0.1",
|
||||
"extraneous": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,6 @@
|
||||
"workspaces-run": "^1.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@yaakapp/api": "^0.5.0"
|
||||
"@yaakapp/api": "^0.5.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ function importEnvironment(e: any, workspaceId: string): ExportResources['enviro
|
||||
createdAt: e.created ? new Date(e.created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: e.updated ? new Date(e.updated).toISOString().replace('Z', '') : undefined,
|
||||
workspaceId: convertId(workspaceId),
|
||||
environmentId: e.parentId === workspaceId ? null : convertId(e.parentId),
|
||||
base: e.parentId === workspaceId,
|
||||
model: 'environment',
|
||||
name: e.name,
|
||||
variables: Object.entries(e.data).map(([name, value]) => ({
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"environments": [
|
||||
{
|
||||
"createdAt": "2025-01-13T15:15:43.767",
|
||||
"environmentId": null,
|
||||
"base": true,
|
||||
"id": "GENERATE_ID::env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
||||
"model": "environment",
|
||||
"name": "Base Environment",
|
||||
@@ -18,7 +18,7 @@
|
||||
},
|
||||
{
|
||||
"createdAt": "2025-01-13T15:15:58.515",
|
||||
"environmentId": "GENERATE_ID::env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
||||
"base": false,
|
||||
"id": "GENERATE_ID::env_799ae3d723ef44af91b4817e5d057e6d",
|
||||
"model": "environment",
|
||||
"name": "Production",
|
||||
@@ -33,7 +33,7 @@
|
||||
},
|
||||
{
|
||||
"createdAt": "2025-01-13T15:16:14.707",
|
||||
"environmentId": "GENERATE_ID::env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
||||
"base": false,
|
||||
"id": "GENERATE_ID::env_030fbfdbb274426ebd78e2e6518f8553",
|
||||
"model": "environment",
|
||||
"name": "Staging",
|
||||
|
||||
@@ -46,7 +46,7 @@ export function migrateImport(contents: string) {
|
||||
parsed.resources.environments = parsed.resources.environments ?? [];
|
||||
parsed.resources.environments.push(baseEnvironment);
|
||||
|
||||
// Delete variables key from workspace
|
||||
// Delete variables key from the workspace
|
||||
delete workspace.variables;
|
||||
|
||||
// Add environmentId to relevant environments
|
||||
@@ -58,6 +58,14 @@ export function migrateImport(contents: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate v3 to v4
|
||||
for (const environment of parsed.resources.environments ?? []) {
|
||||
if ('environmentId' in environment) {
|
||||
environment.base = environment.environmentId == null;
|
||||
delete environment.environmentId;
|
||||
}
|
||||
}
|
||||
|
||||
return { resources: parsed.resources }; // Should already be in the correct format
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ describe('importer-yaak', () => {
|
||||
}],
|
||||
environments: [{
|
||||
id: 'e_1',
|
||||
environmentId: 'GENERATE_ID::base_env_w_1',
|
||||
base: false,
|
||||
workspaceId: 'w_1',
|
||||
name: 'Production',
|
||||
variables: [{ name: 'E1', value: 'E1!' }],
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"name": "@yaakapp/template-function-file",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"build": "yaakcli build ./src/index.ts",
|
||||
"dev": "yaakcli dev ./src/index.js"
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
|
||||
import fs from 'node:fs';
|
||||
|
||||
export const plugin: PluginDefinition = {
|
||||
templateFunctions: [{
|
||||
name: 'fs.readFile',
|
||||
args: [{ title: 'Select File', type: 'file', name: 'path', label: 'File' }],
|
||||
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
|
||||
if (!args.values.path) return null;
|
||||
|
||||
try {
|
||||
return fs.promises.readFile(args.values.path, 'utf-8');
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
}],
|
||||
};
|
||||
Reference in New Issue
Block a user