1
1
import { ContentTypeElements , ContentTypeSnippetModels , ManagementClient } from "@kontent-ai/management-sdk" ;
2
+ import { oraPromise } from "ora" ;
2
3
3
4
import { logInfo , LogOptions } from "../../../log.js" ;
4
5
import { omit } from "../../../utils/object.js" ;
5
6
import { serially } from "../../../utils/requests.js" ;
6
7
import { elementTypes } from "../constants/elements.js" ;
8
+ import { noSyncTaskEmoji } from "../constants/emojiCodes.js" ;
7
9
import { DiffModel } from "../types/diffModel.js" ;
8
10
import { PatchOperation } from "../types/patchOperation.js" ;
9
11
import {
@@ -21,12 +23,16 @@ export const addSnippetsWithoutReferences = async (
21
23
logOptions : LogOptions ,
22
24
) => {
23
25
if ( ! addSnippets . length ) {
24
- logInfo ( logOptions , "standard" , " No content type snippets to add" ) ;
26
+ logInfo ( logOptions , "standard" , ` ${ noSyncTaskEmoji } No content type snippets to add` ) ;
25
27
return ;
26
28
}
27
- logInfo ( logOptions , "standard" , "Adding content type snippets" ) ;
28
29
const addSnippetsWithoutReferences = addSnippets . map ( removeReferencesFromAddOp ) ;
29
- await serially ( addSnippetsWithoutReferences . map ( s => ( ) => addSnippet ( client , s ) ) ) ;
30
+ await oraPromise (
31
+ serially ( addSnippetsWithoutReferences . map ( s => ( ) => addSnippet ( client , s ) ) ) ,
32
+ {
33
+ text : "Adding content type snippets" ,
34
+ } ,
35
+ ) ;
30
36
} ;
31
37
32
38
export const addSnippetsReferences = async (
@@ -52,22 +58,24 @@ export const addSnippetsReferences = async (
52
58
const snippetsReplaceReferencesOps = addSnippets . map ( createUpdateReferencesOps ) ;
53
59
54
60
if ( snippetsReplaceReferencesOps . every ( ( [ , arr ] ) => ! arr . length ) ) {
55
- logInfo ( logOptions , "standard" , " No content type snippet's references to update" ) ;
61
+ logInfo ( logOptions , "standard" , ` ${ noSyncTaskEmoji } No content type snippet's references to update` ) ;
56
62
return ;
57
63
}
58
64
59
- logInfo ( logOptions , "standard" , "Updating content type snippet's references" ) ;
60
- await serially (
61
- [ ...snippetReplaceOpsAddIntoReferencingElements , ...snippetsReplaceReferencesOps ] . map (
62
- ( [ codename , operations ] ) => ( ) =>
63
- operations . length
64
- ? updateSnippet (
65
- client ,
66
- codename ,
67
- operations . map ( o => omit ( o , [ "oldValue" ] ) ) ,
68
- )
69
- : Promise . resolve ( ) ,
65
+ await oraPromise (
66
+ serially (
67
+ [ ...snippetReplaceOpsAddIntoReferencingElements , ...snippetsReplaceReferencesOps ] . map (
68
+ ( [ codename , operations ] ) => ( ) =>
69
+ operations . length
70
+ ? updateSnippet (
71
+ client ,
72
+ codename ,
73
+ operations . map ( o => omit ( o , [ "oldValue" ] ) ) ,
74
+ )
75
+ : Promise . resolve ( ) ,
76
+ ) ,
70
77
) ,
78
+ { text : "Updating content type snippet's references" } ,
71
79
) ;
72
80
} ;
73
81
@@ -95,17 +103,19 @@ export const addElementsIntoSnippetsWithoutReferences = async (
95
103
) ;
96
104
97
105
if ( addSnippetsOpsWithoutRefs . every ( ( [ , ops ] ) => ! ops . length ) ) {
98
- logInfo ( logOptions , "standard" , " No elements to add into content type snippets" ) ;
106
+ logInfo ( logOptions , "standard" , ` ${ noSyncTaskEmoji } No elements to add into content type snippets` ) ;
99
107
return ;
100
108
}
101
109
102
- logInfo ( logOptions , "standard" , "Adding elements into content type snippets" ) ;
103
- await serially ( addSnippetsOpsWithoutRefs . map (
104
- ( [ codename , operations ] ) => ( ) =>
105
- operations . length
106
- ? updateSnippet ( client , codename , operations )
107
- : Promise . resolve ( ) ,
108
- ) ) ;
110
+ await oraPromise (
111
+ serially ( addSnippetsOpsWithoutRefs . map (
112
+ ( [ codename , operations ] ) => ( ) =>
113
+ operations . length
114
+ ? updateSnippet ( client , codename , operations )
115
+ : Promise . resolve ( ) ,
116
+ ) ) ,
117
+ { text : "Adding elements into content type snippets" } ,
118
+ ) ;
109
119
} ;
110
120
111
121
export const updateSnippets = async (
@@ -117,22 +127,24 @@ export const updateSnippets = async (
117
127
. map ( ( [ c , ops ] ) => [ c , ops . filter ( o => ! isOp ( "addInto" ) ( o ) ) ] as const ) ;
118
128
119
129
if ( otherSnippetOps . flatMap ( ( [ , ops ] ) => ops ) . length === 0 ) {
120
- logInfo ( logOptions , "standard" , " No content type snippets to update" ) ;
130
+ logInfo ( logOptions , "standard" , ` ${ noSyncTaskEmoji } No content type snippets to update` ) ;
121
131
return ;
122
132
}
123
133
124
- logInfo ( logOptions , "standard" , "Updating content type snippets" ) ;
125
- await serially (
126
- otherSnippetOps . map (
127
- ( [ codename , operations ] ) => ( ) =>
128
- operations . length
129
- ? updateSnippet (
130
- client ,
131
- codename ,
132
- operations . map ( op => "oldValue" in op ? omit ( op , [ "oldValue" ] ) : op ) ,
133
- )
134
- : Promise . resolve ( ) ,
134
+ await oraPromise (
135
+ serially (
136
+ otherSnippetOps . map (
137
+ ( [ codename , operations ] ) => ( ) =>
138
+ operations . length
139
+ ? updateSnippet (
140
+ client ,
141
+ codename ,
142
+ operations . map ( op => "oldValue" in op ? omit ( op , [ "oldValue" ] ) : op ) ,
143
+ )
144
+ : Promise . resolve ( ) ,
145
+ ) ,
135
146
) ,
147
+ { text : "Updating content type snippets" } ,
136
148
) ;
137
149
} ;
138
150
@@ -142,10 +154,11 @@ export const deleteContentTypeSnippets = async (
142
154
logOptions : LogOptions ,
143
155
) => {
144
156
if ( snippetOps . deleted . size ) {
145
- logInfo ( logOptions , "standard" , "Deleting content type snippets" ) ;
146
- await serially ( Array . from ( snippetOps . deleted ) . map ( c => ( ) => deleteSnippet ( client , c ) ) ) ;
157
+ await oraPromise ( serially ( Array . from ( snippetOps . deleted ) . map ( c => ( ) => deleteSnippet ( client , c ) ) ) , {
158
+ text : "Deleting content type snippets" ,
159
+ } ) ;
147
160
} else {
148
- logInfo ( logOptions , "standard" , " No content type snippets to delete" ) ;
161
+ logInfo ( logOptions , "standard" , ` ${ noSyncTaskEmoji } No content type snippets to delete` ) ;
149
162
}
150
163
} ;
151
164
0 commit comments