@scandipwa/magento-scripts 1.14.1-alpha.7 → 1.15.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 (177) hide show
  1. package/lib/commands/cli.js +9 -4
  2. package/lib/commands/logs.js +1 -0
  3. package/lib/commands/start.js +18 -5
  4. package/lib/config/cma-config.js +16 -0
  5. package/lib/config/dependencies-for-platforms.js +15 -3
  6. package/lib/config/docker.js +46 -13
  7. package/lib/config/get-port-config.js +7 -2
  8. package/lib/config/index.js +2 -1
  9. package/lib/config/php/extensions/libsodium.js +2 -1
  10. package/lib/config/port-config.js +2 -1
  11. package/lib/config/scandipwa-versions.js +2 -1
  12. package/lib/config/ssl-terminator/index.js +10 -0
  13. package/lib/config/system-config.js +34 -5
  14. package/lib/config/templates/magentorc.template +2 -0
  15. package/lib/config/templates/nginx.template.conf +0 -31
  16. package/lib/config/templates/ssl-terminator.template.conf +27 -0
  17. package/lib/config/templates/varnish.template.vcl +9 -4
  18. package/lib/config/versions/magento-2.3.0.js +3 -1
  19. package/lib/config/versions/magento-2.3.1.js +3 -1
  20. package/lib/config/versions/magento-2.3.2-p2.js +3 -1
  21. package/lib/config/versions/magento-2.3.2.js +3 -1
  22. package/lib/config/versions/magento-2.3.3-p1.js +3 -1
  23. package/lib/config/versions/magento-2.3.3.js +3 -1
  24. package/lib/config/versions/magento-2.3.4-p2.js +3 -1
  25. package/lib/config/versions/magento-2.3.4.js +3 -1
  26. package/lib/config/versions/magento-2.3.5-p1.js +3 -1
  27. package/lib/config/versions/magento-2.3.5-p2.js +3 -1
  28. package/lib/config/versions/magento-2.3.5.js +3 -1
  29. package/lib/config/versions/magento-2.3.6-p1.js +3 -1
  30. package/lib/config/versions/magento-2.3.6.js +3 -1
  31. package/lib/config/versions/magento-2.3.7-p1.js +3 -1
  32. package/lib/config/versions/magento-2.3.7-p2.js +3 -1
  33. package/lib/config/versions/magento-2.3.7-p3.js +3 -1
  34. package/lib/config/versions/magento-2.3.7.js +3 -1
  35. package/lib/config/versions/magento-2.4.0-p1.js +3 -1
  36. package/lib/config/versions/magento-2.4.0.js +3 -1
  37. package/lib/config/versions/magento-2.4.1-p1.js +3 -1
  38. package/lib/config/versions/magento-2.4.1.js +3 -1
  39. package/lib/config/versions/magento-2.4.2-p1.js +3 -1
  40. package/lib/config/versions/magento-2.4.2-p2.js +3 -1
  41. package/lib/config/versions/magento-2.4.2.js +3 -1
  42. package/lib/config/versions/magento-2.4.3-p1.js +3 -1
  43. package/lib/config/versions/magento-2.4.3-p2.js +3 -1
  44. package/lib/config/versions/magento-2.4.3.js +3 -1
  45. package/lib/config/versions/magento-2.4.4.js +3 -1
  46. package/lib/config/xml-parser.js +63 -0
  47. package/lib/errors/known-error.js +15 -0
  48. package/lib/errors/unknown-error.js +15 -0
  49. package/lib/tasks/cli/create-bashrc-config.js +2 -1
  50. package/lib/tasks/composer/index.js +5 -3
  51. package/lib/tasks/composer/local-auth-json.js +8 -4
  52. package/lib/tasks/docker/network.js +2 -1
  53. package/lib/tasks/execute/index.js +2 -3
  54. package/lib/tasks/file-system/create-nginx-config.js +4 -43
  55. package/lib/tasks/file-system/create-php-config.js +2 -1
  56. package/lib/tasks/file-system/create-php-fpm-config.js +2 -1
  57. package/lib/tasks/file-system/create-phpstorm-config/database-config.js +249 -0
  58. package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +85 -0
  59. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +154 -0
  60. package/lib/tasks/file-system/create-phpstorm-config/index.js +27 -0
  61. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +26 -0
  62. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/config.js +54 -0
  63. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +28 -0
  64. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +42 -0
  65. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/eslint-inspection-config.js +37 -0
  66. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/index.js +80 -0
  67. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +26 -0
  68. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +142 -0
  69. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/paths.js +20 -0
  70. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-fixer-validation-inspection-config.js +60 -0
  71. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +116 -0
  72. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/stylelint-inspection-config.js +37 -0
  73. package/lib/tasks/file-system/create-phpstorm-config/keys.js +14 -0
  74. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +67 -0
  75. package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +54 -0
  76. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +66 -0
  77. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +58 -0
  78. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +59 -0
  79. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +77 -0
  80. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +97 -0
  81. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/format-setting-config.js +57 -0
  82. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +66 -0
  83. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +64 -0
  84. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +57 -0
  85. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +49 -0
  86. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +64 -0
  87. package/lib/tasks/file-system/create-phpstorm-config/xml-utils.js +5 -0
  88. package/lib/tasks/file-system/create-ssl-terminator-config.js +96 -0
  89. package/lib/tasks/file-system/create-varnish-config.js +2 -1
  90. package/lib/tasks/file-system/create-vscode-config.js +3 -2
  91. package/lib/tasks/file-system/index.js +3 -1
  92. package/lib/tasks/magento/enable-magento-composer-plugins.js +3 -2
  93. package/lib/tasks/magento/install-magento.js +7 -5
  94. package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +26 -0
  95. package/lib/tasks/magento/setup-magento/delete-admin-users.js +1 -1
  96. package/lib/tasks/magento/setup-magento/delete-customers.js +7 -4
  97. package/lib/tasks/magento/setup-magento/delete-orders.js +6 -4
  98. package/lib/tasks/magento/setup-magento/flush-redis-config.js +2 -1
  99. package/lib/tasks/magento/setup-magento/index.js +3 -1
  100. package/lib/tasks/magento/setup-magento/install-magento.js +2 -1
  101. package/lib/tasks/magento/setup-magento/set-base-url.js +7 -2
  102. package/lib/tasks/magento/setup-magento/upgrade-magento.js +11 -1
  103. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +41 -0
  104. package/lib/tasks/mysql/connect-to-mysql.js +2 -1
  105. package/lib/tasks/mysql/import-dump-to-mysql.js +13 -2
  106. package/lib/tasks/mysql/import-remote-db/index.js +2 -1
  107. package/lib/tasks/mysql/import-remote-db/ssh/index.js +2 -1
  108. package/lib/tasks/mysql/import-remote-db/ssh/regular-server.js +2 -1
  109. package/lib/tasks/php/bundled-extensions.js +28 -0
  110. package/lib/tasks/php/compile-options.js +27 -54
  111. package/lib/tasks/php/compile.js +6 -4
  112. package/lib/tasks/php/configure.js +7 -66
  113. package/lib/tasks/php/extensions/disable.js +2 -1
  114. package/lib/tasks/php/extensions/enable.js +2 -1
  115. package/lib/tasks/php/extensions/index.js +74 -0
  116. package/lib/tasks/php/extensions/install.js +3 -3
  117. package/lib/tasks/php/index.js +7 -6
  118. package/lib/tasks/php/install-sodium.js +93 -0
  119. package/lib/tasks/php/update-phpbrew.js +7 -3
  120. package/lib/tasks/php/validate-php.js +67 -0
  121. package/lib/tasks/php-fpm/start-php-fpm.js +4 -2
  122. package/lib/tasks/requirements/composer.js +59 -5
  123. package/lib/tasks/requirements/dependency/arch.js +2 -1
  124. package/lib/tasks/requirements/dependency/centos.js +2 -1
  125. package/lib/tasks/requirements/dependency/fedora.js +2 -1
  126. package/lib/tasks/requirements/dependency/mac.js +18 -3
  127. package/lib/tasks/requirements/docker/index.js +94 -40
  128. package/lib/tasks/requirements/docker/install-on-mac.js +29 -0
  129. package/lib/tasks/requirements/docker/install.js +2 -1
  130. package/lib/tasks/requirements/docker/running-status.js +32 -31
  131. package/lib/tasks/requirements/docker/version.js +2 -1
  132. package/lib/tasks/requirements/index.js +3 -0
  133. package/lib/tasks/requirements/node-version.js +2 -1
  134. package/lib/tasks/requirements/php-version.js +26 -24
  135. package/lib/tasks/requirements/phpbrew/index.js +2 -1
  136. package/lib/tasks/requirements/phpbrew/install.js +14 -2
  137. package/lib/tasks/requirements/phpbrew/version.js +2 -1
  138. package/lib/tasks/requirements/platform.js +5 -3
  139. package/lib/tasks/requirements/rosetta.js +32 -0
  140. package/lib/tasks/start.js +10 -2
  141. package/lib/tasks/status/index.js +24 -8
  142. package/lib/tasks/theme/build-theme.js +2 -1
  143. package/lib/tasks/theme/install-theme.js +2 -1
  144. package/lib/tasks/theme/link-theme.js +2 -2
  145. package/lib/tasks/theme/retrieve-theme-data.js +2 -1
  146. package/lib/tasks/theme/setup-persisted-query.js +2 -1
  147. package/lib/tasks/theme/setup-themes.js +10 -3
  148. package/lib/tasks/theme/symlink-theme.js +8 -1
  149. package/lib/util/CSA-theme.js +4 -0
  150. package/lib/util/analytics.js +317 -0
  151. package/lib/util/arch.js +1 -1
  152. package/lib/util/config-file-validator.js +4 -2
  153. package/lib/util/config-php-json.js +3 -2
  154. package/lib/util/env-php-json.js +3 -2
  155. package/lib/util/exec-async-command.d.ts +2 -0
  156. package/lib/util/exec-async-command.js +31 -15
  157. package/lib/util/exec-async.js +9 -0
  158. package/lib/util/get-brew-bin-path.js +64 -0
  159. package/lib/util/get-installed-magento-version.js +3 -2
  160. package/lib/util/get-jsonfile-data.js +2 -1
  161. package/lib/util/install-dependencies-task.js +15 -5
  162. package/lib/util/instance-metadata.js +11 -4
  163. package/lib/util/ip.js +47 -1
  164. package/lib/util/magento-task.js +20 -9
  165. package/lib/util/php-task.js +7 -7
  166. package/lib/util/request.js +0 -0
  167. package/lib/util/resolve-configuration-with-overrides.js +2 -1
  168. package/lib/util/run-composer.js +5 -3
  169. package/lib/util/run-magento.js +3 -2
  170. package/lib/util/run-php.js +7 -2
  171. package/lib/util/wait-for-it.js +3 -2
  172. package/package.json +5 -3
  173. package/typings/context.d.ts +4 -0
  174. package/typings/index.d.ts +13 -1
  175. package/typings/phpstorm.d.ts +33 -0
  176. package/lib/tasks/file-system/create-php-storm-config.js +0 -82
  177. package/lib/tasks/magento/setup-magento/disable-full-page-cache.js +0 -20
