Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit 182551f

Browse files
committed
Merge branch 'develop' of https://github.com/DivanteLtd/vue-storefront-api into develop
2 parents d11a21a + 83dca80 commit 182551f

File tree

2 files changed

+160
-68
lines changed

2 files changed

+160
-68
lines changed

scripts/mage2vs.js

Lines changed: 154 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -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
MAGENTO_CONSUMER_KEY: apiConfig.consumerKey,
2834
MAGENTO_CONSUMER_SECRET: apiConfig.consumerSecret,
2935
MAGENTO_ACCESS_TOKEN: apiConfig.accessToken,
@@ -33,7 +39,7 @@ function getMagentoDefaultConfig(storeCode) {
3339
REDIS_PORT: config.redis.port,
3440
INDEX_NAME: config.elasticsearch.indices[0],
3541
DATABASE_URL: `${config.elasticsearch.protocol}://${config.elasticsearch.host}:${config.elasticsearch.port}`
36-
}
42+
}
3743
}
3844

3945
function exec(cmd, args, opts) {
@@ -42,19 +48,19 @@ function exec(cmd, args, opts) {
4248
child.stdout.on('data', (data) => {
4349
console.log(data.toString('utf8'));
4450
});
45-
51+
4652
child.stderr.on('data', (data) => {
4753
console.log(data.toString('utf8'));
4854
});
49-
55+
5056
child.on('close', (code) => {
5157
resolve(code)
52-
});
58+
});
5359

5460
child.on('error', (error) => {
5561
console.error(error)
5662
reject(error)
57-
});
63+
});
5864
})
5965
}
6066

@@ -106,6 +112,12 @@ program
106112
program
107113
.command('import')
108114
.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)
109121
.action((cmd) => {
110122
let magentoConfig = getMagentoDefaultConfig(cmd.storeCode)
111123

@@ -118,82 +130,158 @@ program
118130
magentoConfig.INDEX_NAME = storeView.elasticsearch.index;
119131
}
120132
}
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+
122153
const env = Object.assign({}, magentoConfig, process.env) // use process env as well
123154
console.log('=== The mage2vuestorefront full reindex is about to start. Using the following Magento2 config ===', magentoConfig)
124155

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+
}
131166

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+
}
138180

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', [
141188
'--harmony',
142189
'node_modules/mage2vuestorefront/src/cli.js',
143190
'categories',
144191
'--removeNonExistent=true',
145192
'--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+
})
189277
})
190-
})
278+
})
191279
})
192280
})
193281
})
194282
})
195283
})
196-
})
284+
});
197285

198286

199287
program

src/lib/image.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ export async function resize (buffer, width, height) {
2626
const transformer = sharp(buffer);
2727

2828
if (width || height) {
29-
transformer.resize(width, height).max().withoutEnlargement();
29+
const options = {
30+
withoutEnlargement: true,
31+
fit: sharp.fit.inside
32+
}
33+
transformer.resize(width, height, options)
3034
}
3135

3236
return transformer.toBuffer();
@@ -61,4 +65,4 @@ export async function crop (buffer, width, height, x, y) {
6165
} catch (err) {
6266
console.log(err);
6367
}
64-
}
68+
}

0 commit comments

Comments
 (0)