@@ -7,13 +7,33 @@ const chalk = require('chalk');
77const inquirer = require ( 'inquirer' ) ;
88const { isEmpty } = require ( 'lodash' ) ;
99const strapi = require ( '@strapi/strapi' ) ; // eslint-disable-line
10+ const tsUtils = require ( '@strapi/typescript-utils' ) ; // eslint-disable-line
1011const gitDiff = require ( 'git-diff' ) ;
1112
1213const warnings = require ( './warnings' ) ;
1314const packageJSON = require ( '../package.json' ) ;
1415
1516const 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+
1737const 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
7191const 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