@@ -0,0 +1,67 @@
1
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
2
+ const { bundledExtensions } = require('./bundled-extensions');
3
+ const configurePHP = require('./configure');
4
+ const { getEnabledExtensions } = require('./extensions');
5
+ const { installPhp } = require('./index');
6
+
7
+ /**
8
+ * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
9
+ */
10
+ const validatePHPInstallation = () => ({
11
+ title: 'Validating PHP installation',
12
+ task: async (ctx, task) => {
13
+ const enabledExtensions = await getEnabledExtensions(ctx.config);
14
+ const enabledExtensionsKeys = Object.keys(enabledExtensions);
15
+
16
+ enabledExtensionsKeys.push('fpm');
17
+
18
+ if (enabledExtensionsKeys.some((ext) => ext.includes('mysql'))) {
19
+ enabledExtensionsKeys.push('mysql');
20
+ }
21
+
22
+ const missingBundledExtensions = bundledExtensions.filter(
23
+ (ext) => !enabledExtensionsKeys.some(
24
+ (ex) => ex.toLowerCase() === ext.toLowerCase()
25
+ )
26
+ );
27
+
28
+ if (missingBundledExtensions.length > 0) {
29
+ const selectedOption = await task.prompt({
30
+ type: 'Select',
31
+ message: `Your PHP version compiled by PHPBrew is missing important extensions that are bundled by default by ${logger.style.misc('magento-scripts')}
32
+ Maybe you ran PHPBrew by yourself?
33
+
34
+ Please, consider recompiling PHP using ${logger.style.misc('magento-scripts')}.
35
+
36
+ ${logger.style.command('npm start -- --recompile-php')}
37
+ `,
38
+ choices: [
39
+ {
40
+ name: 'recompile-php',
41
+ message: `I want ${logger.style.misc('magento-scripts')} to recompile PHP`
42
+ },
43
+ {
44
+ name: 'skip',
45
+ message: 'I am sure that it is okay and want to continue with this setup'
46
+ }
47
+ ]
48
+ });
49
+
50
+ if (selectedOption === 'skip') {
51
+ task.skip('User skipped PHP recompilation');
52
+ return;
53
+ }
54
+
55
+ ctx.recompilePhp = true;
56
+
57
+ return task.newListr([
58
+ installPhp(),
59
+ configurePHP()
60
+ ], {
61
+ concurrent: false
62
+ });
63
+ }
64
+ }
65
+ });
66
+
67
+ module.exports = validatePHPInstallation;
@@ -2,6 +2,7 @@ const { execAsyncSpawn } = require('../../util/exec-async-command');
2
2
  const getPhpConfig = require('../../config/php-config');
