@scandipwa/magento-scripts 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@ const { statusContainers } = require('../tasks/docker/containers')
9
9
  const getProjectConfiguration = require('../config/get-project-configuration')
10
10
  const checkConfigurationFile = require('../config/check-configuration-file')
11
11
  const checkPHPVersion = require('../tasks/requirements/php-version')
12
+ const checkElasticSearchVersion = require('../tasks/requirements/elasticsearch-version')
12
13
  const { getComposerVersionTask } = require('../tasks/composer')
13
14
  const { systemApi } = require('../tasks/docker/system')
14
15
 
@@ -35,6 +36,7 @@ module.exports = (yargs) => {
35
36
  [
36
37
  checkPHPVersion(),
37
38
  getComposerVersionTask(),
39
+ checkElasticSearchVersion(),
38
40
  {
39
41
  title: 'Retrieving Docker System data',
40
42
  task: async (ctx) => {
@@ -68,11 +68,12 @@ Note that you will lose your existing database!`,
68
68
  choices: [
69
69
  {
70
70
  name: 'delete',
71
- message: 'YES I AM SURE I WANT TO DELETE magento DATABASE!'
71
+ message: 'YES I WANT TO DELETE magento DATABASE!'
72
72
  },
73
73
  {
74
74
  name: 'skip',
75
- message: 'Skip this step'
75
+ message:
76
+ "NO I DON'T wANT TO DELETE magento DATABASE! (Skip this step)"
76
77
  }
77
78
  ]
78
79
  })
@@ -27,6 +27,7 @@ const { createCacheFolder } = require('../cache')
27
27
  const { getSystemConfigTask } = require('../../config/system-config')
28
28
  const sleep = require('../../util/sleep')
29
29
  const { setProjectConfigTask } = require('../project-config')
30
+ const checkElasticSearchVersion = require('../requirements/elasticsearch-version')
30
31
 
31
32
  /**
32
33
  * @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
242
243
  }
243
244
  )
244
245
  },
245
- checkPHPVersion(),
246
+ {
247
+ task: (ctx, subTask) =>
248
+ subTask.newListr(
249
+ [
250
+ checkPHPVersion(),
251
+ checkElasticSearchVersion()
252
+ ],
253
+ {
254
+ concurrent: true
255
+ }
256
+ )
257
+ },
246
258
  getComposerVersionTask(),
247
259
  prepareFileSystem(),
248
260
  installMagentoProject(),
@@ -1,31 +1,131 @@
1
+ const semver = require('semver')
2
+ const path = require('path')
1
3
  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
+ }
2
28
 
3
29
  /**
4
30
  * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
5
31
  */
6
- module.exports = () => ({
32
+ const configureElasticSearchInDatabase = () => ({
7
33
  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
+ },
10
59
  task: async (ctx, task) => {
11
60
  const { ports, databaseConnection, isDockerDesktop } = ctx
12
61
  const hostMachine = !isDockerDesktop
13
62
  ? '127.0.0.1'
14
63
  : '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
+
15
76
  await updateTableValues(
16
77
  '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
+ })),
28
82
  { databaseConnection, task }
29
83
  )
30
84
  }
31
85
  })
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
+ })
@@ -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
@@ -34,6 +34,7 @@ const {
34
34
  } = require('../util/instance-metadata')
35
35
  const waitingForVarnish = require('./magento/setup-magento/waiting-for-varnish')
36
36
  const checkPHPVersion = require('./requirements/php-version')
37
+ const checkElasticSearchVersion = require('./requirements/elasticsearch-version')
37
38
  const volumes = require('./docker/volume/tasks')
38
39
  const convertMySQLDatabaseToMariaDB = require('./docker/convert-mysql-to-mariadb')
39
40
  const { cmaGlobalConfig } = require('../config/cma-config')
@@ -125,16 +126,24 @@ const configureProject = () => ({
125
126
  task.newListr([
126
127
  convertMySQLDatabaseToMariaDB(),
127
128
  {
128
- task: (ctx, task) =>
129
- task.newListr(
129
+ task: (ctx, subTask) =>
130
+ subTask.newListr(
130
131
  [pullImages(), dockerNetwork.tasks.createNetwork()],
131
132
  { concurrent: true }
132
133
  )
133
134
  },
134
- checkPHPVersion(),
135
135
  {
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(
138
147
  [buildProjectImage(), buildDebugProjectImage()],
139
148
  {
140
149
  concurrent: true
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Scripts and configuration used by CMA.",
4
4
  "homepage": "https://docs.create-magento-app.com/",
5
5
  "repository": "github:scandipwa/create-magento-app",
6
- "version": "2.1.1",
6
+ "version": "2.1.2",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -58,5 +58,5 @@
58
58
  "devDependencies": {
59
59
  "@types/yargs": "^17.0.13"
60
60
  },
61
- "gitHead": "0c665d04295cce4c7f4e924389e50c3eb29f0f75"
61
+ "gitHead": "7342c891aaaf3c1ff2967a945b1c75d78607f3c7"
62
62
  }
@@ -23,6 +23,7 @@ export interface ListrContext {
23
23
  magentoVersion: string
24
24
  composerVersion: string
25
25
  phpVersion: string
26
+ elasticSearchVersion: string
26
27
  port?: number
27
28
  ports: {
28
29
  app: number