I am currently working more intensively on plugin development and am facing a small problem:
My plugin has several components and content types. Content types are created correctly and automatically when starting. Components, on the other hand, have to be created manually, as with the Strapi SEO plugin (Create components using a plugin). I do this within register.js so that I can react to updates within the schemas before initialising strapi. If I create or update the components, I restart the server using strapi.reload().
Now this is my problem:
Sometimes the plugin creates collection types before the creation of components is done. I want to make sure that the creation of all components is finished and after that the plugin should begin creating collection types.
Is that even possible or is there another way to solve this?
You can create components. but not trough the file system with plugins. if you go into yarn strapi console and type in strapi.components you see a list of all components. you can in the register faze of your plugin do strapi.components.push({object same format as all the others}) and it will register the component for you.
Thank you @Boegie19 .
But if I try to use strapi.components.push(...) within bootstrap.js or register.js, the server no longer starts: strapi.components.push is not a function
The server starts but the components are neither visible in the DB nor in the admin interface.
For now, I’m copying the components into the strapi directories using npm until there is an official way from strapi.
I correct you are right in the database the component appears correctly. As soon as I switch to the Content Type Builder in the admin, only a white page appears. When I restart the server, it no longer starts up with the following message:
TypeError: Cannot read properties of undefined (reading 'attributes')
I’m using Strapi 4.14.5 and I writing my plugin with Typescript. The object strapi.components[“uid”] expect the type Schema.Component. The type does not provide all attrbiutes for the component to be accepted. I had to add info, filename and schema for it to work. I also have to specify a filename even though i don’t have a file.
Thank you @Boegie19 for your hint with the strapi console.