@scandipwa/magento-scripts 2.1.4 → 2.2.0

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.
Files changed (98) hide show
  1. package/lib/config/docker.js +29 -12
  2. package/lib/config/get-magento-version-config.js +4 -1
  3. package/lib/config/php-config.js +2 -1
  4. package/lib/config/services/composer/versions/composer-1.js +1 -1
  5. package/lib/config/services/composer/versions/composer-2.2.js +8 -0
  6. package/lib/config/services/composer/versions/composer-2.js +1 -1
  7. package/lib/config/services/composer/versions/index.js +2 -1
  8. package/lib/config/services/elasticsearch/versions/elasticsearch-8.4.js +4 -1
  9. package/lib/config/services/elasticsearch/versions/elasticsearch-8.5.js +4 -1
  10. package/lib/config/services/elasticsearch/versions/elasticsearch-8.7.js +14 -0
  11. package/lib/config/services/elasticsearch/versions/index.js +3 -1
  12. package/lib/config/services/mysql/versions/mysql-8.0.js +1 -1
  13. package/lib/config/services/php/default-php-env.js +6 -0
  14. package/lib/config/services/php/versions/php-7.2.js +3 -1
  15. package/lib/config/services/php/versions/php-7.3.js +3 -1
  16. package/lib/config/services/php/versions/php-7.4.js +3 -1
  17. package/lib/config/services/php/versions/php-8.1.js +3 -1
  18. package/lib/config/services/php/versions/php-8.2.js +3 -1
  19. package/lib/config/ssl-config.js +9 -0
  20. package/lib/config/templates/nginx.fastcgi_params.template +2 -2
  21. package/lib/config/templates/nginx.template.conf +19 -2
  22. package/lib/config/templates/ssl-terminator.template.conf +2 -6
  23. package/lib/config/versions/index.js +16 -33
  24. package/lib/config/versions/magento-2.2.10.js +3 -12
  25. package/lib/config/versions/magento-2.3.0.js +3 -12
  26. package/lib/config/versions/magento-2.3.1.js +3 -12
  27. package/lib/config/versions/magento-2.3.2-p1.js +3 -12
  28. package/lib/config/versions/magento-2.3.2-p2.js +3 -12
  29. package/lib/config/versions/magento-2.3.2.js +3 -12
  30. package/lib/config/versions/magento-2.3.3-p1.js +3 -12
  31. package/lib/config/versions/magento-2.3.3.js +3 -12
  32. package/lib/config/versions/magento-2.3.4-p1.js +3 -12
  33. package/lib/config/versions/magento-2.3.4-p2.js +3 -12
  34. package/lib/config/versions/magento-2.3.4.js +3 -12
  35. package/lib/config/versions/magento-2.3.5-p1.js +3 -12
  36. package/lib/config/versions/magento-2.3.5-p2.js +3 -12
  37. package/lib/config/versions/magento-2.3.5.js +3 -17
  38. package/lib/config/versions/magento-2.3.6-p1.js +3 -12
  39. package/lib/config/versions/magento-2.3.6.js +3 -12
  40. package/lib/config/versions/magento-2.3.7-p1.js +3 -12
  41. package/lib/config/versions/magento-2.3.7-p2.js +3 -12
  42. package/lib/config/versions/magento-2.3.7-p3.js +3 -12
  43. package/lib/config/versions/magento-2.3.7-p4.js +3 -12
  44. package/lib/config/versions/magento-2.3.7.js +3 -12
  45. package/lib/config/versions/magento-2.4.0-p1.js +3 -12
  46. package/lib/config/versions/magento-2.4.0.js +3 -12
  47. package/lib/config/versions/magento-2.4.1-p1.js +3 -12
  48. package/lib/config/versions/magento-2.4.1.js +3 -12
  49. package/lib/config/versions/magento-2.4.2-p1.js +3 -13
  50. package/lib/config/versions/magento-2.4.2-p2.js +3 -13
  51. package/lib/config/versions/magento-2.4.2.js +3 -12
  52. package/lib/config/versions/magento-2.4.3-p1.js +3 -13
  53. package/lib/config/versions/magento-2.4.3-p2.js +3 -13
  54. package/lib/config/versions/magento-2.4.3-p3.js +3 -13
  55. package/lib/config/versions/magento-2.4.3.js +3 -13
  56. package/lib/config/versions/magento-2.4.4-p1.js +3 -13
  57. package/lib/config/versions/magento-2.4.4-p2.js +3 -13
  58. package/lib/config/versions/magento-2.4.4-p3.js +3 -13
  59. package/lib/config/versions/magento-2.4.4-p4.js +1 -10
  60. package/lib/config/versions/magento-2.4.4-p5.js +38 -0
  61. package/lib/config/versions/magento-2.4.4-p6.js +38 -0
  62. package/lib/config/versions/magento-2.4.4.js +3 -13
  63. package/lib/config/versions/magento-2.4.5-p1.js +3 -13
  64. package/lib/config/versions/magento-2.4.5-p2.js +3 -13
  65. package/lib/config/versions/magento-2.4.5-p3.js +1 -10
  66. package/lib/config/versions/magento-2.4.5-p4.js +38 -0
  67. package/lib/config/versions/magento-2.4.5-p5.js +38 -0
  68. package/lib/config/versions/magento-2.4.5.js +3 -12
  69. package/lib/config/versions/magento-2.4.6-p1.js +1 -10
  70. package/lib/config/versions/magento-2.4.6-p2.js +38 -0
  71. package/lib/config/versions/magento-2.4.6-p3.js +39 -0
  72. package/lib/config/versions/magento-2.4.6.js +1 -10
  73. package/lib/config/versions/magento-2.4.7-beta2.js +38 -0
  74. package/lib/tasks/database/import-dump-to-database.js +1 -1
  75. package/lib/tasks/database/import-remote-db/ssh/database-dump-command.js +0 -2
  76. package/lib/tasks/database/import-remote-db/ssh/readymage.js +29 -28
  77. package/lib/tasks/docker/containers/container-api.d.ts +5 -0
  78. package/lib/tasks/docker/containers/container-api.js +4 -1
  79. package/lib/tasks/docker/project-image-builder.js +21 -0
  80. package/lib/tasks/file-system/create-nginx-config.js +7 -2
  81. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/workspace-config.js +1 -1
  82. package/lib/tasks/file-system/create-ssl-terminator-config.js +9 -7
  83. package/lib/tasks/magento/install-magento-project.js +10 -7
  84. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +1 -1
  85. package/lib/tasks/magento/setup-magento/index-products.js +41 -1
  86. package/lib/tasks/magento/setup-magento/index.js +4 -1
  87. package/lib/tasks/magento/setup-magento/set-base-url.js +121 -13
  88. package/lib/tasks/requirements/elasticsearch-version.js +21 -6
  89. package/lib/util/config-file-validator.js +60 -19
  90. package/lib/util/config-php-json.js +2 -0
  91. package/lib/util/database.js +83 -1
  92. package/lib/util/instance-metadata.js +16 -19
  93. package/lib/util/match-filesystem.js +1 -0
  94. package/lib/util/run-magento.js +1 -0
  95. package/package.json +2 -2
  96. package/tsconfig.json +2 -1
  97. package/typings/common.d.ts +53 -0
  98. package/typings/index.d.ts +55 -0