3
3
  const { getBaseConfig } = require('../../config/index');
4
4
  const getProcessId = require('./get-process-id');
5
+ const UnknownError = require('../../errors/unknown-error');
5
6
 
6
7
  /**
7
8
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
@@ -31,11 +32,12 @@ const startPhpFpm = () => ({
31
32
  {
32
33
  callback: (t) => {
33
34
  task.output = t;
34
- }
35
+ },
36
+ useRosetta2: true
35
37
  }
36
38
  );
37
39
  } catch (e) {
38
- throw new Error(`Error during PHP-FPM start\n\n${e}`);
40
+ throw new UnknownError(`Error during PHP-FPM start\n\n${e}`);
39
41
  }
40
42
  },
41
43
  options: {
@@ -1,8 +1,11 @@
1
+ /* eslint-disable no-nested-ternary */
1
2
  const path = require('path');
2
3
  const fs = require('fs');
3
4
  const os = require('os');
4
5
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
5
6
  const pathExists = require('../../util/path-exists');
7
+ const KnownError = require('../../errors/known-error');
8
+ const UnknownError = require('../../errors/unknown-error');
6
9
 
7
10
  const authJsonPath = path.join(process.cwd(), 'auth.json');
8
11
  const shellName = process.env.SHELL.split('/').pop();
