@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,57 @@
1
+ const { nameKey } = require('../keys');
2
+
3
+ const PHP_SERVERS_COMPONENT_NAME = 'PhpServers';
4
+
5
+ const hostKey = '@_host';
6
+
7
+ /**
8
+ * @param {Array} workspaceConfigs
9
+ * @param {import('../../../../../typings/phpstorm').PHPStormConfig} phpStormConfiguration
10
+ * @returns {Promise<Boolean>}
11
+ */
12
+ const setupPHPServers = async (workspaceConfigs, phpStormConfiguration) => {
13
+ const { xdebug } = phpStormConfiguration;
14
+ let hasChanges = false;
15
+ const phpServersComponent = workspaceConfigs.find(
16
+ (workspaceConfig) => workspaceConfig[nameKey] === PHP_SERVERS_COMPONENT_NAME
17
+ );
18
+
19
+ const defaultServerConfig = {
20
+ [hostKey]: xdebug.debugServerAddress,
21
+ id: '7e16e907-9ce3-4559-9d26-a30a5650d11f',
22
+ [nameKey]: xdebug.serverName
23
+ };
24
+
25
+ if (phpServersComponent) {
26
+ if (phpServersComponent.servers && !Array.isArray(phpServersComponent.servers)) {
27
+ hasChanges = true;
28
+ phpServersComponent.servers = [phpServersComponent.servers];
29
+ } else if (!phpServersComponent.servers) {
30
+ hasChanges = true;
31
+ phpServersComponent.servers = [];
32
+ }
33
+
34
+ const serverConfiguration = phpServersComponent.servers.find((server) => server.server[nameKey] === xdebug.serverName);
35
+
36
+ if (!serverConfiguration) {
37
+ hasChanges = true;
38
+ phpServersComponent.servers.push({
39
+ server: defaultServerConfig
40
+ });
41
+ }
42
+ } else {
43
+ hasChanges = true;
44
+ workspaceConfigs.push({
45
+ [nameKey]: PHP_SERVERS_COMPONENT_NAME,
46
+ servers: [
47
+ {
48
+ server: defaultServerConfig
49
+ }
50
+ ]
51
+ });
52
+ }
53
+
54
+ return hasChanges;
55
+ };
56
+
57
+ module.exports = setupPHPServers;
@@ -0,0 +1,49 @@
1
+ const path = require('path');
2
+ // const { baseConfig } = require('../../../../config');
3
+ const { getCSAThemes } = require('../../../../util/CSA-theme');
4
+ const pathExists = require('../../../../util/path-exists');
5
+ const { nameKey } = require('../keys');
6
+ // const { formatPathForPHPStormConfig } = require('../xml-utils');
7
+
8
+ const PROPERTIES_COMPONENT_NAME = 'PropertiesComponent';
9
+
10
+ const defaultProperties = {
11
+ keyToString: {
12
+ 'RunOnceActivity.OpenProjectViewOnStart': 'true',
13
+ 'RunOnceActivity.ShowReadmeOnStart': 'true'
14
+ }
15
+ };
16
+
17
+ /**
18
+ * @param {Array} workspaceConfigs
19
+ * @returns {Promise<Boolean>}
20
+ */
21
+ const setupPropertiesComponent = async (workspaceConfigs) => {
22
+ let hasChanges = false;
23
+ const propertiesComponent = workspaceConfigs.find(
24
+ (workspaceConfig) => workspaceConfig[nameKey] === PROPERTIES_COMPONENT_NAME
25
+ );
26
+
27
+ if (!propertiesComponent) {
28
+ hasChanges = true;
29
+ const themes = await getCSAThemes();
30
+ if (themes.length > 0) {
31
+ const theme = themes[0];
32
+ const themeESLintPath = path.join(process.cwd(), theme.themePath, 'node_modules', 'eslint');
33
+ if (await pathExists(themeESLintPath)) {
34
+ defaultProperties.keyToString['node.js.selected.package.eslint'] = themeESLintPath;
35
+ defaultProperties.keyToString['js.linters.configure.manually.selectedeslint'] = 'true';
36
+ defaultProperties.keyToString['node.js.detected.package.eslint'] = 'true';
37
+ defaultProperties.keyToString['settings.editor.selected.configurable'] = 'settings.javascript.linters.eslint';
38
+ }
39
+ }
40
+ workspaceConfigs.push({
41
+ [nameKey]: PROPERTIES_COMPONENT_NAME,
42
+ _cdata: JSON.stringify(defaultProperties)
43
+ });
44
+ }
45
+
46
+ return hasChanges;
47
+ };
48
+
49
+ module.exports = setupPropertiesComponent;
@@ -0,0 +1,64 @@
1
+ const { nameKey } = require('../keys');
2
+
3
+ const RUN_MANAGER_COMPONENT_NAME = 'RunManager';
4
+
5
+ const PHP_REMOTE_DEBUG_RUN_CONFIGURATION_TYPE = 'PhpRemoteDebugRunConfigurationType';
6
+
7
+ const serverNameKey = '@_server_name';
8
+ const sessionIdKey = '@_session_id';
9
+
10
+ /**
11
+ * @param {Array} workspaceConfigs
12
+ * @param {import('../../../../../typings/phpstorm').PHPStormConfig} phpStormConfiguration
13
+ * @returns {Promise<Boolean>}
14
+ */
15
+ const setupRunManager = async (workspaceConfigs, phpStormConfiguration) => {
16
+ const { xdebug } = phpStormConfiguration;
17
+ let hasChanges = false;
18
+ const runManagerComponent = workspaceConfigs.find(
19
+ (workspaceConfig) => workspaceConfig[nameKey] === RUN_MANAGER_COMPONENT_NAME
20
+ );
21
+
22
+ const defaultRunManagerConfiguration = {
23
+ [nameKey]: xdebug.runManagerName,
24
+ '@_type': PHP_REMOTE_DEBUG_RUN_CONFIGURATION_TYPE,
25
+ '@_factoryName': 'PHP Remote Debug',
26
+ '@_filter_connections': 'FILTER',
27
+ [serverNameKey]: xdebug.serverName,
28
+ [sessionIdKey]: xdebug.sessionId,
29
+ method: {
30
+ '@_v': '2'
31
+ }
32
+ };
33
+
34
+ if (runManagerComponent) {
35
+ if (runManagerComponent.configuration && !Array.isArray(runManagerComponent.configuration)) {
36
+ hasChanges = true;
37
+ runManagerComponent.configuration = [runManagerComponent.configuration];
38
+ } else if (!runManagerComponent.configuration) {
39
+ hasChanges = true;
40
+ runManagerComponent.configuration = [];
41
+ }
42
+
43
+ const phpRemoteDebugRunConfiguration = runManagerComponent.configuration.find(
44
+ (configuration) => configuration['@_type'] === PHP_REMOTE_DEBUG_RUN_CONFIGURATION_TYPE && configuration[nameKey] === xdebug.runManagerName
45
+ );
46
+
47
+ if (!phpRemoteDebugRunConfiguration) {
48
+ hasChanges = true;
49
+ runManagerComponent.configuration.push(defaultRunManagerConfiguration);
50
+ }
51
+ } else {
52
+ hasChanges = true;
53
+ workspaceConfigs.push({
54
+ [nameKey]: RUN_MANAGER_COMPONENT_NAME,
55
+ configuration: [
56
+ defaultRunManagerConfiguration
57
+ ]
58
+ });
59
+ }
60
+
61
+ return hasChanges;
62
+ };
63
+
64
+ module.exports = setupRunManager;
@@ -0,0 +1,5 @@
1
+ const formatPathForPHPStormConfig = (p) => p.replace(process.cwd(), '$PROJECT_DIR$');
2
+
3
+ module.exports = {
4
+ formatPathForPHPStormConfig
5
+ };
@@ -0,0 +1,96 @@
1
+ const os = require('os');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const setConfigFile = require('../../util/set-config');
5
+ const pathExists = require('../../util/path-exists');
6
+ const { isIpAddress } = require('../../util/ip');
7
+ const KnownError = require('../../errors/known-error');
8
+ const UnknownError = require('../../errors/unknown-error');
9
+
10
+ /**
11
+ * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
12
+ */
13
+ const createSSLTerminatorConfig = () => ({
14
+ title: 'Setting ssl terminator config',
15
+ task: async (ctx) => {
16
+ const {
17
+ ports,
18
+ config: {
19
+ overridenConfiguration,
20
+ baseConfig
21
+ },
22
+ isWsl
23
+ } = ctx;
24
+
25
+ const {
26
+ configuration: {
27
+ sslTerminator
28
+ },
29
+ ssl,
30
+ host
31
+ } = overridenConfiguration;
32
+
33
+ if (ssl.enabled) {
34
+ if (!(await pathExists(ssl.ssl_certificate))) {
35
+ throw new KnownError('ssl.ssl_certificate file does not exist!');
36
+ }
37
+ if (!(await pathExists(ssl.ssl_certificate_key))) {
38
+ throw new KnownError('ssl.ssl_certificate_key file does not exist!');
39
+ }
40
+
41
+ const nginxCacheDir = path.join(baseConfig.cacheDir, 'nginx', 'conf.d');
42
+ if (!await pathExists(nginxCacheDir)) {
43
+ await fs.promises.mkdir(nginxCacheDir, { recursive: true });
44
+ }
45
+
46
+ await fs.promises.copyFile(
47
+ ssl.ssl_certificate,
48
+ path.join(
49
+ baseConfig.cacheDir,
50
+ 'ssl-terminator',
51
+ 'conf.d',
52
+ 'ssl_certificate.pem'
53
+ )
54
+ );
55
+ await fs.promises.copyFile(
56
+ ssl.ssl_certificate_key,
57
+ path.join(
58
+ baseConfig.cacheDir,
59
+ 'ssl-terminator',
60
+ 'conf.d',
61
+ 'ssl_certificate-key.pem'
62
+ )
63
+ );
64
+ }
65
+
66
+ const networkToBindTo = isIpAddress(host) ? host : '127.0.0.1';
67
+ const isLinux = os.platform() === 'linux';
68
+ const isNativeLinux = isLinux && !isWsl;
69
+ const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
70
+ const hostPort = isNativeLinux ? ports.sslTerminator : 80;
71
+
72
+ try {
73
+ await setConfigFile({
74
+ configPathname: path.join(
75
+ baseConfig.cacheDir,
76
+ 'ssl-terminator',
77
+ 'conf.d',
78
+ 'default.conf'
79
+ ),
80
+ template: sslTerminator.configTemplate,
81
+ overwrite: true,
82
+ templateArgs: {
83
+ ports,
84
+ hostMachine,
85
+ hostPort,
86
+ config: overridenConfiguration,
87
+ networkToBindTo
88
+ }
89
+ });
90
+ } catch (e) {
91
+ throw new UnknownError(`Unexpected error accrued during ssl terminator config creation\n\n${e}`);
92
+ }
93
+ }
94
+ });
95
+
96
+ module.exports = createSSLTerminatorConfig;
@@ -1,4 +1,5 @@
1
1
  const path = require('path');
