From c9e45c3909f7d628d0d6c93bc77e27ca97c94742 Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Wed, 8 Jun 2022 22:43:55 +0200 Subject: [PATCH 1/2] feat: Support for typescript in Strapi v4.2.0 --- server/cli.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/server/cli.js b/server/cli.js index 2cd9739..24ef5f8 100644 --- a/server/cli.js +++ b/server/cli.js @@ -7,6 +7,7 @@ const chalk = require('chalk'); const inquirer = require('inquirer'); const { isEmpty } = require('lodash'); const strapi = require('@strapi/strapi'); // eslint-disable-line +const tsUtils = require('@strapi/typescript-utils'); // eslint-disable-line const gitDiff = require('git-diff'); const warnings = require('./warnings'); @@ -14,6 +15,25 @@ const packageJSON = require('../package.json'); const program = new Command(); +const getStrapiApp = async () => { + const appDir = process.cwd(); + const isTSProject = await tsUtils.isUsingTypeScript(appDir); + const outDir = await tsUtils.resolveOutDir(appDir); + + if (isTSProject) { + await tsUtils.compile(appDir, { + watch: false, + configOptions: { options: { incremental: true } }, + }); + } + + const distDir = isTSProject ? outDir : appDir; + + const app = await strapi({ appDir, distDir }).load(); + + return app; +}; + const initTable = (head) => { return new Table({ head: [chalk.green('Name'), chalk.green(head || 'State')], @@ -69,7 +89,7 @@ const getConfigState = (diff, configName, syncType) => { }; const handleAction = async (syncType, skipConfirm, configType, partials) => { - const app = await strapi().load(); + const app = await getStrapiApp(); const hasSyncDir = fs.existsSync(app.config.get('plugin.config-sync.syncDir')); // No import with empty sync dir. @@ -218,7 +238,7 @@ program .description('The config diff') .action(async (options, { args }) => { const single = args[0]; - const app = await strapi().load(); + const app = await getStrapiApp(); const diff = await app.plugin('config-sync').service('main').getFormattedDiff(); // No changes. From 56ee854e718f0ec09e446ef3fa1645e940506269 Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Tue, 14 Jun 2022 18:38:05 +0200 Subject: [PATCH 2/2] fix: Fallback for pre Strapi 4.2 --- server/cli.js | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/server/cli.js b/server/cli.js index 24ef5f8..cf6a7fc 100644 --- a/server/cli.js +++ b/server/cli.js @@ -7,7 +7,6 @@ const chalk = require('chalk'); const inquirer = require('inquirer'); const { isEmpty } = require('lodash'); const strapi = require('@strapi/strapi'); // eslint-disable-line -const tsUtils = require('@strapi/typescript-utils'); // eslint-disable-line const gitDiff = require('git-diff'); const warnings = require('./warnings'); @@ -16,22 +15,30 @@ const packageJSON = require('../package.json'); const program = new Command(); const getStrapiApp = async () => { - const appDir = process.cwd(); - const isTSProject = await tsUtils.isUsingTypeScript(appDir); - const outDir = await tsUtils.resolveOutDir(appDir); + try { + const tsUtils = require('@strapi/typescript-utils'); // eslint-disable-line - if (isTSProject) { - await tsUtils.compile(appDir, { - watch: false, - configOptions: { options: { incremental: true } }, - }); + const appDir = process.cwd(); + const isTSProject = await tsUtils.isUsingTypeScript(appDir); + const outDir = await tsUtils.resolveOutDir(appDir); + + if (isTSProject) { + await tsUtils.compile(appDir, { + watch: false, + configOptions: { options: { incremental: true } }, + }); + } + + const distDir = isTSProject ? outDir : appDir; + + const app = await strapi({ appDir, distDir }).load(); + + return app; + } catch (e) { + // Fallback for pre Strapi 4.2. + const app = await strapi().load(); + return app; } - - const distDir = isTSProject ? outDir : appDir; - - const app = await strapi({ appDir, distDir }).load(); - - return app; }; const initTable = (head) => {