@scandipwa/magento-scripts 1.14.1-alpha.9 → 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 (143) 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 +4 -3
  7. package/lib/config/get-port-config.js +2 -1
  8. package/lib/config/index.js +2 -1
  9. package/lib/config/php/extensions/libsodium.js +2 -1
  10. package/lib/config/scandipwa-versions.js +2 -1
  11. package/lib/config/system-config.js +34 -5
  12. package/lib/config/templates/magentorc.template +2 -0
  13. package/lib/config/templates/varnish.template.vcl +9 -4
  14. package/lib/config/xml-parser.js +63 -0
  15. package/lib/errors/known-error.js +15 -0
  16. package/lib/errors/unknown-error.js +15 -0
  17. package/lib/tasks/cli/create-bashrc-config.js +2 -1
  18. package/lib/tasks/composer/index.js +5 -3
  19. package/lib/tasks/composer/local-auth-json.js +8 -4
  20. package/lib/tasks/docker/network.js +2 -1
  21. package/lib/tasks/execute/index.js +2 -3
  22. package/lib/tasks/file-system/create-nginx-config.js +2 -1
  23. package/lib/tasks/file-system/create-php-config.js +2 -1
  24. package/lib/tasks/file-system/create-php-fpm-config.js +2 -1
  25. package/lib/tasks/file-system/create-phpstorm-config/database-config.js +249 -0
  26. package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +85 -0
  27. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +154 -0
  28. package/lib/tasks/file-system/create-phpstorm-config/index.js +27 -0
  29. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +26 -0
  30. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/config.js +54 -0
  31. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +28 -0
  32. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +42 -0
  33. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/eslint-inspection-config.js +37 -0
  34. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/index.js +80 -0
  35. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +26 -0
  36. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +142 -0
  37. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/paths.js +20 -0
  38. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-fixer-validation-inspection-config.js +60 -0
  39. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +116 -0
  40. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/stylelint-inspection-config.js +37 -0
  41. package/lib/tasks/file-system/create-phpstorm-config/keys.js +14 -0
  42. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +67 -0
  43. package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +54 -0
  44. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +66 -0
  45. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +58 -0
  46. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +59 -0
  47. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +77 -0
  48. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +97 -0
  49. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/format-setting-config.js +57 -0
  50. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +66 -0
  51. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +64 -0
  52. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +57 -0
  53. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +49 -0
  54. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +64 -0
  55. package/lib/tasks/file-system/create-phpstorm-config/xml-utils.js +5 -0
  56. package/lib/tasks/file-system/create-ssl-terminator-config.js +5 -3
  57. package/lib/tasks/file-system/create-varnish-config.js +2 -23
  58. package/lib/tasks/file-system/create-vscode-config.js +3 -2
  59. package/lib/tasks/file-system/index.js +1 -1
  60. package/lib/tasks/magento/enable-magento-composer-plugins.js +3 -2
  61. package/lib/tasks/magento/install-magento.js +7 -5
  62. package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +26 -0
  63. package/lib/tasks/magento/setup-magento/delete-admin-users.js +1 -1
  64. package/lib/tasks/magento/setup-magento/delete-customers.js +7 -4
  65. package/lib/tasks/magento/setup-magento/delete-orders.js +6 -4
  66. package/lib/tasks/magento/setup-magento/flush-redis-config.js +2 -1
  67. package/lib/tasks/magento/setup-magento/index.js +3 -1
  68. package/lib/tasks/magento/setup-magento/install-magento.js +2 -1
  69. package/lib/tasks/magento/setup-magento/set-base-url.js +7 -2
  70. package/lib/tasks/magento/setup-magento/upgrade-magento.js +11 -1
  71. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +41 -0
  72. package/lib/tasks/mysql/connect-to-mysql.js +2 -1
  73. package/lib/tasks/mysql/import-dump-to-mysql.js +13 -2
  74. package/lib/tasks/mysql/import-remote-db/index.js +2 -1
  75. package/lib/tasks/mysql/import-remote-db/ssh/index.js +2 -1
  76. package/lib/tasks/mysql/import-remote-db/ssh/regular-server.js +2 -1
  77. package/lib/tasks/php/bundled-extensions.js +28 -0
  78. package/lib/tasks/php/compile-options.js +27 -54
  79. package/lib/tasks/php/compile.js +6 -4
  80. package/lib/tasks/php/configure.js +7 -66
  81. package/lib/tasks/php/extensions/disable.js +2 -1
  82. package/lib/tasks/php/extensions/enable.js +2 -1
  83. package/lib/tasks/php/extensions/index.js +74 -0
  84. package/lib/tasks/php/extensions/install.js +3 -3
  85. package/lib/tasks/php/index.js +7 -6
  86. package/lib/tasks/php/install-sodium.js +93 -0
  87. package/lib/tasks/php/update-phpbrew.js +7 -3
  88. package/lib/tasks/php/validate-php.js +67 -0
  89. package/lib/tasks/php-fpm/start-php-fpm.js +4 -2
  90. package/lib/tasks/requirements/composer.js +59 -5
  91. package/lib/tasks/requirements/dependency/arch.js +2 -1
  92. package/lib/tasks/requirements/dependency/centos.js +2 -1
  93. package/lib/tasks/requirements/dependency/fedora.js +2 -1
  94. package/lib/tasks/requirements/dependency/mac.js +18 -3
  95. package/lib/tasks/requirements/docker/index.js +94 -40
  96. package/lib/tasks/requirements/docker/install-on-mac.js +29 -0
  97. package/lib/tasks/requirements/docker/install.js +2 -1
  98. package/lib/tasks/requirements/docker/running-status.js +32 -31
  99. package/lib/tasks/requirements/docker/version.js +2 -1
  100. package/lib/tasks/requirements/index.js +3 -0
  101. package/lib/tasks/requirements/node-version.js +2 -1
  102. package/lib/tasks/requirements/php-version.js +26 -24
  103. package/lib/tasks/requirements/phpbrew/index.js +2 -1
  104. package/lib/tasks/requirements/phpbrew/install.js +14 -2
  105. package/lib/tasks/requirements/phpbrew/version.js +2 -1
  106. package/lib/tasks/requirements/platform.js +5 -3
  107. package/lib/tasks/requirements/rosetta.js +32 -0
  108. package/lib/tasks/start.js +10 -2
  109. package/lib/tasks/theme/build-theme.js +2 -1
  110. package/lib/tasks/theme/install-theme.js +2 -1
  111. package/lib/tasks/theme/link-theme.js +2 -2
  112. package/lib/tasks/theme/retrieve-theme-data.js +2 -1
  113. package/lib/tasks/theme/setup-persisted-query.js +2 -1
  114. package/lib/tasks/theme/setup-themes.js +10 -3
  115. package/lib/tasks/theme/symlink-theme.js +8 -1
  116. package/lib/util/CSA-theme.js +4 -0
  117. package/lib/util/analytics.js +317 -0
  118. package/lib/util/arch.js +1 -1
  119. package/lib/util/config-file-validator.js +2 -1
  120. package/lib/util/config-php-json.js +3 -2
  121. package/lib/util/env-php-json.js +3 -2
  122. package/lib/util/exec-async-command.d.ts +2 -0
  123. package/lib/util/exec-async-command.js +31 -15
  124. package/lib/util/exec-async.js +9 -0
  125. package/lib/util/get-brew-bin-path.js +64 -0
  126. package/lib/util/get-installed-magento-version.js +3 -2
  127. package/lib/util/get-jsonfile-data.js +2 -1
  128. package/lib/util/install-dependencies-task.js +15 -5
  129. package/lib/util/instance-metadata.js +9 -2
  130. package/lib/util/ip.js +47 -1
  131. package/lib/util/magento-task.js +20 -9
  132. package/lib/util/php-task.js +7 -7
  133. package/lib/util/request.js +0 -0
  134. package/lib/util/resolve-configuration-with-overrides.js +2 -1
  135. package/lib/util/run-composer.js +5 -3
  136. package/lib/util/run-magento.js +3 -2
  137. package/lib/util/run-php.js +7 -2
  138. package/lib/util/wait-for-it.js +3 -2
  139. package/package.json +5 -3
  140. package/typings/context.d.ts +4 -0
  141. package/typings/phpstorm.d.ts +33 -0
  142. package/lib/tasks/file-system/create-php-storm-config.js +0 -82
  143. package/lib/tasks/magento/setup-magento/disable-full-page-cache.js +0 -20
