@scandipwa/magento-scripts 1.16.1 → 2.0.0-alpha.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 (189) hide show
  1. package/lib/commands/cli.js +2 -4
  2. package/lib/commands/execute.js +28 -3
  3. package/lib/commands/start.js +37 -15
  4. package/lib/commands/status.js +2 -0
  5. package/lib/config/docker.js +65 -42
  6. package/lib/config/get-project-configuration.js +3 -1
  7. package/lib/config/index.js +10 -7
  8. package/lib/config/magento/required-php-extensions/index.js +29 -0
  9. package/lib/config/magento/required-php-extensions/magento-2.3.js +19 -0
  10. package/lib/config/magento/required-php-extensions/magento-2.4.js +29 -0
  11. package/lib/config/php/base-repo.js +3 -0
  12. package/lib/config/php/extensions/apcu.js +12 -0
  13. package/lib/config/php/extensions/bcmath.js +7 -0
  14. package/lib/config/php/extensions/curl.js +11 -0
  15. package/lib/config/php/extensions/gd.js +14 -0
  16. package/lib/config/php/extensions/index.js +18 -2
  17. package/lib/config/php/extensions/intl.js +10 -0
  18. package/lib/config/php/extensions/opcache.js +10 -0
  19. package/lib/config/php/extensions/pdo_mysql.js +7 -0
  20. package/lib/config/php/extensions/soap.js +10 -0
  21. package/lib/config/php/extensions/sodium.js +10 -0
  22. package/lib/config/php/extensions/xdebug.js +8 -5
  23. package/lib/config/php/extensions/xsl.js +10 -0
  24. package/lib/config/php/extensions/zip.js +10 -0
  25. package/lib/config/php/{releases → versions}/index.js +0 -0
  26. package/lib/config/php/versions/php-7.2.js +23 -0
  27. package/lib/config/php/versions/php-7.3.js +23 -0
  28. package/lib/config/php/versions/php-7.4.js +23 -0
  29. package/lib/config/php/versions/php-8.1.js +23 -0
  30. package/lib/config/php-config.js +8 -12
  31. package/lib/config/port-config.js +1 -5
  32. package/lib/config/templates/magentorc.template +3 -3
  33. package/lib/config/templates/php-fpm.template.conf +3 -3
  34. package/lib/config/templates/php.template.ini +12 -6
  35. package/lib/config/templates/ssl-terminator.template.conf +1 -1
  36. package/lib/config/templates/vscode-launch.template.json +3 -1
  37. package/lib/config/versions/magento-2.3.0.js +8 -2
  38. package/lib/config/versions/magento-2.3.1.js +8 -2
  39. package/lib/config/versions/magento-2.3.2-p1.js +44 -0
  40. package/lib/config/versions/magento-2.3.2-p2.js +8 -2
  41. package/lib/config/versions/magento-2.3.2.js +8 -2
  42. package/lib/config/versions/magento-2.3.3-p1.js +8 -2
  43. package/lib/config/versions/magento-2.3.3.js +8 -2
  44. package/lib/config/versions/magento-2.3.4-p1.js +44 -0
  45. package/lib/config/versions/magento-2.3.4-p2.js +8 -2
  46. package/lib/config/versions/magento-2.3.4.js +8 -2
  47. package/lib/config/versions/magento-2.3.5-p1.js +8 -2
  48. package/lib/config/versions/magento-2.3.5-p2.js +8 -2
  49. package/lib/config/versions/magento-2.3.5.js +8 -2
  50. package/lib/config/versions/magento-2.3.6-p1.js +8 -2
  51. package/lib/config/versions/magento-2.3.6.js +8 -2
  52. package/lib/config/versions/magento-2.3.7-p1.js +8 -2
  53. package/lib/config/versions/magento-2.3.7-p2.js +8 -2
  54. package/lib/config/versions/magento-2.3.7-p3.js +8 -2
  55. package/lib/config/versions/magento-2.3.7.js +8 -2
  56. package/lib/config/versions/magento-2.4.0-p1.js +9 -3
  57. package/lib/config/versions/magento-2.4.0.js +9 -3
  58. package/lib/config/versions/magento-2.4.1-p1.js +6 -5
  59. package/lib/config/versions/magento-2.4.1.js +9 -2
  60. package/lib/config/versions/magento-2.4.2-p1.js +6 -5
  61. package/lib/config/versions/magento-2.4.2-p2.js +6 -6
  62. package/lib/config/versions/magento-2.4.2.js +6 -6
  63. package/lib/config/versions/magento-2.4.3-p1.js +7 -7
  64. package/lib/config/versions/magento-2.4.3-p2.js +7 -7
  65. package/lib/config/versions/magento-2.4.3.js +7 -7
  66. package/lib/config/versions/magento-2.4.4.js +9 -2
  67. package/lib/tasks/cleanup.js +2 -2
  68. package/lib/tasks/composer/index.js +14 -104
  69. package/lib/tasks/docker/api.d.ts +71 -0
  70. package/lib/tasks/docker/api.js +30 -0
  71. package/lib/tasks/docker/containers/container-api.d.ts +128 -0
  72. package/lib/tasks/docker/containers/container-api.js +153 -0
  73. package/lib/tasks/docker/containers/index.js +19 -0
  74. package/lib/tasks/docker/containers/tasks.js +215 -0
  75. package/lib/tasks/docker/convert-legacy-volumes.js +7 -3
  76. package/lib/tasks/docker/image/image-api.d.ts +34 -0
  77. package/lib/tasks/docker/image/image-api.js +49 -0
  78. package/lib/tasks/docker/image/index.js +5 -0
  79. package/lib/tasks/docker/index.js +1 -13
  80. package/lib/tasks/docker/network/index.js +7 -0
  81. package/lib/tasks/docker/network/network-api.d.ts +103 -0
  82. package/lib/tasks/docker/network/network-api.js +99 -0
  83. package/lib/tasks/docker/{network.js → network/tasks.js} +17 -10
  84. package/lib/tasks/docker/project-image-builder.js +167 -0
  85. package/lib/tasks/docker/volumes.js +1 -1
  86. package/lib/tasks/file-system/create-nginx-config.js +2 -3
  87. package/lib/tasks/file-system/create-php-config.js +20 -5
  88. package/lib/tasks/file-system/create-php-fpm-config.js +8 -4
  89. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +41 -29
  90. package/lib/tasks/file-system/create-phpstorm-config/index.js +2 -0
  91. package/lib/tasks/file-system/create-phpstorm-config/keys.js +15 -1
  92. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +4 -1
  93. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-config.js +3 -3
  94. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-interpreters-config.js +81 -0
  95. package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/index.js +42 -0
  96. package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/php-docker-settings-config.js +9 -0
  97. package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/setup-php-docker-container-settings-config.js +66 -0
  98. package/lib/tasks/file-system/create-phpstorm-config/setup-xml-structure.js +11 -9
  99. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +2 -1
  100. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +15 -30
  101. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +24 -5
  102. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/mess-detector-project-configuration-config.js +50 -0
  103. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-code-sniffer-project-configuration-config.js +50 -0
  104. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-cs-fixer-project-configuration-config.js +50 -0
  105. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +15 -15
  106. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +29 -3
  107. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-stan-project-configuration-config.js.js +50 -0
  108. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-workspace-project-configuration-config.js +42 -0
  109. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/psalm-project-configuration-config.js.js +50 -0
  110. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/workspace-config.js +0 -2
  111. package/lib/tasks/file-system/create-ssl-terminator-config.js +4 -2
  112. package/lib/tasks/file-system/create-vscode-config.js +57 -42
  113. package/lib/tasks/file-system/index.js +2 -1
  114. package/lib/tasks/link.js +1 -2
  115. package/lib/tasks/magento/install-magento-project.js +31 -63
  116. package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +4 -4
  117. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +6 -2
  118. package/lib/tasks/magento/setup-magento/create-admin.js +5 -6
  119. package/lib/tasks/magento/setup-magento/disable-2fa.js +3 -5
  120. package/lib/tasks/magento/setup-magento/disable-maintenance-mode.js +3 -4
  121. package/lib/tasks/magento/setup-magento/install-magento.js +10 -9
  122. package/lib/tasks/magento/setup-magento/migrate-database.js +7 -8
  123. package/lib/tasks/magento/setup-magento/set-deployment-mode.js +4 -4
  124. package/lib/tasks/magento/setup-magento/varnish-config.js +6 -4
  125. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +128 -3
  126. package/lib/tasks/mysql/connect-to-mysql.js +34 -21
  127. package/lib/tasks/mysql/import-dump-to-mysql.js +46 -3
  128. package/lib/tasks/php/php-container.js +108 -0
  129. package/lib/tasks/php/update-env-php.js +35 -19
  130. package/lib/tasks/php/update-env.php +61 -56
  131. package/lib/tasks/php/working_health_check.php +85 -0
  132. package/lib/tasks/requirements/{composer.js → composer-credentials.js} +3 -1
  133. package/lib/tasks/requirements/docker/index.js +15 -12
  134. package/lib/tasks/requirements/docker/performance.js +54 -0
  135. package/lib/tasks/requirements/docker/version.js +8 -8
  136. package/lib/tasks/requirements/index.js +5 -8
  137. package/lib/tasks/requirements/php-version.js +8 -116
  138. package/lib/tasks/requirements/platform.js +12 -25
  139. package/lib/tasks/start.js +38 -47
  140. package/lib/tasks/status/index.js +4 -10
  141. package/lib/tasks/stop.js +0 -2
  142. package/lib/tasks/theme/install-theme.js +1 -1
  143. package/lib/tasks/theme/symlink-theme.js +2 -3
  144. package/lib/util/config-php-json.js +13 -4
  145. package/lib/util/dockerfile-builder/build-instructions.js +197 -0
  146. package/lib/util/dockerfile-builder/index.js +276 -0
  147. package/lib/util/dockerfile-builder/types.d.ts +123 -0
  148. package/lib/util/env-php-json.js +10 -6
  149. package/lib/util/exec-async-command.js +3 -9
  150. package/lib/util/macos-version.js +20 -0
  151. package/lib/util/magento-task.js +3 -4
  152. package/lib/util/nginx-logs-parser.js +122 -0
  153. package/lib/util/php-task.js +3 -6
  154. package/lib/util/prefix.js +1 -1
  155. package/lib/util/run-composer.js +6 -14
  156. package/lib/util/run-container-image.js +17 -0
  157. package/lib/util/run-magento.js +6 -14
  158. package/lib/util/run-php.js +6 -17
  159. package/package.json +9 -9
  160. package/typings/context.d.ts +3 -9
  161. package/typings/index.d.ts +38 -57
  162. package/lib/config/composer.js +0 -11
  163. package/lib/config/php/extensions/libsodium.js +0 -36
  164. package/lib/config/php/releases/php-7.2.js +0 -25
  165. package/lib/config/php/releases/php-7.3.js +0 -25
  166. package/lib/config/php/releases/php-7.4.js +0 -23
  167. package/lib/config/php/releases/php-8.1.js +0 -25
  168. package/lib/config/phpbrew.js +0 -12
  169. package/lib/tasks/composer/install-prestissimo.js +0 -103
  170. package/lib/tasks/docker/containers.js +0 -231
  171. package/lib/tasks/php/bundled-extensions.js +0 -27
  172. package/lib/tasks/php/compile-options.js +0 -56
  173. package/lib/tasks/php/compile.js +0 -55
  174. package/lib/tasks/php/configure.js +0 -89
  175. package/lib/tasks/php/extensions/disable.js +0 -49
  176. package/lib/tasks/php/extensions/enable.js +0 -52
  177. package/lib/tasks/php/extensions/index.js +0 -80
  178. package/lib/tasks/php/extensions/install.js +0 -54
  179. package/lib/tasks/php/index.js +0 -79
  180. package/lib/tasks/php/install-sodium.js +0 -93
  181. package/lib/tasks/php/update-phpbrew.js +0 -45
  182. package/lib/tasks/php/validate-php.js +0 -67
  183. package/lib/tasks/php-fpm/get-process-id.js +0 -14
  184. package/lib/tasks/php-fpm/index.js +0 -4
  185. package/lib/tasks/php-fpm/start-php-fpm.js +0 -49
  186. package/lib/tasks/php-fpm/stop-php-fpm.js +0 -48
  187. package/lib/tasks/requirements/phpbrew/index.js +0 -61
  188. package/lib/tasks/requirements/phpbrew/install.js +0 -159
  189. package/lib/tasks/requirements/phpbrew/version.js +0 -28
