@scandipwa/magento-scripts 1.16.0 → 2.0.0-alpha.1

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 (225) hide show
  1. package/lib/commands/cli.js +4 -6
  2. package/lib/commands/execute.js +29 -4
  3. package/lib/commands/import-db.js +1 -1
  4. package/lib/commands/logs.js +1 -1
  5. package/lib/commands/start.js +38 -20
  6. package/lib/commands/status.js +2 -0
  7. package/lib/config/docker.js +98 -83
  8. package/lib/config/get-project-configuration.js +3 -1
  9. package/lib/config/index.js +10 -7
  10. package/lib/config/magento/required-php-extensions/index.js +29 -0
  11. package/lib/config/magento/required-php-extensions/magento-2.3.js +19 -0
  12. package/lib/config/magento/required-php-extensions/magento-2.4.js +29 -0
  13. package/lib/config/php/base-repo.js +3 -0
  14. package/lib/config/php/extensions/apcu.js +12 -0
  15. package/lib/config/php/extensions/bcmath.js +7 -0
  16. package/lib/config/php/extensions/curl.js +11 -0
  17. package/lib/config/php/extensions/gd.js +14 -0
  18. package/lib/config/php/extensions/index.js +18 -2
  19. package/lib/config/php/extensions/intl.js +10 -0
  20. package/lib/config/php/extensions/opcache.js +10 -0
  21. package/lib/config/php/extensions/pdo_mysql.js +7 -0
  22. package/lib/config/php/extensions/soap.js +10 -0
  23. package/lib/config/php/extensions/sodium.js +10 -0
  24. package/lib/config/php/extensions/xdebug.js +8 -5
  25. package/lib/config/php/extensions/xsl.js +10 -0
  26. package/lib/config/php/extensions/zip.js +10 -0
  27. package/lib/config/php/{releases → versions}/index.js +0 -0
  28. package/lib/config/php/versions/php-7.2.js +23 -0
  29. package/lib/config/php/versions/php-7.3.js +23 -0
  30. package/lib/config/php/versions/php-7.4.js +23 -0
  31. package/lib/config/php/versions/php-8.1.js +23 -0
  32. package/lib/config/php-config.js +8 -12
  33. package/lib/config/port-config.js +2 -6
  34. package/lib/config/services/elasticsearch/base-repo.js +3 -0
  35. package/lib/config/services/elasticsearch/versions/elasticsearch-6.8.js +23 -0
  36. package/lib/config/services/elasticsearch/versions/index.js +5 -0
  37. package/lib/config/templates/magentorc.template +5 -5
  38. package/lib/config/templates/mariadb.template.cnf +191 -0
  39. package/lib/config/templates/php-fpm.template.conf +3 -3
  40. package/lib/config/templates/php.template.ini +12 -6
  41. package/lib/config/templates/ssl-terminator.template.conf +1 -1
  42. package/lib/config/templates/vscode-launch.template.json +3 -1
  43. package/lib/config/versions/magento-2.3.0.js +10 -5
  44. package/lib/config/versions/magento-2.3.1.js +10 -5
  45. package/lib/config/versions/magento-2.3.2-p1.js +43 -0
  46. package/lib/config/versions/magento-2.3.2-p2.js +10 -5
  47. package/lib/config/versions/magento-2.3.2.js +10 -5
  48. package/lib/config/versions/magento-2.3.3-p1.js +10 -5
  49. package/lib/config/versions/magento-2.3.3.js +10 -5
  50. package/lib/config/versions/magento-2.3.4-p1.js +43 -0
  51. package/lib/config/versions/magento-2.3.4-p2.js +10 -5
  52. package/lib/config/versions/magento-2.3.4.js +10 -5
  53. package/lib/config/versions/magento-2.3.5-p1.js +8 -2
  54. package/lib/config/versions/magento-2.3.5-p2.js +8 -2
  55. package/lib/config/versions/magento-2.3.5.js +8 -2
  56. package/lib/config/versions/magento-2.3.6-p1.js +8 -2
  57. package/lib/config/versions/magento-2.3.6.js +8 -2
  58. package/lib/config/versions/magento-2.3.7-p1.js +8 -2
  59. package/lib/config/versions/magento-2.3.7-p2.js +8 -2
  60. package/lib/config/versions/magento-2.3.7-p3.js +8 -2
  61. package/lib/config/versions/magento-2.3.7.js +8 -2
  62. package/lib/config/versions/magento-2.4.0-p1.js +9 -3
  63. package/lib/config/versions/magento-2.4.0.js +9 -3
  64. package/lib/config/versions/magento-2.4.1-p1.js +6 -5
  65. package/lib/config/versions/magento-2.4.1.js +9 -2
  66. package/lib/config/versions/magento-2.4.2-p1.js +6 -5
  67. package/lib/config/versions/magento-2.4.2-p2.js +6 -6
  68. package/lib/config/versions/magento-2.4.2.js +6 -6
  69. package/lib/config/versions/magento-2.4.3-p1.js +7 -7
  70. package/lib/config/versions/magento-2.4.3-p2.js +7 -7
  71. package/lib/config/versions/magento-2.4.3.js +7 -7
  72. package/lib/config/versions/magento-2.4.4.js +9 -2
  73. package/lib/tasks/cleanup.js +3 -3
  74. package/lib/tasks/composer/index.js +14 -104
  75. package/lib/tasks/database/connect-to-database.js +117 -0
  76. package/lib/tasks/database/create-magento-database.js +18 -0
  77. package/lib/tasks/{mysql → database}/dump-theme-config.js +3 -3
  78. package/lib/tasks/{mysql → database}/fix-db.js +2 -2
  79. package/lib/tasks/{mysql/import-dump-to-mysql.js → database/import-dump-to-database.js} +65 -22
  80. package/lib/tasks/{mysql → database}/import-remote-db/index.js +0 -0
  81. package/lib/tasks/{mysql/import-remote-db/ssh/mysqldump-command.js → database/import-remote-db/ssh/database-dump-command.js} +2 -2
  82. package/lib/tasks/{mysql → database}/import-remote-db/ssh/index.js +0 -0
  83. package/lib/tasks/{mysql → database}/import-remote-db/ssh/readymage.js +4 -4
  84. package/lib/tasks/{mysql → database}/import-remote-db/ssh/regular-server.js +2 -2
  85. package/lib/tasks/{mysql → database}/index.js +2 -2
  86. package/lib/tasks/{mysql → database}/magento-tables.js +0 -0
  87. package/lib/tasks/{mysql → database}/restore-theme-config.js +4 -4
  88. package/lib/tasks/docker/api.d.ts +71 -0
  89. package/lib/tasks/docker/api.js +30 -0
  90. package/lib/tasks/docker/containers/container-api.d.ts +128 -0
  91. package/lib/tasks/docker/containers/container-api.js +153 -0
  92. package/lib/tasks/docker/containers/index.js +19 -0
  93. package/lib/tasks/docker/containers/tasks.js +215 -0
  94. package/lib/tasks/docker/convert-legacy-volumes.js +15 -10
  95. package/lib/tasks/docker/convert-mysql-to-mariadb.js +284 -0
  96. package/lib/tasks/docker/image/image-api.d.ts +34 -0
  97. package/lib/tasks/docker/image/image-api.js +49 -0
  98. package/lib/tasks/docker/image/index.js +5 -0
  99. package/lib/tasks/docker/index.js +1 -13
  100. package/lib/tasks/docker/network/index.js +7 -0
  101. package/lib/tasks/docker/network/network-api.d.ts +103 -0
  102. package/lib/tasks/docker/network/network-api.js +99 -0
  103. package/lib/tasks/docker/{network.js → network/tasks.js} +17 -10
  104. package/lib/tasks/docker/project-image-builder.js +167 -0
  105. package/lib/tasks/docker/volume/index.js +8 -0
  106. package/lib/tasks/docker/{volumes.js → volume/tasks.js} +5 -19
  107. package/lib/tasks/docker/volume/volume-api.d.ts +39 -0
  108. package/lib/tasks/docker/volume/volume-api.js +66 -0
  109. package/lib/tasks/execute/index.js +5 -2
  110. package/lib/tasks/file-system/create-mariadb-config.js +23 -0
  111. package/lib/tasks/file-system/create-nginx-config.js +2 -3
  112. package/lib/tasks/file-system/create-php-config.js +20 -5
  113. package/lib/tasks/file-system/create-php-fpm-config.js +8 -4
  114. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +41 -29
  115. package/lib/tasks/file-system/create-phpstorm-config/index.js +2 -0
  116. package/lib/tasks/file-system/create-phpstorm-config/keys.js +15 -1
  117. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +4 -1
  118. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-config.js +3 -3
  119. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-interpreters-config.js +81 -0
  120. package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/index.js +42 -0
  121. package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/php-docker-settings-config.js +9 -0
  122. package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/setup-php-docker-container-settings-config.js +66 -0
  123. package/lib/tasks/file-system/create-phpstorm-config/setup-xml-structure.js +11 -9
  124. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +2 -1
  125. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +15 -30
  126. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +24 -5
  127. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/mess-detector-project-configuration-config.js +50 -0
  128. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-code-sniffer-project-configuration-config.js +50 -0
  129. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-cs-fixer-project-configuration-config.js +50 -0
  130. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +15 -15
  131. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +29 -3
  132. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-stan-project-configuration-config.js.js +50 -0
  133. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-workspace-project-configuration-config.js +42 -0
  134. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/psalm-project-configuration-config.js.js +50 -0
  135. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/workspace-config.js +0 -2
  136. package/lib/tasks/file-system/create-ssl-terminator-config.js +4 -2
  137. package/lib/tasks/file-system/create-vscode-config.js +57 -42
  138. package/lib/tasks/file-system/index.js +5 -2
  139. package/lib/tasks/import-dump.js +6 -6
  140. package/lib/tasks/link.js +5 -4
  141. package/lib/tasks/magento/install-magento-project.js +31 -63
  142. package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +4 -4
  143. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +7 -3
  144. package/lib/tasks/magento/setup-magento/create-admin.js +5 -6
  145. package/lib/tasks/magento/setup-magento/delete-admin-users.js +2 -2
  146. package/lib/tasks/magento/setup-magento/delete-customers.js +4 -4
  147. package/lib/tasks/magento/setup-magento/delete-orders.js +4 -4
  148. package/lib/tasks/magento/setup-magento/disable-2fa.js +3 -5
  149. package/lib/tasks/magento/setup-magento/disable-maintenance-mode.js +3 -4
  150. package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +2 -2
  151. package/lib/tasks/magento/setup-magento/index.js +3 -3
  152. package/lib/tasks/magento/setup-magento/install-magento.js +47 -40
  153. package/lib/tasks/magento/setup-magento/migrate-database.js +7 -14
  154. package/lib/tasks/magento/setup-magento/set-base-url.js +2 -2
  155. package/lib/tasks/magento/setup-magento/set-deployment-mode.js +4 -4
  156. package/lib/tasks/magento/setup-magento/set-url-rewrite.js +2 -2
  157. package/lib/tasks/magento/setup-magento/varnish-config.js +11 -9
  158. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +128 -3
  159. package/lib/tasks/php/php-container.js +108 -0
  160. package/lib/tasks/php/update-env-php.js +39 -21
  161. package/lib/tasks/php/update-env.php +66 -61
  162. package/lib/tasks/php/working_health_check.php +85 -0
  163. package/lib/tasks/requirements/{composer.js → composer-credentials.js} +3 -1
  164. package/lib/tasks/requirements/docker/index.js +15 -12
  165. package/lib/tasks/requirements/docker/performance.js +54 -0
  166. package/lib/tasks/requirements/docker/version.js +8 -8
  167. package/lib/tasks/requirements/index.js +5 -8
  168. package/lib/tasks/requirements/php-version.js +8 -116
  169. package/lib/tasks/requirements/platform.js +12 -25
  170. package/lib/tasks/start.js +24 -51
  171. package/lib/tasks/status/index.js +8 -12
  172. package/lib/tasks/stop.js +0 -2
  173. package/lib/tasks/theme/install-theme.js +1 -1
  174. package/lib/tasks/theme/link-theme.js +2 -2
  175. package/lib/tasks/theme/symlink-theme.js +2 -3
  176. package/lib/util/config-file-validator.js +27 -13
  177. package/lib/util/config-php-json.js +13 -4
  178. package/lib/util/database.js +7 -7
  179. package/lib/util/dockerfile-builder/build-instructions.js +197 -0
  180. package/lib/util/dockerfile-builder/index.js +276 -0
  181. package/lib/util/dockerfile-builder/types.d.ts +123 -0
  182. package/lib/util/env-php-json.js +10 -6
  183. package/lib/util/exec-async-command.js +3 -9
  184. package/lib/util/macos-version.js +20 -0
  185. package/lib/util/magento-task.js +3 -4
  186. package/lib/util/nginx-logs-parser.js +122 -0
  187. package/lib/util/php-task.js +3 -6
  188. package/lib/util/run-composer.js +6 -14
  189. package/lib/util/run-container-image.js +17 -0
  190. package/lib/util/run-magento.js +6 -14
  191. package/lib/util/run-php.js +6 -17
  192. package/package.json +9 -9
  193. package/typings/context.d.ts +7 -13
  194. package/typings/index.d.ts +67 -85
  195. package/yarn-error.log +9660 -0
  196. package/lib/config/composer.js +0 -11
  197. package/lib/config/php/extensions/libsodium.js +0 -36
  198. package/lib/config/php/releases/php-7.2.js +0 -25
  199. package/lib/config/php/releases/php-7.3.js +0 -25
  200. package/lib/config/php/releases/php-7.4.js +0 -23
  201. package/lib/config/php/releases/php-8.1.js +0 -25
  202. package/lib/config/phpbrew.js +0 -12
  203. package/lib/tasks/composer/install-prestissimo.js +0 -103
  204. package/lib/tasks/docker/containers.js +0 -231
  205. package/lib/tasks/mysql/connect-to-mysql.js +0 -114
  206. package/lib/tasks/mysql/create-magento-database.js +0 -18
  207. package/lib/tasks/php/bundled-extensions.js +0 -27
  208. package/lib/tasks/php/compile-options.js +0 -56
  209. package/lib/tasks/php/compile.js +0 -55
  210. package/lib/tasks/php/configure.js +0 -89
  211. package/lib/tasks/php/extensions/disable.js +0 -49
  212. package/lib/tasks/php/extensions/enable.js +0 -52
  213. package/lib/tasks/php/extensions/index.js +0 -80
  214. package/lib/tasks/php/extensions/install.js +0 -54
  215. package/lib/tasks/php/index.js +0 -79
  216. package/lib/tasks/php/install-sodium.js +0 -93
  217. package/lib/tasks/php/update-phpbrew.js +0 -45
  218. package/lib/tasks/php/validate-php.js +0 -67
  219. package/lib/tasks/php-fpm/get-process-id.js +0 -14
  220. package/lib/tasks/php-fpm/index.js +0 -4
  221. package/lib/tasks/php-fpm/start-php-fpm.js +0 -49
  222. package/lib/tasks/php-fpm/stop-php-fpm.js +0 -48
  223. package/lib/tasks/requirements/phpbrew/index.js +0 -61
  224. package/lib/tasks/requirements/phpbrew/install.js +0 -159
  225. package/lib/tasks/requirements/phpbrew/version.js +0 -28
