mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 00:58:32 +02:00
Clean up importers
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
function I(e, t) {
|
function S(e, t) {
|
||||||
return (
|
return (
|
||||||
console.log('IMPORTING Environment', e._id, e.name, JSON.stringify(e, null, 2)),
|
console.log('IMPORTING Environment', e._id, e.name, JSON.stringify(e, null, 2)),
|
||||||
{
|
{
|
||||||
@@ -16,13 +16,13 @@ function I(e, t) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
function S(e) {
|
function I(e) {
|
||||||
return m(e) && e._type === 'workspace';
|
return m(e) && e._type === 'workspace';
|
||||||
}
|
}
|
||||||
function O(e) {
|
function g(e) {
|
||||||
return m(e) && e._type === 'request_group';
|
return m(e) && e._type === 'request_group';
|
||||||
}
|
}
|
||||||
function g(e) {
|
function y(e) {
|
||||||
return m(e) && e._type === 'request';
|
return m(e) && e._type === 'request';
|
||||||
}
|
}
|
||||||
function f(e) {
|
function f(e) {
|
||||||
@@ -31,10 +31,10 @@ function f(e) {
|
|||||||
function m(e) {
|
function m(e) {
|
||||||
return Object.prototype.toString.call(e) === '[object Object]';
|
return Object.prototype.toString.call(e) === '[object Object]';
|
||||||
}
|
}
|
||||||
function y(e) {
|
function O(e) {
|
||||||
return Object.prototype.toString.call(e) === '[object String]';
|
return Object.prototype.toString.call(e) === '[object String]';
|
||||||
}
|
}
|
||||||
function h(e) {
|
function _(e) {
|
||||||
return Object.entries(e).map(([t, n]) => ({
|
return Object.entries(e).map(([t, n]) => ({
|
||||||
enabled: !0,
|
enabled: !0,
|
||||||
name: t,
|
name: t,
|
||||||
@@ -42,9 +42,9 @@ function h(e) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
function d(e) {
|
function d(e) {
|
||||||
return y(e) ? e.replaceAll(/{{\s*(_\.)?([^}]+)\s*}}/g, '${[$2]}') : e;
|
return O(e) ? e.replaceAll(/{{\s*(_\.)?([^}]+)\s*}}/g, '${[$2]}') : e;
|
||||||
}
|
}
|
||||||
function _(e, t, n = 0) {
|
function h(e, t, n = 0) {
|
||||||
var u, r;
|
var u, r;
|
||||||
console.log('IMPORTING REQUEST', e._id, e.name, JSON.stringify(e, null, 2));
|
console.log('IMPORTING REQUEST', e._id, e.name, JSON.stringify(e, null, 2));
|
||||||
let s = null,
|
let s = null,
|
||||||
@@ -92,7 +92,7 @@ function _(e, t, n = 0) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
function N(e, t) {
|
function w(e, t) {
|
||||||
return (
|
return (
|
||||||
console.log('IMPORTING Workspace', e._id, e.name, JSON.stringify(e, null, 2)),
|
console.log('IMPORTING Workspace', e._id, e.name, JSON.stringify(e, null, 2)),
|
||||||
{
|
{
|
||||||
@@ -119,35 +119,31 @@ function D(e, t) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
function w(e) {
|
function b(e) {
|
||||||
let t;
|
let t;
|
||||||
try {
|
try {
|
||||||
t = JSON.parse(e);
|
t = JSON.parse(e);
|
||||||
} catch {
|
} catch {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!m(t) || !Array.isArray(t.requests)) return;
|
if (!m(t)) return;
|
||||||
const n = {
|
const n = {
|
||||||
workspaces: [],
|
workspaces: [],
|
||||||
requests: [],
|
requests: [],
|
||||||
environments: [],
|
environments: [],
|
||||||
folders: [],
|
folders: [],
|
||||||
},
|
},
|
||||||
s = t.resources.filter(S);
|
s = t.resources.filter(I);
|
||||||
for (const o of s) {
|
for (const o of s) {
|
||||||
console.log('IMPORTING WORKSPACE', o.name);
|
|
||||||
const a = t.resources.find((r) => f(r) && r.parentId === o._id);
|
const a = t.resources.find((r) => f(r) && r.parentId === o._id);
|
||||||
console.log('FOUND BASE ENV', a.name),
|
n.workspaces.push(w(o, a ? _(a.data) : []));
|
||||||
n.workspaces.push(N(o, a ? h(a.data) : [])),
|
|
||||||
console.log('IMPORTING ENVIRONMENTS', a.name);
|
|
||||||
const l = t.resources.filter((r) => f(r) && r.parentId === (a == null ? void 0 : a._id));
|
const l = t.resources.filter((r) => f(r) && r.parentId === (a == null ? void 0 : a._id));
|
||||||
console.log('FOUND', l.length, 'ENVIRONMENTS'),
|
n.environments.push(...l.map((r) => S(r, o._id)));
|
||||||
n.environments.push(...l.map((r) => I(r, o._id)));
|
|
||||||
const u = (r) => {
|
const u = (r) => {
|
||||||
const c = t.resources.filter((i) => i.parentId === r);
|
const c = t.resources.filter((i) => i.parentId === r);
|
||||||
let p = 0;
|
let p = 0;
|
||||||
for (const i of c)
|
for (const i of c)
|
||||||
O(i) ? (n.folders.push(D(i, o._id)), u(i._id)) : g(i) && n.requests.push(_(i, o._id, p++));
|
g(i) ? (n.folders.push(D(i, o._id)), u(i._id)) : y(i) && n.requests.push(h(i, o._id, p++));
|
||||||
};
|
};
|
||||||
u(o._id);
|
u(o._id);
|
||||||
}
|
}
|
||||||
@@ -155,7 +151,7 @@ function w(e) {
|
|||||||
(n.requests = n.requests.filter(Boolean)),
|
(n.requests = n.requests.filter(Boolean)),
|
||||||
(n.environments = n.environments.filter(Boolean)),
|
(n.environments = n.environments.filter(Boolean)),
|
||||||
(n.workspaces = n.workspaces.filter(Boolean)),
|
(n.workspaces = n.workspaces.filter(Boolean)),
|
||||||
n
|
{ resources: n }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
export { w as pluginHookImport };
|
export { b as pluginHookImport };
|
||||||
|
|||||||
@@ -23,10 +23,6 @@ export function pluginHookImport(contents) {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray(parsed.requests)) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const resources = {
|
const resources = {
|
||||||
workspaces: [],
|
workspaces: [],
|
||||||
requests: [],
|
requests: [],
|
||||||
@@ -37,22 +33,18 @@ export function pluginHookImport(contents) {
|
|||||||
// Import workspaces
|
// Import workspaces
|
||||||
const workspacesToImport = parsed.resources.filter(isWorkspace);
|
const workspacesToImport = parsed.resources.filter(isWorkspace);
|
||||||
for (const workspaceToImport of workspacesToImport) {
|
for (const workspaceToImport of workspacesToImport) {
|
||||||
console.log('IMPORTING WORKSPACE', workspaceToImport.name);
|
|
||||||
const baseEnvironment = parsed.resources.find(
|
const baseEnvironment = parsed.resources.find(
|
||||||
(r) => isEnvironment(r) && r.parentId === workspaceToImport._id,
|
(r) => isEnvironment(r) && r.parentId === workspaceToImport._id,
|
||||||
);
|
);
|
||||||
console.log('FOUND BASE ENV', baseEnvironment.name);
|
|
||||||
resources.workspaces.push(
|
resources.workspaces.push(
|
||||||
importWorkspace(
|
importWorkspace(
|
||||||
workspaceToImport,
|
workspaceToImport,
|
||||||
baseEnvironment ? parseVariables(baseEnvironment.data) : [],
|
baseEnvironment ? parseVariables(baseEnvironment.data) : [],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
console.log('IMPORTING ENVIRONMENTS', baseEnvironment.name);
|
|
||||||
const environmentsToImport = parsed.resources.filter(
|
const environmentsToImport = parsed.resources.filter(
|
||||||
(r) => isEnvironment(r) && r.parentId === baseEnvironment?._id,
|
(r) => isEnvironment(r) && r.parentId === baseEnvironment?._id,
|
||||||
);
|
);
|
||||||
console.log('FOUND', environmentsToImport.length, 'ENVIRONMENTS');
|
|
||||||
resources.environments.push(
|
resources.environments.push(
|
||||||
...environmentsToImport.map((r) => importEnvironment(r, workspaceToImport._id)),
|
...environmentsToImport.map((r) => importEnvironment(r, workspaceToImport._id)),
|
||||||
);
|
);
|
||||||
@@ -79,5 +71,5 @@ export function pluginHookImport(contents) {
|
|||||||
resources.environments = resources.environments.filter(Boolean);
|
resources.environments = resources.environments.filter(Boolean);
|
||||||
resources.workspaces = resources.workspaces.filter(Boolean);
|
resources.workspaces = resources.workspaces.filter(Boolean);
|
||||||
|
|
||||||
return resources;
|
return { resources };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ function u(r) {
|
|||||||
} catch {
|
} catch {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (t(e) && e.yaakSchema === 1) return e.resources;
|
if (t(e) && e.yaakSchema === 1) return { resources: e.resources };
|
||||||
}
|
}
|
||||||
function t(r) {
|
function t(r) {
|
||||||
return Object.prototype.toString.call(r) === '[object Object]';
|
return Object.prototype.toString.call(r) === '[object Object]';
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export function pluginHookImport(contents) {
|
|||||||
|
|
||||||
if (parsed.yaakSchema !== 1) return undefined;
|
if (parsed.yaakSchema !== 1) return undefined;
|
||||||
|
|
||||||
return parsed.resources; // Should already be in the correct format
|
return { resources: parsed.resources }; // Should already be in the correct format
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isJSObject(obj) {
|
export function isJSObject(obj) {
|
||||||
|
|||||||
Reference in New Issue
Block a user