From 8167bb95d2c68cdb5e3c842a8cdc4fb9b99f4602 Mon Sep 17 00:00:00 2001 From: Convly Date: Wed, 26 Apr 2023 12:18:02 +0200 Subject: [PATCH 1/2] Automatically generate schemas TS types on dev server restart Default to false & add experimental tag --- .../lib/commands/actions/develop/action.js | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/core/strapi/lib/commands/actions/develop/action.js b/packages/core/strapi/lib/commands/actions/develop/action.js index f49e321c45..377a404df6 100644 --- a/packages/core/strapi/lib/commands/actions/develop/action.js +++ b/packages/core/strapi/lib/commands/actions/develop/action.js @@ -106,12 +106,33 @@ const primaryProcess = async ({ distDir, appDir, build, isTSProject, watchAdmin, cluster.fork(); }; -const workerProcess = ({ appDir, distDir, watchAdmin, polling, isTSProject }) => { - const strapiInstance = strapi({ +const workerProcess = async ({ appDir, distDir, watchAdmin, polling, isTSProject }) => { + const strapiInstance = await strapi({ distDir, autoReload: true, serveAdminPanel: !watchAdmin, - }); + }).load(); + + /** + * TypeScript automatic type generation upon dev server restart + * Its implementation, configuration and behavior can change in future releases + * @experimental + */ + const shouldGenerateTypeScriptTypes = strapiInstance.config.get( + 'server.typescript.dev.generate', + false + ); + + if (shouldGenerateTypeScriptTypes) { + // This is run in an uncaught promise on purpose so that it doesn't block Strapi startup + // NOTE: We should probably add some configuration options to manage the file structure output or the verbosity level + tsUtils.generators.generateSchemasDefinitions({ + strapi: strapiInstance, + outDir: appDir, + verbose: false, + silent: true, + }); + } const adminWatchIgnoreFiles = strapiInstance.config.get('admin.watchIgnoreFiles', []); watchFileChanges({ @@ -179,6 +200,7 @@ function watchFileChanges({ appDir, strapiInstance, watchIgnoreFiles, polling }) '**/*.db*', '**/exports/**', '**/dist/**', + '**/*.d.ts', ...watchIgnoreFiles, ], }); From 3e8abc125d9518145b14e1e60bbf5299e094ecc7 Mon Sep 17 00:00:00 2001 From: Convly Date: Fri, 28 Apr 2023 15:21:58 +0200 Subject: [PATCH 2/2] Change the config key for ts autogenerate --- packages/core/strapi/lib/commands/actions/develop/action.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/core/strapi/lib/commands/actions/develop/action.js b/packages/core/strapi/lib/commands/actions/develop/action.js index 377a404df6..f9133858ef 100644 --- a/packages/core/strapi/lib/commands/actions/develop/action.js +++ b/packages/core/strapi/lib/commands/actions/develop/action.js @@ -118,10 +118,7 @@ const workerProcess = async ({ appDir, distDir, watchAdmin, polling, isTSProject * Its implementation, configuration and behavior can change in future releases * @experimental */ - const shouldGenerateTypeScriptTypes = strapiInstance.config.get( - 'server.typescript.dev.generate', - false - ); + const shouldGenerateTypeScriptTypes = strapiInstance.config.get('typescript.autogenerate', false); if (shouldGenerateTypeScriptTypes) { // This is run in an uncaught promise on purpose so that it doesn't block Strapi startup