Comments (11)
Yep! But it’s a devDependency—users don’t download it just by using this library.
from contentful-typescript-codegen.
@stevenpetryk Was about to correct myself. Also I was posting to the wrong repo anyways! I realized this file is a relic of my attempting to use this before. With Gatsby I've used graphql-codegen, because (I think) this doesn't work with Gatsby+Contentful setup
from contentful-typescript-codegen.
Hi @G-Rath, I don't work at Intercom anymore and so I cannot make changes to this project. I would recommend tagging a recent committer.
from contentful-typescript-codegen.
I didn’t want ts-node
to be a dependency of the project when it’s not necessary. You’re welcome to make it TypeScript if you prefer, and compile it to JS.
from contentful-typescript-codegen.
@stevenpetryk ts-node already is a dependency https://github.com/intercom/contentful-typescript-codegen/blob/master/package.json#L68
from contentful-typescript-codegen.
@stevenpetryk would you be open to supporting using TypeScript with ts-node
as an optional peer dependency?
I've implemented this in a few projects like jest & postcss, and would be happy to do it again here if you're happy with that :)
from contentful-typescript-codegen.
Hi @G-Rath 👋🏻 I'd be interested in seeing how that would work! I'd be open to that as long as we keep backwards compatibility 😃 Would you mind going in a bit more detail on how your proposal would work? Or maybe if it's easier you can create a PR with your proposal and tag me there!
from contentful-typescript-codegen.
@GabrielAnca no problem - I'll look at doing a PR over the weekend.
The general way it's implemented is by doing a require for ts-node
and if that's successful enabling it as a register before requiring the config file, then disabling it afterwards.
The implementation generally ends up looking something like this:
let registerer;
export const loadTSConfig = (configPath: string) => {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
registerer ||= require('ts-node').register() as Service;
} catch (e: any) {
if (e.code === 'MODULE_NOT_FOUND') {
throw new Error(
`'ts-node' is required for TypeScript configuration files. Make sure it is installed\nError: ${e.message}`
);
}
throw e;
}
registerer.enabled(true);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const configObject = interopRequireDefault(require(configPath)).default;
registerer.enabled(false);
return configObject;
};
There's some variation depending on how the config loading is actually done which I've not looked at yet e.g. for postcss
that was using a config loading library (cosmic-config, iirc) so it was implemented like above but as a loader (which the config library handled determining when to actually try and use that loader), whereas for jest we check if the config file we've found ends with .ts
(and consider jest.config.ts
as a valid config when searching on-disk) and call the config before disabling the registerer if it's a function so that dynamic imports still work.
(tbh it's getting to the point where I've been considering publishing a package for handling it, because of how similar the core code is 🙈)
from contentful-typescript-codegen.
Looking over the codebase, I think it should be a matter of wrapping these lines in some logic mixed with the above.
What I can't see is an interface that defines what the config should look like as this is type any
- @GabrielAnca is that something you could help with creating? (as I expect you probably know all the supported options and their types better than me at this point)
from contentful-typescript-codegen.
@GabrielAnca I just realised that this is using TypeScript 3 - would you be interested in me upgrading it to use v4? (and prettier?)
from contentful-typescript-codegen.
🎉 This issue has been resolved in version 3.4.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
from contentful-typescript-codegen.
Related Issues (20)
- The automated release is failing 🚨 HOT 2
- Smooth integration with next.js , env.local and alternative to getContentfulEnvironment HOT 5
- TypeError: Cannot read property 'getContentTypes' of undefined HOT 6
- Imports { Document } when it is not used HOT 2
- Feature Request: Export union of all entries HOT 1
- Fields are incorrectly extending Entry HOT 7
- ERR_REQUIRE_ESM in Node 16.6 HOT 5
- Not using prettierrc.json
- Missing collection types in generated file HOT 3
- Type narrowing not working with current setup HOT 1
- generating typescript models fails for specific space with TypeError: contentTypeValidation.linkContentType.map is not a function
- Syntax error from code generation
- TypeError: functionMap[field.type] is not a function HOT 2
- Update to work with Contentful v10 HOT 8
- Non-required attributes are not automatically generated to have `| null` appended to type
- getContenfulEnvironment.ts HOT 1
- Incorrectly classifies EntryCollection as an Entry type
- Prettier not mandatory
- Top level id, contentType and type on Entry HOT 1
- have option to add namespace and own commenting to generated types
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contentful-typescript-codegen.