@scandipwa/magento-scripts 2.1.1 → 2.1.3

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) => {
@@ -10,7 +10,8 @@ const scandipwaMagentoVersionMapping = {
10
10
  '2.4.1': '3.2.0 - 4.2.1',
11
11
  '2.4.2': '4.3.0 - 5.0.3',
12
12
  '2.4.3': '5.0.4 - 5.2.7',
13
- '2.4.4': '5.3.0+'
13
+ '2.4.4': '5.3.0+',
14
+ '2.4.6': '6.2.0+'
14
15
  }
15
16
 
16
17
  module.exports = scandipwaMagentoVersionMapping
@@ -0,0 +1,11 @@
1
+ const defaultEnv = require('../default-es-env')
2
+
3
+ /**
4
+ * @returns {import('../../../../../typings/index').ElasticSearchConfiguration}
5
+ */
6
+ const elasticsearch85 = () => ({
7
+ image: 'elasticsearch:8.5.3',
8
+ env: defaultEnv
9
+ })
10
+
11
+ module.exports = elasticsearch85
@@ -7,6 +7,7 @@ const elasticsearch712 = require('./elasticsearch-7.12')
7
7
  const elasticsearch716 = require('./elasticsearch-7.16')
8
8
  const elasticsearch717 = require('./elasticsearch-7.17')
9
9
  const elasticsearch84 = require('./elasticsearch-8.4')
10
+ const elasticsearch85 = require('./elasticsearch-8.5')
10
11
 
11
12
  module.exports = {
12
13
  elasticsearch68,
@@ -17,5 +18,6 @@ module.exports = {
17
18
  elasticsearch712,
18
19
  elasticsearch716,
19
20
  elasticsearch717,
20
- elasticsearch84
21
+ elasticsearch84,
22
+ elasticsearch85
21
23
  }
@@ -2,5 +2,6 @@ module.exports = {
2
2
  varnish60: require('./varnish-6-0'),
3
3
  varnish66: require('./varnish-6-6'),
4
4
  varnish70: require('./varnish-7-0'),
5
- varnish71: require('./varnish-7-1')
5
+ varnish71: require('./varnish-7-1'),
6
+ varnish73: require('./varnish-7-3')
6
7
  }
@@ -0,0 +1,15 @@
1
+ const path = require('path')
2
+
3
+ /**
4
+ * @param {Object} param0
5
+ * @param {string} param0.templateDir
6
+ * @returns {import('../../../../typings/index').VarnishConfiguration}
7
+ */
8
+ const varnish73 = ({ templateDir }) => ({
9
+ enabled: true,
10
+ healthCheck: false,
11
+ image: 'varnish:7.3',
12
+ configTemplate: path.join(templateDir || '', 'varnish.template.vcl')
13
+ })
14
+
15
+ module.exports = varnish73
@@ -0,0 +1,47 @@
1
+ const { defaultMagentoConfig } = require('../magento-config')
2
+ const sodium = require('../services/php/extensions/sodium')
3
+ const {
4
+ magento24PHPExtensionList
5
+ } = require('../magento/required-php-extensions')
6
+ const { php81 } = require('../services/php/versions')
7
+ const { sslTerminator } = require('../services/ssl-terminator')
8
+ const { varnish73 } = require('../services/varnish')
9
+ const { repo } = require('../services/php/base-repo')
10
+ const { nginx118 } = require('../services/nginx/versions')
11
+ const { composer2 } = require('../services/composer/versions')
12
+ const { maildev } = require('../services/maildev')
13
+ const { redis62 } = require('../services/redis')
14
+ const { mariadb104 } = require('../services/mariadb/versions')
15
+ const { elasticsearch717 } = require('../services/elasticsearch/versions')
16
+ const { mysql80 } = require('../services/mysql/versions')
17
+
18
+ /**
19
+ * @param {Object} param0
20
+ * @param {string} param0.templateDir
21
+ * @returns {import('../../../typings/index').CMAConfiguration & { magentoVersion: string, isDefault?: boolean }}
22
+ */
23
+ module.exports = ({ templateDir }) => ({
24
+ magentoVersion: '2.4.4-p4',
25
+ isDefault: true,
26
+ configuration: {
27
+ php: php81({
28
+ templateDir,
29
+ extensions: { ...magento24PHPExtensionList, sodium },
30
+ baseImage: `${repo}:php-8.1-magento-2.4`
31
+ }),
32
+ nginx: nginx118({ templateDir }),
33
+ redis: redis62(),
34
+ mysql: mysql80(),
35
+ mariadb: mariadb104(),
36
+ elasticsearch: elasticsearch717(),
37
+ composer: composer2(),
38
+ varnish: varnish73({ templateDir }),
39
+ sslTerminator: sslTerminator({ templateDir }),
40
+ maildev: maildev()
41
+ },
42
+ magento: defaultMagentoConfig,
43
+ host: 'localhost',
44
+ ssl: {
45
+ enabled: false
46
+ }
47
+ })
@@ -0,0 +1,47 @@
1
+ const { defaultMagentoConfig } = require('../magento-config')
2
+ const sodium = require('../services/php/extensions/sodium')
3
+ const {
4
+ magento24PHPExtensionList
5
+ } = require('../magento/required-php-extensions')
6
+ const { php81 } = require('../services/php/versions')
7
+ const { sslTerminator } = require('../services/ssl-terminator')
8
+ const { varnish73 } = require('../services/varnish')
9
+ const { repo } = require('../services/php/base-repo')
10
+ const { nginx118 } = require('../services/nginx/versions')
11
+ const { composer2 } = require('../services/composer/versions')
12
+ const { maildev } = require('../services/maildev')
13
+ const { redis62 } = require('../services/redis')
14
+ const { mariadb104 } = require('../services/mariadb/versions')
15
+ const { elasticsearch717 } = require('../services/elasticsearch/versions')
16
+ const { mysql80 } = require('../services/mysql/versions')
17
+
18
+ /**
19
+ * @param {Object} param0
20
+ * @param {string} param0.templateDir
21
+ * @returns {import('../../../typings/index').CMAConfiguration & { magentoVersion: string, isDefault?: boolean }}
22
+ */
23
+ module.exports = ({ templateDir }) => ({
24
+ magentoVersion: '2.4.5-p3',
25
+ isDefault: true,
26
+ configuration: {
27
+ php: php81({
28
+ templateDir,
29
+ extensions: { ...magento24PHPExtensionList, sodium },
30
+ baseImage: `${repo}:php-8.1-magento-2.4`
31
+ }),
32
+ nginx: nginx118({ templateDir }),
33
+ redis: redis62(),
34
+ mysql: mysql80(),
35
+ mariadb: mariadb104(),
36
+ elasticsearch: elasticsearch717(),
37
+ composer: composer2(),
38
+ varnish: varnish73({ templateDir }),
39
+ sslTerminator: sslTerminator({ templateDir }),
40
+ maildev: maildev()
41
+ },
42
+ magento: defaultMagentoConfig,
43
+ host: 'localhost',
44
+ ssl: {
45
+ enabled: false
46
+ }
47
+ })
@@ -0,0 +1,47 @@
1
+ const { defaultMagentoConfig } = require('../magento-config')
2
+ const sodium = require('../services/php/extensions/sodium')
3
+ const {
4
+ magento24PHPExtensionList
5
+ } = require('../magento/required-php-extensions')
6
+ const { php81 } = require('../services/php/versions')
7
+ const { sslTerminator } = require('../services/ssl-terminator')
8
+ const { varnish73 } = require('../services/varnish')
9
+ const { repo } = require('../services/php/base-repo')
10
+ const { nginx118 } = require('../services/nginx/versions')
11
+ const { composer2 } = require('../services/composer/versions')
12
+ const { maildev } = require('../services/maildev')
13
+ const { redis70 } = require('../services/redis')
14
+ const { mariadb104 } = require('../services/mariadb/versions')
15
+ const { elasticsearch85 } = require('../services/elasticsearch/versions')
16
+ const { mysql80 } = require('../services/mysql/versions')
17
+
18
+ /**
19
+ * @param {Object} param0
20
+ * @param {string} param0.templateDir
21
+ * @returns {import('../../../typings/index').CMAConfiguration & { magentoVersion: string, isDefault?: boolean }}
22
+ */
23
+ module.exports = ({ templateDir }) => ({
24
+ magentoVersion: '2.4.6-p1',
25
+ isDefault: true,
26
+ configuration: {
27
+ php: php81({
28
+ templateDir,
29
+ extensions: { ...magento24PHPExtensionList, sodium },
30
+ baseImage: `${repo}:php-8.1-magento-2.4`
31
+ }),
32
+ nginx: nginx118({ templateDir }),
33
+ redis: redis70(),
34
+ mysql: mysql80(),
35
+ mariadb: mariadb104(),
36
+ elasticsearch: elasticsearch85(),
37
+ composer: composer2(),
38
+ varnish: varnish73({ templateDir }),
39
+ sslTerminator: sslTerminator({ templateDir }),
40
+ maildev: maildev()
41
+ },
42
+ magento: defaultMagentoConfig,
43
+ host: 'localhost',
44
+ ssl: {
45
+ enabled: false
46
+ }
47
+ })
@@ -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
@@ -1,5 +1,4 @@
1
1
  const Joi = require('joi')
2
- const semver = require('semver')
3
2
  const KnownError = require('../errors/known-error')
4
3
  const pathExistsSync = require('./path-exists-sync')
5
4
 
@@ -16,14 +15,27 @@ const fileExistsValidator = (value) => {
16
15
  return undefined
17
16
  }
18
17
 
18
+ const composerVersionRegex =
19
+ /^latest-(\d+\.\d+\.?(x|\d)+?)$|^latest-stable$|^latest-preview$|^latest-(\d+\.x)$|^(\d+\.\d+\.\d+?)$/gi
20
+
19
21
  /**
20
22
  * @type {Joi.CustomValidator<string>}
21
23
  */
22
24
  const versionValidator = (value, helpers) => {
23
- const isValid = semver.valid(value)
24
-
25
- if (!isValid) {
26
- return helpers.error('any.invalid')
25
+ const isValidComposerVersion = composerVersionRegex.test(value)
26
+
27
+ if (!isValidComposerVersion) {
28
+ return helpers.error('any.invalid', {
29
+ label: `Not a valid composer version!
30
+ Allowed patterns:
31
+ - latest-stable
32
+ - latest-preview
33
+ - latest-2.2.x
34
+ - latest-2.x
35
+ - latest-1.x
36
+ - 2.2.21
37
+ `
38
+ })
27
39
  }
28
40
 
29
41
  return undefined
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.3",
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": "46f263a31736f8973bc04760b5bbdf779811cd32"
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
@@ -89,7 +89,12 @@ export interface ComposerConfiguration {
89
89
  *
90
90
  * @url https://getcomposer.org/download/
91
91
  */
92
- version: string
92
+ version: 'latest-stable'
93
+ | 'latest-preview'
94
+ | 'latest-1.x'
95
+ | 'latest-2.x'
96
+ | 'latest-2.2.x'
97
+ | ''
93
98
 
94
99
  /**
95
100
  * Composer global plugins that will be added to Docker image