Conversation
bbaf98e to
dcc207c
Compare
| const { inputSchema, inputSchemaPath } = await readAndValidateInputSchema({ | ||
| forcePath: this.args.path, | ||
| cwd: process.cwd(), | ||
| action: 'Generating types from', | ||
| }); |
There was a problem hiding this comment.
generate-type share a validation logic with validate-schema now
src/commands/actor/generate-types.ts
Outdated
| char: 'o', | ||
| description: 'Directory where the generated files should be outputted.', | ||
| required: false, | ||
| default: './.generated/actor/', |
There was a problem hiding this comment.
actor templates have typescript setup with only src as include, so you cannot import it right away and you have to adjust it. Maybe better idea is to generate it directly to src/.generated/actor/ ? cc @vladfrangu
There was a problem hiding this comment.
this might be best to discuss with @B4nan and @patrikbraborec too. Or maybe we wanna make it like how prisma handles it? so you'd have @apify/actor in node-modules which gets filled out by the cli?
There was a problem hiding this comment.
so you'd have @apify/actor in node-modules which gets filled out by the cli?
I think changed this in v7, because it produced a lot of side effects, e.g. with caching. But we could explore this as well, maybe for our use case it would be fine.
If we won't go that way, I am slightly in favor of putting this into the src folder, the alternative would be dynamically appending the .generated folder to includes in tsconfig. But that would mean you end up with dist/src and dist/.generated if I'm not mistaken, which is a bit ugly (but also rather irrelevant).
There was a problem hiding this comment.
fwiw modifying tsconfig can be risky, people may have god knows what setups in their tsconfig files and we shouldn't randomly append our folder.
I think changed this in v7, because it produced a lot of side effects, e.g. with caching. But we could explore this as well, maybe for our use case it would be fine.
Can you help me understand what you mean by this? Did prisma change this or what are you referring to with v7?
There was a problem hiding this comment.
There was a problem hiding this comment.
I just came back cuz I read that, holy heck I did not know.... But they also use the top level generated dir by def, interesting
There was a problem hiding this comment.
lets use 'src/.generated/actor/' for now, we can change in next iteration if needed, now it should work out of the box 3f47502
| import { readFile } from 'node:fs/promises'; | ||
|
|
There was a problem hiding this comment.
Really just starting point of tests. No complex scenarios.
| }); | ||
|
|
||
| expect(lastErrorMessage()).toMatch(/Generated types written to/); | ||
| expect(lastErrorMessage()).toMatch(/\.generated\/actor\/complex\.ts/); |
There was a problem hiding this comment.
use path.join and i think you can do .toInclude or just expect(lastErrorMessage().includes()).toBeTruthy()
| const { lastErrorMessage } = useConsoleSpy(); | ||
|
|
||
| describe('apify actor generate-types', () => { | ||
| const { joinPath, beforeAllCalls, afterAllCalls } = useTempPath('generate-types', { |
There was a problem hiding this comment.
Usually this hook is called from the top level, followed by importing the commands with await import, but if it WORKS even like this... fun
There was a problem hiding this comment.
I will keep it this way, If I run on some problems I let you know
…e-definitions-from-schemas
…mand-for-generating-type-definitions-from-schemas
…rating-type-definitions-from-schemas' into 993-implement-a-command-for-generating-type-definitions-from-schemas
…mand-for-generating-type-definitions-from-schemas
Draft summary
output: path to a directory where the files generated should be outputted, default ./.generated/actor/ (actual path in code is gonna be resolve(cwd(), output), followed by mkdir(), then storing in there). char: o
strict: whether generated interfaces should have an index definition ([key: string]: unknown if this is set to false), default true. char: s
[can optionally be done] language: the language to generate the types for (currently only TypeScript, but ideally structure the code in a way where we can easily add in new languages). char: l
[optional, nice to have, can be for future work] [input/output/dataset/key-value-store]-schema: path to a specific schema to generate types for
[don't implement this until we discuss it] add-to-ignore: whether the cli should add the generated files to files like .prettierignore or the biome config, default: false.
tests
Feedback
srcdue to tsconfigactor generate-schema->generate-schema-typesto keep consistency withactor validate-schema?