@scandipwa/magento-scripts 1.14.1-alpha.1 → 1.14.1-alpha.12

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 (179) hide show
  1. package/index.js +13 -0
  2. package/lib/commands/cli.js +28 -1
  3. package/lib/commands/execute.js +2 -1
  4. package/lib/commands/logs.js +1 -0
  5. package/lib/commands/start.js +18 -5
  6. package/lib/config/cma-config.js +16 -0
  7. package/lib/config/dependencies-for-platforms.js +15 -3
  8. package/lib/config/docker.js +89 -15
  9. package/lib/config/get-port-config.js +9 -3
  10. package/lib/config/index.js +2 -1
  11. package/lib/config/php/extensions/libsodium.js +2 -1
  12. package/lib/config/port-config.js +3 -1
  13. package/lib/config/scandipwa-versions.js +2 -1
  14. package/lib/config/ssl-terminator/index.js +10 -0
  15. package/lib/config/system-config.js +34 -5
  16. package/lib/config/templates/magentorc.template +3 -5
  17. package/lib/config/templates/nginx.template.conf +0 -14
  18. package/lib/config/templates/php.template.ini +6 -4
  19. package/lib/config/templates/ssl-terminator.template.conf +27 -0
  20. package/lib/config/templates/varnish.template.vcl +255 -0
  21. package/lib/config/varnish/varnish-6-0.js +11 -0
  22. package/lib/config/varnish/varnish-6-6.js +11 -0
  23. package/lib/config/varnish/varnish-7-0.js +11 -0
  24. package/lib/config/versions/magento-2.3.0.js +9 -1
  25. package/lib/config/versions/magento-2.3.1.js +9 -1
  26. package/lib/config/versions/magento-2.3.2-p2.js +9 -1
  27. package/lib/config/versions/magento-2.3.2.js +9 -1
  28. package/lib/config/versions/magento-2.3.3-p1.js +9 -1
  29. package/lib/config/versions/magento-2.3.3.js +9 -1
  30. package/lib/config/versions/magento-2.3.4-p2.js +9 -1
  31. package/lib/config/versions/magento-2.3.4.js +9 -1
  32. package/lib/config/versions/magento-2.3.5-p1.js +9 -1
  33. package/lib/config/versions/magento-2.3.5-p2.js +9 -1
  34. package/lib/config/versions/magento-2.3.5.js +9 -1
  35. package/lib/config/versions/magento-2.3.6-p1.js +9 -1
  36. package/lib/config/versions/magento-2.3.6.js +9 -1
  37. package/lib/config/versions/magento-2.3.7-p1.js +9 -1
  38. package/lib/config/versions/magento-2.3.7-p2.js +9 -1
  39. package/lib/config/versions/magento-2.3.7-p3.js +9 -1
  40. package/lib/config/versions/magento-2.3.7.js +9 -1
  41. package/lib/config/versions/magento-2.4.0-p1.js +9 -1
  42. package/lib/config/versions/magento-2.4.0.js +9 -1
  43. package/lib/config/versions/magento-2.4.1-p1.js +9 -1
  44. package/lib/config/versions/magento-2.4.1.js +9 -1
  45. package/lib/config/versions/magento-2.4.2-p1.js +9 -1
  46. package/lib/config/versions/magento-2.4.2-p2.js +9 -1
  47. package/lib/config/versions/magento-2.4.2.js +9 -1
  48. package/lib/config/versions/magento-2.4.3-p1.js +9 -1
  49. package/lib/config/versions/magento-2.4.3-p2.js +9 -1
  50. package/lib/config/versions/magento-2.4.3.js +9 -1
  51. package/lib/config/versions/magento-2.4.4.js +9 -1
  52. package/lib/config/xml-parser.js +5 -3
  53. package/lib/errors/known-error.js +15 -0
  54. package/lib/errors/unknown-error.js +15 -0
  55. package/lib/tasks/cli/create-bashrc-config.js +7 -3
  56. package/lib/tasks/composer/index.js +5 -3
  57. package/lib/tasks/composer/local-auth-json.js +4 -2
  58. package/lib/tasks/docker/containers.js +13 -8
  59. package/lib/tasks/docker/network.js +2 -1
  60. package/lib/tasks/docker/volumes.js +4 -4
  61. package/lib/tasks/file-system/create-nginx-config.js +9 -40
  62. package/lib/tasks/file-system/create-php-config.js +2 -1
  63. package/lib/tasks/file-system/create-php-fpm-config.js +2 -1
  64. package/lib/tasks/file-system/create-phpstorm-config/database-config.js +5 -4
  65. package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +12 -10
  66. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +0 -3
  67. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +0 -3
  68. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +1 -1
  69. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +0 -3
  70. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +0 -3
  71. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +1 -4
  72. package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +1 -4
  73. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +1 -11
  74. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +1 -6
  75. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +1 -11
  76. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +2 -3
  77. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +1 -4
  78. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +2 -4
  79. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +1 -11
  80. package/lib/tasks/file-system/create-ssl-terminator-config.js +96 -0
  81. package/lib/tasks/file-system/create-varnish-config.js +53 -0
  82. package/lib/tasks/file-system/create-vscode-config.js +3 -2
  83. package/lib/tasks/file-system/index.js +5 -1
  84. package/lib/tasks/magento/enable-magento-composer-plugins.js +3 -2
  85. package/lib/tasks/magento/install-magento.js +7 -5
  86. package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +26 -0
  87. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +1 -1
  88. package/lib/tasks/magento/setup-magento/delete-admin-users.js +1 -1
  89. package/lib/tasks/magento/setup-magento/delete-customers.js +7 -4
  90. package/lib/tasks/magento/setup-magento/delete-orders.js +6 -4
  91. package/lib/tasks/magento/setup-magento/disable-2fa.js +4 -12
  92. package/lib/tasks/magento/setup-magento/flush-redis-config.js +2 -1
  93. package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +14 -16
  94. package/lib/tasks/magento/setup-magento/index.js +3 -1
  95. package/lib/tasks/magento/setup-magento/install-magento.js +2 -1
  96. package/lib/tasks/magento/setup-magento/migrate-database.js +24 -11
  97. package/lib/tasks/magento/setup-magento/set-base-url.js +7 -2
  98. package/lib/tasks/magento/setup-magento/upgrade-magento.js +27 -3
  99. package/lib/tasks/magento/setup-magento/varnish-config.js +69 -0
  100. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +41 -0
  101. package/lib/tasks/mysql/connect-to-mysql.js +2 -1
  102. package/lib/tasks/mysql/fix-db.js +2 -2
  103. package/lib/tasks/mysql/import-dump-to-mysql.js +13 -2
  104. package/lib/tasks/mysql/import-remote-db/index.js +2 -1
  105. package/lib/tasks/mysql/import-remote-db/ssh/index.js +2 -1
  106. package/lib/tasks/mysql/import-remote-db/ssh/regular-server.js +2 -1
  107. package/lib/tasks/php/bundled-extensions.js +28 -0
  108. package/lib/tasks/php/compile-options.js +27 -54
  109. package/lib/tasks/php/compile.js +6 -4
  110. package/lib/tasks/php/configure.js +7 -66
  111. package/lib/tasks/php/extensions/disable.js +2 -1
  112. package/lib/tasks/php/extensions/enable.js +2 -1
  113. package/lib/tasks/php/extensions/index.js +74 -0
  114. package/lib/tasks/php/extensions/install.js +3 -3
  115. package/lib/tasks/php/index.js +8 -7
  116. package/lib/tasks/php/install-sodium.js +93 -0
  117. package/lib/tasks/php/update-env-php.js +16 -1
  118. package/lib/tasks/php/update-env.php +56 -12
  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 +7 -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 +96 -40
  128. package/lib/tasks/requirements/docker/install-on-mac.js +29 -0
  129. package/lib/tasks/requirements/docker/install.js +13 -12
  130. package/lib/tasks/requirements/docker/running-status.js +138 -0
  131. package/lib/tasks/requirements/docker/version.js +3 -0
  132. package/lib/tasks/requirements/index.js +8 -5
  133. package/lib/tasks/requirements/node-version.js +2 -1
  134. package/lib/tasks/requirements/php-version.js +29 -25
  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 +8 -9
  141. package/lib/tasks/status/index.js +25 -9
  142. package/lib/tasks/theme/build-theme.js +27 -8
  143. package/lib/tasks/theme/install-theme.js +18 -5
  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 +5 -4
  147. package/lib/tasks/theme/setup-themes.js +11 -3
  148. package/lib/tasks/theme/symlink-theme.js +26 -4
  149. package/lib/util/CSA-theme.js +4 -0
  150. package/lib/util/analytics.js +337 -0
  151. package/lib/util/arch.js +1 -1
  152. package/lib/util/config-file-validator.js +14 -2
  153. package/lib/util/config-php-json.js +20 -0
  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 +4 -3
  163. package/lib/util/ip.js +45 -1
  164. package/lib/util/is-running-root.js +3 -0
  165. package/lib/util/magento-task.js +20 -9
  166. package/lib/util/match-filesystem.js +2 -1
  167. package/lib/util/php-task.js +7 -3
  168. package/lib/util/request.js +0 -0
  169. package/lib/util/resolve-configuration-with-overrides.js +2 -1
  170. package/lib/util/run-composer.js +5 -3
  171. package/lib/util/run-magento.js +3 -2
  172. package/lib/util/run-php.js +14 -3
  173. package/lib/util/systemctl.js +46 -0
  174. package/lib/util/wait-for-it.js +3 -2
  175. package/package.json +4 -3
  176. package/typings/context.d.ts +6 -1
  177. package/typings/index.d.ts +32 -1
  178. package/lib/tasks/magento/setup-magento/adjust-magento-configuration.js +0 -27
  179. package/lib/tasks/magento/setup-magento/disable-page-cache.js +0 -11