@@ -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
  );
@@ -3,44 +3,45 @@ const fs = require('fs');
3
3
  const path = require('path');
4
4
  const semver = require('semver');
5
5
  const phpbrewConfig = require('../../config/phpbrew');
6
+ const KnownError = require('../../errors/known-error');
7
+ const UnknownError = require('../../errors/unknown-error');
6
8
  const { execAsyncSpawn } = require('../../util/exec-async-command');
9
+ const { getBrewCommandSync } = require('../../util/get-brew-bin-path');
7
10
  const pathExists = require('../../util/path-exists');
8
11
  const compileOptions = require('../php/compile-options');
9
12
 
10
13
  const latestStablePHP74 = '7.4.27';
11
14
  const phpbrewPHPName = `php-${latestStablePHP74}-phpbrew`;
12
15
 
13
- const compileOptionsForPhp = {
14
- linux: {
15
- ...compileOptions.linux,
16
- variants: [
17
- '+default'
18
- ],
19
- extraOptions: []
20
- },
21
- darwin: {
22
- ...compileOptions.darwin,
23
- variants: [
24
- '+default',
25
- '+openssl=$(brew --prefix openssl@1.1)'
26
- ],
27
- extraOptions: []
28
- }
29
- };
30
-
31
16
  /**
32
17
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
33
18
  */
