Skip to content

Commit 038c6e1

Browse files
authored
Merge pull request #127 from scandipwa/2.1.2
2 parents 620961c + 176d999 commit 038c6e1

File tree

41 files changed

+216
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+216
-57
lines changed

build-packages/magento-scripts-php-extensions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"repository": "github:scandipwa/create-magento-app",
66
"main": "./index.js",
77
"license": "OSL-3.0",
8-
"version": "1.0.2",
8+
"version": "1.0.3",
99
"os": [
1010
"darwin",
1111
"linux"

build-packages/magento-scripts/lib/commands/status.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { statusContainers } = require('../tasks/docker/containers')
99
const getProjectConfiguration = require('../config/get-project-configuration')
1010
const checkConfigurationFile = require('../config/check-configuration-file')
1111
const checkPHPVersion = require('../tasks/requirements/php-version')
12+
const checkElasticSearchVersion = require('../tasks/requirements/elasticsearch-version')
1213
const { getComposerVersionTask } = require('../tasks/composer')
1314
const { systemApi } = require('../tasks/docker/system')
1415

@@ -35,6 +36,7 @@ module.exports = (yargs) => {
3536
[
3637
checkPHPVersion(),
3738
getComposerVersionTask(),
39+
checkElasticSearchVersion(),
3840
{
3941
title: 'Retrieving Docker System data',
4042
task: async (ctx) => {

build-packages/magento-scripts/lib/tasks/database/import-dump-to-database.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ Note that you will lose your existing database!`,
6868
choices: [
6969
{
7070
name: 'delete',
71-
message: 'YES I AM SURE I WANT TO DELETE magento DATABASE!'
71+
message: 'YES I WANT TO DELETE magento DATABASE!'
7272
},
7373
{
7474
name: 'skip',
75-
message: 'Skip this step'
75+
message:
76+
"NO I DON'T wANT TO DELETE magento DATABASE! (Skip this step)"
7677
}
7778
]
7879
})

build-packages/magento-scripts/lib/tasks/docker/convert-mysql-to-mariadb.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const { createCacheFolder } = require('../cache')
2727
const { getSystemConfigTask } = require('../../config/system-config')
2828
const sleep = require('../../util/sleep')
2929
const { setProjectConfigTask } = require('../project-config')
30+
const checkElasticSearchVersion = require('../requirements/elasticsearch-version')
3031

3132
/**
3233
* @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
@@ -242,7 +243,18 @@ Please wait, this will take some time and do not restart the MySQL container unt
242243
}
243244
)
244245
},
245-
checkPHPVersion(),
246+
{
247+
task: (ctx, subTask) =>
248+
subTask.newListr(
249+
[
250+
checkPHPVersion(),
251+
checkElasticSearchVersion()
252+
],
253+
{
254+
concurrent: true
255+
}
256+
)
257+
},
246258
getComposerVersionTask(),
247259
prepareFileSystem(),
248260
installMagentoProject(),
Lines changed: 114 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,131 @@
1+
const semver = require('semver')
2+
const path = require('path')
13
const { updateTableValues, isTableExists } = require('../../../util/database')
4+
const getJsonfileData = require('../../../util/get-jsonfile-data')
5+
const runComposerCommand = require('../../../util/run-composer')
6+
7+
const magentoModuleElasticSearch8 = 'magento/module-elasticsearch-8'
8+
9+
/**
10+
* @param {import('../../../../typings/context').ListrContext} ctx
11+
*/
12+
const isNeedToInstallElasticSearch8Module = async (ctx) => {
13+
/**
14+
* @type {{ packages: { name: string, version: string }[] } | null}
15+
*/
16+
const composerLockData = await getJsonfileData(
17+
path.join(ctx.config.baseConfig.magentoDir, 'composer.lock')
18+
)
19+
20+
if (!composerLockData) {
21+
return true
22+
}
23+
24+
return !composerLockData.packages.some(
25+
({ name }) => name === magentoModuleElasticSearch8
26+
)
27+
}
228

329
/**
430
* @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
531
*/
6-
module.exports = () => ({
32+
const configureElasticSearchInDatabase = () => ({
733
title: 'Configuring Elasticsearch',
8-
skip: async (ctx) =>
9-
!(await isTableExists('magento', 'core_config_data', ctx)),
34+
skip: async (ctx) => {
35+
const isCoreConfigDataExists = await isTableExists(
36+
'magento',
37+
'core_config_data',
38+
ctx
39+
)
40+
if (isCoreConfigDataExists) {
41+
const elasticsearchConfig = await ctx.databaseConnection.query(
42+
`SELECT path,value FROM core_config_data WHERE path='catalog/search/engine';`
43+
)
44+
45+
if (elasticsearchConfig.length > 0) {
46+
const { major: parsedESMajorVersion } = semver.parse(
47+
ctx.elasticSearchVersion
48+
) || { major: 7 }
49+
const elasticsearchSearchEngine = `elasticsearch${parsedESMajorVersion}`
50+
51+
return (
52+
elasticsearchConfig[0].value === elasticsearchSearchEngine
53+
)
54+
}
55+
}
56+
57+
return false
58+
},
1059
task: async (ctx, task) => {
1160
const { ports, databaseConnection, isDockerDesktop } = ctx
1261
const hostMachine = !isDockerDesktop
1362
? '127.0.0.1'
1463
: 'host.docker.internal'
64+
65+
const { major: parsedESMajorVersion } = semver.parse(
66+
ctx.elasticSearchVersion
67+
) || { major: 7 }
68+
69+
const elasticsearchConfig = {
70+
'catalog/search/engine': `elasticsearch${parsedESMajorVersion}`,
71+
[`catalog/search/elasticsearch${parsedESMajorVersion}_server_hostname`]:
72+
hostMachine,
73+
[`catalog/search/elasticsearch${parsedESMajorVersion}_server_port`]: `${ports.elasticsearch}`
74+
}
75+
1576
await updateTableValues(
1677
'core_config_data',
17-
[
18-
{ path: 'catalog/search/engine', value: 'elasticsearch7' },
19-
{
20-
path: 'catalog/search/elasticsearch7_server_hostname',
21-
value: hostMachine
22-
},
23-
{
24-
path: 'catalog/search/elasticsearch7_server_port',
25-
value: `${ports.elasticsearch}`
26-
}
27-
],
78+
Object.entries(elasticsearchConfig).map(([path, value]) => ({
79+
path,
80+
value
81+
})),
2882
{ databaseConnection, task }
2983
)
3084
}
3185
})
86+
87+
/**
88+
* @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
89+
*/
90+
const installElasticSearch8Module = () => ({
91+
title: 'Installing Magento ElasticSearch8 Module',
92+
task: async (ctx, task) => {
93+
await runComposerCommand(
94+
ctx,
95+
`require ${magentoModuleElasticSearch8} --with-all-dependencies`,
96+
{
97+
callback: !ctx.verbose
98+
? undefined
99+
: (t) => {
100+
task.output = t
101+
}
102+
}
103+
)
104+
},
105+
options: {
106+
bottomBar: 10
107+
}
108+
})
109+
110+
/**
111+
* @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
112+
*/
113+
module.exports = () => ({
114+
task: async (ctx, task) => {
115+
const { major: parsedESMajorVersion } = semver.parse(
116+
ctx.elasticSearchVersion
117+
) || { major: 7 }
118+
119+
if (
120+
parsedESMajorVersion === 8 &&
121+
(await isNeedToInstallElasticSearch8Module(ctx))
122+
) {
123+
return task.newListr([
124+
installElasticSearch8Module(),
125+
configureElasticSearchInDatabase()
126+
])
127+
}
128+
129+
return task.newListr(configureElasticSearchInDatabase())
130+
}
131+
})
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const UnknownError = require('../../errors/unknown-error')
2+
const { runContainerImage } = require('../../util/run-container-image')
3+
4+
/**
5+
* @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
6+
*/
7+
const checkElasticSearchVersion = () => ({
8+
title: 'Checking container ElasticSearch version',
9+
task: async (ctx, task) => {
10+
const elasticSearchVersionResponse = await runContainerImage(
11+
ctx.config.overridenConfiguration.configuration.elasticsearch.image,
12+
'elasticsearch --version'
13+
)
14+
15+
const elasticSearchVersionResponseResult =
16+
elasticSearchVersionResponse.match(/Version:\s(\d+\.\d+\.\d+)/i)
17+
18+
if (
19+
elasticSearchVersionResponseResult &&
20+
elasticSearchVersionResponseResult.length > 0
21+
) {
22+
const elasticSearchVersion = elasticSearchVersionResponseResult[1]
23+
24+
ctx.elasticSearchVersion = elasticSearchVersion
25+
task.title = `Using ElasticSearch version ${elasticSearchVersion} in container`
26+
} else {
27+
throw new UnknownError(
28+
`Cannot retrieve ElasticSearch Version!\n\n${elasticSearchVersionResponse}`
29+
)
30+
}
31+
}
32+
})
33+
34+
module.exports = checkElasticSearchVersion

build-packages/magento-scripts/lib/tasks/start.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const {
3434
} = require('../util/instance-metadata')
3535
const waitingForVarnish = require('./magento/setup-magento/waiting-for-varnish')
3636
const checkPHPVersion = require('./requirements/php-version')
37+
const checkElasticSearchVersion = require('./requirements/elasticsearch-version')
3738
const volumes = require('./docker/volume/tasks')
3839
const convertMySQLDatabaseToMariaDB = require('./docker/convert-mysql-to-mariadb')
3940
const { cmaGlobalConfig } = require('../config/cma-config')
@@ -125,16 +126,24 @@ const configureProject = () => ({
125126
task.newListr([
126127
convertMySQLDatabaseToMariaDB(),
127128
{
128-
task: (ctx, task) =>
129-
task.newListr(
129+
task: (ctx, subTask) =>
130+
subTask.newListr(
130131
[pullImages(), dockerNetwork.tasks.createNetwork()],
131132
{ concurrent: true }
132133
)
133134
},
134-
checkPHPVersion(),
135135
{
136-
task: (ctx, task) =>
137-
task.newListr(
136+
task: (ctx, subTask) =>
137+
subTask.newListr(
138+
[checkPHPVersion(), checkElasticSearchVersion()],
139+
{
140+
concurrent: true
141+
}
142+
)
143+
},
144+
{
145+
task: (ctx, subTask) =>
146+
subTask.newListr(
138147
[buildProjectImage(), buildDebugProjectImage()],
139148
{
140149
concurrent: true

build-packages/magento-scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Scripts and configuration used by CMA.",
44
"homepage": "https://docs.create-magento-app.com/",
55
"repository": "github:scandipwa/create-magento-app",
6-
"version": "2.1.1",
6+
"version": "2.1.2",
77
"main": "./index.js",
88
"types": "./typings/index.d.ts",
99
"license": "OSL-3.0",

build-packages/magento-scripts/typings/context.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface ListrContext {
2323
magentoVersion: string
2424
composerVersion: string
2525
phpVersion: string
26+
elasticSearchVersion: string
2627
port?: number
2728
ports: {
2829
app: number

sample-packages/magento-2.2.10/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"type": "magento"
1818
},
1919
"dependencies": {
20-
"@scandipwa/magento-scripts": "2.1.1"
20+
"@scandipwa/magento-scripts": "2.1.2"
2121
}
2222
}

0 commit comments

Comments
 (0)