@@ -14,6 +14,7 @@ const { execAsyncSpawn } = require('../../util/exec-async-command');
14
14
  * @param {string} [options.command] Container command
15
15
  * @param {Record<"cmd" | "interval" | "retries" | "start-period" | "timeout", string>} [options.healthCheck] Container heathcheck properties
16
16
  * @param {string[]} [options.securityOptions] Security options [docs](https://docs.docker.com/engine/reference/commandline/run/#optional-security-options---security-opt)
17
+ * @param {string[]} [options.tmpfs]
17
18
  */
18
19
  const run = (options) => {
19
20
  const {
@@ -28,9 +29,12 @@ const run = (options) => {
28
29
  entrypoint,
29
30
  command = '',
30
31
  healthCheck,
31
- securityOptions = []
32
+ securityOptions = [],
33
+ tmpfs = [],
34
+ expose = []
32
35
  } = options;
33
36
 
37
+ const exposeArg = expose && expose.map((e) => `--expose=${ e }`);
34
38
  const restartArg = restart && `--restart ${ restart }`;
35
39
  const networkArg = network && `--network ${ network }`;
36
40
  const portsArgs = ports.map((port) => `-p ${ port }`).join(' ');
@@ -41,6 +45,7 @@ const run = (options) => {
41
45
  const entrypointArg = entrypoint && `--entrypoint "${entrypoint}"`;
42
46
  const healthCheckArg = healthCheck && Object.entries(healthCheck).map(([key, value]) => `--health-${key} '${value}'`).join(' ');
43
47
  const securityArg = securityOptions.length > 0 && securityOptions.map((opt) => `--security-opt ${opt}`).join(' ');
48
+ const tmpfsArg = tmpfs.length > 0 && tmpfs.map((t) => `--tmpfs ${t}`).join(' ');
44
49
 
45
50
  const dockerCommand = [
46
51
  'docker',
@@ -50,12 +55,14 @@ const run = (options) => {
50
55
  networkArg,
51
56
  restartArg,
52
57
  portsArgs,
58
+ exposeArg,
53
59
  mountsArgs,
54
60
  mountVolumesArgs,
55
61
  envArgs,
56
62
  entrypointArg,
57
63
  healthCheckArg,
58
64
  securityArg,
65
+ tmpfsArg,
59
66
  image,
60
67
  command
61
68
  ].filter(Boolean).join(' ');
@@ -107,7 +114,7 @@ const pullContainers = () => ({
107
114
  const startContainers = () => ({
108
115
  title: 'Starting containers',
109
116
  task: async ({ ports, config: { docker } }, task) => {
110
- const containerList = await execAsyncSpawn('docker container ls');
117
+ const containerList = (await execAsyncSpawn('docker container ls --all --format="{{.Names}}"')).split('\n');
111
118
 
112
119
  const missingContainers = Object.values(docker.getContainers(ports)).filter(
113
120
  ({ name }) => !containerList.includes(name)
@@ -133,19 +140,17 @@ const startContainers = () => ({
133
140
  */
134
141
  const stopContainers = () => ({
135
142
  title: 'Stopping Docker containers',
136
- task: async ({ ports, config: { docker } }, task) => {
137
- const containerList = await execAsyncSpawn('docker container ls -a');
143
+ task: async ({ config: { baseConfig: { prefix } } }, task) => {
144
+ const containerList = (await execAsyncSpawn('docker container ls --all --format="{{.Names}}"')).split('\n');
138
145
 
139
- const runningContainers = Object.values(docker.getContainers(ports)).filter(
140
- ({ name }) => containerList.includes(name)
141
- );
146
+ const runningContainers = containerList.filter((containerName) => containerName.startsWith(prefix));
142
147
 
143
148
  if (runningContainers.length === 0) {
144
149
  task.skip();
145
150
  return;
146
151
  }
147
152
 
148
- await stop(runningContainers.map(({ name }) => name));
153
+ await stop(runningContainers);
149
154
  }
150
155
  });
151
156
 
@@ -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
 
4
5
  /**
@@ -29,7 +30,7 @@ Do you want remove all custom networks not used by at least one container?`
29
30
  );
30
31
  }
31
32
 
32
- throw new Error(`Unable to create network for your project.
33
+ throw new KnownError(`Unable to create network for your project.
33
34
  You need to delete unused networks yourself.
34
35
  Use command ${logger.style.command('docker network prune')}`);
35
36
  }
@@ -20,10 +20,10 @@ const create = ({
20
20
  const createVolumes = () => ({
21
21
  title: 'Creating volumes',
22
22
  task: async ({ config: { docker } }, task) => {
23
- const volumeList = (await execAsyncSpawn('docker volume ls -q')).split('\n');
23
+ const volumeList = (await execAsyncSpawn('docker volume ls --format "{{.Name}}"')).split('\n');
24
24
 
25
25
  const missingVolumes = Object.values(docker.volumes).filter(
26
- ({ name }) => !volumeList.some((volume) => volume === name)
26
+ ({ name }) => !volumeList.includes(name)
27
27
  );
28
28
 
29
29
  if (missingVolumes.length === 0) {
@@ -41,10 +41,10 @@ const createVolumes = () => ({
41
41
  const removeVolumes = () => ({
42
42
  title: 'Removing volumes',
43
43
  task: async ({ config: { docker } }, task) => {
44
- const volumeList = (await execAsyncSpawn('docker volume ls -q')).split('\n');
44
+ const volumeList = (await execAsyncSpawn('docker volume ls --format "{{.Name}}"')).split('\n');
45
45
 
46
46
  const deployedVolumes = Object.values(docker.volumes).filter(
47
- ({ name }) => volumeList.some((volume) => volume === name)
47
+ ({ name }) => volumeList.includes(name)
48
48
  );
49
49
 
50
50
  if (deployedVolumes.length === 0) {
@@ -1,9 +1,7 @@
1
1
  const os = require('os');
2
2
  const path = require('path');
3
- const fs = require('fs');
4
3
  const setConfigFile = require('../../util/set-config');
5
- const pathExists = require('../../util/path-exists');
6
- const { isIpAddress } = require('../../util/ip');
4
+ const UnknownError = require('../../errors/unknown-error');
7
5
 
8
6
  /**
9
7
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
@@ -23,41 +21,13 @@ const createNginxConfig = () => ({
23
21
  const {
24
22
  configuration: {
25
23
  nginx
26
- },
27
- ssl,
28
- host
29
- } = overridenConfiguration;
30
-
31
- if (ssl.enabled) {
32
- if (!(await pathExists(ssl.ssl_certificate))) {
33
- throw new Error('ssl.ssl_certificate file does not exist!');
34
- }
35
- if (!(await pathExists(ssl.ssl_certificate_key))) {
36
- throw new Error('ssl.ssl_certificate_key file does not exist!');
37
24
  }
25
+ } = overridenConfiguration;
38
26
 
39
- await fs.promises.copyFile(
40
- ssl.ssl_certificate,
41
- path.join(
42
- baseConfig.cacheDir,
43
- 'nginx',
44
- 'conf.d',
45
- 'ssl_certificate.pem'
46
- )
47
- );
48
- await fs.promises.copyFile(
49
- ssl.ssl_certificate_key,
50
- path.join(
51
- baseConfig.cacheDir,
52
- 'nginx',
53
- 'conf.d',
54
- 'ssl_certificate-key.pem'
55
- )
56
- );
57
- }
58
-
59
- const networkToBindTo = isIpAddress(host) ? host : '127.0.0.1';
60
27
  const isLinux = os.platform() === 'linux';
28
+ const isNativeLinux = isLinux && !isWsl;
29
+ const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
30
+ const hostPort = isNativeLinux ? ports.app : 80;
61
31
 
62
32
  try {
63
33
  await setConfigFile({
@@ -72,14 +42,13 @@ const createNginxConfig = () => ({
72
42
  templateArgs: {
73
43
  ports,
74
44
  mageRoot: baseConfig.magentoDir,
75
- hostMachine: (isLinux && !isWsl) ? '127.0.0.1' : 'host.docker.internal',
76
- hostPort: (isLinux && !isWsl) ? ports.app : 80,
77
- config: overridenConfiguration,
78
- networkToBindTo
45
+ hostMachine,
46
+ hostPort,
47
+ config: overridenConfiguration
79
48
  }
80
49
  });
81
50
  } catch (e) {
82
- throw new Error(`Unexpected error accrued during nginx config creation\n\n${e}`);
51
+ throw new UnknownError(`Unexpected error accrued during nginx config creation\n\n${e}`);
83
52
  }
84
53
  }
85
54
  });
@@ -1,4 +1,5 @@
1
1
  const semver = require('semver');
2
+ const UnknownError = require('../../errors/unknown-error');
2
3
  const setConfigFile = require('../../util/set-config');
3
4
 
4
5
  /**
@@ -21,7 +22,7 @@ const createPhpConfig = () => ({
21
22
  }
22
23
  });
23
24
  } catch (e) {
24
- throw new Error(`Unexpected error accrued during php.ini config creation\n\n${e}`);
25
+ throw new UnknownError(`Unexpected error accrued during php.ini config creation\n\n${e}`);
25
26
  }
26
27
  }
27
28
  });
@@ -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
  /**
@@ -17,7 +18,7 @@ const createPhpFpmConfig = () => ({
17
18
  }
18
19
  });
19
20
  } catch (e) {
20
- throw new Error(`Unexpected error accrued during php-fpm config creation\n\n${e}`);
21
+ throw new UnknownError(`Unexpected error accrued during php-fpm config creation\n\n${e}`);
21
22
  }
22
23
  }
23
24
  });
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable no-param-reassign */
2
2
  const { loadXmlFile, buildXmlFile } = require('../../../config/xml-parser');
3
+ const UnknownError = require('../../../errors/unknown-error');
3
4
  const pathExists = require('../../../util/path-exists');
4
5
  const setConfigFile = require('../../../util/set-config');
5
6
 
@@ -59,12 +60,12 @@ const setupDataSourceLocalConfig = () => ({
59
60
  }
60
61
  );
61
62
 
62
- if (dataSource['@_name'] !== database.dataSourceManagerName) {
63
+ if (!dataSource['@_name']) {
63
64
  hasChanges = true;
64
65
  dataSource['@_name'] = database.dataSourceManagerName;
65
66
  }
66
67
 
67
- if (dataSource['@_uuid'] === undefined) {
68
+ if (!dataSource['@_uuid']) {
68
69
  hasChanges = true;
69
70
  dataSource['@_uuid'] = 'a2eadb3c-6fc9-4d85-b5f4-d8114906ce2f';
70
71
  }
@@ -135,7 +136,7 @@ const setupDataSourceLocalConfig = () => ({
135
136
  }
136
137
  });
137
138
  } catch (e) {
138
- throw new Error(`Unexpected error accrued during dataSources.local.xml config creation\n\n${e}`);
139
+ throw new UnknownError(`Unexpected error accrued during dataSources.local.xml config creation\n\n${e}`);
139
140
  }
140
141
  }
141
142
  }
@@ -228,7 +229,7 @@ const setupDataSourceConfig = () => ({
228
229
  }
229
230
  });
230
231
  } catch (e) {
231
- throw new Error(`Unexpected error accrued during dataSources.xml config creation\n\n${e}`);
232
+ throw new UnknownError(`Unexpected error accrued during dataSources.xml config creation\n\n${e}`);
232
233
  }
233
234
  }
234
235
  }
@@ -61,18 +61,20 @@ const setupESLintConfig = () => ({
61
61
  }
62
62
  };
63
63
  const themes = await getCSAThemes();
64
- const theme = themes[0];
65
64
 
66
- if (await pathExists(theme.themePath)) {
67
- styleLintConfigurationData.project.component['work-dir-pattern'] = {
68
- [valueKey]: formatPathForPHPStormConfig(theme.themePath)
69
- };
70
- const packageJsonPath = path.join(theme.themePath, 'package.json');
71
- if (await pathExists(packageJsonPath)) {
72
- styleLintConfigurationData.project.component['custom-configuration-file'] = {
73
- '@_used': 'true',
74
- '@_path': formatPathForPHPStormConfig(packageJsonPath)
65
+ if (themes.length > 0) {
66
+ const theme = themes[0];
67
+ if (await pathExists(theme.themePath)) {
68
+ styleLintConfigurationData.project.component['work-dir-pattern'] = {
69
+ [valueKey]: formatPathForPHPStormConfig(theme.themePath)
75
70
  };
71
+ const packageJsonPath = path.join(process.cwd(), theme.themePath, 'package.json');
72
+ if (await pathExists(packageJsonPath)) {
73
+ styleLintConfigurationData.project.component['custom-configuration-file'] = {
74
+ '@_used': 'true',
75
+ '@_path': formatPathForPHPStormConfig(packageJsonPath)
76
+ };
77
+ }
76
78
  }
77
79
  }
78
80
 
@@ -18,9 +18,6 @@ const setupCodingStandardOption = async (config) => {
18
18
  [nameKey]: CODING_STANDARD_OPTION_NAME,
19
19
  [valueKey]: CUSTOM_CODING_STANDARD_OPTION_VALUE
20
20
  });
21
- } else if (codingStandardOption[valueKey] !== CUSTOM_CODING_STANDARD_OPTION_VALUE) {
22
- hasChanges = true;
23
- codingStandardOption[valueKey] = CUSTOM_CODING_STANDARD_OPTION_VALUE;
24
21
  }
25
22
 
26
23
  return hasChanges;
@@ -20,9 +20,6 @@ const setupCustomRuleSetPathOption = async (config) => {
20
20
  [nameKey]: CUSTOM_RULE_SET_PATH_OPTION_NAME,
21
21
  [valueKey]: phpCSConfigFormattedPath
22
22
  });
23
- } else if (customRuleSetPathOption && customRuleSetPathOption[valueKey] !== phpCSConfigFormattedPath) {
24
- hasChanges = true;
25
- customRuleSetPathOption[valueKey] = phpCSConfigFormattedPath;
26
23
  }
27
24
 
28
25
  return hasChanges;
@@ -16,7 +16,7 @@ const properties = {
16
16
  */
17
17
  const setupDefaultProperties = (inspectionTool, defaultProperties = properties) => {
18
18
  let hasChanges = false;
19
- if (inspectionTool['@_enabled'] !== defaultProperties.enabled) {
19
+ if (!inspectionTool['@_enabled']) {
20
20
  hasChanges = true;
21
21
  inspectionTool['@_enabled'] = defaultProperties.enabled;
22
22
  }
@@ -18,9 +18,6 @@ const setupMagento2CodingStandardOption = async (config) => {
18
18
  [nameKey]: CODING_STANDARD_OPTION_NAME,
19
19
  [valueKey]: MAGENTO2_CODING_STANDARD_OPTION_VALUE
20
20
  });
21
- } else if (codingStandardOption[valueKey] !== MAGENTO2_CODING_STANDARD_OPTION_VALUE) {
22
- hasChanges = true;
23
- codingStandardOption[valueKey] = MAGENTO2_CODING_STANDARD_OPTION_VALUE;
24
21
  }
25
22
 
26
23
  return hasChanges;
@@ -84,9 +84,6 @@ const setupMessDetectorValidationInspection = async (inspectionToolsData) => {
84
84
  [nameKey]: optionName,
85
85
  [valueKey]: 'true'
86
86
  });
87
- } else if (booleanOption[valueKey] !== 'true') {
88
- hasChanges = true;
89
- booleanOption[valueKey] = 'true';
90
87
  }
91
88
  });
92
89
 
@@ -86,10 +86,7 @@ const setupPhpCSValidationInspection = async (inspectionToolsData) => {
86
86
  (option) => option[nameKey] === EXTENSIONS_OPTION_NAME
87
87
  );
88
88
 
89
- if (extensionsOption && extensionsOption[valueKey] !== 'php') {
90
- hasChanges = true;
91
- extensionsOption[valueKey] = 'php';
92
- } else if (!extensionsOption) {
89
+ if (!extensionsOption) {
93
90
  hasChanges = true;
94
91
  phpCSConfig.option.push({
95
92
  [nameKey]: EXTENSIONS_OPTION_NAME,
@@ -34,10 +34,7 @@ const setupMessDetector = async (phpConfigs) => {
34
34
  (phpmdSetting) => phpmdSetting.MessDetectorConfiguration
35
35
  );
36
36
 
37
- if (messDetectorConfiguration && messDetectorConfiguration[toolPathKey] !== phpMDBinaryFormattedPath) {
38
- hasChanges = true;
39
- messDetectorConfiguration[toolPathKey] = phpMDBinaryFormattedPath;
40
- } else if (!messDetectorConfiguration) {
37
+ if (!messDetectorConfiguration) {
41
38
  hasChanges = true;
42
39
  messDetectorComponent.phpmd_settings.push(defaultMessDetectorSetting);
43
40
  }
@@ -46,17 +46,7 @@ const setupPHPCodeSniffer = async (phpConfigs) => {
46
46
  (phpcsSetting) => phpcsSetting.PhpCSConfiguration
47
47
  );
48
48
 
49
- if (phpCodeSnifferConfiguration) {
50
- if (phpCodeSnifferConfiguration[toolPathKey] !== phpCodeSnifferBinaryFormattedPath) {
51
- hasChanges = true;
52
- phpCodeSnifferConfiguration[toolPathKey] = phpCodeSnifferBinaryFormattedPath;
53
- }
54
-
55
- if (phpCodeSnifferConfiguration[beautifierPathKey] !== phpCodeSnifferBeautifierBinaryFormattedPath) {
56
- hasChanges = true;
57
- phpCodeSnifferConfiguration[beautifierPathKey] = phpCodeSnifferBeautifierBinaryFormattedPath;
58
- }
59
- } else {
49
+ if (!phpCodeSnifferConfiguration) {
60
50
  hasChanges = true;
61
51
  phpCodeSnifferComponent.phpcs_settings.push(defaultPHPCSSetting);
62
52
  }
@@ -38,12 +38,7 @@ const setupPHPCSFixer = async (phpConfigs) => {
38
38
  (phpcsfixerSetting) => phpcsfixerSetting.PhpCSFixerConfiguration
39
39
  );
40
40
 
41
- if (phpCSFixerConfiguration) {
42
- if (phpCSFixerConfiguration[toolPathKey] !== phpCSFixerBinaryFormattedPath) {
43
- hasChanges = true;
44
- phpCSFixerConfiguration[toolPathKey] = phpCSFixerBinaryFormattedPath;
45
- }
46
- } else {
41
+ if (!phpCSFixerConfiguration) {
47
42
  hasChanges = true;
48
43
  phpCSFixerComponent.phpcsfixer_settings.push(defaultPHPCSFixerSettings);
49
44
  }
@@ -34,21 +34,11 @@ const setupPHPProjectSharedConfiguration = async (phpConfigs, currentPhpLanguage
34
34
  phpProjectSharedConfigurationComponent.option = [];
35
35
  }
36
36
 
37
- if (phpProjectSharedConfigurationComponent[phpLanguageLevelKey] !== currentPhpLanguageLevel) {
38
- hasChanges = true;
39
- phpProjectSharedConfigurationComponent[phpLanguageLevelKey] = currentPhpLanguageLevel;
40
- }
41
-
42
37
  const suggestedChangeDefaultLanguageLevelOption = phpProjectSharedConfigurationComponent.option.find(
43
38
  (phpProjectSharedConfigOption) => phpProjectSharedConfigOption[nameKey] === SUGGESTED_CHANGE_DEFAULT_LANGUAGE_LEVEL_OPTION_NAME
44
39
  );
45
40
 
46
- if (suggestedChangeDefaultLanguageLevelOption) {
47
- if (suggestedChangeDefaultLanguageLevelOption[valueKey] !== 'false') {
48
- hasChanges = true;
49
- suggestedChangeDefaultLanguageLevelOption[valueKey] = 'false';
50
- }
51
- } else {
41
+ if (!suggestedChangeDefaultLanguageLevelOption) {
52
42
  hasChanges = true;
53
43
  phpProjectSharedConfigurationComponent.option.push(defaultSuggestChangeDefaultLanguageLevelOption);
54
44
  }
@@ -48,9 +48,8 @@ const setupComposerSettings = async (workspaceConfigs) => {
48
48
 
49
49
  if (composerSettingsComponent) {
50
50
  if (
51
- 'pharConfigPath' in composerSettingsComponent
51
+ !('pharConfigPath' in composerSettingsComponent)
52
52
  && isComposerJsonExists
53
- && composerSettingsComponent.pharConfigPath !== composerJsonFormattedPath
54
53
  ) {
55
54
  hasChanges = true;
56
55
  composerSettingsComponent.pharConfigPath = composerJsonFormattedPath;
@@ -58,7 +57,7 @@ const setupComposerSettings = async (workspaceConfigs) => {
58
57
 
59
58
  const pharConfig = composerSettingsComponent.execution && composerSettingsComponent.execution.phar;
60
59
 
61
- if (pharConfig && isComposerPharExists && pharConfig[pharPathKey] !== composerPharFormattedPath) {
60
+ if (pharConfig && isComposerPharExists && !(pharPathKey in pharConfig)) {
62
61
  hasChanges = true;
63
62
  pharConfig[pharPathKey] = composerPharFormattedPath;
64
63
  } else if (!pharConfig && isComposerPharExists) {
@@ -33,10 +33,7 @@ const setupPHPServers = async (workspaceConfigs, phpStormConfiguration) => {
33
33
 
34
34
  const serverConfiguration = phpServersComponent.servers.find((server) => server.server[nameKey] === xdebug.serverName);
35
35
 
36
- if (serverConfiguration && serverConfiguration.server[hostKey] !== xdebug.debugServerAddress) {
37
- hasChanges = true;
38
- serverConfiguration.server[hostKey] = xdebug.debugServerAddress;
39
- } else if (!serverConfiguration) {
36
+ if (!serverConfiguration) {
40
37
  hasChanges = true;
41
38
  phpServersComponent.servers.push({
42
39
  server: defaultServerConfig
@@ -24,9 +24,7 @@ const setupPropertiesComponent = async (workspaceConfigs) => {
24
24
  (workspaceConfig) => workspaceConfig[nameKey] === PROPERTIES_COMPONENT_NAME
25
25
  );
26
26
 
27
- if (propertiesComponent) {
28
- // check later
29
- } else {
27
+ if (!propertiesComponent) {
30
28
  hasChanges = true;
31
29
  const themes = await getCSAThemes();
32
30
  if (themes.length > 0) {
@@ -41,7 +39,7 @@ const setupPropertiesComponent = async (workspaceConfigs) => {
41
39
  }
42
40
  workspaceConfigs.push({
43
41
  [nameKey]: PROPERTIES_COMPONENT_NAME,
44
- '#text': JSON.stringify(defaultProperties)
42
+ _cdata: JSON.stringify(defaultProperties)
45
43
  });
46
44
  }
47
45
 
@@ -44,17 +44,7 @@ const setupRunManager = async (workspaceConfigs, phpStormConfiguration) => {
44
44
  (configuration) => configuration['@_type'] === PHP_REMOTE_DEBUG_RUN_CONFIGURATION_TYPE && configuration[nameKey] === xdebug.runManagerName
45
45
  );
46
46
 
47
- if (phpRemoteDebugRunConfiguration) {
48
- if (phpRemoteDebugRunConfiguration[serverNameKey] !== xdebug.serverName) {
49
- hasChanges = true;
50
- phpRemoteDebugRunConfiguration[serverNameKey] = xdebug.serverName;
51
- }
52
-
53
- if (phpRemoteDebugRunConfiguration[sessionIdKey] !== xdebug.sessionId) {
54
- hasChanges = true;
55
- phpRemoteDebugRunConfiguration[sessionIdKey] = xdebug.sessionId;
56
- }
57
- } else {
47
+ if (!phpRemoteDebugRunConfiguration) {
58
48
  hasChanges = true;
59
49
  runManagerComponent.configuration.push(defaultRunManagerConfiguration);
60
50
  }
@@ -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;