34
19
  const installPHPForPHPBrew = () => ({
35
20
  title: `Installing PHP ${latestStablePHP74} for PHPBrew...`,
36
21
  task: async (ctx, task) => {
22
+ const compileOptionsForPhp = {
23
+ linux: {
24
+ ...compileOptions.linux,
25
+ variants: [
26
+ '+default'
27
+ ],
28
+ extraOptions: []
29
+ },
30
+ darwin: {
31
+ ...compileOptions.darwin,
32
+ variants: [
33
+ '+default',
34
+ `+openssl=$(${getBrewCommandSync({ native: false })} --prefix openssl@1.1)`
35
+ ],
36
+ extraOptions: []
37
+ }
38
+ };
37
39
  const platformCompileOptions = compileOptionsForPhp[process.platform];
38
40
 
39
41
  if (!await pathExists(path.join(phpbrewConfig.phpPath, `${phpbrewPHPName}`, 'bin'))) {
40
42
  const commandEnv = Object.entries(platformCompileOptions.env || {}).map(([key, value]) => `${key}="${value}"`).join(' ');
41
-
42
43
  // eslint-disable-next-line max-len
43
- const compileCommand = `${commandEnv ? `${commandEnv} && ` : ''}phpbrew install -j ${platformCompileOptions.cpuCount} ${latestStablePHP74} as ${phpbrewPHPName} ${platformCompileOptions.variants.join(' ')}`;
44
+ const compileCommand = ` ${commandEnv ? `${commandEnv} && ` : ''}phpbrew install -j ${platformCompileOptions.cpuCount} ${latestStablePHP74} as ${phpbrewPHPName} ${platformCompileOptions.variants.join(' ')}`;
44
45
 
45
46
  try {
46
47
  await execAsyncSpawn(
@@ -48,11 +49,12 @@ const installPHPForPHPBrew = () => ({
48
49
  {
49
50
  callback: (t) => {
50
51
  task.output = t;
51
- }
52
+ },
53
+ useRosetta2: true
52
54
  }
53
55
  );
54
56
  } catch (e) {
55
- throw new Error(
57
+ throw new KnownError(
56
58
  `Failed to compile the required by PHPBrew PHP version.
57
59
  Tried compiling the PHP version ${ latestStablePHP74 }.
58
60
  Use your favorite search engine to resolve the issue.
@@ -79,10 +81,10 @@ export PHPBREW_PATH=${phpbrewConfig.homePath}/php/${phpbrewPHPName}/bin
79
81
  }
80
82
  );
81
83
  } catch (e) {
82
- throw new Error(`Something went wrong when trying to switch PHP to ${phpbrewPHPName}!\n\n${e}`);
84
+ throw new UnknownError(`Something went wrong when trying to switch PHP to ${phpbrewPHPName}!\n\n${e}`);
83
85
  }
84
86
 
85
- throw new Error(`You will need to restart your terminal and run ${logger.style.command('start')} again.
87
+ throw new KnownError(`You will need to restart your terminal and run ${logger.style.command('start')} again.
86
88
 
87
89
  You can use keyboard shortcut ${logger.style.command('CTRL+D')} to close terminal.`);
88
90
  },
@@ -1,4 +1,5 @@
1
1
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
2
+ const KnownError = require('../../../errors/known-error');
2
3
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
3
4
  const installPHPBrew = require('./install');
4
5
  const getPHPBrewVersion = require('./version');
@@ -32,7 +33,7 @@ Do you want to install it automatically?`
32
33
  ]);
33
34
  }
34
35
 
35
- throw new Error(
36
+ throw new KnownError(
36
37
  `To install PHPBrew, you must first make sure the requirements are met.
37
38
  The requirements are available here: ${ logger.style.link('https://github.com/phpbrew/phpbrew/wiki/Requirement') }.
38
39
  Then, you can follow the installation instruction, here: ${ logger.style.link('https://phpbrew.github.io/phpbrew/#installation') }.