@@ -86,8 +89,8 @@ ${ logger.style.misc('Password') } (${ logger.style.misc('Private key') }):`,
86
89
  const authContent = {
87
90
  'http-basic': {
88
91
  'repo.magento.com': {
89
- username: usernameCredentials,
90
- password: passwordCredentials
92
+ username: usernameCredentials.trim(),
93
+ password: passwordCredentials.trim()
91
94
  }
92
95
  }
93
96
  };
@@ -112,7 +115,7 @@ ${ logger.style.misc('Password') } (${ logger.style.misc('Private key') }):`,
112
115
  break;
113
116
  }
114
117
  default: {
115
- throw new Error(
118
+ throw new KnownError(
116
119
  `Unfortunately we cannot automatically add credentials for your shell ${process.env.SHELL}!
117
120
 
118
121
  You will need to that manually!
@@ -193,9 +196,60 @@ Would you like to load them now?`
193
196
 
194
197
  composerAuthContent = JSON.parse(composerAuthFileContent);
195
198
 
199
+ // eslint-disable-next-line max-len
200
+ const repoMagentoCredentials = composerAuthContent && composerAuthContent['http-basic'] && composerAuthContent['http-basic']['repo.magento.com'];
201
+
202
+ const hasEmptyCharacterInUsername = repoMagentoCredentials && /\s/i.test(repoMagentoCredentials.username);
203
+ const hasEmptyCharacterInPassword = repoMagentoCredentials && /\s/i.test(repoMagentoCredentials.password);
204
+
205
+ // TODO refactor to check all fields, not only for magento
206
+ const message = (hasEmptyCharacterInUsername && hasEmptyCharacterInPassword)
207
+ ? `Both ${logger.style.misc('username')} and ${logger.style.misc('password')} fields in ${logger.style.misc('http-basic -> repo.magento.com')} in ${logger.style.file('./auth.json')} contains empty characters (spaces).
208
+ Do you want to remove them now? File will be overwritten.`
209
+ : hasEmptyCharacterInUsername
210
+ ? `Your ${logger.style.misc('http-basic -> repo.magento.com -> username')} field in ${logger.style.file('./auth.json')} contains empty characters (spaces).
211
+ Do you want to remove them now? File will be overwritten.`
212
+ : hasEmptyCharacterInPassword
213
+ ? `Your ${logger.style.misc('http-basic -> repo.magento.com -> password')} field in ${logger.style.file('./auth.json')} contains empty characters (spaces).
214
+ Do you want to remove them now? File will be overwritten.`
215
+ : null;
216
+
217
+ if (message) {
218
+ const response = await task.prompt({
219
+ message,
220
+ type: 'Select',
221
+ choices: [
222
+ {
223
+ name: 'overwrite',
224
+ message: 'Yes, please!'
225
+ },
226
+ {
227
+ name: 'skip',
228
+ message: 'No, I know what I\'m doing'
229
+ }
230
+ ]
231
+ });
232
+
233
+ if (response === 'overwrite') {
234
+ if (repoMagentoCredentials.username) {
235
+ repoMagentoCredentials.username = repoMagentoCredentials.username.replace(/\s/i, '');
236
+ }
237
+
238
+ if (repoMagentoCredentials.password) {
239
+ repoMagentoCredentials.password = repoMagentoCredentials.password.replace(/\s/i, '');
240
+ }
241
+
242
+ await fs.promises.writeFile(
243
+ authJsonPath,
244
+ JSON.stringify(composerAuthContent, null, 4),
245
+ 'utf-8'
246
+ );
247
+ }
248
+ }
249
+
196
250
  process.env.COMPOSER_AUTH = composerAuthFileContent;
197
251
  } catch (e) {
198
- throw new Error(
252
+ throw new UnknownError(
199
253
  `We found an error in your ${ logger.style.file('./auth.json') } file.
200
254
 
201
255
  Make sure that this file contains a valid JSON!
@@ -211,7 +265,7 @@ Error message that we got: ${e}`
211
265
  try {
212
266
  composerAuthContent = JSON.parse(process.env.COMPOSER_AUTH);
213
267
  } catch (e) {
214
- throw new Error(
268
+ throw new UnknownError(
215
269
  `We found an error in your ${ logger.style.misc('$COMPOSER_AUTH') } environment variable.
216
270
 
217
271
  Make sure that this variable contains a valid JSON!
@@ -1,4 +1,5 @@
1
1
  const dependenciesForPlatforms = require('../../../config/dependencies-for-platforms');
2
+ const UnknownError = require('../../../errors/unknown-error');
2
3
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
3
4
  const installDependenciesTask = require('../../../util/install-dependencies-task');
4
5
 
@@ -15,7 +16,7 @@ const archDependenciesCheck = () => ({
15
16
  const result = pkg.match(pkgRegex);
16
17
 
17
18
  if (!result) {
18
- throw new Error(`Package without a version!\n\n${pkg}\n\nHOW?`);
19
+ throw new UnknownError(`Package without a version!\n\n${pkg}\n\nHOW?`);
19
20
  }
20
21
 
21
22
  return result[1];
@@ -11,9 +11,10 @@ const centosDependenciesCheck = () => ({
11
11
  const installedDependencies = (await execAsyncSpawn('yum list installed')).split('\n')
12
12
  .filter((pkg) => !pkg.toLowerCase().includes('installed packages'))
13
13
  .map((pkg) => pkg.match(/^(\S+)/i))
14
- .filter((pkg) => pkg)
14
+ .filter(Boolean)
15
15
  .map((pkg) => pkg[1])
16
16
  .map((pkg) => pkg.match(/^(\S+)\.\S+/i))
17
+ .filter(Boolean)
17
18
  .map((pkg) => pkg[1]);
18
19
 
19
20
  const dependenciesToInstall = dependenciesForPlatforms
@@ -11,9 +11,10 @@ const fedoraDependenciesCheck = () => ({
11
11
  const installedDependencies = (await execAsyncSpawn('yum list installed')).split('\n')
12
12
  .filter((pkg) => !pkg.toLowerCase().includes('installed packages'))
13
13
  .map((pkg) => pkg.match(/^(\S+)/i))
14
- .filter((pkg) => pkg)
14
+ .filter(Boolean)
15
15
  .map((pkg) => pkg[1])
16
16
  .map((pkg) => pkg.match(/^(\S+)\.\S+/i))
17
+ .filter(Boolean)
17
18
  .map((pkg) => pkg[1]);
18
19
 
19
20
  const dependenciesToInstall = dependenciesForPlatforms
@@ -1,14 +1,28 @@
1
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
1
2
  const dependenciesForPlatforms = require('../../../config/dependencies-for-platforms');
3
+ const KnownError = require('../../../errors/known-error');
2
4
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
5
+ const {
6
+ BREW_BIN_PATH_ARM_NATIVE,
7
+ BREW_BIN_PATH_ARM_ROSETTA,
8
+ getBrewCommand
9
+ } = require('../../../util/get-brew-bin-path');
3
10
  const installDependenciesTask = require('../../../util/install-dependencies-task');
4
-
11
+ const pathExists = require('../../../util/path-exists');
5
12
  /**
6
13
  * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
7
14
  */
8
15
  const macDependenciesCheck = () => ({
9
16
  title: 'Checking MacOS dependencies',
10
17
  task: async (ctx, task) => {
11
- const installedDependencies = (await execAsyncSpawn('brew list')).split('\n');
18
+ if (ctx.arch === 'arm64') {
19
+ if (!await pathExists(BREW_BIN_PATH_ARM_ROSETTA) && await pathExists(BREW_BIN_PATH_ARM_NATIVE)) {
20
+ throw new KnownError(`Missing rosetta brew!
21
+ Please make sure that you have installed brew in rosetta2 terminal!
22
+ Follow the instructions: ${logger.style.link('https://docs.create-magento-app.com/getting-started/prerequisites/installation-on-macos/installation-on-macos-apple-silicon')}`);
23
+ }
24
+ }
25
+ const installedDependencies = (await execAsyncSpawn(`${await getBrewCommand()} list`)).split('\n');
12
26
 
13
27
  const dependenciesToInstall = dependenciesForPlatforms
14
28
  .darwin
@@ -19,7 +33,8 @@ const macDependenciesCheck = () => ({
19
33
  return task.newListr(
20
34
  installDependenciesTask({
21
35
  platform: 'darwin',
22
- dependenciesToInstall
36
+ dependenciesToInstall,
37
+ useMacNativeEnvironment: false
23
38
  })
24
39
  );
25
40
  }
@@ -1,12 +1,94 @@
1
1
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
2
- const os = require('os');
2
+ const KnownError = require('../../../errors/known-error');
3
3
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
4
- const getIsWsl = require('../../../util/is-wsl');
4
+ const openBrowser = require('../../../util/open-browser');
5
5
  const installDocker = require('./install');
6
+ const installDockerOnMac = require('./install-on-mac');
6
7
  const { checkDockerSocketPermissions } = require('./permissions');
7
8
  const checkDockerStatus = require('./running-status');
8
9
  const getDockerVersion = require('./version');
9
10
 
11
+ const dockerInstallPromptLinux = async (task) => {
12
+ const automaticallyInstallDocker = await task.prompt({
13
+ type: 'Confirm',
14
+ message: `You don't have Docker installed!
15
+ Do you want to install it automatically?
16
+ NOTE: After installation it's recommended to log out and log back in so your group membership is re-evaluated!`
17
+ });
18
+
19
+ if (automaticallyInstallDocker) {
20
+ return task.newListr([
21
+ installDocker(),
22
+ getDockerVersion(),
23
+ {
24
+ task: (ctx) => {
25
+ task.title = `Using docker version ${ctx.dockerVersion}`;
26
+
27
+ throw new KnownError(
28
+ `Docker is installed successfully!
29
+ Please log out and log back to so your group membership is re-evaluated!
30
+ Learn more here: ${ logger.style.link('https://docs.docker.com/engine/install/linux-postinstall/') }`
31
+ );
32
+ }
33
+ }
34
+ ]);
35
+ }
36
+
37
+ throw new KnownError('Docker is not installed!');
38
+ };
39
+
40
+ // maybe in the future docker will be possible to install on wsl from terminal...
41
+ const dockerInstallPromptWindows = () => {
42
+ throw new KnownError(
43
+ `You don't have Docker installed!
44
+ Follow this instructions to install Docker on Windows:
45
+ ${ logger.style.link('https://docs.create-magento-app.com/getting-started/prerequisites/windows-requirements#2-install-docker-desktop-for-windows') }`
46
+ );
47
+ };
48
+
49
+ /**
50
+ *
51
+ * @param {import('listr2').ListrTaskWrapper} task
52
+ */
53
+ const dockerInstallPromptMacOS = async (task) => {
54
+ const confirmationToInstallDocker = await task.prompt({
55
+ type: 'Select',
56
+ message: `You don't have Docker installed!
57
+ Would you like to install it automatically using brew cask or you prefer to install it manually?`,
58
+ choices: [
59
+ {
60
+ name: 'automatic',
61
+ message: 'Install Docker using brew cask'
62
+ },
63
+ {
64
+ name: 'manually',
65
+ message: 'Install Docker manually'
66
+ }
67
+ ]
68
+ });
69
+
70
+ if (confirmationToInstallDocker === 'automatic') {
71
+ return task.newListr([
72
+ installDockerOnMac(),
73
+ checkDockerStatus(),
74
+ getDockerVersion(),
75
+ {
76
+ task: (ctx) => {
77
+ task.title = `Using Docker version ${ctx.dockerVersion}`;
78
+ }
79
+ }
80
+ ]);
81
+ }
82
+
83
+ const dockerInstallLink = 'https://docs.create-magento-app.com/getting-started/prerequisites/installation-on-macos#3.-install-docker-for-mac';
84
+ await openBrowser(dockerInstallLink);
85
+
86
+ throw new KnownError(
87
+ `Follow this instructions to install Docker on Mac:
88
+ ${ logger.style.link(dockerInstallLink) }`
89
+ );
90
+ };
91
+
10
92
  /**
11
93
  * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
12
94
  */
@@ -18,46 +100,18 @@ const checkDocker = () => ({
18
100
  });
19
101
 
20
102
  if (code !== 0) {
21
- const isWsl = await getIsWsl();
22
- if (os.platform() === 'linux' && !isWsl) {
23
- const automaticallyInstallDocker = await task.prompt({
24
- type: 'Confirm',
25
- message: `You don't have Docker installed!
26
- Do you want to install it automatically?
27
- NOTE: After installation it's recommended to log out and log back in so your group membership is re-evaluated!`
28
- });
29
-
30
- if (automaticallyInstallDocker) {
31
- return task.newListr([
32
- installDocker(),
33
- getDockerVersion(),
34
- {
35
- task: (ctx) => {
36
- task.title = `Using docker version ${ctx.dockerVersion}`;
37
-
38
- throw new Error(
39
- `Docker is installed successfully!
40
- Please log out and log back to so your group membership is re-evaluated!
41
- Learn more here: ${ logger.style.link('https://docs.docker.com/engine/install/linux-postinstall/') }`
42
- );
43
- }
44
- }
45
- ]);
103
+ if (ctx.platform === 'linux' && !ctx.isWsl) {
104
+ const result = await dockerInstallPromptLinux(task);
105
+ if (result) {
106
+ return result;
46
107
  }
47
-
48
- throw new Error('Docker is not installed!');
49
- } else if (isWsl) {
50
- throw new Error(
51
- `You don't have Docker installed!
52
- Follow this instructions to install Docker on Windows:
53
- ${ logger.style.link('https://docs.create-magento-app.com/getting-started/prerequisites/windows-requirements#2-install-docker-desktop-for-windows') }`
54
- );
108
+ } else if (ctx.isWsl) {
109
+ dockerInstallPromptWindows();
55
110
  } else {
56
- throw new Error(
57
- `You don't have Docker installed!
58
- Follow this instructions to install Docker on Mac:
59
- ${ logger.style.link('https://docs.create-magento-app.com/getting-started/prerequisites/installation-on-macos#3-install-docker-for-mac') }`
60
- );
111
+ const result = await dockerInstallPromptMacOS(task);
112
+ if (result) {
113
+ return result;
114
+ }
61
115
  }
62
116
  }
63
117
 
@@ -0,0 +1,29 @@
1
+ const { execAsyncSpawn } = require('../../../util/exec-async-command');
2
+ const { getBrewCommand } = require('../../../util/get-brew-bin-path');
3
+
4
+ /**
5
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
6
+ */
7
+ const installDockerOnMac = () => ({
8
+ title: 'Installing Docker on Mac OS',
9
+ task: async (ctx, task) => {
10
+ const interval = !ctx.verbose ? setInterval(() => {
11
+ task.output = `Installing Docker on Mac... Yep, still in progress ${new Date().toUTCString()}`;
12
+ }, 5000) : null;
13
+
14
+ await execAsyncSpawn(`${await getBrewCommand({ native: true })} install --cask docker`, {
15
+ callback: !ctx.verbose ? undefined : (t) => {
16
+ task.output = t;
17
+ }
18
+ });
19
+
20
+ if (!ctx.verbose) {
21
+ clearInterval(interval);
22
+ }
23
+ },
24
+ options: {
25
+ bottomBar: 10
26
+ }
27
+ });
28
+
29
+ module.exports = installDockerOnMac;
@@ -2,6 +2,7 @@ const osPlatform = require('../../../util/os-platform');
2
2
  const { execCommandTask } = require('../../../util/exec-async-command');
3
3
  const installDependenciesTask = require('../../../util/install-dependencies-task');
4
4
  const executeSudoCommand = require('../../../util/execute-sudo-command');
5
+ const KnownError = require('../../../errors/known-error');
5
6
 
6
7
  const downloadDockerInstallScriptCommand = () => execCommandTask('curl -fsSL https://get.docker.com -o get-docker.sh');
7
8
  const runDockerInstallScriptCommand = () => executeSudoCommand('sudo sh get-docker.sh');
@@ -48,7 +49,7 @@ const installDocker = () => ({
48
49
  ]);
49
50
  }
50
51
  default: {
51
- throw new Error(`Docker is not installed!
52
+ throw new KnownError(`Docker is not installed!
52
53
  Your distro ${distro} is not supported by automatic installation.`);
53
54
  }
54
55
  }
@@ -1,6 +1,5 @@
1
- const os = require('os');
1
+ const KnownError = require('../../../errors/known-error');
2
2
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
3
- const getIsWsl = require('../../../util/is-wsl');
4
3
  const pathExists = require('../../../util/path-exists');
5
4
  const sleep = require('../../../util/sleep');
6
5
  const { systemctlControl } = require('../../../util/systemctl');
@@ -19,38 +18,40 @@ const checkDockerStatusMacOS = () => ({
19
18
  task: async (ctx, task) => {
20
19
  const { result, code } = await getDockerVersion();
21
20
 
22
- if (code !== 0 && result.includes('Is the docker daemon running?')) {
23
- const dockerOpenAppConfirmation = await task.prompt({
24
- type: 'Confirm',
25
- message: 'Looks like Docker is not running, would you like us to open a Docker for Mac application and wait for it to start up?'
26
- });
27
-
28
- if (dockerOpenAppConfirmation && await pathExists(pathToDockerApplication)) {
29
- await execAsyncSpawn(`open ${pathToDockerApplication}`);
30
- let ready = false;
31
- let attempts = 0;
32
- while (!ready) {
33
- if (attempts > 24 && !ready) {
34
- throw new Error('Docker haven\'t started in 2 mins, exiting...');
35
- }
36
- try {
37
- const { code: startupCode } = await getDockerVersion();
38
- if (startupCode !== 0) {
39
- task.output = `Waiting for Docker to startup for ${attempts * 5} seconds...`;
40
- attempts++;
41
- await sleep(5000);
42
- } else {
43
- ready = true;
21
+ if (code !== 0) {
22
+ if (result.includes('Is the docker daemon running?') || result.includes('docker: command not found')) {
23
+ const dockerOpenAppConfirmation = await task.prompt({
24
+ type: 'Confirm',
25
+ message: 'Looks like Docker is not running, would you like us to open a Docker for Mac application and wait for it to start up?'
26
+ });
27
+
28
+ if (dockerOpenAppConfirmation && await pathExists(pathToDockerApplication)) {
29
+ await execAsyncSpawn(`open ${pathToDockerApplication}`);
30
+ let ready = false;
31
+ let attempts = 0;
32
+ while (!ready) {
33
+ if (attempts > 24 && !ready) {
34
+ throw new KnownError('Docker haven\'t started in 2 mins, exiting...');
44
35
  }
45
- } catch (e) {
36
+ try {
37
+ const { code: startupCode } = await getDockerVersion();
38
+ if (startupCode !== 0) {
39
+ task.output = `Waiting for Docker to startup for ${attempts * 5} seconds...`;
40
+ attempts++;
41
+ await sleep(5000);
42
+ } else {
43
+ ready = true;
44
+ }
45
+ } catch (e) {
46
46
  //
47
+ }
47
48
  }
49
+
50
+ return;
48
51
  }
49
52
 
50
- return;
53
+ task.skip('User skipped running Docker');
51
54
  }
52
-
53
- task.skip('User skipped running Docker');
54
55
  }
55
56
  },
56
57
  options: {
@@ -67,7 +68,7 @@ const checkDockerStatusWSL = () => ({
67
68
  const { result, code } = await getDockerVersion();
68
69
 
69
70
  if (code !== 0 && result.includes('Is the docker daemon running?')) {
70
- throw new Error(`Docker is not running!
71
+ throw new KnownError(`Docker is not running!
71
72
 
72
73
  Please open Docker Desktop application for Windows and make sure that Docker is running. Then you can try again!`);
73
74
  }
@@ -123,10 +124,10 @@ This action requires root privileges.`
123
124
  const checkDockerStatus = () => ({
124
125
  title: 'Checking Docker status',
125
126
  task: async (ctx, task) => {
126
- if (os.platform() === 'darwin') {
127
+ if (ctx.platform === 'darwin') {
127
128
  return task.newListr(checkDockerStatusMacOS());
128
129
  }
129
- if (!await getIsWsl()) {
130
+ if (!ctx.isWsl) {
130
131
  return task.newListr(checkDockerStatusLinux());
131
132
  }
132
133
 
@@ -1,3 +1,4 @@
1
+ const UnknownError = require('../../../errors/unknown-error');
1
2
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
2
3
 
3
4
  /**
@@ -14,7 +15,7 @@ const getDockerVersion = () => ({
14
15
 
15
16
  ctx.dockerVersion = dockerVersion;
16
17
  } else {
17
- throw new Error(`Got unexpected result during Docker version retrieval!\n\n${ result }`);
18
+ throw new UnknownError(`Got unexpected result during Docker version retrieval!\n\n${ result }`);
18
19
  }
19
20
  }
20
21
  });
@@ -4,6 +4,7 @@ const checkComposer = require('./composer');
4
4
  const checkDocker = require('./docker');
5
5
  const checkNodeVersion = require('./node-version');
6
6
  const checkPHPVersion = require('./php-version');
7
+ const checkRosetta = require('./rosetta');
7
8
 
8
9
  /**
9
10
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
@@ -13,6 +14,8 @@ const checkRequirements = () => ({
13
14
  task: (ctx, task) => task.newListr([
14
15
  // checking if user is on supported platform
15
16
  checkPlatform(),
17
+ // check if rosetta 2 is installed or not on m1 macs
18
+ checkRosetta(),
16
19
  // check the Docker installation
17
20
  checkDocker(),
18
21
  // check for Node.js version
@@ -1,4 +1,5 @@
1
1
  const semver = require('semver');
2
+ const KnownError = require('../../errors/known-error');
2
3
 
3
4
  /**
4
5
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
@@ -9,7 +10,7 @@ const checkNodeVersion = () => ({
9
10
  const { node } = process.versions;
10
11
 
11
12
  if (!semver.gte(node, '12.0.0')) {
12
- throw new Error(
13
+ throw new KnownError(
13
14
  `Your Node.js version is out of date!
14
15
  You need to upgrade Node.js to at lease version 12 to work with this software!`
15
16
  );