@@ -36,39 +36,50 @@ const registerHook: HookConfig = async ({ action, init }, { env, services, datab
3636
3737 // We need to do this in async in order to load the config files
3838 let _exportManager : ExportManager ;
39- const exportManager = async ( ) => {
40- if ( ! _exportManager ) {
41- _exportManager = new ExportManager ( logger ) ;
4239
43- if ( env . SCHEMA_SYNC_DATA_ONLY !== true ) {
44- _exportManager . addExporter ( {
45- watch : [ 'collections' , 'fields' , 'relations' ] ,
46- exporter : new SchemaExporter ( getSchemaService , logger , schemaOptions ) ,
47- } ) ;
48- }
40+ const createExportManager = async ( dataOnly = false ) => {
41+ const exportMng = new ExportManager ( logger ) ;
4942
50- const { syncDirectusCollections } = ( await nodeImport ( ExportHelper . schemaDir , 'directus_config.js' ) ) as {
51- syncDirectusCollections : ExportCollectionConfig ;
52- } ;
53- const { syncCustomCollections } = ( await nodeImport ( ExportHelper . schemaDir , 'config.js' ) ) as {
43+ if ( ! dataOnly ) {
44+ exportMng . addExporter ( {
45+ watch : [ 'collections' , 'fields' , 'relations' ] ,
46+ exporter : new SchemaExporter ( getSchemaService , logger , schemaOptions ) ,
47+ } ) ;
48+ }
49+
50+ const { syncDirectusCollections } = ( await nodeImport ( ExportHelper . schemaDir , 'directus_config.js' ) ) as {
51+ syncDirectusCollections : ExportCollectionConfig ;
52+ } ;
53+ const { syncCustomCollections } = ( await nodeImport ( ExportHelper . schemaDir , 'config.js' ) ) as {
54+ syncCustomCollections : ExportCollectionConfig ;
55+ } ;
56+ exportMng . addCollectionExporter ( syncDirectusCollections , getItemsService ) ;
57+ exportMng . addCollectionExporter ( syncCustomCollections , getItemsService ) ;
58+
59+ // Additional config
60+ if ( env . SCHEMA_SYNC_CONFIG ) {
61+ const { syncCustomCollections } = ( await nodeImport ( ExportHelper . schemaDir , env . SCHEMA_SYNC_CONFIG ) ) as {
5462 syncCustomCollections : ExportCollectionConfig ;
5563 } ;
56- _exportManager . addCollectionExporter ( syncDirectusCollections , getItemsService ) ;
57- _exportManager . addCollectionExporter ( syncCustomCollections , getItemsService ) ;
58-
59- // Additional config
60- if ( env . SCHEMA_SYNC_CONFIG ) {
61- const { syncCustomCollections } = ( await nodeImport ( ExportHelper . schemaDir , env . SCHEMA_SYNC_CONFIG ) ) as {
62- syncCustomCollections : ExportCollectionConfig ;
63- } ;
64- if ( syncCustomCollections ) {
65- _exportManager . addCollectionExporter ( syncCustomCollections , getItemsService ) ;
66- } else {
67- logger . warn ( `Additonal config specified but not exporting "syncCustomCollections"` ) ;
68- }
64+ if ( syncCustomCollections ) {
65+ exportMng . addCollectionExporter ( syncCustomCollections , getItemsService ) ;
66+ } else {
67+ logger . warn ( `Additonal config specified but not exporting "syncCustomCollections"` ) ;
6968 }
7069 }
7170
71+ return exportMng ;
72+ }
73+
74+ const exportManager = async ( dataOnly = false ) => {
75+ if ( dataOnly && env . SCHEMA_SYNC_DATA_ONLY !== true ) {
76+ return await createExportManager ( true ) ;
77+ }
78+
79+ if ( ! _exportManager ) {
80+ _exportManager = await createExportManager ( env . SCHEMA_SYNC_DATA_ONLY !== true ) ;
81+ }
82+
7283 return _exportManager ;
7384 } ;
7485
@@ -177,10 +188,11 @@ const registerHook: HookConfig = async ({ action, init }, { env, services, datab
177188 . command ( 'import' )
178189 . description ( 'Import the schema and all available data from file to DB.' )
179190 . option ( '--merge' , 'Only upsert data and not delete' )
180- . action ( async ( { merge } : { merge : boolean } ) => {
191+ . option ( '--data' , 'Only import data and not schema' )
192+ . action ( async ( { merge, data } : { merge : boolean ; data : boolean } ) => {
181193 try {
182194 logger . info ( `Importing everything from: ${ ExportHelper . dataDir } ` ) ;
183- const expMng = await exportManager ( ) ;
195+ const expMng = await exportManager ( data ) ;
184196 await expMng . loadAll ( merge ) ;
185197
186198 logger . info ( 'Done!' ) ;
0 commit comments