strapi-plugin-schemas-to-ts icon indicating copy to clipboard operation
strapi-plugin-schemas-to-ts copied to clipboard

destinationFolder property has unexpected behaviours

Open gregg-cbs opened this issue 1 year ago • 8 comments

Types are not getting generated into specified folder.

schema-to-ts config ("^1.3.0"):

'schemas-to-ts': { 
  enabled: true,
  logLevel: 0,
  usePrettierIfAvailable: true,
  destinationFolder: "src/types/strapi",
}

Result: image

gregg-cbs avatar Mar 25 '24 15:03 gregg-cbs

I am on windows os. strapi 4.20.4.

gregg-cbs avatar Mar 25 '24 15:03 gregg-cbs

And the types are still getting generated under collections such as api/event/content-types/event/event.ts.

I dont know if this is intended or fallback behaviour but it is unexpected that the plugin does this when setting the destinationFolder.

gregg-cbs avatar Mar 25 '24 15:03 gregg-cbs

Hi @gregg-cbs I introduced a bug on the components paths, but it should be fixed now. Please, update to 1.3.1 and tell me if you get the expected behavior

mancku avatar Mar 25 '24 15:03 mancku

Now im getting "TypeError: Cannot read properties of undefined (reading 'needsComponentSuffix')"

More of the error: PostV414InterfaceBuilder.buildInterfaceText (D:\Devbox\cbs\my-project\server\node_modules\strapi-plugin-schemas-to-ts\dist\server\schemas-to-ts\interface-builders\interfaceBuilder.js:258:35

gregg-cbs avatar Mar 26 '24 07:03 gregg-cbs

@gregg-cbs that's weird 🤔 That line is inside the block that builds the interface for the component, yet in converter.ts, inside the parseSchema method, there's this code:

let needsComponentSuffix = schemaSource === schemaSource_1.SchemaSource.Component &&
            (this.config.alwaysAddComponentSuffix || apiSchemas?.some(x => x.pascalName === pascalName));

if (needsComponentSuffix) {
  pascalName += 'Component';
}

This method is called for every file, so it should never be undefined for the components because apiSchemas should always have a value there. Can you provide more info about your schemas or the component that was being parsed when the exception happened?

mancku avatar Mar 26 '24 09:03 mancku

@gregg-cbs shouldn't your config look like this?

"schemas-to-ts": {
  enabled: true,
  config: {
    logLevel: 0,
    usePrettierIfAvailable: true,
    destinationFolder: "src/types/strapi",
  }
},

creazy231 avatar Jun 20 '24 21:06 creazy231

I unfortunately ditched this plugin due to hurdles at the time. It was slowing down our dev server reloads because it was building types every reload + coupled with these issues i thought its best to leave it and come back to it at a later stage.

Thanks for the responses. I will try this again when I have some time :)

gregg-cbs avatar Jun 24 '24 18:06 gregg-cbs

Will have a look at the repo in future since I’m using it constantly and will try to do my best to contribute. So I’d suggest to open a new issue with future request and I’ll try to look into them (:

creazy231 avatar Jun 24 '24 20:06 creazy231