Not able to generate types independently #12677
mvarchdev
started this conversation in
Feature Requests
Replies: 1 comment 3 replies
-
Hey @mvarchdev // src/scripts/generate-types.ts
import loaders, { initializeContainer } from '@medusajs/medusa/loaders/index';
import { MedusaModule } from '@medusajs/modules-sdk';
import { ContainerRegistrationKeys, FileSystem, generateContainerTypes, gqlSchemaToTypes } from "@medusajs/utils";
import express from "express";
import path from "path";
export default async function generateTypes() {
console.log("Generating types...")
const directory = path.resolve(`.`)
const app = express()
const container = await initializeContainer(directory)
const logger = container.resolve(ContainerRegistrationKeys.LOGGER)
const configModule = container.resolve(ContainerRegistrationKeys.CONFIG_MODULE)
// Here we disable the admin for types generation, to make sure we'll not have any errors
configModule.admin.disable = true
const { shutdown, gqlSchema, modules } = await loaders({
directory,
expressApp: app,
})
const typesDirectory = path.join(directory, ".medusa/types")
await new FileSystem(typesDirectory).cleanup({ recursive: true })
await generateContainerTypes(modules, {
outputDir: typesDirectory,
interfaceName: "ModuleImplementations",
})
logger.debug("Generated container types")
if (gqlSchema) {
await gqlSchemaToTypes({
outputDir: typesDirectory,
filename: "query-entry-points",
interfaceName: "RemoteQueryEntryPoints",
schema: gqlSchema,
joinerConfigs: MedusaModule.getAllJoinerConfigs(),
})
logger.debug("Generated modules types")
}
// Then we enable the admin again to make it work as usual before you build the project
configModule.admin.disable = false
await shutdown()
}
// Just in case you want to run this file using `npx ts-node src/scripts/generate-types.ts`
if (require.main === module) {
generateTypes().catch(console.error)
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! We would have use-case that is currently not supported by medusa.js!
In our company we have strict TS typing in our linter configurations. We need to have generated types for linting to pass. Currently, the only way to generate types is using running either
medusa develop
ormedusa start --types
, which is tbh really not quite modular/flexible. We would need to have ability to generate types in CI and locally for example before build/commit.Is there some easy way to do this currently?
Beta Was this translation helpful? Give feedback.
All reactions