@@ -23,49 +23,65 @@ export const createExecuteMutationsCommand = ({
2323 command . description ( 'Execute mutations with different set (client-side).' ) ;
2424 command . addArgument ( new Argument ( '<tenant-identifier>' , 'The tenant identifier to use.' ) ) ;
2525 command . addArgument ( new Argument ( '<file>' , 'The file that contains the Mutations.' ) ) ;
26- command . addArgument ( new Argument ( '[image-mapping-file]' , 'An optional file for images mapping.' ) ) ;
26+ command . addArgument ( new Argument ( '[image-mapping-file]' , 'An optional file for images mapping. Use - to skip' ) ) ;
27+ command . addArgument ( new Argument ( '[file-mapping-file]' , 'An optional file for files mapping.' ) ) ;
2728 addInteractiveAndTokenOption ( command ) ;
2829
29- command . action ( async ( tenantIdentifier : string , inputFile : string , imageMappingFile : string , flags ) => {
30- if ( ! ( await flySystem . isFileExists ( inputFile ) ) ) {
31- throw new Error ( `File ${ inputFile } was not found.` ) ;
32- }
33- try {
34- const { credentials } = await getAuthenticatedUser ( {
35- isInteractive : ! flags . noInteractive ,
36- token_id : flags . token_id ,
37- token_secret : flags . token_secret ,
38- } ) ;
39-
40- let imageMapping : Record < string , string > = { } ;
41- if ( imageMappingFile ) {
42- imageMapping = await flySystem . loadJsonFile < Record < string , string > > ( imageMappingFile ) ;
30+ command . action (
31+ async (
32+ tenantIdentifier : string ,
33+ inputFile : string ,
34+ imageMappingFile : string ,
35+ fileMappingFile : string ,
36+ flags ,
37+ ) => {
38+ if ( ! ( await flySystem . isFileExists ( inputFile ) ) ) {
39+ throw new Error ( `File ${ inputFile } was not found.` ) ;
4340 }
4441
45- const intent = commandBus . createCommand ( 'ExecuteMutations' , {
46- filePath : inputFile ,
47- tenant : {
48- identifier : tenantIdentifier ,
49- } ,
50- credentials,
51- placeholderMap : {
52- images : imageMapping ,
53- } ,
54- } ) ;
55- const { result } = await commandBus . dispatch ( intent ) ;
56- if ( ! result ) {
57- throw new Error ( 'Failed to execute the Mutations file.' ) ;
58- }
59- // console.dir({ result }, { depth: null });
60- logger . success ( `Mutations executed.` ) ;
61- } catch ( error ) {
62- if ( error instanceof ZodError ) {
63- for ( const issue of error . issues ) {
64- logger . error ( `[${ issue . path . join ( '.' ) } ]: ${ issue . message } ` ) ;
42+ try {
43+ const { credentials } = await getAuthenticatedUser ( {
44+ isInteractive : ! flags . noInteractive ,
45+ token_id : flags . token_id ,
46+ token_secret : flags . token_secret ,
47+ } ) ;
48+
49+ let imageMapping : Record < string , string > = { } ;
50+ if ( imageMappingFile && imageMappingFile !== '-' ) {
51+ imageMapping = await flySystem . loadJsonFile < Record < string , string > > ( imageMappingFile ) ;
52+ }
53+
54+ let fileMapping : Record < string , string > = { } ;
55+ if ( fileMappingFile && fileMappingFile !== '-' ) {
56+ fileMapping = await flySystem . loadJsonFile < Record < string , string > > ( fileMappingFile ) ;
57+ }
58+
59+ const intent = commandBus . createCommand ( 'ExecuteMutations' , {
60+ filePath : inputFile ,
61+ tenant : {
62+ identifier : tenantIdentifier ,
63+ } ,
64+ credentials,
65+ placeholderMap : {
66+ images : imageMapping ,
67+ files : fileMapping ,
68+ } ,
69+ } ) ;
70+ const { result } = await commandBus . dispatch ( intent ) ;
71+ if ( ! result ) {
72+ throw new Error ( 'Failed to execute the Mutations file.' ) ;
73+ }
74+ // console.dir({ result }, { depth: null });
75+ logger . success ( `Mutations executed.` ) ;
76+ } catch ( error ) {
77+ if ( error instanceof ZodError ) {
78+ for ( const issue of error . issues ) {
79+ logger . error ( `[${ issue . path . join ( '.' ) } ]: ${ issue . message } ` ) ;
80+ }
6581 }
82+ throw error ;
6683 }
67- throw error ;
68- }
69- } ) ;
84+ } ,
85+ ) ;
7086 return command ;
7187} ;
0 commit comments