@@ -9,7 +9,7 @@ function multiStoreConfig(apiConfig, storeCode) {
99 {
1010 if ( config . magento2 [ 'api_' + storeCode ] ) {
1111 confCopy = Object . assign ( { } , config . magento2 [ 'api_' + storeCode ] ) // we're to use the specific api configuration - maybe even separate magento instance
12- }
12+ }
1313 confCopy . url = confCopy . url + '/' + storeCode
1414 } else {
1515 if ( storeCode ) {
@@ -24,6 +24,12 @@ function getMagentoDefaultConfig(storeCode) {
2424 return {
2525 TIME_TO_EXIT : 2000 ,
2626 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 ,
2733 PRODUCTS_EXCLUDE_DISABLED : config . catalog . excludeDisabledProducts ,
2834 MAGENTO_CONSUMER_KEY : apiConfig . consumerKey ,
2935 MAGENTO_CONSUMER_SECRET : apiConfig . consumerSecret ,
@@ -34,7 +40,7 @@ function getMagentoDefaultConfig(storeCode) {
3440 REDIS_PORT : config . redis . port ,
3541 INDEX_NAME : config . elasticsearch . indices [ 0 ] ,
3642 DATABASE_URL : `${ config . elasticsearch . protocol } ://${ config . elasticsearch . host } :${ config . elasticsearch . port } `
37- }
43+ }
3844}
3945
4046function exec ( cmd , args , opts ) {
@@ -43,19 +49,19 @@ function exec(cmd, args, opts) {
4349 child . stdout . on ( 'data' , ( data ) => {
4450 console . log ( data . toString ( 'utf8' ) ) ;
4551 } ) ;
46-
52+
4753 child . stderr . on ( 'data' , ( data ) => {
4854 console . log ( data . toString ( 'utf8' ) ) ;
4955 } ) ;
50-
56+
5157 child . on ( 'close' , ( code ) => {
5258 resolve ( code )
53- } ) ;
59+ } ) ;
5460
5561 child . on ( 'error' , ( error ) => {
5662 console . error ( error )
5763 reject ( error )
58- } ) ;
64+ } ) ;
5965 } )
6066}
6167
@@ -107,6 +113,12 @@ program
107113program
108114 . command ( 'import' )
109115 . option ( '--store-code <storeCode>' , 'storeCode in multistore setup' , null )
116+ . option ( '--skip-reviews <skipReviews>' , 'skip import of reviews' , false )
117+ . option ( '--skip-categories <skipCategories>' , 'skip import of categories' , false )
118+ . option ( '--skip-productcategories <skipProductcategories>' , 'skip import of productcategories' , false )
119+ . option ( '--skip-attributes <skipAttributes>' , 'skip import of attributes' , false )
120+ . option ( '--skip-taxrule <skipTaxrule>' , 'skip import of taxrule' , false )
121+ . option ( '--skip-products <skipProducts>' , 'skip import of products' , false )
110122 . action ( ( cmd ) => {
111123 let magentoConfig = getMagentoDefaultConfig ( cmd . storeCode )
112124
@@ -119,82 +131,158 @@ program
119131 magentoConfig . INDEX_NAME = storeView . elasticsearch . index ;
120132 }
121133 }
122-
134+
135+ if ( cmd . skipReviews ) {
136+ magentoConfig . SKIP_REVIEWS = true ;
137+ }
138+ if ( cmd . skipCategories ) {
139+ magentoConfig . SKIP_CATEGORIES = true ;
140+ }
141+ if ( cmd . skipProductcategories ) {
142+ magentoConfig . SKIP_PRODUCTCATEGORIES = true ;
143+ }
144+ if ( cmd . skipAttributes ) {
145+ magentoConfig . SKIP_ATTRIBUTES = true ;
146+ }
147+ if ( cmd . skipTaxrule ) {
148+ magentoConfig . SKIP_TAXRULE = true ;
149+ }
150+ if ( cmd . skipProducts ) {
151+ magentoConfig . SKIP_PRODUCTS = true ;
152+ }
153+
123154 const env = Object . assign ( { } , magentoConfig , process . env ) // use process env as well
124155 console . log ( '=== The mage2vuestorefront full reindex is about to start. Using the following Magento2 config ===' , magentoConfig )
125156
126- console . log ( ' == CREATING NEW DATABASE ==' )
127- exec ( 'node' , [
128- 'scripts/db.js' ,
129- 'new' ,
130- `--indexName=${ env . INDEX_NAME } `
131- ] , { env : env , shell : true } ) . then ( ( res ) => {
157+ let createDbPromise = function ( ) {
158+
159+ console . log ( ' == CREATING NEW DATABASE ==' )
160+ return exec ( 'node' , [
161+ 'scripts/db.js' ,
162+ 'new' ,
163+ `--indexName=${ env . INDEX_NAME } `
164+ ] , { env : env , shell : true } )
165+
166+ }
132167
133- console . log ( ' == REVIEWS IMPORTER ==' )
134- exec ( 'node' , [
135- '--harmony' ,
136- 'node_modules/mage2vuestorefront/src/cli.js' ,
137- 'reviews'
138- ] , { env : env , shell : true } ) . then ( ( res ) => {
168+ let importReviewsPromise = function ( ) {
169+ if ( magentoConfig . SKIP_REVIEWS ) {
170+ return Promise . resolve ( ) ;
171+ }
172+ else {
173+ console . log ( ' == REVIEWS IMPORTER ==' ) ;
174+ return exec ( 'node' , [
175+ '--harmony' ,
176+ 'node_modules/mage2vuestorefront/src/cli.js' ,
177+ 'reviews'
178+ ] , { env : env , shell : true } )
179+ }
180+ }
139181
140- console . log ( ' == CATEGORIES IMPORTER ==' )
141- exec ( 'node' , [
182+ let importCategoriesPromise = function ( ) {
183+ if ( magentoConfig . SKIP_CATEGORIES ) {
184+ return Promise . resolve ( ) ;
185+ }
186+ else {
187+ console . log ( ' == CATEGORIES IMPORTER ==' ) ;
188+ return exec ( 'node' , [
142189 '--harmony' ,
143190 'node_modules/mage2vuestorefront/src/cli.js' ,
144191 'categories' ,
145192 '--removeNonExistent=true' ,
146193 '--extendedCategories=true'
147- ] , { env : env , shell : true } ) . then ( ( res ) => {
148-
149- console . log ( ' == PRODUCT-CATEGORIES IMPORTER ==' )
150- exec ( 'node' , [
151- '--harmony' ,
152- 'node_modules/mage2vuestorefront/src/cli.js' ,
153- 'productcategories'
154- ] , { env : env , shell : true } ) . then ( ( res ) => {
155-
156- console . log ( ' == ATTRIBUTES IMPORTER ==' )
157- exec ( 'node' , [
158- '--harmony' ,
159- 'node_modules/mage2vuestorefront/src/cli.js' ,
160- 'attributes' ,
161- '--removeNonExistent=true'
162- ] , { env : env , shell : true } ) . then ( ( res ) => {
163-
164- console . log ( ' == TAXRULE IMPORTER ==' )
165- exec ( 'node' , [
166- '--harmony' ,
167- 'node_modules/mage2vuestorefront/src/cli.js' ,
168- 'taxrule' ,
169- '--removeNonExistent=true'
170- ] , { env : env , shell : true } ) . then ( ( res ) => {
171-
172- console . log ( ' == PRODUCTS IMPORTER ==' )
173- exec ( 'node' , [
174- '--harmony' ,
175- 'node_modules/mage2vuestorefront/src/cli.js' ,
176- 'products' ,
177- '--removeNonExistent=true' ,
178- '--partitions=1'
179- ] , { env : env , shell : true } ) . then ( ( res ) => {
180-
181- console . log ( ' == REINDEXING DATABASE ==' )
182- exec ( 'node' , [
183- 'scripts/db.js' ,
184- 'rebuild' ,
185- `--indexName=${ env . INDEX_NAME } `
186- ] , { env : env , shell : true } ) . then ( ( res ) => {
187- console . log ( 'Done! Bye Bye!' )
188- process . exit ( 0 )
189- } ) ;
194+ ] , { env : env , shell : true } )
195+ }
196+ }
197+
198+ let importProductcategoriesPromise = function ( ) {
199+ if ( magentoConfig . SKIP_PRODUCTCATEGORIES ) {
200+ return Promise . resolve ( ) ;
201+ }
202+ else {
203+ console . log ( ' == PRODUCT-CATEGORIES IMPORTER ==' ) ;
204+ return exec ( 'node' , [
205+ '--harmony' ,
206+ 'node_modules/mage2vuestorefront/src/cli.js' ,
207+ 'productcategories'
208+ ] , { env : env , shell : true } )
209+ }
210+ }
211+
212+ let importAttributesPromise = function ( ) {
213+ if ( magentoConfig . SKIP_ATTRIBUTES ) {
214+ return Promise . resolve ( ) ;
215+ }
216+ else {
217+ console . log ( ' == ATTRIBUTES IMPORTER ==' ) ;
218+ return exec ( 'node' , [
219+ '--harmony' ,
220+ 'node_modules/mage2vuestorefront/src/cli.js' ,
221+ 'attributes' ,
222+ '--removeNonExistent=true'
223+ ] , { env : env , shell : true } )
224+ }
225+ }
226+
227+ let importTaxrulePromise = function ( ) {
228+ if ( magentoConfig . SKIP_TAXRULE ) {
229+ return Promise . resolve ( ) ;
230+ }
231+ else {
232+ console . log ( ' == TAXRULE IMPORTER ==' ) ;
233+ return exec ( 'node' , [
234+ '--harmony' ,
235+ 'node_modules/mage2vuestorefront/src/cli.js' ,
236+ 'taxrule' ,
237+ '--removeNonExistent=true'
238+ ] , { env : env , shell : true } )
239+ }
240+ }
241+
242+ let importProductsPromise = function ( ) {
243+ if ( magentoConfig . SKIP_PRODUCTS ) {
244+ return Promise . resolve ( ) ;
245+ }
246+ else {
247+ console . log ( ' == PRODUCTS IMPORTER ==' ) ;
248+ return exec ( 'node' , [
249+ '--harmony' ,
250+ 'node_modules/mage2vuestorefront/src/cli.js' ,
251+ 'products' ,
252+ '--removeNonExistent=true' ,
253+ '--partitions=1'
254+ ] , { env : env , shell : true } )
255+ }
256+ }
257+
258+ let reindexPromise = function ( ) {
259+ console . log ( ' == REINDEXING DATABASE ==' )
260+ return exec ( 'node' , [
261+ 'scripts/db.js' ,
262+ 'rebuild' ,
263+ `--indexName=${ env . INDEX_NAME } `
264+ ] , { env : env , shell : true } )
265+ }
266+
267+ createDbPromise ( ) . then ( ( ) => {
268+ importReviewsPromise ( ) . then ( ( ) => {
269+ importCategoriesPromise ( ) . then ( ( ) => {
270+ importProductcategoriesPromise ( ) . then ( ( ) => {
271+ importAttributesPromise ( ) . then ( ( ) => {
272+ importTaxrulePromise ( ) . then ( ( ) => {
273+ importProductsPromise ( ) . then ( ( ) => {
274+ reindexPromise ( ) . then ( ( ) => {
275+ console . log ( 'Done! Bye Bye!' )
276+ process . exit ( 0 )
277+ } )
190278 } )
191- } )
279+ } )
192280 } )
193281 } )
194282 } )
195283 } )
196284 } )
197- } )
285+ } ) ;
198286
199287
200288program
0 commit comments