@@ -99,7 +99,89 @@ const isTableExists = async (database, tableName, { databaseConnection }) => {
99
99
  return tableCount > 0
100
100
  }
101
101
 
102
+ /**
103
+ * @param {TemplateStringsArray} sqlString
104
+ * @param {...any} variables
105
+ * @returns {string}
106
+ */
107
+ const sql = (sqlString, ...variables) => {
108
+ return sqlString.reduce(
109
+ (acc, val, i) =>
110
+ `${acc}${
111
+ typeof variables[i] === 'undefined'
112
+ ? ''
113
+ : typeof variables[i] === 'string'
114
+ ? `'${variables[i]}'`
115
+ : String(variables[i])
116
+ }${val}`,
117
+ ''
118
+ )
119
+ }
120
+
121
+ /**
122
+ * @param {Object} param0
123
+ * @param {string} param0.table
124
+ * @param {[string, string, any][]} param0.where
125
+ * @param {Record<string, any>} param0.data
126
+ * @param {import('../../typings/context').ListrContext} param1
127
+ */
128
+ const databaseQuery = async (
129
+ { table, where, data },
130
+ { databaseConnection }
131
+ ) => {
132
+ const values = Object.entries(data).map(([key, val]) => ({
133
+ path: key,
134
+ value: val
135
+ }))
136
+
137
+ const whereInQuery = where
138
+ .map(([key, operator, val]) => `${key} ${operator} ${sql`${val}`}`)
139
+ .join(' AND ')
140
+
141
+ const query = `
142
+ SELECT * FROM ${table}
143
+ WHERE ${whereInQuery};`
144
+
145
+ const [rows] = await databaseConnection.query(query)
146
+
147
+ if (rows.length === 0) {
148
+ const query2 = `INSERT INTO ${table}
149
+ (${[...where.map(([key]) => key), ...values.map((p) => p.path)].join(
150
+ ', '
151
+ )})
152
+ VALUES (${[
153
+ ...where.map(([, , val]) => sql`${val}`),
154
+ ...values.map((p) => sql`${p.value}`)
155
+ ].join(', ')});`
156
+
157
+ await databaseConnection.query(query2)
158
+
159
+ return true
160
+ }
161
+
162
+ const [row] = rows
163
+
164
+ const incorrectData = Object.entries(data).filter(
165
+ ([key, val]) => row[key] !== val
166
+ )
167
+
168
+ if (incorrectData.length > 0) {
169
+ await databaseConnection.query(
170
+ `UPDATE ${table}
171
+ SET ${incorrectData
172
+ .map(([key, val]) => `${key} = ${sql`${val}`}`)
173
+ .join(', ')}
174
+ WHERE ${whereInQuery};`
175
+ )
176
+
177
+ return true
178
+ }
179
+
180
+ return false
181
+ }
182
+
102
183
  module.exports = {
103
184
  updateTableValues,
104
- isTableExists
185
+ isTableExists,
186
+ databaseQuery
105
187
  }
