UNPKG

strapi-plugin-gen-types

Version:

Generate types for the different collections, single types & components found in your application

87 lines (86 loc) 2.79 kB
"use strict"; const React = require("react"); const jsxRuntime = require("react/jsx-runtime"); const icons = require("@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 = React.useRef(setPlugin); React.useEffect(() => { ref.current(PLUGIN_ID); }, []); return null; }; const PluginIcon = () => /* @__PURE__ */ jsxRuntime.jsx(icons.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: () => Promise.resolve().then(() => require("./App-BJA0_4AT.js")).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": () => Promise.resolve().then(() => require("./en-Blu7bBKM.js")) }), `./translations/${locale}.json`, 3).then(({ default: data }) => { return { data: prefixPluginTranslations(data, PLUGIN_ID), locale }; }).catch(() => { return { data: {}, locale }; }); }) ); return Promise.resolve(importedTrads); } }; exports.PLUGIN_ID = PLUGIN_ID; exports.index = index; exports.pluginName = pluginName;