@@ -14,6 +14,33 @@ const packageJSON = require('../package.json');
1414
1515const 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+
1744const 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
7198const 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