@@ -24,7 +24,7 @@ const getInstanceMetadata = (ctx) => {
24
24
  ports,
25
25
  config: {
26
26
  magentoConfiguration,
27
- overridenConfiguration: { host, ssl }
27
+ overridenConfiguration: { ssl, storeDomains }
28
28
  }
29
29
  } = ctx
30
30
 
@@ -43,25 +43,22 @@ const getInstanceMetadata = (ctx) => {
43
43
  */
44
44
  const maildev = []
45
45
 
46
- const isNgrok = host.endsWith('ngrok.io')
46
+ frontend.push({
47
+ title: WEB_LOCATION_TITLE,
48
+ text: `${ssl.enabled ? 'https' : 'http'}://${storeDomains.admin}${
49
+ ssl.enabled || ports.sslTerminator === 80
50
+ ? ''
51
+ : `:${ports.sslTerminator}`
52
+ }/`
53
+ })
47
54
 
48
- if (isNgrok) {
49
- frontend.push({
50
- title: WEB_LOCAL_LOCATION_TITLE,
51
- text: `${ssl.enabled ? 'https' : 'http'}://localhost${
52
- ssl.enabled || ports.sslTerminator === 80
53
- ? ''
54
- : `:${ports.sslTerminator}`
55
- }/`
56
- })
57
- frontend.push({
58
- title: WEB_LOCATION_TITLE,
59
- text: `${ssl.enabled ? 'https' : 'http'}://${host}/`
60
- })
61
- } else {
55
+ for (const [storeCode, domain] of Object.entries(storeDomains)) {
56
+ if (storeCode === 'admin') {
57
+ continue
58
+ }
62
59
  frontend.push({
63
- title: WEB_LOCATION_TITLE,
64
- text: `${ssl.enabled ? 'https' : 'http'}://${host}${
60
+ title: `Frontend store ${logger.style.file(storeCode)} location`,
61
+ text: `${ssl.enabled ? 'https' : 'http'}://${domain}${
65
62
  ssl.enabled || ports.sslTerminator === 80
66
63
  ? ''
67
64
  : `:${ports.sslTerminator}`
@@ -87,7 +84,7 @@ const getInstanceMetadata = (ctx) => {
87
84
 
88
85
  maildev.push({
89
86
  title: WEB_MAILDEV_LOCATION_TITLE,
90
- text: `http://${host}:${ports.maildevWeb}/`
87
+ text: `http://localhost:${ports.maildevWeb}/`
91
88
  })
92
89
 
93
90
  return {
@@ -17,6 +17,7 @@ const matchFilesystem = async (cwd, structure) => {
17
17
 
18
18
  return ok
19
19
  }
20
+
20
21
  if (typeof structure === 'object') {
21
22
  const ok = (
22
23
  await Promise.all(
@@ -6,6 +6,7 @@ const { runPHPContainerCommand } = require('../tasks/php/php-container')
6
6
  * @param {import('../../typings/context').ListrContext} ctx
7
7
  * @param {String} command magento command
8
8
  * @param {Parameters<typeof import('../tasks/php/php-container')['runPHPContainerCommand']>[2] & { throwNonZeroCode?: boolean }} options
9
+ * @returns {Promise<{ code: number, result: string }>}
9
10
  */
10
11
  const runMagentoCommand = async (ctx, command, options = {}) => {
11
12
  const { throwNonZeroCode = true } = options
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.4",
6
+ "version": "2.2.0",
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": "71b3bef6b620023fedca851dd529b60e22b113e0"
61
+ "gitHead": "395e82651091c1355946c60224457b01f9e7204d"
62
62
  }
package/tsconfig.json CHANGED
@@ -12,7 +12,8 @@
12
12
  "moduleResolution": "Node",
13
13
  "types": [
14
14
  "./typings"
15
- ]
15
+ ],
16
+ "noEmit": true
16
17
  },
17
18
  "exclude": [
18
19
  "**/node_modules",
@@ -0,0 +1,53 @@
1
+ import { CMAConfiguration, ServiceWithImage } from "./index"
2
+ import { ListrContext } from "./context"
3
+
4
+ export type MagentoVersionConfigurationFunction = (args: ListrContext['config']['baseConfig']) => MagentoVersionConfiguration
5
+
6
+ export type MagentoVersionConfiguration = CMAConfigurationWithMySQL & {
7
+ magentoVersion: string
8
+ isDefault?: boolean
9
+ }
10
+
11
+ export type CMAConfigurationWithMySQL = Optional<CMAConfiguration, 'storeDomains' | 'host' | 'magento' | 'prefix' | 'ssl'> & {
12
+ configuration: {
13
+ mysql: Optional<ServiceWithImage, 'image'>
14
+ }
15
+ }
16
+
17
+ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
18
+
19
+ export interface ConfigPHPType {
20
+ modules: Record<string, number>
21
+ scopes?: {
22
+ websites: {
23
+ [websiteCode: string]: {
24
+ website_id: string
25
+ code: string
26
+ name: string
27
+ sort_order: string
28
+ default_group_id: string
29
+ is_default: string
30
+ }
31
+ }
32
+ groups: {
33
+ group_id: string
34
+ website_id: string
35
+ code: string
36
+ name: string
37
+ root_category_id: string
38
+ default_store_id: string
39
+ }[]
40
+ stores: {
41
+ [storeCode: string]: {
42
+ store_id: string
43
+ code: string
44
+ website_id: string
45
+ group_id: string
46
+ name: string
47
+ sort_order: string
48
+ is_active: string
49
+ }
50
+ }
51
+ }
52
+ system?: any
53
+ }
@@ -202,6 +202,11 @@ export interface PHPConfiguration {
202
202
  * Extensions for PHP
203
203
  */
204
204
  extensions: PHPExtensions
205
+
206
+ /**
207
+ * Environmental variables used for PHP container
208
+ */
209
+ env: Record<string, unknown>
205
210
  }
206
211
  export interface SSLConfiguration {
207
212
  /**
@@ -224,6 +229,32 @@ export interface SSLConfiguration {
224
229
  * `./ssl_certificate-key.pem`
225
230
  */
226
231
  ssl_certificate_key?: string
232
+
233
+ /**
234
+ * SSL external provider configuration
235
+ *
236
+ * Set to `true` if you don't need locally provided SSL certificates
237
+ *
238
+ * @default false
239
+ */
240
+ external_provider?: boolean
241
+ }
242
+
243
+ export interface NewRelicConfiguration {
244
+ /**
245
+ * Enables or disables New Relic in application
246
+ */
247
+ enabled: boolean
248
+
249
+ /**
250
+ * New Relic Agent version
251
+ */
252
+ agentVersion?: string
253
+
254
+ /**
255
+ * New Relic license key
256
+ */
257
+ licenseKey?: string
227
258
  }
228
259
 
229
260
  export interface CMAConfiguration {
@@ -271,6 +302,11 @@ export interface CMAConfiguration {
271
302
  */
272
303
  sslTerminator: SSLTerminatorConfiguration
273
304
 
305
+ /**
306
+ * New Relic configuration
307
+ */
308
+ newRelic?: NewRelicConfiguration
309
+
274
310
  /**
275
311
  * MailDev configuration
276
312
  */
@@ -316,9 +352,28 @@ export interface CMAConfiguration {
316
352
  /**
317
353
  * Custom host for website base url
318
354
  * @default 'localhost'
355
+ *
356
+ * @deprecated Use `storeDomains` instead, as follows: `storeDomains: { admin: 'localhost' }`
319
357
  */
320
358
  host: string
321
359
 
360
+ /**
361
+ * Custom domains for magento stores by store code
362
+ *
363
+ * Note: you can look up **scope_id** in `app/etc/config.php` in `scopes` section.
364
+ *
365
+ * @default { admin: 'localhost' }
366
+ *
367
+ * @example ```js
368
+ * storeDomains: {
369
+ * admin: 'localhost',
370
+ * custom_store_code: 'scandipwa.local',
371
+ * another_store_code: 'another-store.local'
372
+ * }
373
+ * ```
374
+ */
375
+ storeDomains: { admin: string } & Record<string, string>
376
+
322
377
  /**
323
378
  * SSL Configuration
324
379
  */