Skip to content

Commit c9e45c3

Browse files
committed
feat: Support for typescript in Strapi v4.2.0
1 parent fea127f commit c9e45c3

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

server/cli.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,33 @@ const chalk = require('chalk');
77
const inquirer = require('inquirer');
88
const { isEmpty } = require('lodash');
99
const strapi = require('@strapi/strapi'); // eslint-disable-line
10+
const tsUtils = require('@strapi/typescript-utils'); // eslint-disable-line
1011
const gitDiff = require('git-diff');
1112

1213
const warnings = require('./warnings');
1314
const packageJSON = require('../package.json');
1415

1516
const program = new Command();
1617

18+
const getStrapiApp = async () => {
19+
const appDir = process.cwd();
20+
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
21+
const outDir = await tsUtils.resolveOutDir(appDir);
22+
23+
if (isTSProject) {
24+
await tsUtils.compile(appDir, {
25+
watch: false,
26+
configOptions: { options: { incremental: true } },
27+
});
28+
}
29+
30+
const distDir = isTSProject ? outDir : appDir;
31+
32+
const app = await strapi({ appDir, distDir }).load();
33+
34+
return app;
35+
};
36+
1737
const initTable = (head) => {
1838
return new Table({
1939
head: [chalk.green('Name'), chalk.green(head || 'State')],
@@ -69,7 +89,7 @@ const getConfigState = (diff, configName, syncType) => {
6989
};
7090

7191
const handleAction = async (syncType, skipConfirm, configType, partials) => {
72-
const app = await strapi().load();
92+
const app = await getStrapiApp();
7393
const hasSyncDir = fs.existsSync(app.config.get('plugin.config-sync.syncDir'));
7494

7595
// No import with empty sync dir.
@@ -218,7 +238,7 @@ program
218238
.description('The config diff')
219239
.action(async (options, { args }) => {
220240
const single = args[0];
221-
const app = await strapi().load();
241+
const app = await getStrapiApp();
222242
const diff = await app.plugin('config-sync').service('main').getFormattedDiff();
223243

224244
// No changes.

0 commit comments

Comments
 (0)