strapi-plugin-gen-types
Version:
Generate types for the different collections, single types & components found in your application
88 lines (87 loc) • 2.66 kB
JavaScript
import { useRef, useEffect } from "react";
import { jsx } from "react/jsx-runtime";
import { Plant } from "@strapi/icons";
const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
const v = glob[path];
if (v) {
return typeof v === "function" ? v() : Promise.resolve(v);
}
return new Promise((_, reject) => {
(typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
reject.bind(
null,
new Error(
"Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
)
)
);
});
};
const PLUGIN_ID = "gen-types";
const pluginName = "gen-types";
const Initializer = ({ setPlugin }) => {
const ref = useRef(setPlugin);
useEffect(() => {
ref.current(PLUGIN_ID);
}, []);
return null;
};
const PluginIcon = () => /* @__PURE__ */ jsx(Plant, {});
const prefixPluginTranslations = (trad, pluginId) => {
return Object.keys(trad).reduce((acc, current) => {
acc[`${pluginId}.${current}`] = trad[current];
return acc;
}, {});
};
const PERMISSIONS = {
// This permission regards the main component (App) and is used to tell
// If the plugin link should be displayed in the menu
// And also if the plugin is accessible. This use case is found when a user types the url of the
// plugin directly in the browser
"menu-link": [{ action: "plugin::gen-types.menu-link", subject: null }]
};
const index = {
register(app) {
app.addMenuLink({
to: `plugins/${PLUGIN_ID}`,
icon: PluginIcon,
intlLabel: {
id: `${PLUGIN_ID}.page.title`,
defaultMessage: PLUGIN_ID
},
Component: () => import("./App-C_2BhOzx.mjs").then((mod) => ({
default: mod.App
})),
permissions: PERMISSIONS["menu-link"]
});
app.registerPlugin({
id: PLUGIN_ID,
initializer: Initializer,
isReady: false,
name: PLUGIN_ID
});
},
async registerTrads({ locales }) {
const importedTrads = await Promise.all(
locales.map((locale) => {
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => import("./en-BRmJb_fY.mjs") }), `./translations/${locale}.json`, 3).then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, PLUGIN_ID),
locale
};
}).catch(() => {
return {
data: {},
locale
};
});
})
);
return Promise.resolve(importedTrads);
}
};
export {
PLUGIN_ID as P,
index as i,
pluginName as p
};