mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 09:38:29 +02: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/*"
|
"plugins/*"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@yaakapp/api": "^0.5.0"
|
"@yaakapp/api": "^0.5.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.7.4",
|
"@types/node": "^22.7.4",
|
||||||
@@ -999,9 +999,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@yaakapp/api": {
|
"node_modules/@yaakapp/api": {
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.5.1.tgz",
|
||||||
"integrity": "sha512-M0PPLGWQft+eQOOJ7ubwvRm3LTYXjAWQ8nniiqV3TkRcwa5++PteIH0OHV2L3Pei8cRQA8S25AD+RajyvFC8XQ==",
|
"integrity": "sha512-0YFrrTJVjrnsSm9BTxSnz1pd1+Q52/CBV1QpTVtXPPqlSIwcvj7jMdwuDpSKy5G8xbaoVzTgBnW25RgKog/q7g==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "^22.5.4"
|
"@types/node": "^22.5.4"
|
||||||
}
|
}
|
||||||
@@ -1054,10 +1054,6 @@
|
|||||||
"resolved": "plugins/importer-yaak",
|
"resolved": "plugins/importer-yaak",
|
||||||
"link": true
|
"link": true
|
||||||
},
|
},
|
||||||
"node_modules/@yaakapp/template-function-file": {
|
|
||||||
"resolved": "plugins/template-function-file",
|
|
||||||
"link": true
|
|
||||||
},
|
|
||||||
"node_modules/@yaakapp/template-function-fs": {
|
"node_modules/@yaakapp/template-function-fs": {
|
||||||
"resolved": "plugins/template-function-fs",
|
"resolved": "plugins/template-function-fs",
|
||||||
"link": true
|
"link": true
|
||||||
@@ -7196,7 +7192,8 @@
|
|||||||
},
|
},
|
||||||
"plugins/template-function-file": {
|
"plugins/template-function-file": {
|
||||||
"name": "@yaakapp/template-function-file",
|
"name": "@yaakapp/template-function-file",
|
||||||
"version": "0.0.1"
|
"version": "0.0.1",
|
||||||
|
"extraneous": true
|
||||||
},
|
},
|
||||||
"plugins/template-function-fs": {
|
"plugins/template-function-fs": {
|
||||||
"name": "@yaakapp/template-function-fs",
|
"name": "@yaakapp/template-function-fs",
|
||||||
@@ -7225,6 +7222,11 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jsonpath": "^0.2.4"
|
"@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"
|
"workspaces-run": "^1.0.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"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,
|
createdAt: e.created ? new Date(e.created).toISOString().replace('Z', '') : undefined,
|
||||||
updatedAt: e.updated ? new Date(e.updated).toISOString().replace('Z', '') : undefined,
|
updatedAt: e.updated ? new Date(e.updated).toISOString().replace('Z', '') : undefined,
|
||||||
workspaceId: convertId(workspaceId),
|
workspaceId: convertId(workspaceId),
|
||||||
environmentId: e.parentId === workspaceId ? null : convertId(e.parentId),
|
base: e.parentId === workspaceId,
|
||||||
model: 'environment',
|
model: 'environment',
|
||||||
name: e.name,
|
name: e.name,
|
||||||
variables: Object.entries(e.data).map(([name, value]) => ({
|
variables: Object.entries(e.data).map(([name, value]) => ({
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"environments": [
|
"environments": [
|
||||||
{
|
{
|
||||||
"createdAt": "2025-01-13T15:15:43.767",
|
"createdAt": "2025-01-13T15:15:43.767",
|
||||||
"environmentId": null,
|
"base": true,
|
||||||
"id": "GENERATE_ID::env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
"id": "GENERATE_ID::env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
||||||
"model": "environment",
|
"model": "environment",
|
||||||
"name": "Base Environment",
|
"name": "Base Environment",
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"createdAt": "2025-01-13T15:15:58.515",
|
"createdAt": "2025-01-13T15:15:58.515",
|
||||||
"environmentId": "GENERATE_ID::env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
"base": false,
|
||||||
"id": "GENERATE_ID::env_799ae3d723ef44af91b4817e5d057e6d",
|
"id": "GENERATE_ID::env_799ae3d723ef44af91b4817e5d057e6d",
|
||||||
"model": "environment",
|
"model": "environment",
|
||||||
"name": "Production",
|
"name": "Production",
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"createdAt": "2025-01-13T15:16:14.707",
|
"createdAt": "2025-01-13T15:16:14.707",
|
||||||
"environmentId": "GENERATE_ID::env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
"base": false,
|
||||||
"id": "GENERATE_ID::env_030fbfdbb274426ebd78e2e6518f8553",
|
"id": "GENERATE_ID::env_030fbfdbb274426ebd78e2e6518f8553",
|
||||||
"model": "environment",
|
"model": "environment",
|
||||||
"name": "Staging",
|
"name": "Staging",
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export function migrateImport(contents: string) {
|
|||||||
parsed.resources.environments = parsed.resources.environments ?? [];
|
parsed.resources.environments = parsed.resources.environments ?? [];
|
||||||
parsed.resources.environments.push(baseEnvironment);
|
parsed.resources.environments.push(baseEnvironment);
|
||||||
|
|
||||||
// Delete variables key from workspace
|
// Delete variables key from the workspace
|
||||||
delete workspace.variables;
|
delete workspace.variables;
|
||||||
|
|
||||||
// Add environmentId to relevant environments
|
// 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
|
return { resources: parsed.resources }; // Should already be in the correct format
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ describe('importer-yaak', () => {
|
|||||||
}],
|
}],
|
||||||
environments: [{
|
environments: [{
|
||||||
id: 'e_1',
|
id: 'e_1',
|
||||||
environmentId: 'GENERATE_ID::base_env_w_1',
|
base: false,
|
||||||
workspaceId: 'w_1',
|
workspaceId: 'w_1',
|
||||||
name: 'Production',
|
name: 'Production',
|
||||||
variables: [{ name: 'E1', value: 'E1!' }],
|
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