Skip to content

Commit 56ee854

Browse files
committed
fix: Fallback for pre Strapi 4.2
1 parent c9e45c3 commit 56ee854

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

server/cli.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ 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
1110
const gitDiff = require('git-diff');
1211

1312
const warnings = require('./warnings');
@@ -16,22 +15,30 @@ const packageJSON = require('../package.json');
1615
const program = new Command();
1716

1817
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-
}
18+
try {
19+
const tsUtils = require('@strapi/typescript-utils'); // eslint-disable-line
20+
21+
const appDir = process.cwd();
22+
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
23+
const outDir = await tsUtils.resolveOutDir(appDir);
24+
25+
if (isTSProject) {
26+
await tsUtils.compile(appDir, {
27+
watch: false,
28+
configOptions: { options: { incremental: true } },
29+
});
30+
}
2931

30-
const distDir = isTSProject ? outDir : appDir;
32+
const distDir = isTSProject ? outDir : appDir;
3133

32-
const app = await strapi({ appDir, distDir }).load();
34+
const app = await strapi({ appDir, distDir }).load();
3335

34-
return app;
36+
return app;
37+
} catch (e) {
38+
// Fallback for pre Strapi 4.2.
39+
const app = await strapi().load();
40+
return app;
41+
}
3542
};
3643

3744
const initTable = (head) => {

0 commit comments

Comments
 (0)