Skip to content

Commit d700928

Browse files
authored
Merge pull request #59 from boazpoolman/feature/typescript-support
Feature/typescript support
2 parents a6035e1 + 56ee854 commit d700928

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

server/cli.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,33 @@ const packageJSON = require('../package.json');
1414

1515
const program = new Command();
1616

17+
const getStrapiApp = async () => {
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+
}
31+
32+
const distDir = isTSProject ? outDir : appDir;
33+
34+
const app = await strapi({ appDir, distDir }).load();
35+
36+
return app;
37+
} catch (e) {
38+
// Fallback for pre Strapi 4.2.
39+
const app = await strapi().load();
40+
return app;
41+
}
42+
};
43+
1744
const initTable = (head) => {
1845
return new Table({
1946
head: [chalk.green('Name'), chalk.green(head || 'State')],
@@ -69,7 +96,7 @@ const getConfigState = (diff, configName, syncType) => {
6996
};
7097

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

75102
// No import with empty sync dir.
@@ -218,7 +245,7 @@ program
218245
.description('The config diff')
219246
.action(async (options, { args }) => {
220247
const single = args[0];
221-
const app = await strapi().load();
248+
const app = await getStrapiApp();
222249
const diff = await app.plugin('config-sync').service('main').getFormattedDiff();
223250

224251
// No changes.

0 commit comments

Comments
 (0)