2
+ const UnknownError = require('../../errors/unknown-error');
2
3
  const setConfigFile = require('../../util/set-config');
3
4
 
4
5
  /**
@@ -44,7 +45,7 @@ const createVarnishConfig = () => ({
44
45
  }
45
46
  });
46
47
  } catch (e) {
47
- throw new Error(`Unexpected error accrued during varnish config creation\n\n${e}`);
48
+ throw new UnknownError(`Unexpected error accrued during varnish config creation\n\n${e}`);
48
49
  }
49
50
  }
50
51
  });
@@ -5,6 +5,7 @@ const os = require('os');
5
5
  const hjson = require('hjson');
6
6
  const pathExists = require('../../util/path-exists');
7
7
  const setConfigFile = require('../../util/set-config');
8
+ const UnknownError = require('../../errors/unknown-error');
8
9
 
9
10
  const phpXDebug2port = 9111;
10
11
  const phpXDebug3port = 9003;
@@ -87,7 +88,7 @@ const createPhpFpmConfig = () => ({
87
88
  try {
88
89
  await fs.promises.mkdir(path.join(process.cwd(), '.vscode'));
89
90
  } catch (e) {
90
- throw new Error(`Unable to creade .vscode directory in your project!\n\n${e}`);
91
+ throw new UnknownError(`Unable to creade .vscode directory in your project!\n\n${e}`);
91
92
  }
92
93
  }
93
94
 
@@ -103,7 +104,7 @@ const createPhpFpmConfig = () => ({
103
104
  }
104
105
  });
105
106
  } catch (e) {
106
- throw new Error(`Unexpected error accrued during launch.json config creation!\n\n${e}`);
107
+ throw new UnknownError(`Unexpected error accrued during launch.json config creation!\n\n${e}`);
107
108
  }
108
109
  }
109
110
  });
@@ -1,7 +1,8 @@
1
1
  const createNginxConfig = require('./create-nginx-config');
2
2
  const createPhpConfig = require('./create-php-config');
3
3
  const createPhpFpmConfig = require('./create-php-fpm-config');
4
- const createPhpStormConfig = require('./create-php-storm-config');
4
+ const createPhpStormConfig = require('./create-phpstorm-config');
5
+ const createSSLTerminatorConfig = require('./create-ssl-terminator-config');
5
6
  const createVarnishConfig = require('./create-varnish-config');
6
7
  const createVSCodeConfig = require('./create-vscode-config');
7
8
 
@@ -11,6 +12,7 @@ const createVSCodeConfig = require('./create-vscode-config');
11
12
  const prepareFileSystem = () => ({
12
13
  title: 'Preparing file system',
13
14
  task: (ctx, task) => task.newListr([
15
+ createSSLTerminatorConfig(),
14
16
  createNginxConfig(),
15
17
  createPhpFpmConfig(),
16
18
  createPhpConfig(),
@@ -4,6 +4,7 @@ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
4
4
  const semver = require('semver');
5
5
  const pathExists = require('../../util/path-exists');
6
6
  const getJsonfileData = require('../../util/get-jsonfile-data');
7
+ const KnownError = require('../../errors/known-error');
7
8
 
8
9
  const vendorPath = path.join(process.cwd(), 'vendor');
9
10
  const composerJsonPath = path.join(process.cwd(), 'composer.json');
@@ -121,7 +122,7 @@ Do you want to enable them all or disable some of them?`,
121
122
  encoding: 'utf-8'
122
123
  });
123
124
  } else {
124
- throw new Error('Please confirm your choice or choose other option.');
125
+ throw new KnownError('Please confirm your choice or choose other option.');
125
126
  }
126
127
  break;
127
128
  }
@@ -153,7 +154,7 @@ Do you want to enable them all or disable some of them?`,
153
154
  encoding: 'utf-8'
154
155
  });
155
156
  } else {
156
- throw new Error('Please confirm your choice or choose other option.');
157
+ throw new KnownError('Please confirm your choice or choose other option.');
157
158
  }
158
159
 
159
160
  break;
@@ -6,6 +6,8 @@ const moveFile = require('../../util/move-file');
6
6
  const pathExists = require('../../util/path-exists');
7
7
  const getJsonFileData = require('../../util/get-jsonfile-data');
8
8
  const rmdirSafe = require('../../util/rmdir-safe');
9
+ const KnownError = require('../../errors/known-error');
10
+ const UnknownError = require('../../errors/unknown-error');
9
11
 
10
12
  const magentoProductEnterpriseEdition = 'magento/product-enterprise-edition';
11
13
  const magentoProductCommunityEdition = 'magento/product-community-edition';
@@ -58,7 +60,7 @@ const adjustComposerJson = async ({
58
60
  composerData.require[magentoProductCommunityEdition]
59
61
  && composerData.require[magentoProductEnterpriseEdition]
60
62
  ) {
61
- throw new Error('Somehow, both Magento editions are installed!\nPlease choose only one edition an modify your composer.json manually!');
63
+ throw new KnownError('Somehow, both Magento editions are installed!\nPlease choose only one edition an modify your composer.json manually!');
62
64
  }
63
65
 
64
66
  const oppositeEdition = [magentoProductCommunityEdition, magentoProductEnterpriseEdition]
@@ -66,7 +68,7 @@ const adjustComposerJson = async ({
66
68
 
67
69
  // if opposite edition is installed than selected in config file, throw an error
68
70
  if (composerData.require[oppositeEdition]) {
69
- throw new Error(`You have installed ${oppositeEdition} but selected magento.edition as ${magentoEdition} in config file!
71
+ throw new KnownError(`You have installed ${oppositeEdition} but selected magento.edition as ${magentoEdition} in config file!
70
72
 
71
73
  Change magento edition in config file or manually reinstall correct magento edition!`);
72
74
  }
@@ -187,11 +189,11 @@ const installMagento = () => ({
187
189
  });
188
190
  } catch (e) {
189
191
  if (e.message.includes('man-in-the-middle attack')) {
190
- throw new Error(`Probably you haven't setup pubkeys in composer.
191
- Please run composer diagnose in cli to get mode.\n\n${e}`);
192
+ throw new KnownError(`Probably you haven't setup pubkeys in composer.
193
+ Please run composer diagnose in cli to get mode.\n\n${e}`);
192
194
  }
193
195
 
194
- throw new Error(`Unexpected error during composer install.\n\n${e}`);
196
+ throw new UnknownError(`Unexpected error during composer install.\n\n${e}`);
195
197
  }
196
198
  ctx.magentoFirstInstall = true;
197
199
  },
@@ -0,0 +1,26 @@
1
+ const envPhpToJson = require('../../../util/env-php-json');
2
+ const magentoTask = require('../../../util/magento-task');
3
+
4
+ /**
5
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
6
+ */
7
+ const disableFullPageCache = () => ({
8
+ title: 'Adjusting full_page cache setting',
9
+ task: async ({ magentoVersion, config }, task) => {
10
+ const { cache_types } = await envPhpToJson(process.cwd(), { magentoVersion });
11
+
12
+ if (cache_types.full_page !== 0 && !config.overridenConfiguration.configuration.varnish.enabled) {
13
+ task.title = 'Disabling full_page cache in Magento';
14
+ return task.newListr(magentoTask('cache:disable full_page'));
15
+ }
16
+
17
+ if (config.overridenConfiguration.configuration.varnish.enabled && cache_types.full_page !== 1) {
18
+ task.title = 'Enabling full_page cache in Magento (Varnish is enabled)';
19
+ return task.newListr(magentoTask('cache:enable full_page'));
20
+ }
21
+
22
+ task.skip();
23
+ }
24
+ });
25
+
26
+ module.exports = disableFullPageCache;
@@ -1,7 +1,7 @@
1
1
  const { isTableExists } = require('../../../util/database');