@@ -1,4 +1,3 @@
1
- const os = require('os');
2
1
  const path = require('path');
3
2
  const setConfigFile = require('../../util/set-config');
4
3
  const UnknownError = require('../../errors/unknown-error');
@@ -24,7 +23,7 @@ const createNginxConfig = () => ({
24
23
  }
25
24
  } = overridenConfiguration;
26
25
 
27
- const isLinux = os.platform() === 'linux';
26
+ const isLinux = ctx.platform === 'linux';
28
27
  const isNativeLinux = isLinux && !isWsl;
29
28
  const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
30
29
  const hostPort = isNativeLinux ? ports.app : 80;
@@ -41,7 +40,7 @@ const createNginxConfig = () => ({
41
40
  overwrite: true,
42
41
  templateArgs: {
43
42
  ports,
44
- mageRoot: baseConfig.magentoDir,
43
+ mageRoot: baseConfig.containerMagentoDir,
45
44
  hostMachine,
46
45
  hostPort,
47
46
  config: overridenConfiguration
@@ -1,24 +1,39 @@
1
1
  const semver = require('semver');
2
2
  const UnknownError = require('../../errors/unknown-error');
3
3
  const setConfigFile = require('../../util/set-config');
4
+ const { getEnabledExtensionsFromImage } = require('../docker/project-image-builder');
4
5
 
5
6
  /**
6
7
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
7
8
  */
8
9
  const createPhpConfig = () => ({
9
10
  title: 'Setting PHP config',
10
- task: async ({ config: { php, baseConfig, overridenConfiguration: { configuration } }, debug, ports }) => {
11
- const isXDebug2 = semver.satisfies(configuration.php.extensions.xdebug.version, '2');
11
+ task: async (ctx) => {
12
+ const {
13
+ config: {
14
+ php,
15
+ baseConfig
16
+ },
17
+ debug
18
+ } = ctx;
19
+ const containers = ctx.config.docker.getContainers(ctx.ports);
20
+ const phpExtensions = await getEnabledExtensionsFromImage(containers.php.debugImage);
21
+ const isXDebug2 = semver.satisfies(phpExtensions.xdebug, '2');
22
+
23
+ const isLinux = ctx.platform === 'linux';
24
+ const isNativeLinux = isLinux && !ctx.isWsl;
25
+ const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
26
+
12
27
  try {
13
28
  await setConfigFile({
14
29
  configPathname: php.iniPath,
15
30
  template: php.iniTemplatePath,
16
31
  overwrite: true,
17
32
  templateArgs: {
18
- ports,
19
33
  debug,
20
- mageRoot: baseConfig.magentoDir,
21
- isXDebug2
34
+ mageRoot: baseConfig.containerMagentoDir,
35
+ isXDebug2,
36
+ hostMachine
22
37
  }
23
38
  });
24
39
  } catch (e) {
@@ -1,4 +1,3 @@
1
- const path = require('path');
2
1
  const UnknownError = require('../../errors/unknown-error');
3
2
  const setConfigFile = require('../../util/set-config');
4
3
 
@@ -7,14 +6,19 @@ const setConfigFile = require('../../util/set-config');
7
6
  */
8
7
  const createPhpFpmConfig = () => ({
9
8
  title: 'Setting php-fpm config',
10
- task: async ({ ports, config: { php, baseConfig } }) => {
9
+ task: async (ctx) => {
10
+ const { config: { php } } = ctx;
11
+ const isLinux = ctx.platform === 'linux';
12
+ const isNativeLinux = isLinux && !ctx.isWsl;
13
+ const port = isNativeLinux ? ctx.ports.fpm : 9000;
14
+
11
15
  try {
12
16
  await setConfigFile({
13
17
  configPathname: php.fpmConfPath,
14
- template: path.join(baseConfig.templateDir, 'php-fpm.template.conf'),
18
+ template: php.fpmTemplatePath,
15
19
  overwrite: true,
16
20
  templateArgs: {
17
- ports
21
+ port
18
22
  }
19
23
  });
20
24
  } catch (e) {
@@ -1,17 +1,26 @@
1
1
  const path = require('path');
2
2
  const { loadXmlFile, buildXmlFile } = require('../../../config/xml-parser');
3
3
  const pathExists = require('../../../util/path-exists');
4
+ const {
5
+ urlKey, typeKey, versionKey, nameKey
6
+ } = require('./keys');
4
7
  const { formatPathForPHPStormConfig } = require('./xml-utils');
5
8
 
6
9
  const pathToModulesConfig = path.join(process.cwd(), '.idea', 'modules.xml');
7
10
  const excludeFoldersPaths = [
8
11
  'bin',
9
12
  'dev',
10
- 'pub',
11
- 'setup',
13
+ 'pub/static',
12
14
  'var/cache',
13
15
  'var/page_cache',
14
- 'var/log'
16
+ 'var/log',
17
+ 'var/composer_home',
18
+ 'var/view_preprocessed'
19
+ ].map((p) => `file://$MODULE_DIR$/${p}`);
20
+
21
+ const mustBeIncludedPaths = [
22
+ 'pub',
23
+ 'setup'
15
24
  ].map((p) => `file://$MODULE_DIR$/${p}`);
16
25
 
17
26
  /**
@@ -24,26 +33,23 @@ const getProjectConfigFilePath = async () => {
24
33
  return modulesConfigData.project.component.modules.module['@_filepath'].replace('$PROJECT_DIR$', process.cwd());
25
34
  };
26
35
 
27
- /**
28
- * @returns {Array<{'@_url': string}>}
29
- */
30
- const getExcludedFoldersConfig = (projectConfigData) => {
36
+ const setupDefaultsForExcludedFoldersConfig = (projectConfigData) => {
31
37
  if (!projectConfigData.module) {
32
38
  projectConfigData.module = {
33
- '@_type': 'WEB_MODULE',
34
- '@_version': '4'
39
+ [typeKey]: 'WEB_MODULE',
40
+ [versionKey]: '4'
35
41
  };
36
42
  }
37
43
 
38
44
  if (!projectConfigData.module.component) {
39
45
  projectConfigData.module.component = {
40
- '@_name': 'NewModuleRootManager',
46
+ [nameKey]: 'NewModuleRootManager',
41
47
  orderEntry: [
42
48
  {
43
- '@_type': 'inheritedJdk'
49
+ [typeKey]: 'inheritedJdk'
44
50
  },
45
51
  {
46
- '@_type': 'sourceFolder',
52
+ [typeKey]: 'sourceFolder',
47
53
  '@_forTest': 'false'
48
54
  }
49
55
  ]
@@ -52,37 +58,42 @@ const getExcludedFoldersConfig = (projectConfigData) => {
52
58
 
53
59
  if (!projectConfigData.module.component.content) {
54
60
  projectConfigData.module.component.content = {
55
- '@_url': 'file://$MODULE_DIR$'
61
+ [urlKey]: 'file://$MODULE_DIR$'
56
62
  };
57
63
  }
58
64
 
59
65
  if (!projectConfigData.module.component.content.excludeFolder) {
60
66
  projectConfigData.module.component.content.excludeFolder = [];
61
67
  }
62
-
63
- return projectConfigData
64
- .module.component.content.excludeFolder;
65
68
  };
66
69
 
67
- const setupExcludedFolders = (excludedFoldersConfig) => {
70
+ const setupExcludedFolders = (projectConfigData) => {
71
+ const { excludeFolder } = projectConfigData.module.component.content;
68
72
  let hasChanges = false;
69
73
  // filter excluded folders to get ones that needs to be added to excluded folders list
70
74
  const missingExcludedFolders = excludeFoldersPaths
71
75
  .filter(
72
- (excludeFoldersPath) => !excludedFoldersConfig.some(
73
- (config) => config['@_url'] === excludeFoldersPath
76
+ (excludeFoldersPath) => !excludeFolder.some(
77
+ (config) => config[urlKey] === excludeFoldersPath
74
78
  )
75
79
  );
76
80
 
77
81
  if (missingExcludedFolders.length > 0) {
78
82
  hasChanges = true;
79
83
  missingExcludedFolders.forEach((missingExcludedFolder) => {
80
- excludedFoldersConfig.unshift({
81
- '@_url': missingExcludedFolder
84
+ projectConfigData.module.component.content.excludeFolder.unshift({
85
+ [urlKey]: missingExcludedFolder
82
86
  });
83
87
  });
84
88
  }
85
89
 
90
+ const hasSomePathsThatMustBeFiltered = excludeFolder.some((config) => mustBeIncludedPaths.includes(config[urlKey]));
91
+
92
+ if (hasSomePathsThatMustBeFiltered) {
93
+ projectConfigData.module.component.content.excludeFolder = excludeFolder.filter((config) => !mustBeIncludedPaths.includes(config[urlKey]));
94
+ hasChanges = true;
95
+ }
96
+
86
97
  return hasChanges;
87
98
  };
88
99
 
@@ -94,13 +105,13 @@ const getIMLFilePath = async () => {
94
105
 
95
106
  const modulesConfig = {
96
107
  '?xml': {
97
- '@_version': '1.0',
108
+ [versionKey]: '1.0',
98
109
  '@_encoding': 'UTF-8'
99
110
  },
100
111
  project: {
101
- '@_version': '4',
112
+ [versionKey]: '4',
102
113
  component: {
103
- '@_name': 'ProjectModuleManager',
114
+ [nameKey]: 'ProjectModuleManager',
104
115
  modules: [
105
116
  {
106
117
  module: {
@@ -129,8 +140,8 @@ const setupExcludedFoldersConfig = () => ({
129
140
  const projectFilePath = await getProjectConfigFilePath();
130
141
  if (await pathExists(projectFilePath)) {
131
142
  const projectConfigData = await loadXmlFile(projectFilePath);
132
- const excludedFoldersConfig = getExcludedFoldersConfig(projectConfigData);
133
- const hasChanges = setupExcludedFolders(excludedFoldersConfig);
143
+ setupDefaultsForExcludedFoldersConfig(projectConfigData);
144
+ const hasChanges = setupExcludedFolders(projectConfigData);
134
145
  if (hasChanges) {
135
146
  await buildXmlFile(projectFilePath, projectConfigData);
136
147
  } else {
@@ -144,12 +155,13 @@ const setupExcludedFoldersConfig = () => ({
144
155
  const projectFilePath = await getIMLFilePath();
145
156
  const projectConfigData = {
146
157
  '?xml': {
147
- '@_version': '1.0',
158
+ [versionKey]: '1.0',
148
159
  '@_encoding': 'UTF-8'
149
160
  }
150
161
  };
151
- const excludedFoldersConfig = getExcludedFoldersConfig(projectConfigData);
152
- setupExcludedFolders(excludedFoldersConfig);
162
+
163
+ setupDefaultsForExcludedFoldersConfig(projectConfigData);
164
+ setupExcludedFolders(projectConfigData);
153
165
 
154
166
  await buildXmlFile(projectFilePath, projectConfigData);
155
167
  }
@@ -5,6 +5,7 @@ const setupInspectionToolsConfig = require('./inspection-tools-config');
5
5
  const setupExcludedFoldersConfig = require('./exclude-folder-config');
6
6
  const setupStylelintConfig = require('./stylelint-config');
7
7
  const setupESLintConfig = require('./eslint-config');
8
+ const setupPhpDockerSettingsConfig = require('./php-docker-settings-config');
8
9
 
9
10
  /**
10
11
  * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
@@ -14,6 +15,7 @@ const createPhpStormConfig = () => ({
14
15
  task: (ctx, task) => task.newListr([
15
16
  setupWorkspaceConfig(),
16
17
  setupPhpConfig(),
18
+ setupPhpDockerSettingsConfig(),
17
19
  setupDatabaseConfig(),
18
20
  setupInspectionToolsConfig(),
19
21
  setupExcludedFoldersConfig(),
@@ -4,11 +4,25 @@ const nameKey = '@_name';
4
4
  const valueKey = '@_value';
5
5
  const toolPathKey = '@_tool_path';
6
6
  const standardsKey = '@_standards';
7
+ const urlKey = '@_url';
8
+ const typeKey = '@_type';
9
+ const versionKey = '@_version';
10
+
11
+ /**
12
+ * Makes a xml property key
13
+ * @param {string} key
14
+ * @returns {string}
15
+ */
16
+ const propertyKey = (key) => `@_${key}`;
7
17
 
8
18
  module.exports = {
9
19
  classKey,
10
20
  nameKey,
11
21
  valueKey,
12
22
  toolPathKey,
13
- standardsKey
23
+ standardsKey,
24
+ urlKey,
25
+ typeKey,
26
+ versionKey,
27
+ propertyKey
14
28
  };
@@ -5,6 +5,7 @@ const setupMessDetector = require('./mess-detector-config');
5
5
  const setupPHPCodeSniffer = require('./php-code-sniffer-config');
6
6
  const { getPhpConfig } = require('./php-config');
7
7
  const setupPHPCSFixer = require('./php-cs-fixer-config');
8
+ const setupPHPInterpreters = require('./php-interpreters-config');
8
9
  const setupPHPProjectSharedConfiguration = require('./php-project-shared-configuration-config');
9
10
 
10
11
  /**
@@ -13,7 +14,7 @@ const setupPHPProjectSharedConfiguration = require('./php-project-shared-configu
13
14
  const setupPhpConfig = () => ({
14
15
  title: 'Set up PHP configuration',
15
16
  task: async (ctx, task) => {
16
- const phpConfig = getPhpConfig(ctx.config.overridenConfiguration);
17
+ const phpConfig = getPhpConfig(ctx);
17
18
 
18
19
  if (await pathExists(phpConfig.path)) {
19
20
  const phpConfigContent = setupXMLStructure(await loadXmlFile(phpConfig.path));
@@ -22,6 +23,7 @@ const setupPhpConfig = () => ({
22
23
  setupMessDetector(phpConfigs),
23
24
  setupPHPCodeSniffer(phpConfigs),
24
25
  setupPHPCSFixer(phpConfigs),
26
+ setupPHPInterpreters(phpConfigs, ctx),
25
27
  setupPHPProjectSharedConfiguration(phpConfigs, phpConfig.phpLanguageLevel)
26
28
  ]);
27
29
 
@@ -41,6 +43,7 @@ const setupPhpConfig = () => ({
41
43
  setupMessDetector(phpConfigs),
42
44
  setupPHPCodeSniffer(phpConfigs),
43
45
  setupPHPCSFixer(phpConfigs),
46
+ setupPHPInterpreters(phpConfigs, ctx),
44
47
  setupPHPProjectSharedConfiguration(phpConfigs, phpConfig.phpLanguageLevel)
45
48
  ]);
46
49
 
@@ -2,10 +2,10 @@ const path = require('path');
2
2
  const { baseConfig } = require('../../../../config');
3
3
 
4
4
  /**
5
- * @param {import('../../../../../typings/index').CMAConfiguration} app
5
+ * @param {import('../../../../../typings/context').ListrContext} ctx
6
6
  */
7
- const getPhpConfig = (app) => {
8
- const [majorPHPVersion, minorPHPVersion] = app.configuration.php.version.split('.');
7
+ const getPhpConfig = (ctx) => {
8
+ const [majorPHPVersion, minorPHPVersion] = ctx.phpVersion.split('.');
9
9
  const phpLanguageLevel = `${ majorPHPVersion }.${ minorPHPVersion }`;
10
10
 
11
11
  return {
@@ -0,0 +1,81 @@
1
+ const { nameKey, propertyKey } = require('../keys');
2
+
3
+ const PHP_INTERPRETERS_COMPONENT_NAME = 'PhpInterpreters';
4
+
5
+ /**
6
+ * @param {Array} phpConfigs
7
+ * @param {import('../../../../../typings/context').ListrContext} ctx
8
+ * @returns {Promise<Boolean>}
9
+ */
10
+ const setupPHPInterpreters = async (phpConfigs, ctx) => {
11
+ let hasChanges = false;
12
+ const phpInterpretersComponent = phpConfigs.find(
13
+ (phpConfig) => phpConfig[nameKey] === PHP_INTERPRETERS_COMPONENT_NAME
14
+ );
15
+
16
+ const { php } = ctx.config.docker.getContainers(ctx.ports);
17
+ const currentInterpreterImage = ctx.debug ? php.debugImage : php.image;
18
+
19
+ const defaultPhpInterpreterConfiguration = {
20
+ [nameKey]: currentInterpreterImage,
21
+ [propertyKey('id')]: '2fbe75d5-bc8f-4adb-8e62-ddb0ccee6428',
22
+ [propertyKey('home')]: 'docker://DATA',
23
+ [propertyKey('debugger_id')]: 'php.debugger.XDebug',
24
+ remote_data: {
25
+ [propertyKey('INTERPRETER_PATH')]: 'php',
26
+ [propertyKey('HELPERS_PATH')]: '/opt/.phpstorm_helpers',
27
+ [propertyKey('VALID')]: 'true',
28
+ [propertyKey('RUN_AS_ROOT_VIA_SUDO')]: 'false',
29
+ [propertyKey('DOCKER_ACCOUNT_NAME')]: 'Docker',
30
+ [propertyKey('DOCKER_IMAGE_NAME')]: currentInterpreterImage,
31
+ [propertyKey('DOCKER_REMOTE_PROJECT_PATH')]: ctx.config.baseConfig.containerMagentoDir
32
+ }
33
+ };
34
+
35
+ if (phpInterpretersComponent) {
36
+ if (!phpInterpretersComponent.interpreters) {
37
+ hasChanges = true;
38
+ phpInterpretersComponent.interpreters = {};
39
+ }
40
+
41
+ if (!Array.isArray(phpInterpretersComponent.interpreters.interpreter)) {
42
+ hasChanges = true;
43
+ phpInterpretersComponent.interpreters.interpreter = [phpInterpretersComponent.interpreters.interpreter];
44
+ }
45
+
46
+ const phpInterpreterConfiguration = phpInterpretersComponent.interpreters.interpreter.find(
47
+ (interpreter) => interpreter[nameKey] === php.image || interpreter[nameKey] === php.debugImage
48
+ );
49
+
50
+ if (!phpInterpreterConfiguration) {
51
+ hasChanges = true;
52
+ phpInterpretersComponent.interpreters.interpreter.push(defaultPhpInterpreterConfiguration);
53
+ } else {
54
+ if (phpInterpreterConfiguration[nameKey] !== currentInterpreterImage) {
55
+ hasChanges = true;
56
+ phpInterpreterConfiguration[nameKey] = currentInterpreterImage;
57
+ }
58
+ if (phpInterpreterConfiguration.remote_data[propertyKey('DOCKER_IMAGE_NAME')] !== currentInterpreterImage) {
59
+ hasChanges = true;
60
+ phpInterpreterConfiguration.remote_data[propertyKey('DOCKER_IMAGE_NAME')] = currentInterpreterImage;
61
+ }
62
+
63
+ if (phpInterpreterConfiguration.remote_data[propertyKey('DOCKER_REMOTE_PROJECT_PATH')] !== ctx.config.baseConfig.containerMagentoDir) {
64
+ hasChanges = true;
65
+ phpInterpreterConfiguration.remote_data[propertyKey('DOCKER_REMOTE_PROJECT_PATH')] = ctx.config.baseConfig.containerMagentoDir;
66
+ }
67
+ }
68
+ } else {
69
+ hasChanges = true;
70
+ phpConfigs.push({
71
+ [nameKey]: PHP_INTERPRETERS_COMPONENT_NAME,
72
+ interpreters: {
73
+ interpreter: defaultPhpInterpreterConfiguration
74
+ }
75
+ });
76
+ }
77
+
78
+ return hasChanges;
79
+ };
80
+
81
+ module.exports = setupPHPInterpreters;
@@ -0,0 +1,42 @@
1
+ const { loadXmlFile, buildXmlFile } = require('../../../../config/xml-parser');
2
+ const pathExists = require('../../../../util/path-exists');
3
+ const { setupXMLStructure } = require('../setup-xml-structure');
4
+ const { getPhpDockerSettingsConfig } = require('./php-docker-settings-config');
5
+ const setupPHPDockerContainerSettingsConfig = require('./setup-php-docker-container-settings-config');
6
+
7
+ /**
8
+ * @type {() => import('listr2').ListrTask<import('../../../../../typings/context').ListrContext>}
9
+ */
10
+ const setupPhpDockerSettingsConfig = () => ({
11
+ title: 'Set up PHP Docker Settings configuration',
12
+ task: async (ctx, task) => {
13
+ const phpDockerSettingsConfig = getPhpDockerSettingsConfig();
14
+
15
+ if (await pathExists(phpDockerSettingsConfig.path)) {
16
+ const phpDockerSettingsConfigContent = setupXMLStructure(await loadXmlFile(phpDockerSettingsConfig.path));
17
+ const phpDockerSettingsConfigs = phpDockerSettingsConfigContent.project.component;
18
+ const hasChanges = await Promise.all([
19
+ setupPHPDockerContainerSettingsConfig(phpDockerSettingsConfigs, ctx)
20
+ ]);
21
+
22
+ if (hasChanges.includes(true)) {
23
+ await buildXmlFile(phpDockerSettingsConfig.path, phpDockerSettingsConfigContent);
24
+ } else {
25
+ task.skip();
26
+ }
27
+
28
+ return;
29
+ }
30
+
31
+ const phpDockerSettingsConfigContent = setupXMLStructure({});
32
+ const phpDockerSettingsConfigs = phpDockerSettingsConfigContent.project.component;
33
+
34
+ await Promise.all([
35
+ setupPHPDockerContainerSettingsConfig(phpDockerSettingsConfigs, ctx)
36
+ ]);
37
+
38
+ await buildXmlFile(phpDockerSettingsConfig.path, phpDockerSettingsConfigContent);
39
+ }
40
+ });
41
+
42
+ module.exports = setupPhpDockerSettingsConfig;
@@ -0,0 +1,9 @@
1
+ const path = require('path');
2
+
3
+ const getPhpDockerSettingsConfig = () => ({
4
+ path: path.join(process.cwd(), '.idea', 'php-docker-settings.xml')
5
+ });
6
+
7
+ module.exports = {
8
+ getPhpDockerSettingsConfig
9
+ };
@@ -0,0 +1,66 @@
1
+ const { propertyKey } = require('../keys');
2
+
3
+ const PHP_DOCKER_CONTAINER_SETTINGS_COMPONENT_NAME = 'PhpDockerContainerSettings';
4
+
5
+ /**
6
+ * @param {Array} phpDockerSettingsConfigs
7
+ * @param {import('../../../../../typings/context').ListrContext} ctx
8
+ * @returns {Promise<Boolean>}
9
+ */
10
+ const setupPHPDockerContainerSettingsConfig = async (phpDockerSettingsConfigs, ctx) => {
11
+ let hasChanges = false;
12
+ const phpDockerContainerSettingsComponent = phpDockerSettingsConfigs.find(
13
+ (phpDockerSettingsConfig) => phpDockerSettingsConfig[propertyKey('name')] === PHP_DOCKER_CONTAINER_SETTINGS_COMPONENT_NAME
14
+ );
15
+
16
+ const defaultList = {
17
+ map: {
18
+ entry: {
19
+ [propertyKey('key')]: '2fbe75d5-bc8f-4adb-8e62-ddb0ccee6428',
20
+ value: {
21
+ DockerContainerSettings: {
22
+ option: [
23
+ {
24
+ [propertyKey('name')]: 'runCliOptions',
25
+ [propertyKey('value')]: ''
26
+ },
27
+ {
28
+ [propertyKey('name')]: 'version',
29
+ [propertyKey('value')]: '1'
30
+ },
31
+ {
32
+ [propertyKey('name')]: 'volumeBindings',
33
+ list: {
34
+ DockerVolumeBindingImpl: {
35
+ option: [
36
+ {
37
+ [propertyKey('name')]: 'containerPath',
38
+ [propertyKey('value')]: ctx.config.baseConfig.containerMagentoDir
39
+ },
40
+ {
41
+ [propertyKey('name')]: 'hostPath',
42
+ [propertyKey('value')]: '$PROJECT_DIR$'
43
+ }
44
+ ]
45
+ }
46
+ }
47
+ }
48
+ ]
49
+ }
50
+ }
51
+ }
52
+ }
53
+ };
54
+
55
+ if (!phpDockerContainerSettingsComponent) {
56
+ hasChanges = true;
57
+ phpDockerSettingsConfigs.push({
58
+ [propertyKey('name')]: PHP_DOCKER_CONTAINER_SETTINGS_COMPONENT_NAME,
59
+ list: defaultList
60
+ });
61
+ }
62
+
63
+ return hasChanges;
64
+ };
65
+
66
+ module.exports = setupPHPDockerContainerSettingsConfig;
@@ -1,29 +1,31 @@
1
- const xmlConfiguration = {
1
+ const { propertyKey } = require('./keys');
2
+
3
+ const xmlConfiguration = () => ({
2
4
  '?xml': {
3
- '@_version': '1.0',
4
- '@_encoding': 'UTF-8'
5
+ [propertyKey('version')]: '1.0',
6
+ [propertyKey('encoding')]: 'UTF-8'
5
7
  },
6
8
  project: {
7
- '@_version': '4',
9
+ [propertyKey('version')]: '4',
8
10
  component: []
9
11
  }
10
- };
12
+ });
11
13
 
12
14
  const setupXMLStructure = (data) => {
13
15
  if (!data) {
14
- data = xmlConfiguration;
16
+ data = xmlConfiguration();
15
17
  }
16
18
 
17
19
  if (data['?xml'] === undefined) {
18
- data['?xml'] = xmlConfiguration['?xml'];
20
+ data['?xml'] = xmlConfiguration()['?xml'];
19
21
  }
20
22
 
21
23
  if (data.project === undefined) {
22
- data.project = xmlConfiguration.project;
24
+ data.project = xmlConfiguration().project;
23
25
  }
24
26
 
25
27
  if (data.project.component === undefined) {
26
- data.project.component = xmlConfiguration.project.component;
28
+ data.project.component = [];
27
29
  }
28
30
 
29
31
  if (!Array.isArray(data.project.component) && Boolean(data.project.component)) {
@@ -3,6 +3,7 @@ const fs = require('fs');
3
3
  const { loadXmlFile, buildXmlFile } = require('../../../config/xml-parser');
4
4
  const pathExists = require('../../../util/path-exists');
5
5
  const { valueKey, nameKey } = require('./keys');
6
+ const { setupXMLStructure } = require('./setup-xml-structure');
6
7
 
7
8
  const STYLELINT_CONFIGURATION_COMPONENT_NAME = 'StylelintConfiguration';
8
9
 
@@ -26,7 +27,7 @@ const setupStylelintConfig = () => ({
26
27
  task: async (ctx, task) => {
27
28
  if (await pathExists(pathToStylelintConfig)) {
28
29
  let hasChanges = false;
29
- const styleLintConfigurationData = await loadXmlFile(pathToStylelintConfig);
30
+ const styleLintConfigurationData = setupXMLStructure(await loadXmlFile(pathToStylelintConfig));
30
31
 
31
32
  if (styleLintConfigurationData.project.component && !Array.isArray(styleLintConfigurationData.project.component)) {
32
33
  hasChanges = true;