@@ -2,7 +2,7 @@ const os = require('os');
2
2
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
3
3
  const { spawn } = require('child_process');
4
4
  const { getArchSync } = require('./arch');
5
- const compileOptions = require('../tasks/php/compile-options');
5
+ const UnknownError = require('../errors/unknown-error');
6
6
 
7
7
  const execAsyncSpawn = (command, {
8
8
  callback = () => {},
@@ -31,13 +31,7 @@ const execAsyncSpawn = (command, {
31
31
  'arch',
32
32
  // eslint-disable-next-line max-len
33
33
  ['-x86_64', 'bash', '-c', command],
34
- {
35
- ...spawnOptions,
36
- env: {
37
- ...process.env,
38
- PATH: compileOptions.darwin.env.PATH
39
- }
40
- }
34
+ spawnOptions
41
35
  );
42
36
  } else {
43
37
  childProcess = spawn(
@@ -79,7 +73,7 @@ const execAsyncSpawn = (command, {
79
73
  return;
80
74
  }
81
75
  if (code > 0) {
82
- reject(result);
76
+ reject(new UnknownError(result));
83
77
  } else {
84
78
  resolve(result);
85
79
  }
@@ -0,0 +1,20 @@
1
+ const semver = require('semver');
2
+ const macosVersion = require('macos-version');
3
+ const { execAsyncSpawn } = require('./exec-async-command');
4
+
5
+ const getMacOSVersion = async () => {
6
+ const { code, result } = await execAsyncSpawn('sw_vers -productVersion',
7
+ {
8
+ withCode: true
9
+ });
10
+
11
+ if (code !== 0) {
12
+ return macosVersion();
13
+ }
14
+
15
+ return semver.coerce(result).version;
16
+ };
17
+
18
+ module.exports = {
19
+ getMacOSVersion
20
+ };
@@ -8,13 +8,12 @@ const runMagentoCommand = require('./run-magento');
8
8
  */
9
9
  const magentoTask = (command, options = {}) => ({
10
10
  title: `Running command 'magento ${command}'`,
11
- task: async ({ magentoVersion, verbose }, task) => {
11
+ task: async (ctx, task) => {
12
12
  try {
13
- await runMagentoCommand(command, {
14
- callback: !verbose ? undefined : (t) => {
13
+ await runMagentoCommand(ctx, command, {
14
+ callback: !ctx.verbose ? undefined : (t) => {
15
15
  task.output = t;
16
16
  },
17
- magentoVersion,
18
17
  throwNonZeroCode: true
19
18
  });
20
19
  } catch (e) {
@@ -0,0 +1,122 @@
1
+ /* eslint-disable no-bitwise */
2
+ /* eslint-disable max-len */
3
+ class NginxParser {
4
+ constructor(format) {
5
+ this.directives = {};
6
+
7
+ const prefix = format.match(/^[^$]*/);
8
+ if (prefix) {
9
+ format = this.escape(prefix[0]) + format.slice(prefix[0].length);
10
+ }
11
+
12
+ this.parser = format;
13
+
14
+ const directive = /\$([a-z_]+)(.)?([^$]+)?/g;
15
+ let match;
16
+ let regex;
17
+ let boundary;
18
+ let i = 1;
19
+
20
+ // eslint-disable-next-line no-cond-assign
21
+ while ((match = directive.exec(format))) {
22
+ this.directives[match[1]] = i++;
23
+ if (match[2]) {
24
+ boundary = this.escape(match[2]);
25
+ regex = `([^${ boundary }]*?)${ boundary}`;
26
+ if (match[3]) {
27
+ regex += this.escape(match[3]);
28
+ }
29
+ } else {
30
+ regex = '(.+)$';
31
+ }
32
+ this.parser = this.parser.replace(match[0], regex);
33
+ }
34
+
35
+ this.parser = new RegExp(this.parser);
36
+ }
37
+
38
+ /**
39
+ * Parse a log line.
40
+ *
41
+ * @param {String} line
42
+ * @returns {Record<'msec' | 'time_iso8601' | 'remote_addr' | 'query_string' | 'http_x_forwarded_for' | 'http_user_agent' | 'http_referer' | 'time_local' | 'request' | 'status' | 'request_time' | 'request_length' | 'pipe' | 'connection' | 'bytes_sent' | 'body_bytes_sent' | 'date' | 'timestamp' | 'ip' | 'ip_str', string>}
43
+ */
44
+ parseLine(line) {
45
+ const match = line.match(this.parser);
46
+ if (!match) {
47
+ return;
48
+ }
49
+
50
+ const row = {
51
+ msec: null,
52
+ time_iso8601: null,
53
+ remote_addr: null,
54
+ query_string: null,
55
+ http_x_forwarded_for: null,
56
+ http_user_agent: null,
57
+ http_referer: null,
58
+ time_local: null,
59
+ request: null,
60
+ status: null,
61
+ request_time: null,
62
+ request_length: null,
63
+ pipe: null,
64
+ connection: null,
65
+ bytes_sent: null,
66
+ body_bytes_sent: null,
67
+
68
+ date: null,
69
+ timestamp: null,
70
+ ip: null,
71
+ ip_str: null
72
+ };
73
+
74
+ // eslint-disable-next-line guard-for-in
75
+ for (const key in this.directives) {
76
+ row[key] = match[this.directives[key]];
77
+ if (row[key] === '-') {
78
+ row[key] = null;
79
+ }
80
+ }
81
+
82
+ // Parse the timestamp
83
+ if (row.time_iso8601) {
84
+ row.date = new Date(row.time_iso8601);
85
+ } else if (row.msec) {
86
+ row.date = new Date(Number(row.msec.replace('.', '')));
87
+ }
88
+ if (row.date) {
89
+ row.timestamp = row.date.getTime();
90
+ }
91
+
92
+ // Parse the user's IP
93
+ if (row.http_x_forwarded_for) {
94
+ row.ip_str = row.http_x_forwarded_for;
95
+ } else if (row.remote_addr) {
96
+ row.ip_str = row.remote_addr;
97
+ }
98
+ if (row.ip_str) {
99
+ const ip = row.ip_str.split('.', 4);
100
+ row.ip = Number(ip[0]) * (2 << 23)
101
+ + Number(ip[1]) * (2 << 15)
102
+ + Number(ip[2]) * (2 << 7)
103
+ + Number(ip[3]);
104
+ }
105
+
106
+ return row;
107
+ }
108
+
109
+ /**
110
+ * Escape regular expression tokens.
111
+ *
112
+ * @param {String} str
113
+ * @return {String}
114
+ */
115
+ escape(str) {
116
+ return str.replace(new RegExp('[.*+?|()\\[\\]{}]', 'g'), '\\$&');
117
+ }
118
+ }
119
+
120
+ module.exports = {
121
+ NginxParser
122
+ };
@@ -1,4 +1,4 @@
1
- const runPhpCode = require('./run-php');
1
+ const { runPHPContainerCommand } = require('../tasks/php/php-container');
2
2
 
3
3
  /**
4
4
  * @param {String} command
@@ -7,14 +7,11 @@ const runPhpCode = require('./run-php');
7
7
  */
8
8
  const phpTask = (command, options = {}) => ({
9
9
  title: !options.noTitle ? `Running command 'php ${command}` : undefined,
10
- task: (ctx, task) => runPhpCode(command, {
10
+ task: (ctx, task) => runPHPContainerCommand(ctx, command, {
11
11
  callback: (t) => {
12
12
  task.output = t;
13
13
  },
14
- throwNonZeroCode: true,
15
- magentoVersion: ctx.magentoVersion,
16
- env: options.env,
17
- useRosettaOnMac: ctx.arch === 'arm64' && ctx.platform === 'darwin'
14
+ throwNonZeroCode: true
18
15
  })
19
16
  });
20
17
 
@@ -22,7 +22,7 @@ const getPrefix = (fName = folderName) => {
22
22
  }
23
23
 
24
24
  if (projectInGlobalConfig && projectInGlobalConfig.prefix) {
25
- return `${fName}-${projectInGlobalConfig.prefix}`;
25
+ return `${fName}.${projectInGlobalConfig.prefix}`;
26
26
  }
27
27
 
28
28
  return fName;
@@ -1,28 +1,20 @@
1
- const { execAsyncSpawn } = require('./exec-async-command');
2
- const { getConfigFromMagentoVersion, defaultConfiguration } = require('../config');
3
1
  const UnknownError = require('../errors/unknown-error');
2
+ const { runPHPContainerCommand } = require('../tasks/php/php-container');
4
3
  /**
5
4
  * Execute composer command
5
+ * @param {import('../../typings/context').ListrContext} ctx
6
6
  * @param {String} command composer command
7
7
  * @param {Object} options
8
8
  * @param {Boolean} options.throwNonZeroCode Throw if command return non 0 code.
9
9
  * @param {String} options.magentoVersion Magento version for config
10
10
  */
11
- const runComposerCommand = async (command, options = {}) => {
11
+ const runComposerCommand = async (ctx, command, options = {}) => {
12
12
  const {
13
- throwNonZeroCode = true,
14
- magentoVersion = defaultConfiguration.name
13
+ throwNonZeroCode = true
15
14
  } = options;
16
- const {
17
- php,
18
- composer,
19
- baseConfig: { magentoDir }
20
- } = await getConfigFromMagentoVersion(magentoVersion);
21
- const { code, result } = await execAsyncSpawn(`${php.binPath} -c ${php.iniPath} ${composer.binPath} ${command}`, {
15
+ const { code, result } = await runPHPContainerCommand(ctx, `composer ${command}`, {
22
16
  ...options,
23
- cwd: magentoDir,
24
- withCode: true,
25
- useRosetta2: true
17
+ withCode: true
26
18
  });
27
19
 
28
20
  if (throwNonZeroCode && code !== 0) {
@@ -0,0 +1,17 @@
1
+ const { execAsyncSpawn } = require('./exec-async-command');
2
+
3
+ const runContainerImage = async (imageWithTag, command) => execAsyncSpawn(`docker run --rm ${imageWithTag} ${command}`);
4
+
5
+ /**
6
+ * @param {string} imageWithTag
7
+ * @param {string} command
8
+ * @returns {import('listr2').ListrTask<import('../../typings/context').ListrContext>}
9
+ */
10
+ const runContainerImageTask = (imageWithTag, command) => ({
11
+ task: () => runContainerImage(imageWithTag, command)
12
+ });
13
+
14
+ module.exports = {
15
+ runContainerImage,
16
+ runContainerImageTask
17
+ };
@@ -1,8 +1,9 @@
1
- const { execAsyncSpawn } = require('./exec-async-command');
2
- const { getConfigFromMagentoVersion, defaultConfiguration, magento } = require('../config');
3
1
  const UnknownError = require('../errors/unknown-error');
2
+ const { runPHPContainerCommand } = require('../tasks/php/php-container');
4
3
  /**
5
4
  * Execute magento command
5
+ *
6
+ * @param {import('../../typings/context').ListrContext} ctx
6
7
  * @param {String} command magento command
7
8
  * @param {Object} options
8
9
  * @param {Boolean} options.logOutput Log output to console using logger
@@ -10,20 +11,11 @@ const UnknownError = require('../errors/unknown-error');
10
11
  * @param {String} options.cwd
11
12
  * @param {() => {}} options.callback
12
13
  * @param {Boolean} options.throwNonZeroCode Throw if command return non 0 code.
13
- * @param {String} options.magentoVersion Magento version for config
14
14
  */
15
- const runMagentoCommand = async (command, options = {}) => {
16
- const {
17
- throwNonZeroCode = true,
18
- magentoVersion = defaultConfiguration.name
19
- } = options;
20
- const {
21
- php,
22
- baseConfig: { magentoDir }
23
- } = await getConfigFromMagentoVersion(magentoVersion);
24
- const { code, result } = await execAsyncSpawn(`${php.binPath} -c ${php.iniPath} ${magento.binPath} ${command}`, {
15
+ const runMagentoCommand = async (ctx, command, options = {}) => {
16
+ const { throwNonZeroCode = true } = options;
17
+ const { code, result } = await runPHPContainerCommand(ctx, `bin/magento ${command}`, {
25
18
  ...options,
26
- cwd: magentoDir,
27
19
  withCode: true
28
20
  });
29
21
 
@@ -1,34 +1,23 @@
1
- const { execAsyncSpawn } = require('./exec-async-command');
2
- const { getConfigFromMagentoVersion, defaultConfiguration } = require('../config');
3
1
  const UnknownError = require('../errors/unknown-error');
2
+ const { runPHPContainerCommand } = require('../tasks/php/php-container');
4
3
  /**
5
4
  * Execute PHP code
6
- * @param {String} command magento command
5
+ * @param {import('../../typings/context').ListrContext} ctx
6
+ * @param {String} command php command
7
7
  * @param {Object} options
8
8
  * @param {Boolean} options.logOutput Log output to console using logger
9
9
  * @param {Boolean} options.withCode
10
10
  * @param {String} options.cwd
11
11
  * @param {() => {}} options.callback
12
12
  * @param {Boolean} options.throwNonZeroCode Throw if command return non 0 code.
13
- * @param {String} options.magentoVersion Magento version for config
14
13
  * @param {Record<string, string>} options.env Environment variables
15
14
  * @param {Boolean} options.useRosettaOnMac Use Rosetta 2 on MacOS
16
15
  */
17
- const runPhpCode = async (command, options = {}) => {
16
+ const runPhpCode = async (ctx, command, options = {}) => {
18
17
  const {
19
- throwNonZeroCode = true,
20
- magentoVersion = defaultConfiguration.magentoVersion
18
+ throwNonZeroCode = true
21
19
  } = options;
22
- const { php } = await getConfigFromMagentoVersion(magentoVersion);
23
- let spawnCommand = `${php.binPath} -c ${php.iniPath} ${command}`;
24
- if (options.env && Object.keys(options.env).length > 0) {
25
- const env = Object.entries(options.env).map(([key, value]) => `${key}=${value}`).join(' ');
26
- spawnCommand = `${env} ${spawnCommand}`;
27
- }
28
- if (options.useRosettaOnMac) {
29
- spawnCommand = `arch -x86_64 bash -c '${spawnCommand}'`;
30
- }
31
- const { code, result } = await execAsyncSpawn(spawnCommand, {
20
+ const { code, result } = await runPHPContainerCommand(ctx, `php ${command}`, {
32
21
  ...options,
33
22
  withCode: true
34
23
  });
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": "1.16.1",
6
+ "version": "2.0.0-alpha.0",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -23,22 +23,22 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "@scandipwa/scandipwa-dev-utils": "0.1.13",
26
- "conf": "10.1.1",
26
+ "conf": "10.1.2",
27
27
  "enquirer": "2.3.6",
28
28
  "eta": "1.12.3",
29
- "fast-xml-parser": "^4.0.7",
29
+ "fast-xml-parser": "^4.0.9",
30
30
  "hjson": "^3.2.2",
31
31
  "is-installed-globally": "0.4.0",
32
32
  "joi": "17.6.0",
33
33
  "listr2": "4.0.5",
34
34
  "macos-version": "5.2.1",
35
35
  "merge-files": "0.1.2",
36
- "mysql2": "2.3.2",
37
- "node-ssh": "12.0.0",
38
- "semver": "7.3.5",
36
+ "mysql2": "2.3.3",
37
+ "node-ssh": "12.0.5",
38
+ "semver": "7.3.7",
39
39
  "smol-request": "^2.1.2",
40
- "systeminformation": "5.11.7",
41
- "yargs": "17.3.1"
40
+ "systeminformation": "5.12.1",
41
+ "yargs": "17.5.1"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"
@@ -53,5 +53,5 @@
53
53
  "mysql",
54
54
  "scandipwa"
55
55
  ],
56
- "gitHead": "ced1b75c1b448ef198a658edf010f53179aaaeb0"
56
+ "gitHead": "a63454a3015891e4ebe5a7e84a0c88989a1d0edc"
57
57
  }
@@ -31,12 +31,8 @@ export interface ListrContext {
31
31
  edition?: 'community' | 'enterprise'
32
32
  config: {
33
33
  php: {
34
- binPath: string
35
- iniPath: string
36
34
  iniTemplatePath: string
37
- fpmBinPath: string
38
35
  fpmConfPath: string
39
- fpmPidFilePath: string
40
36
  extensions: PHPExtensions
41
37
  version: string
42
38
  }
@@ -57,7 +53,7 @@ export interface ListrContext {
57
53
  o: string
58
54
  }
59
55
  }>
60
- getContainers(): Record<'nginx' | 'redis' | 'mysql' | 'elasticsearch' | 'varnish', {
56
+ getContainers(): Record<'php' | 'sslTerminator' | 'nginx' | 'redis' | 'mysql' | 'elasticsearch' | 'varnish', {
61
57
  _: string
62
58
  ports: string[]
63
59
  healthCheck: {
@@ -70,10 +66,7 @@ export interface ListrContext {
70
66
  securityOptions: string[]
71
67
  network: string
72
68
  image: string
73
- imageDetails: {
74
- name: string
75
- tag: string
76
- }
69
+ debugImage?: string
77
70
  name: string
78
71
  command: string
79
72
  connectCommand: string[]
@@ -84,6 +77,7 @@ export interface ListrContext {
84
77
  magentoDir: string
85
78
  templateDir: string
86
79
  cacheDir: string
80
+ containerMagentoDir: string
87
81
  }
88
82
  overridenConfiguration: Omit<CMAConfiguration, 'prefix' | 'useNonOverlappingPorts'>
89
83
  userConfiguration: Omit<CMAConfiguration, 'prefix' | 'useNonOverlappingPorts'>
@@ -1,5 +1,3 @@
1
- import { ListrTaskWrapper } from 'listr2';
2
-
3
1
  import { ListrContext } from './context';
4
2
 
5
3
  /* eslint-disable no-use-before-define */
@@ -42,80 +40,56 @@ export interface VarnishConfiguration extends ServiceWithVersion {
42
40
  configTemplate: string
43
41
  }
44
42
 
45
- export interface PHPExtension extends Record<string, unknown> {
46
- version?: string
43
+ export interface PHPExtensionInstallationInstruction {
47
44
  /**
48
- * Name of the extension loaded to PHP.
49
- *
50
- * @example `libsodium` extension is using `sodium` extensionName because it is loaded into PHP as `sodium` extension
51
- * and dynamic library that it requires called `sodium`
45
+ * Alternative name for extension
52
46
  *
53
- * ```
54
- * {
55
- * php: {
56
- * extensions: {
57
- * libsodium: {
58
- * extensionName: 'sodium'
59
- * }
60
- * }
61
- * }
62
- * }
47
+ * @example ```js
48
+ * alternativeName: ['Zend OPcache']
63
49
  * ```
64
50
  */
65
- linuxOptions?: string
66
- macosOptions?: string
67
- extensionName?: string
68
- hooks?: {
69
- preEnable?: (config: CMAConfiguration['configuration']) => Promise<void> | void
70
- postEnable?: (config: CMAConfiguration['configuration']) => Promise<void> | void
71
- preDisable?: (config: CMAConfiguration['configuration']) => Promise<void> | void
72
- postDisable?: (config: CMAConfiguration['configuration']) => Promise<void> | void
73
- preInstall?: (config: CMAConfiguration['configuration']) => Promise<void> | void
74
- postInstall?: (config: CMAConfiguration['configuration']) => Promise<void> | void
75
- }
51
+ alternativeName?: string[]
76
52
  /**
77
- * Allow to define custom logic to install extension
53
+ * Command to install extension
54
+ *
55
+ * @example ```bash
56
+ * docker-php-ext-install bcmath
57
+ * ```
58
+ * @example ```bash
59
+ * pecl install xdebug && docker-php-ext-enable xdebug
60
+ * ```
78
61
  */
79
- install?: (
80
- ctx: ListrContext,
81
- task: ListrTaskWrapper<ListrContext, any>
82
- ) => Promise<void> | void
62
+ command: (arg0: (Omit<PHPExtensionInstallationInstruction, 'command'> & { ctx: ListrContext})) => string | string
83
63
 
84
64
  /**
85
- * Allow to define custom logic to enable an extension
65
+ * System dependencies required by the extension
66
+ *
67
+ * @example ```js
68
+ * dependencies: ['icu-dev']
69
+ * ```
86
70
  */
87
- enable?: (
88
- ctx: ListrContext,
89
- task: ListrTaskWrapper<ListrContext, any>
90
- ) => Promise<void> | void
71
+ dependencies?: string[]
91
72
 
92
73
  /**
93
- * Allow to define custom logic to disable an extension
74
+ * Extension version (if supported)
94
75
  */
95
- disable?: (
96
- ctx: ListrContext,
97
- task: ListrTaskWrapper<ListrContext, any>
98
- ) => Promise<void> | void
76
+ version?: string
99
77
  }
100
78
 
101
79
  export interface PHPExtensions {
102
- gd: PHPExtension
103
- intl: PHPExtension
104
- zlib: PHPExtension
105
- openssl: PHPExtension
106
- sockets: PHPExtension
107
- simpleXML: PHPExtension
108
- xdebug: PHPExtension
109
- fileinfo: PHPExtension
110
- libsodium: PHPExtension
111
- [key: string]: PHPExtension
80
+ [key: string]: PHPExtensionInstallationInstruction
112
81
  }
113
82
 
114
83
  export interface PHPConfiguration {
115
84
  /**
116
- * PHP version
85
+ * Base image with tag
117
86
  */
118
- version: string
87
+ baseImage?: string
88
+
89
+ /**
90
+ * Image with XDebug enabled
91
+ */
92
+ debugImage?: string
119
93
 
120
94
  /**
121
95
  * Configuration file template location
@@ -124,10 +98,17 @@ export interface PHPConfiguration {
124
98
  */
125
99
  configTemplate: string
126
100
 
101
+ /**
102
+ * PHP-FPM configuration file template location
103
+ *
104
+ * @example ./my-php-fpm-template.conf
105
+ */
106
+ fpmConfigTemplate: string
107
+
127
108
  /**
128
109
  * Extensions for PHP
129
110
  */
130
- extensions: PHPExtensions & Record<string, PHPExtension>
111
+ extensions: PHPExtensions
131
112
 
132
113
  /**
133
114
  * Disabled extension list
@@ -1,11 +0,0 @@
1
- const path = require('path');
2
-
3
- module.exports = ({ composer }, config) => {
4
- const { cacheDir } = config;
5
-
6
- return {
7
- dirPath: path.join(cacheDir, 'composer'),
8
- binPath: path.join(cacheDir, 'composer', 'composer.phar'),
9
- version: composer.version
10
- };
11
- };
@@ -1,36 +0,0 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
- const pathExists = require('../../../util/path-exists');
4
- const UnknownError = require('../../../errors/unknown-error');
5
- const phpbrewConfig = require('../../phpbrew');
6
-
7
- /**
8
- * @type {import('../../../../typings/index').PHPExtension}
9
- */
10
- module.exports = {
11
- extensionName: 'sodium',
12
- hooks: {
13
- postInstall: async ({ php }) => {
14
- const sodiumDynamicLibraryPath = path.join(
15
- phpbrewConfig.phpPath,
16
- `php-${php.version}`,
17
- 'var',
18
- 'db',
19
- 'libsodium.ini'
20
- );
21
-
22
- if (!await pathExists(sodiumDynamicLibraryPath)) {
23
- throw new UnknownError(`libsodium dynamic library file configuration not found: ${sodiumDynamicLibraryPath}`);
24
- }
25
- const fileContent = await fs.promises.readFile(sodiumDynamicLibraryPath, 'utf-8');
26
-
27
- if (/^extension=libsodium\.so$/.test(fileContent.trim())) {
28
- await fs.promises.writeFile(
29
- sodiumDynamicLibraryPath,
30
- 'extension=sodium.so\n',
31
- 'utf-8'
32
- );
33
- }
34
- }
35
- }
36
- };
@@ -1,25 +0,0 @@
1
- const path = require('path');
2
- const { xdebug } = require('../extensions');
3
-
4
- const php72 = ({ templateDir, additionalExtensions = {} }) => ({
5
- version: '7.2.34',
6
- configTemplate: path.join(templateDir || '', 'php.template.ini'),
7
- extensions: {
8
- gd: {
9
- macosOptions: '--with-zlib-dir=$(brew --prefix zlib) --with-freetype-dir=$(brew --prefix freetype)'
10
- },
11
- intl: {},
12
- zlib: {},
13
- openssl: {},
14
- sockets: {},
15
- SimpleXML: {},
16
- xdebug,
17
- apcu: {},
18
- opcache: {
19
- extensionName: 'Zend OPcache'
20
- },
21
- ...additionalExtensions
22
- }
23
- });
24
-
25
- module.exports = php72;