2
2
 
3
3
  /**
4
- * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
4
+ * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
5
5
  */
6
6
  const deleteAdminUsers = () => ({
7
7
  title: 'Deleting old admin users',
@@ -1,7 +1,7 @@
1
1
  const { customerTables } = require('../../mysql/magento-tables');
2
2
 
3
3
  /**
4
- * @type {() => import(listr2).ListrTask<import(../../../../typings/context).ListrContext>}
4
+ * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
5
5
  */
6
6
  const deleteCustomers = () => ({
7
7
  title: 'Deleting customers',
@@ -12,10 +12,13 @@ const deleteCustomers = () => ({
12
12
  task.skip();
13
13
  return;
14
14
  }
15
+
16
+ const [rows] = await mysqlConnection.query('select TABLE_NAME from information_schema.TABLES;');
17
+
15
18
  await Promise.all(
16
- customerTables.map(
17
- (tableName) => mysqlConnection.query(`TRUNCATE TABLE \`${ tableName }\`;`)
18
- )
19
+ customerTables
20
+ .filter((tableName) => rows.some((row) => row.TABLE_NAME === tableName))
21
+ .map((tableName) => mysqlConnection.query(`TRUNCATE TABLE \`${ tableName }\`;`))
19
22
  );
20
23
  }
21
24
  });
@@ -1,7 +1,7 @@
1
1
  const { orderTables } = require('../../mysql/magento-tables');
2
2
 
3
3
  /**
4
- * @type {import(listr2).ListrTask<import(../../../../typings/context).ListrContext>}
4
+ * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
5
5
  */
6
6
  const deleteOrders = () => ({
7
7
  title: 'Deleting orders',
@@ -13,10 +13,12 @@ const deleteOrders = () => ({
13
13
  return;
14
14
  }
15
15
 
16
+ const [rows] = await mysqlConnection.query('select TABLE_NAME from information_schema.TABLES;');
17
+
16
18
  await Promise.all(
17
- orderTables.map(
18
- (tableName) => mysqlConnection.query(`TRUNCATE TABLE \`${ tableName }\`;`)
19
- )
19
+ orderTables
20
+ .filter((tableName) => rows.some((row) => row.TABLE_NAME === tableName))
21
+ .map((tableName) => mysqlConnection.query(`TRUNCATE TABLE \`${ tableName }\`;`))
20
22
  );
21
23
  }
22
24
  });
@@ -1,5 +1,6 @@
1
1
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
2
2
  const os = require('os');
3
+ const UnknownError = require('../../../errors/unknown-error');
3
4
 
4
5
  const isLinux = os.platform() === 'linux';
5
6
 
@@ -15,7 +16,7 @@ module.exports = () => ({
15
16
  const result = await execAsyncSpawn(`docker exec ${ name } redis-cli -h ${ host } -p ${ port } -n 0 flushdb`);
16
17
 
17
18
  if (!result.trim().includes('OK')) {
18
- throw new Error(`Unexpected output from redis flush command: ${result}`);
19
+ throw new UnknownError(`Unexpected output from redis flush command: ${result}`);
19
20
  }
20
21
  }
21
22
  });
@@ -11,6 +11,7 @@ const updateEnvPHP = require('../../php/update-env-php');
11
11
  const increaseAdminSessionLifetime = require('./increase-admin-session-lifetime');
12
12
  const magentoTask = require('../../../util/magento-task');
13
13
  const urnHighlighter = require('./urn-highlighter');
14
+ const waitingForVarnish = require('./waiting-for-varnish');
14
15
 
15
16
  /**
16
17
  * @type {({ onlyInstallMagento: boolean }) => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
@@ -48,7 +49,8 @@ const setupMagento = (options = {}) => ({
48
49
  disableMaintenanceMode(),
49
50
  disable2fa(),
50
51
  urnHighlighter(),
51
- magentoTask('cache:flush')
52
+ magentoTask('cache:flush'),
53
+ waitingForVarnish()
52
54
  ], {
53
55
  concurrent: false,
54
56
  exitOnError: true,
@@ -1,4 +1,5 @@
1
1
  const semver = require('semver');
2
+ const UnknownError = require('../../../errors/unknown-error');
2
3
  const runMagentoCommand = require('../../../util/run-magento');
3
4
 
4
5
  /**
@@ -86,7 +87,7 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
86
87
 
87
88
  if (!installed) {
88
89
  const errorMessages = errors.map((e) => e.message).join('\n\n');
89
- throw new Error(`Unable to install Magento!\n${errorMessages}`);
90
+ throw new UnknownError(`Unable to install Magento!\n${errorMessages}`);
90
91
  }
91
92
  },
92
93
  options: {
@@ -8,12 +8,17 @@ module.exports = () => ({
8
8
  task: async (ctx, task) => {
9
9
  const {
10
10
  ports,
11
- config: { overridenConfiguration: { host, ssl } },
11
+ config: {
12
+ overridenConfiguration: {
13
+ host,
14
+ ssl
15
+ }
16
+ },
12
17
  mysqlConnection
13
18
  } = ctx;
14
19
  const isNgrok = host.endsWith('ngrok.io');
15
20
  const enableSecureFrontend = ssl.enabled ? '1' : '0';
16
- const location = `${host}${ !isNgrok && ports.app !== 80 ? `:${ports.app}` : '' }/`;
21
+ const location = `${host}${ !isNgrok && ports.sslTerminator !== 80 ? `:${ports.sslTerminator }` : '' }/`;
17
22
  const secureLocation = `${host}/`; // SSL will work only on port 443, so you cannot run multiple projects with SSL at the same time.
18
23
  const httpUrl = `http://${location}`;
19
24
  const httpsUrl = `https://${secureLocation}`;
@@ -1,4 +1,6 @@
1
1
  const magentoTask = require('../../../util/magento-task');
2
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
3
+ const KnownError = require('../../../errors/known-error');
2
4
 
3
5
  /**
4
6
  * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
@@ -12,7 +14,15 @@ const upgradeMagento = () => ({
12
14
  return false;
13
15
  },
14
16
  task: (_ctx, task) => task.newListr([
15
- magentoTask('setup:upgrade --no-interaction'),
17
+ magentoTask('setup:upgrade --no-interaction', {
18
+ onError: (e) => {
19
+ throw new KnownError(`Magento setup:upgrade command failed!
20
+ You can try disabling failed module and try again.
21
+ To disable module, open ${logger.style.misc('cli')} and type the following command: ${logger.style.command('m module:disable <module-name>')}
22
+
23
+ Error: ${e}`);
24
+ }
25
+ }),
16
26
  {
17
27
  task: (ctx) => {
18
28
  ctx.isSetupUpgradeNeeded = false;
@@ -0,0 +1,41 @@
1
+ const { request } = require('smol-request');
2
+ const KnownError = require('../../../errors/known-error');
3
+ const sleep = require('../../../util/sleep');
4
+
5
+ /**
6
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
7
+ */
8
+ const waitingForVarnish = () => ({
9
+ title: 'Waiting for Varnish to return code 200',
10
+ skip: (ctx) => !ctx.config.overridenConfiguration.configuration.varnish.enabled,
11
+ task: async (ctx) => {
12
+ let tries = 0;
13
+ while (tries < 10) {
14
+ try {
15
+ const response = await request(`http://localhost:${ctx.ports.sslTerminator}/`, {
16
+ responseType: 'headers'
17
+ });
18
+
19
+ if (response.status !== 200) {
20
+ tries++;
21
+ await sleep(2000);
22
+ } else {
23
+ break;
24
+ }
25
+ } catch (e) {
26
+ tries++;
27
+ await sleep(200);
28
+ }
29
+ }
30
+
31
+ if (tries === 10) {
32
+ throw new KnownError(`After 20 seconds website is still responding with non-200 code, which might indicate issue with setup.
33
+ Or Varnish is still loading...
34
+
35
+ Please check the logs!`);
36
+ }
37
+ },
38
+ exitOnError: false
39
+ });
40
+
41
+ module.exports = waitingForVarnish;
@@ -1,4 +1,5 @@
1
1
  const mysql = require('mysql2/promise');
2
+ const UnknownError = require('../../errors/unknown-error');
2
3
  const { execAsyncSpawn } = require('../../util/exec-async-command');
3
4
  const sleep = require('../../util/sleep');
4
5
 
@@ -44,7 +45,7 @@ Please wait, this will take some time and do not restart the MySQL container unt
44
45
  }
45
46
 
46
47
  if (tries === maxTries) {
47
- throw new Error(`Unable to connect to MySQL server. Check your server configuration!\n\n${ errors.join(' ') }`);
48
+ throw new UnknownError(`Unable to connect to MySQL server. Check your server configuration!\n\n${ errors.join(' ') }`);
48
49
  }
49
50
 
50
51
  task.title = 'MySQL server connected!';