@@ -9,7 +9,7 @@ function multiStoreConfig(apiConfig, storeCode) {
9
9
{
10
10
if ( config . magento2 [ 'api_' + storeCode ] ) {
11
11
confCopy = Object . assign ( { } , config . magento2 [ 'api_' + storeCode ] ) // we're to use the specific api configuration - maybe even separate magento instance
12
- }
12
+ }
13
13
confCopy . url = confCopy . url + '/' + storeCode
14
14
} else {
15
15
if ( storeCode ) {
@@ -24,6 +24,12 @@ function getMagentoDefaultConfig(storeCode) {
24
24
return {
25
25
TIME_TO_EXIT : 2000 ,
26
26
PRODUCTS_SPECIAL_PRICES : true ,
27
+ SKIP_REVIEWS : false ,
28
+ SKIP_CATEGORIES : false ,
29
+ SKIP_PRODUCTCATEGORIES : false ,
30
+ SKIP_ATTRIBUTES : false ,
31
+ SKIP_TAXRULE : false ,
32
+ SKIP_PRODUCTS : false ,
27
33
MAGENTO_CONSUMER_KEY : apiConfig . consumerKey ,
28
34
MAGENTO_CONSUMER_SECRET : apiConfig . consumerSecret ,
29
35
MAGENTO_ACCESS_TOKEN : apiConfig . accessToken ,
@@ -33,7 +39,7 @@ function getMagentoDefaultConfig(storeCode) {
33
39
REDIS_PORT : config . redis . port ,
34
40
INDEX_NAME : config . elasticsearch . indices [ 0 ] ,
35
41
DATABASE_URL : `${ config . elasticsearch . protocol } ://${ config . elasticsearch . host } :${ config . elasticsearch . port } `
36
- }
42
+ }
37
43
}
38
44
39
45
function exec ( cmd , args , opts ) {
@@ -42,19 +48,19 @@ function exec(cmd, args, opts) {
42
48
child . stdout . on ( 'data' , ( data ) => {
43
49
console . log ( data . toString ( 'utf8' ) ) ;
44
50
} ) ;
45
-
51
+
46
52
child . stderr . on ( 'data' , ( data ) => {
47
53
console . log ( data . toString ( 'utf8' ) ) ;
48
54
} ) ;
49
-
55
+
50
56
child . on ( 'close' , ( code ) => {
51
57
resolve ( code )
52
- } ) ;
58
+ } ) ;
53
59
54
60
child . on ( 'error' , ( error ) => {
55
61
console . error ( error )
56
62
reject ( error )
57
- } ) ;
63
+ } ) ;
58
64
} )
59
65
}
60
66
@@ -106,6 +112,12 @@ program
106
112
program
107
113
. command ( 'import' )
108
114
. option ( '--store-code <storeCode>' , 'storeCode in multistore setup' , null )
115
+ . option ( '--skip-reviews <skipReviews>' , 'skip import of reviews' , false )
116
+ . option ( '--skip-categories <skipCategories>' , 'skip import of categories' , false )
117
+ . option ( '--skip-productcategories <skipProductcategories>' , 'skip import of productcategories' , false )
118
+ . option ( '--skip-attributes <skipAttributes>' , 'skip import of attributes' , false )
119
+ . option ( '--skip-taxrule <skipTaxrule>' , 'skip import of taxrule' , false )
120
+ . option ( '--skip-products <skipProducts>' , 'skip import of products' , false )
109
121
. action ( ( cmd ) => {
110
122
let magentoConfig = getMagentoDefaultConfig ( cmd . storeCode )
111
123
@@ -118,82 +130,158 @@ program
118
130
magentoConfig . INDEX_NAME = storeView . elasticsearch . index ;
119
131
}
120
132
}
121
-
133
+
134
+ if ( cmd . skipReviews ) {
135
+ magentoConfig . SKIP_REVIEWS = true ;
136
+ }
137
+ if ( cmd . skipCategories ) {
138
+ magentoConfig . SKIP_CATEGORIES = true ;
139
+ }
140
+ if ( cmd . skipProductcategories ) {
141
+ magentoConfig . SKIP_PRODUCTCATEGORIES = true ;
142
+ }
143
+ if ( cmd . skipAttributes ) {
144
+ magentoConfig . SKIP_ATTRIBUTES = true ;
145
+ }
146
+ if ( cmd . skipTaxrule ) {
147
+ magentoConfig . SKIP_TAXRULE = true ;
148
+ }
149
+ if ( cmd . skipProducts ) {
150
+ magentoConfig . SKIP_PRODUCTS = true ;
151
+ }
152
+
122
153
const env = Object . assign ( { } , magentoConfig , process . env ) // use process env as well
123
154
console . log ( '=== The mage2vuestorefront full reindex is about to start. Using the following Magento2 config ===' , magentoConfig )
124
155
125
- console . log ( ' == CREATING NEW DATABASE ==' )
126
- exec ( 'node' , [
127
- 'scripts/db.js' ,
128
- 'new' ,
129
- `--indexName=${ env . INDEX_NAME } `
130
- ] , { env : env , shell : true } ) . then ( ( res ) => {
156
+ let createDbPromise = function ( ) {
157
+
158
+ console . log ( ' == CREATING NEW DATABASE ==' )
159
+ return exec ( 'node' , [
160
+ 'scripts/db.js' ,
161
+ 'new' ,
162
+ `--indexName=${ env . INDEX_NAME } `
163
+ ] , { env : env , shell : true } )
164
+
165
+ }
131
166
132
- console . log ( ' == REVIEWS IMPORTER ==' )
133
- exec ( 'node' , [
134
- '--harmony' ,
135
- 'node_modules/mage2vuestorefront/src/cli.js' ,
136
- 'reviews'
137
- ] , { env : env , shell : true } ) . then ( ( res ) => {
167
+ let importReviewsPromise = function ( ) {
168
+ if ( magentoConfig . SKIP_REVIEWS ) {
169
+ return Promise . resolve ( ) ;
170
+ }
171
+ else {
172
+ console . log ( ' == REVIEWS IMPORTER ==' ) ;
173
+ return exec ( 'node' , [
174
+ '--harmony' ,
175
+ 'node_modules/mage2vuestorefront/src/cli.js' ,
176
+ 'reviews'
177
+ ] , { env : env , shell : true } )
178
+ }
179
+ }
138
180
139
- console . log ( ' == CATEGORIES IMPORTER ==' )
140
- exec ( 'node' , [
181
+ let importCategoriesPromise = function ( ) {
182
+ if ( magentoConfig . SKIP_CATEGORIES ) {
183
+ return Promise . resolve ( ) ;
184
+ }
185
+ else {
186
+ console . log ( ' == CATEGORIES IMPORTER ==' ) ;
187
+ return exec ( 'node' , [
141
188
'--harmony' ,
142
189
'node_modules/mage2vuestorefront/src/cli.js' ,
143
190
'categories' ,
144
191
'--removeNonExistent=true' ,
145
192
'--extendedCategories=true'
146
- ] , { env : env , shell : true } ) . then ( ( res ) => {
147
-
148
- console . log ( ' == PRODUCT-CATEGORIES IMPORTER ==' )
149
- exec ( 'node' , [
150
- '--harmony' ,
151
- 'node_modules/mage2vuestorefront/src/cli.js' ,
152
- 'productcategories'
153
- ] , { env : env , shell : true } ) . then ( ( res ) => {
154
-
155
- console . log ( ' == ATTRIBUTES IMPORTER ==' )
156
- exec ( 'node' , [
157
- '--harmony' ,
158
- 'node_modules/mage2vuestorefront/src/cli.js' ,
159
- 'attributes' ,
160
- '--removeNonExistent=true'
161
- ] , { env : env , shell : true } ) . then ( ( res ) => {
162
-
163
- console . log ( ' == TAXRULE IMPORTER ==' )
164
- exec ( 'node' , [
165
- '--harmony' ,
166
- 'node_modules/mage2vuestorefront/src/cli.js' ,
167
- 'taxrule' ,
168
- '--removeNonExistent=true'
169
- ] , { env : env , shell : true } ) . then ( ( res ) => {
170
-
171
- console . log ( ' == PRODUCTS IMPORTER ==' )
172
- exec ( 'node' , [
173
- '--harmony' ,
174
- 'node_modules/mage2vuestorefront/src/cli.js' ,
175
- 'products' ,
176
- '--removeNonExistent=true' ,
177
- '--partitions=1'
178
- ] , { env : env , shell : true } ) . then ( ( res ) => {
179
-
180
- console . log ( ' == REINDEXING DATABASE ==' )
181
- exec ( 'node' , [
182
- 'scripts/db.js' ,
183
- 'rebuild' ,
184
- `--indexName=${ env . INDEX_NAME } `
185
- ] , { env : env , shell : true } ) . then ( ( res ) => {
186
- console . log ( 'Done! Bye Bye!' )
187
- process . exit ( 0 )
188
- } ) ;
193
+ ] , { env : env , shell : true } )
194
+ }
195
+ }
196
+
197
+ let importProductcategoriesPromise = function ( ) {
198
+ if ( magentoConfig . SKIP_PRODUCTCATEGORIES ) {
199
+ return Promise . resolve ( ) ;
200
+ }
201
+ else {
202
+ console . log ( ' == PRODUCT-CATEGORIES IMPORTER ==' ) ;
203
+ return exec ( 'node' , [
204
+ '--harmony' ,
205
+ 'node_modules/mage2vuestorefront/src/cli.js' ,
206
+ 'productcategories'
207
+ ] , { env : env , shell : true } )
208
+ }
209
+ }
210
+
211
+ let importAttributesPromise = function ( ) {
212
+ if ( magentoConfig . SKIP_ATTRIBUTES ) {
213
+ return Promise . resolve ( ) ;
214
+ }
215
+ else {
216
+ console . log ( ' == ATTRIBUTES IMPORTER ==' ) ;
217
+ return exec ( 'node' , [
218
+ '--harmony' ,
219
+ 'node_modules/mage2vuestorefront/src/cli.js' ,
220
+ 'attributes' ,
221
+ '--removeNonExistent=true'
222
+ ] , { env : env , shell : true } )
223
+ }
224
+ }
225
+
226
+ let importTaxrulePromise = function ( ) {
227
+ if ( magentoConfig . SKIP_TAXRULE ) {
228
+ return Promise . resolve ( ) ;
229
+ }
230
+ else {
231
+ console . log ( ' == TAXRULE IMPORTER ==' ) ;
232
+ return exec ( 'node' , [
233
+ '--harmony' ,
234
+ 'node_modules/mage2vuestorefront/src/cli.js' ,
235
+ 'taxrule' ,
236
+ '--removeNonExistent=true'
237
+ ] , { env : env , shell : true } )
238
+ }
239
+ }
240
+
241
+ let importProductsPromise = function ( ) {
242
+ if ( magentoConfig . SKIP_PRODUCTS ) {
243
+ return Promise . resolve ( ) ;
244
+ }
245
+ else {
246
+ console . log ( ' == PRODUCTS IMPORTER ==' ) ;
247
+ return exec ( 'node' , [
248
+ '--harmony' ,
249
+ 'node_modules/mage2vuestorefront/src/cli.js' ,
250
+ 'products' ,
251
+ '--removeNonExistent=true' ,
252
+ '--partitions=1'
253
+ ] , { env : env , shell : true } )
254
+ }
255
+ }
256
+
257
+ let reindexPromise = function ( ) {
258
+ console . log ( ' == REINDEXING DATABASE ==' )
259
+ return exec ( 'node' , [
260
+ 'scripts/db.js' ,
261
+ 'rebuild' ,
262
+ `--indexName=${ env . INDEX_NAME } `
263
+ ] , { env : env , shell : true } )
264
+ }
265
+
266
+ createDbPromise ( ) . then ( ( ) => {
267
+ importReviewsPromise ( ) . then ( ( ) => {
268
+ importCategoriesPromise ( ) . then ( ( ) => {
269
+ importProductcategoriesPromise ( ) . then ( ( ) => {
270
+ importAttributesPromise ( ) . then ( ( ) => {
271
+ importTaxrulePromise ( ) . then ( ( ) => {
272
+ importProductsPromise ( ) . then ( ( ) => {
273
+ reindexPromise ( ) . then ( ( ) => {
274
+ console . log ( 'Done! Bye Bye!' )
275
+ process . exit ( 0 )
276
+ } )
189
277
} )
190
- } )
278
+ } )
191
279
} )
192
280
} )
193
281
} )
194
282
} )
195
283
} )
196
- } )
284
+ } ) ;
197
285
198
286
199
287
program
0 commit comments