Skip to content

Commit

Permalink
fix(plugins): Add support for add/remove paths in global.d.ts in fron…
Browse files Browse the repository at this point in the history
…tend
  • Loading branch information
aXenDeveloper committed Jun 5, 2024
1 parent 98f0e12 commit 1c42de2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 6 deletions.
13 changes: 13 additions & 0 deletions backend/src/plugins/core/admin/plugins/delete/contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ export const removeDatabaseFromService = ({
""
);
};

export const removeLangFromTypes = ({
code,
content
}: {
code: string;
content: string;
}) => {
return content.replace(
`\n typeof import("@/plugins/${code}/langs/en.json") &`,
""
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class DeleteAdminPluginsService {
const modulePath = ABSOLUTE_PATHS.plugin({ code }).root;
this.deleteFolderWhenExists(modulePath);
// Frontend
const frontendPaths = ["admin_pages", "pages", "plugin"];
const frontendPaths = ["admin_pages", "pages", "plugin", "pages_container"];
frontendPaths.forEach(path => {
this.deleteFolderWhenExists(
ABSOLUTE_PATHS.plugin({ code }).frontend[path]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import * as fs from "fs";

import { Injectable } from "@nestjs/common";

import { changeDatabaseService, changeModuleRootSchema } from "./contents";
import {
changeDatabaseService,
changeLangTypes,
changeModuleRootSchema
} from "./contents";

import {
removeDatabaseFromService,
removeLangFromTypes,
removeModuleFromRootSchema
} from "../../../delete/contents";
import { CustomError } from "@/utils/errors/custom-error";
Expand Down Expand Up @@ -68,6 +73,15 @@ export class ChangeFilesAdminPluginsService {
code
}),
condition: () => true
},
{
path: join(ABSOLUTE_PATHS.frontend.init, "global.d.ts"),
content: content =>
changeLangTypes({
content,
code
}),
condition: () => true
}
];

Expand All @@ -93,6 +107,15 @@ export class ChangeFilesAdminPluginsService {
code
}),
condition: () => true
},
{
path: join(ABSOLUTE_PATHS.frontend.init, "global.d.ts"),
content: content =>
removeLangFromTypes({
content,
code
}),
condition: () => true
}
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,16 @@ export const changeDatabaseService = ({
`\n ...table${name},\n // ! === MODULE ===`
);
};

export const changeLangTypes = ({
code,
content
}: {
code: string;
content: string;
}) => {
return content.replace(
"// ! === IMPORT ===",
`typeof import("@/plugins/${code}/langs/en.json") &\n // ! === IMPORT ===`
);
};
11 changes: 7 additions & 4 deletions backend/src/utils/actions/helpers/update-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const updatePlugins = async ({
}) => {
fs.readdir(join(process.cwd(), "src", "plugins"), async (err, plugins) => {
let isDefaultIndex: number | null = null;
const defaultPlugin = await db.query.core_plugins.findFirst({
where: (table, { eq }) => eq(table.default, true)
});

await Promise.all(
plugins
.filter(
Expand Down Expand Up @@ -48,7 +52,6 @@ export const updatePlugins = async ({
await db
.update(core_plugins)
.set({
updated: new Date(),
name: config.name,
description: config.description,
support_url: config.support_url,
Expand All @@ -60,7 +63,7 @@ export const updatePlugins = async ({
})
.where(eq(core_plugins.id, pluginId));
} else {
const plugin = await db
const pluginInsert = await db
.insert(core_plugins)
.values([
{
Expand All @@ -73,12 +76,12 @@ export const updatePlugins = async ({
allow_default: config.allow_default,
version: version ?? null,
version_code: latestVersion ? +latestVersion : null,
default: isDefaultIndex === index
default: isDefaultIndex === index && !defaultPlugin
}
])
.returning();

pluginId = plugin[0].id;
pluginId = pluginInsert[0].id;
}
})
);
Expand Down

0 comments on commit 1c42de2

Please sign in to comment.