@scandipwa/magento-scripts 1.14.1-alpha.9 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/lib/commands/cli.js +9 -4
  2. package/lib/commands/logs.js +1 -0
  3. package/lib/commands/start.js +18 -5
  4. package/lib/config/cma-config.js +16 -0
  5. package/lib/config/dependencies-for-platforms.js +15 -3
  6. package/lib/config/docker.js +4 -3
  7. package/lib/config/get-port-config.js +2 -1
  8. package/lib/config/index.js +2 -1
  9. package/lib/config/php/extensions/libsodium.js +2 -1
  10. package/lib/config/scandipwa-versions.js +2 -1
  11. package/lib/config/system-config.js +34 -5
  12. package/lib/config/templates/magentorc.template +2 -0
  13. package/lib/config/templates/varnish.template.vcl +9 -4
  14. package/lib/config/xml-parser.js +63 -0
  15. package/lib/errors/known-error.js +15 -0
  16. package/lib/errors/unknown-error.js +15 -0
  17. package/lib/tasks/cli/create-bashrc-config.js +2 -1
  18. package/lib/tasks/composer/index.js +5 -3
  19. package/lib/tasks/composer/local-auth-json.js +8 -4
  20. package/lib/tasks/docker/network.js +2 -1
  21. package/lib/tasks/execute/index.js +2 -3
  22. package/lib/tasks/file-system/create-nginx-config.js +2 -1
  23. package/lib/tasks/file-system/create-php-config.js +2 -1
  24. package/lib/tasks/file-system/create-php-fpm-config.js +2 -1
  25. package/lib/tasks/file-system/create-phpstorm-config/database-config.js +249 -0
  26. package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +85 -0
  27. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +154 -0
  28. package/lib/tasks/file-system/create-phpstorm-config/index.js +27 -0
  29. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +26 -0
  30. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/config.js +54 -0
  31. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +28 -0
  32. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +42 -0
  33. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/eslint-inspection-config.js +37 -0
  34. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/index.js +80 -0
  35. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +26 -0
  36. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +142 -0
  37. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/paths.js +20 -0
  38. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-fixer-validation-inspection-config.js +60 -0
  39. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +116 -0
  40. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/stylelint-inspection-config.js +37 -0
  41. package/lib/tasks/file-system/create-phpstorm-config/keys.js +14 -0
  42. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +67 -0
  43. package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +54 -0
  44. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +66 -0
  45. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +58 -0
  46. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +59 -0
  47. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +77 -0
  48. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +97 -0
  49. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/format-setting-config.js +57 -0
  50. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +66 -0
  51. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +64 -0
  52. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +57 -0
  53. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +49 -0
  54. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +64 -0
  55. package/lib/tasks/file-system/create-phpstorm-config/xml-utils.js +5 -0
  56. package/lib/tasks/file-system/create-ssl-terminator-config.js +5 -3
  57. package/lib/tasks/file-system/create-varnish-config.js +2 -23
  58. package/lib/tasks/file-system/create-vscode-config.js +3 -2
  59. package/lib/tasks/file-system/index.js +1 -1
  60. package/lib/tasks/magento/enable-magento-composer-plugins.js +3 -2
  61. package/lib/tasks/magento/install-magento.js +7 -5
  62. package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +26 -0
  63. package/lib/tasks/magento/setup-magento/delete-admin-users.js +1 -1
  64. package/lib/tasks/magento/setup-magento/delete-customers.js +7 -4
  65. package/lib/tasks/magento/setup-magento/delete-orders.js +6 -4
  66. package/lib/tasks/magento/setup-magento/flush-redis-config.js +2 -1
  67. package/lib/tasks/magento/setup-magento/index.js +3 -1
  68. package/lib/tasks/magento/setup-magento/install-magento.js +2 -1
  69. package/lib/tasks/magento/setup-magento/set-base-url.js +7 -2
  70. package/lib/tasks/magento/setup-magento/upgrade-magento.js +11 -1
  71. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +41 -0
  72. package/lib/tasks/mysql/connect-to-mysql.js +2 -1
  73. package/lib/tasks/mysql/import-dump-to-mysql.js +13 -2
  74. package/lib/tasks/mysql/import-remote-db/index.js +2 -1
  75. package/lib/tasks/mysql/import-remote-db/ssh/index.js +2 -1
  76. package/lib/tasks/mysql/import-remote-db/ssh/regular-server.js +2 -1
  77. package/lib/tasks/php/bundled-extensions.js +28 -0
  78. package/lib/tasks/php/compile-options.js +27 -54
  79. package/lib/tasks/php/compile.js +6 -4
  80. package/lib/tasks/php/configure.js +7 -66
  81. package/lib/tasks/php/extensions/disable.js +2 -1
  82. package/lib/tasks/php/extensions/enable.js +2 -1
  83. package/lib/tasks/php/extensions/index.js +74 -0
  84. package/lib/tasks/php/extensions/install.js +3 -3
  85. package/lib/tasks/php/index.js +7 -6
  86. package/lib/tasks/php/install-sodium.js +93 -0
  87. package/lib/tasks/php/update-phpbrew.js +7 -3
  88. package/lib/tasks/php/validate-php.js +67 -0
  89. package/lib/tasks/php-fpm/start-php-fpm.js +4 -2
  90. package/lib/tasks/requirements/composer.js +59 -5
  91. package/lib/tasks/requirements/dependency/arch.js +2 -1
  92. package/lib/tasks/requirements/dependency/centos.js +2 -1
  93. package/lib/tasks/requirements/dependency/fedora.js +2 -1
  94. package/lib/tasks/requirements/dependency/mac.js +18 -3
  95. package/lib/tasks/requirements/docker/index.js +94 -40
  96. package/lib/tasks/requirements/docker/install-on-mac.js +29 -0
  97. package/lib/tasks/requirements/docker/install.js +2 -1
  98. package/lib/tasks/requirements/docker/running-status.js +32 -31
  99. package/lib/tasks/requirements/docker/version.js +2 -1
  100. package/lib/tasks/requirements/index.js +3 -0
  101. package/lib/tasks/requirements/node-version.js +2 -1
  102. package/lib/tasks/requirements/php-version.js +26 -24
  103. package/lib/tasks/requirements/phpbrew/index.js +2 -1
  104. package/lib/tasks/requirements/phpbrew/install.js +14 -2
  105. package/lib/tasks/requirements/phpbrew/version.js +2 -1
  106. package/lib/tasks/requirements/platform.js +5 -3
  107. package/lib/tasks/requirements/rosetta.js +32 -0
  108. package/lib/tasks/start.js +10 -2
  109. package/lib/tasks/theme/build-theme.js +2 -1
  110. package/lib/tasks/theme/install-theme.js +2 -1
  111. package/lib/tasks/theme/link-theme.js +2 -2
  112. package/lib/tasks/theme/retrieve-theme-data.js +2 -1
  113. package/lib/tasks/theme/setup-persisted-query.js +2 -1
  114. package/lib/tasks/theme/setup-themes.js +10 -3
  115. package/lib/tasks/theme/symlink-theme.js +8 -1
  116. package/lib/util/CSA-theme.js +4 -0
  117. package/lib/util/analytics.js +317 -0
  118. package/lib/util/arch.js +1 -1
  119. package/lib/util/config-file-validator.js +2 -1
  120. package/lib/util/config-php-json.js +3 -2
  121. package/lib/util/env-php-json.js +3 -2
  122. package/lib/util/exec-async-command.d.ts +2 -0
  123. package/lib/util/exec-async-command.js +31 -15
  124. package/lib/util/exec-async.js +9 -0
  125. package/lib/util/get-brew-bin-path.js +64 -0
  126. package/lib/util/get-installed-magento-version.js +3 -2
  127. package/lib/util/get-jsonfile-data.js +2 -1
  128. package/lib/util/install-dependencies-task.js +15 -5
  129. package/lib/util/instance-metadata.js +9 -2
  130. package/lib/util/ip.js +47 -1
  131. package/lib/util/magento-task.js +20 -9
  132. package/lib/util/php-task.js +7 -7
  133. package/lib/util/request.js +0 -0
  134. package/lib/util/resolve-configuration-with-overrides.js +2 -1
  135. package/lib/util/run-composer.js +5 -3
  136. package/lib/util/run-magento.js +3 -2
  137. package/lib/util/run-php.js +7 -2
  138. package/lib/util/wait-for-it.js +3 -2
  139. package/package.json +5 -3
  140. package/typings/context.d.ts +4 -0
  141. package/typings/phpstorm.d.ts +33 -0
  142. package/lib/tasks/file-system/create-php-storm-config.js +0 -82
  143. package/lib/tasks/magento/setup-magento/disable-full-page-cache.js +0 -20
@@ -0,0 +1,66 @@
1
+ const path = require('path');
2
+ const pathExists = require('../../../../util/path-exists');
3
+ const { nameKey, toolPathKey, standardsKey } = require('../keys');
4
+ const { formatPathForPHPStormConfig } = require('../xml-utils');
5
+
6
+ const PHP_CODE_SNIFFER_COMPONENT_NAME = 'PhpCodeSniffer';
7
+
8
+ const beautifierPathKey = '@_beautifier_path';
9
+
10
+ const phpCodeSnifferStandards = 'MySource;PEAR;PHPCompatibility;PSR1;PSR12;PSR2;Squiz;Zend';
11
+ const phpCodeSnifferBinaryPath = path.join(process.cwd(), 'vendor', 'bin', 'phpcs');
12
+ const phpCodeSnifferBinaryFormattedPath = formatPathForPHPStormConfig(phpCodeSnifferBinaryPath);
13
+
14
+ const phpCodeSnifferBeautifierBinaryPath = path.join(process.cwd(), 'vendor', 'bin', 'phpcbf');
15
+ const phpCodeSnifferBeautifierBinaryFormattedPath = formatPathForPHPStormConfig(phpCodeSnifferBeautifierBinaryPath);
16
+
17
+ const defaultPHPCSSetting = {
18
+ PhpCSConfiguration: {
19
+ [toolPathKey]: phpCodeSnifferBinaryFormattedPath,
20
+ [standardsKey]: phpCodeSnifferStandards,
21
+ [beautifierPathKey]: phpCodeSnifferBeautifierBinaryFormattedPath
22
+ }
23
+ };
24
+
25
+ /**
26
+ * @param {Array} phpConfigs
27
+ * @returns {Promise<Boolean>}
28
+ */
29
+ const setupPHPCodeSniffer = async (phpConfigs) => {
30
+ let hasChanges = false;
31
+ const phpCodeSnifferComponent = phpConfigs.find(
32
+ (phpConfig) => phpConfig[nameKey] === PHP_CODE_SNIFFER_COMPONENT_NAME
33
+ );
34
+
35
+ const isPhpCodeSnifferBinPathExists = await pathExists(phpCodeSnifferBinaryPath);
36
+ const isPhpCodeSnifferBeautifierBinPathExists = await pathExists(phpCodeSnifferBeautifierBinaryPath);
37
+ const isAllPHPCSBinsExists = isPhpCodeSnifferBinPathExists && isPhpCodeSnifferBeautifierBinPathExists;
38
+
39
+ if (phpCodeSnifferComponent && isAllPHPCSBinsExists) {
40
+ if (!Array.isArray(phpCodeSnifferComponent.phpcs_settings)) {
41
+ hasChanges = true;
42
+ phpCodeSnifferComponent.phpcs_settings = [phpCodeSnifferComponent.phpcs_settings];
43
+ }
44
+
45
+ const phpCodeSnifferConfiguration = phpCodeSnifferComponent.phpcs_settings.find(
46
+ (phpcsSetting) => phpcsSetting.PhpCSConfiguration
47
+ );
48
+
49
+ if (!phpCodeSnifferConfiguration) {
50
+ hasChanges = true;
51
+ phpCodeSnifferComponent.phpcs_settings.push(defaultPHPCSSetting);
52
+ }
53
+ } else if (isAllPHPCSBinsExists) {
54
+ hasChanges = true;
55
+ phpConfigs.push({
56
+ [nameKey]: PHP_CODE_SNIFFER_COMPONENT_NAME,
57
+ phpcs_settings: [
58
+ defaultPHPCSSetting
59
+ ]
60
+ });
61
+ }
62
+
63
+ return hasChanges;
64
+ };
65
+
66
+ module.exports = setupPHPCodeSniffer;
@@ -0,0 +1,58 @@
1
+ const path = require('path');
2
+ const pathExists = require('../../../../util/path-exists');
3
+ const { nameKey, toolPathKey, standardsKey } = require('../keys');
4
+ const { formatPathForPHPStormConfig } = require('../xml-utils');
5
+
6
+ const PHP_CS_FIXER_COMPONENT_NAME = 'PhpCSFixer';
7
+
8
+ const phpCSFixerStandards = 'PSR1;PSR2;Symfony;DoctrineAnnotation;PHP70Migration;PHP71Migration';
9
+ const phpCSFixerBinaryPath = path.join(process.cwd(), 'vendor', 'bin', 'php-cs-fixer');
10
+ const phpCSFixerBinaryFormattedPath = formatPathForPHPStormConfig(phpCSFixerBinaryPath);
11
+
12
+ const defaultPHPCSFixerSettings = {
13
+ PhpCSFixerConfiguration: {
14
+ [toolPathKey]: phpCSFixerBinaryFormattedPath,
15
+ [standardsKey]: phpCSFixerStandards
16
+ }
17
+ };
18
+
19
+ /**
20
+ * @param {Array} phpConfigs
21
+ * @returns {Promise<Boolean>}
22
+ */
23
+ const setupPHPCSFixer = async (phpConfigs) => {
24
+ let hasChanges = false;
25
+ const phpCSFixerComponent = phpConfigs.find(
26
+ (phpConfig) => phpConfig[nameKey] === PHP_CS_FIXER_COMPONENT_NAME
27
+ );
28
+
29
+ const isPhpCSFixerBinPathExists = await pathExists(phpCSFixerBinaryPath);
30
+
31
+ if (phpCSFixerComponent && isPhpCSFixerBinPathExists) {
32
+ if (!Array.isArray(phpCSFixerComponent.phpcsfixer_settings)) {
33
+ hasChanges = true;
34
+ phpCSFixerComponent.phpcsfixer_settings = [phpCSFixerComponent.phpcsfixer_settings];
35
+ }
36
+
37
+ const phpCSFixerConfiguration = phpCSFixerComponent.phpcsfixer_settings.find(
38
+ (phpcsfixerSetting) => phpcsfixerSetting.PhpCSFixerConfiguration
39
+ );
40
+
41
+ if (!phpCSFixerConfiguration) {
42
+ hasChanges = true;
43
+ phpCSFixerComponent.phpcsfixer_settings.push(defaultPHPCSFixerSettings);
44
+ }
45
+ } else if (isPhpCSFixerBinPathExists) {
46
+ hasChanges = true;
47
+ phpConfigs.push({
48
+ [nameKey]: PHP_CS_FIXER_COMPONENT_NAME,
49
+ phpcsfixer_settings: [
50
+ defaultPHPCSFixerSettings
51
+ ]
52
+ });
53
+ }
54
+
55
+ return hasChanges;
56
+ };
57
+
58
+ module.exports = setupPHPCSFixer;
@@ -0,0 +1,59 @@
1
+ const {
2
+ nameKey,
3
+ valueKey
4
+ } = require('../keys');
5
+
6
+ const PHP_PROJECT_SHARED_CONFIGURATION_COMPONENT_NAME = 'PhpProjectSharedConfiguration';
7
+
8
+ const SUGGESTED_CHANGE_DEFAULT_LANGUAGE_LEVEL_OPTION_NAME = 'suggestChangeDefaultLanguageLevel';
9
+
10
+ const phpLanguageLevelKey = '@_php_language_level';
11
+
12
+ /**
13
+ * @param {Array} phpConfigs
14
+ * @param {String} currentPhpLanguageLevel
15
+ * @returns {Promise<Boolean>}
16
+ */
17
+ const setupPHPProjectSharedConfiguration = async (phpConfigs, currentPhpLanguageLevel) => {
18
+ let hasChanges = false;
19
+ const phpProjectSharedConfigurationComponent = phpConfigs.find(
20
+ (phpConfig) => phpConfig[nameKey] === PHP_PROJECT_SHARED_CONFIGURATION_COMPONENT_NAME
21
+ );
22
+
23
+ const defaultSuggestChangeDefaultLanguageLevelOption = {
24
+ [nameKey]: SUGGESTED_CHANGE_DEFAULT_LANGUAGE_LEVEL_OPTION_NAME,
25
+ [valueKey]: currentPhpLanguageLevel
26
+ };
27
+
28
+ if (phpProjectSharedConfigurationComponent) {
29
+ if (phpProjectSharedConfigurationComponent.option && !Array.isArray(phpProjectSharedConfigurationComponent.option)) {
30
+ hasChanges = true;
31
+ phpProjectSharedConfigurationComponent.option = [phpProjectSharedConfigurationComponent.option];
32
+ } else if (!phpProjectSharedConfigurationComponent.option) {
33
+ hasChanges = true;
34
+ phpProjectSharedConfigurationComponent.option = [];
35
+ }
36
+
37
+ const suggestedChangeDefaultLanguageLevelOption = phpProjectSharedConfigurationComponent.option.find(
38
+ (phpProjectSharedConfigOption) => phpProjectSharedConfigOption[nameKey] === SUGGESTED_CHANGE_DEFAULT_LANGUAGE_LEVEL_OPTION_NAME
39
+ );
40
+
41
+ if (!suggestedChangeDefaultLanguageLevelOption) {
42
+ hasChanges = true;
43
+ phpProjectSharedConfigurationComponent.option.push(defaultSuggestChangeDefaultLanguageLevelOption);
44
+ }
45
+ } else {
46
+ hasChanges = true;
47
+ phpConfigs.push({
48
+ [nameKey]: PHP_PROJECT_SHARED_CONFIGURATION_COMPONENT_NAME,
49
+ [phpLanguageLevelKey]: currentPhpLanguageLevel,
50
+ option: [
51
+ defaultSuggestChangeDefaultLanguageLevelOption
52
+ ]
53
+ });
54
+ }
55
+
56
+ return hasChanges;
57
+ };
58
+
59
+ module.exports = setupPHPProjectSharedConfiguration;
@@ -0,0 +1,77 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const { loadXmlFile, buildXmlFile } = require('../../../config/xml-parser');
4
+ const pathExists = require('../../../util/path-exists');
5
+ const { valueKey, nameKey } = require('./keys');
6
+
7
+ const STYLELINT_CONFIGURATION_COMPONENT_NAME = 'StylelintConfiguration';
8
+
9
+ const pathToStylelintConfig = path.join(process.cwd(), '.idea', 'stylesheetLinters', 'stylelint.xml');
10
+ const pathToStylelintConfigDir = path.parse(pathToStylelintConfig).dir;
11
+
12
+ const DEFAULT_STYLE_PATTERN = '{**/*,*}.{css,scss}';
13
+
14
+ const defaultESLintComponentConfiguration = {
15
+ [nameKey]: STYLELINT_CONFIGURATION_COMPONENT_NAME,
16
+ 'file-patterns': {
17
+ [valueKey]: DEFAULT_STYLE_PATTERN
18
+ }
19
+ };
20
+
21
+ /**
22
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
23
+ */
24
+ const setupStylelintConfig = () => ({
25
+ title: 'Set up Stylelint configuration',
26
+ task: async (ctx, task) => {
27
+ if (await pathExists(pathToStylelintConfig)) {
28
+ let hasChanges = false;
29
+ const styleLintConfigurationData = await loadXmlFile(pathToStylelintConfig);
30
+
31
+ if (styleLintConfigurationData.project.component && !Array.isArray(styleLintConfigurationData.project.component)) {
32
+ hasChanges = true;
33
+ styleLintConfigurationData.project.component = [styleLintConfigurationData.project.component];
34
+ }
35
+
36
+ const styleLintConfigurationComponent = styleLintConfigurationData.project.component.find(
37
+ (component) => component[nameKey] === STYLELINT_CONFIGURATION_COMPONENT_NAME
38
+ );
39
+
40
+ if (!styleLintConfigurationComponent) {
41
+ hasChanges = true;
42
+ styleLintConfigurationData.project.component.push(defaultESLintComponentConfiguration);
43
+ }
44
+
45
+ if (hasChanges) {
46
+ await buildXmlFile(pathToStylelintConfig, styleLintConfigurationData);
47
+ } else {
48
+ task.skip();
49
+ }
50
+
51
+ return;
52
+ }
53
+
54
+ if (!await pathExists(pathToStylelintConfigDir)) {
55
+ await fs.promises.mkdir(pathToStylelintConfigDir, {
56
+ recursive: true
57
+ });
58
+ }
59
+
60
+ const styleLintConfigurationData = {
61
+ '?xml': {
62
+ '@_version': '1.0',
63
+ '@_encoding': 'UTF-8'
64
+ },
65
+ project: {
66
+ '@_version': '4',
67
+ component: [
68
+ defaultESLintComponentConfiguration
69
+ ]
70
+ }
71
+ };
72
+
73
+ await buildXmlFile(pathToStylelintConfig, styleLintConfigurationData);
74
+ }
75
+ });
76
+
77
+ module.exports = setupStylelintConfig;
@@ -0,0 +1,97 @@
1
+ const path = require('path');
2
+ const { baseConfig } = require('../../../../config');
3
+ const pathExists = require('../../../../util/path-exists');
4
+ const { nameKey } = require('../keys');
5
+ const { formatPathForPHPStormConfig } = require('../xml-utils');
6
+
7
+ const COMPOSER_SETTINGS_COMPONENT_NAME = 'ComposerSettings';
8
+
9
+ const pharPathKey = '@_pharPath';
10
+ const doNotAskKey = '@_doNotAsk';
11
+ const synchronizationStateKey = '@_synchronizationState';
12
+
13
+ const composerJsonPath = path.join(process.cwd(), 'composer.json');
14
+ const composerJsonFormattedPath = formatPathForPHPStormConfig(composerJsonPath);
15
+ const composerPharPath = path.join(baseConfig.cacheDir, 'composer', 'composer.phar');
16
+ const composerPharFormattedPath = formatPathForPHPStormConfig(composerPharPath);
17
+
18
+ const defaultComposerSettingsProperties = {
19
+ [doNotAskKey]: 'true',
20
+ [synchronizationStateKey]: 'SYNCHRONIZE'
21
+ };
22
+
23
+ // TODO Ideally, we want to setup interpreter for compose.phar
24
+
25
+ // It should look like this:
26
+ // <component name="ComposerSettings" synchronizationState="DONT_SYNCHRONIZE">
27
+ // <pharConfigPath>$PROJECT_DIR$/composer.json</pharConfigPath>
28
+ // <execution>
29
+ // <phar
30
+ // pharPath="$PROJECT_DIR$/node_modules/.create-magento-app-cache/composer/composer.phar"
31
+ // interpreterId="f19b09e2-16e7-491f-9056-3299df58e578"
32
+ // />
33
+ // </execution>
34
+ // </component>
35
+
36
+ /**
37
+ * @param {Array} workspaceConfigs
38
+ * @returns {Promise<Boolean>}
39
+ */
40
+ const setupComposerSettings = async (workspaceConfigs) => {
41
+ let hasChanges = false;
42
+ const composerSettingsComponent = workspaceConfigs.find(
43
+ (workspaceConfig) => workspaceConfig[nameKey] === COMPOSER_SETTINGS_COMPONENT_NAME
44
+ );
45
+
46
+ const isComposerJsonExists = await pathExists(composerJsonPath);
47
+ const isComposerPharExists = await pathExists(composerPharPath);
48
+
49
+ if (composerSettingsComponent) {
50
+ if (
51
+ !('pharConfigPath' in composerSettingsComponent)
52
+ && isComposerJsonExists
53
+ ) {
54
+ hasChanges = true;
55
+ composerSettingsComponent.pharConfigPath = composerJsonFormattedPath;
56
+ }
57
+
58
+ const pharConfig = composerSettingsComponent.execution && composerSettingsComponent.execution.phar;
59
+
60
+ if (pharConfig && isComposerPharExists && !(pharPathKey in pharConfig)) {
61
+ hasChanges = true;
62
+ pharConfig[pharPathKey] = composerPharFormattedPath;
63
+ } else if (!pharConfig && isComposerPharExists) {
64
+ hasChanges = true;
65
+ composerSettingsComponent.execution = composerSettingsComponent.execution || {};
66
+ composerSettingsComponent.execution.phar = {
67
+ [pharPathKey]: composerPharFormattedPath
68
+ };
69
+ }
70
+
71
+ const composerSettingsMissingProperties = Object.entries(defaultComposerSettingsProperties)
72
+ .filter(([key]) => !(key in composerSettingsComponent));
73
+
74
+ if (composerSettingsMissingProperties.length > 0) {
75
+ hasChanges = true;
76
+ composerSettingsMissingProperties.forEach(([key, value]) => {
77
+ composerSettingsComponent[key] = value;
78
+ });
79
+ }
80
+ } else {
81
+ hasChanges = true;
82
+ workspaceConfigs.push({
83
+ [nameKey]: COMPOSER_SETTINGS_COMPONENT_NAME,
84
+ ...defaultComposerSettingsProperties,
85
+ pharConfigPath: composerJsonFormattedPath,
86
+ execution: {
87
+ phar: {
88
+ [pharPathKey]: composerPharFormattedPath
89
+ }
90
+ }
91
+ });
92
+ }
93
+
94
+ return hasChanges;
95
+ };
96
+
97
+ module.exports = setupComposerSettings;
@@ -0,0 +1,57 @@
1
+ const {
2
+ nameKey,
3
+ valueKey
4
+ } = require('../keys');
5
+
6
+ const FORMAT_ON_SAVE_OPTIONS_COMPONENT_NAME = 'FormatOnSaveOptions';
7
+
8
+ const MY_FORMAT_ONLY_CHANGED_LINES_OPTION_NAME = 'myFormatOnlyChangedLines';
9
+ const MY_RUN_ON_SAVE_OPTION_NAME = 'myRunOnSave';
10
+
11
+ /**
12
+ * @param {Array} workspaceConfigs
13
+ * @returns {Promise<Boolean>}
14
+ */
15
+ const setupFormatOnSave = async (workspaceConfigs) => {
16
+ let hasChanges = false;
17
+ const formatOnSaveOptionsComponent = workspaceConfigs.find(
18
+ (workspaceConfig) => workspaceConfig[nameKey] === FORMAT_ON_SAVE_OPTIONS_COMPONENT_NAME
19
+ );
20
+
21
+ if (formatOnSaveOptionsComponent) {
22
+ if (formatOnSaveOptionsComponent.option && !Array.isArray(formatOnSaveOptionsComponent.option)) {
23
+ hasChanges = true;
24
+ formatOnSaveOptionsComponent.option = [formatOnSaveOptionsComponent.option];
25
+ } else if (!formatOnSaveOptionsComponent.option) {
26
+ hasChanges = true;
27
+ formatOnSaveOptionsComponent.option = [];
28
+ }
29
+
30
+ const missingOptions = [MY_FORMAT_ONLY_CHANGED_LINES_OPTION_NAME, MY_RUN_ON_SAVE_OPTION_NAME].filter(
31
+ (optionName) => !formatOnSaveOptionsComponent.option.some((option) => option[nameKey] === optionName)
32
+ );
33
+
34
+ if (missingOptions.length > 0) {
35
+ hasChanges = true;
36
+ missingOptions.forEach((missingOption) => {
37
+ formatOnSaveOptionsComponent.option.push({
38
+ [nameKey]: missingOption,
39
+ [valueKey]: 'true'
40
+ });
41
+ });
42
+ }
43
+ } else {
44
+ hasChanges = true;
45
+ workspaceConfigs.push({
46
+ [nameKey]: FORMAT_ON_SAVE_OPTIONS_COMPONENT_NAME,
47
+ option: [MY_FORMAT_ONLY_CHANGED_LINES_OPTION_NAME, MY_RUN_ON_SAVE_OPTION_NAME].map((option) => ({
48
+ [nameKey]: option,
49
+ [valueKey]: 'true'
50
+ }))
51
+ });
52
+ }
53
+
54
+ return hasChanges;
55
+ };
56
+
57
+ module.exports = setupFormatOnSave;
@@ -0,0 +1,66 @@
1
+ const { loadXmlFile, buildXmlFile } = require('../../../../config/xml-parser');
2
+ const pathExists = require('../../../../util/path-exists');
3
+ const setupComposerSettings = require('./composer-settings-config');
4
+ const setupFormatOnSave = require('./format-setting-config');
5
+ const setupPHPDebugGeneral = require('./php-debug-general-config');
6
+ const setupPHPServers = require('./php-server-config');
7
+ const setupPropertiesComponent = require('./properties-component-config');
8
+ const setupRunManager = require('./run-manager-config');
9
+
10
+ /**
11
+ * @type {() => import('listr2').ListrTask<import('../../../../../typings/context').ListrContext>}
12
+ */
13
+ const setupWorkspaceConfig = () => ({
14
+ title: 'Set up Workspace configuration',
15
+ task: async (ctx, task) => {
16
+ const {
17
+ config: {
18
+ phpStorm
19
+ }
20
+ } = ctx;
21
+
22
+ if (await pathExists(phpStorm.xdebug.path)) {
23
+ const workspaceConfiguration = await loadXmlFile(phpStorm.xdebug.path);
24
+ const workspaceConfigs = workspaceConfiguration.project.component;
25
+ const hasChanges = await Promise.all([
26
+ setupPHPDebugGeneral(workspaceConfigs, phpStorm),
27
+ setupPHPServers(workspaceConfigs, phpStorm),
28
+ setupRunManager(workspaceConfigs, phpStorm),
29
+ setupPropertiesComponent(workspaceConfigs)
30
+ ]);
31
+
32
+ if (hasChanges.includes(true)) {
33
+ await buildXmlFile(phpStorm.php.path, workspaceConfiguration);
34
+ } else {
35
+ task.skip();
36
+ }
37
+
38
+ return;
39
+ }
40
+
41
+ const workspaceConfiguration = {
42
+ '?xml': {
43
+ '@_version': '1.0',
44
+ '@_encoding': 'UTF-8'
45
+ },
46
+ project: {
47
+ '@_version': '4',
48
+ component: []
49
+ }
50
+ };
51
+ const workspaceConfigs = workspaceConfiguration.project.component;
52
+
53
+ await Promise.all([
54
+ setupPHPDebugGeneral(workspaceConfigs, phpStorm),
55
+ setupPHPServers(workspaceConfigs, phpStorm),
56
+ setupRunManager(workspaceConfigs, phpStorm),
57
+ setupPropertiesComponent(workspaceConfigs),
58
+ setupComposerSettings(workspaceConfigs),
59
+ setupFormatOnSave(workspaceConfigs)
60
+ ]);
61
+
62
+ await buildXmlFile(phpStorm.xdebug.path, workspaceConfiguration);
63
+ }
64
+ });
65
+
66
+ module.exports = setupWorkspaceConfig;
@@ -0,0 +1,64 @@
1
+ const {
2
+ nameKey
3
+ } = require('../keys');
4
+
5
+ const PHP_DEBUG_GENERAL_COMPONENT_NAME = 'PhpDebugGeneral';
6
+
7
+ const portKey = '@_port';
8
+ const xdebugDebugPortKey = '@_xdebug_debug_port';
9
+ const ignoreConnectionsThroughUnregisteredServersKey = '@_ignore_connections_through_unregistered_servers';
10
+
11
+ /**
12
+ * @param {Array} workspaceConfigs
13
+ * @param {import('../../../../../typings/phpstorm').PHPStormConfig} phpStormConfiguration
14
+ * @returns {Promise<Boolean>}
15
+ */
16
+ const setupPHPDebugGeneral = async (workspaceConfigs, phpStormConfiguration) => {
17
+ const { xdebug } = phpStormConfiguration;
18
+ let hasChanges = false;
19
+ const phpDebugGeneralComponent = workspaceConfigs.find(
20
+ (workspaceConfig) => workspaceConfig[nameKey] === PHP_DEBUG_GENERAL_COMPONENT_NAME
21
+ );
22
+
23
+ if (phpDebugGeneralComponent) {
24
+ if (phpDebugGeneralComponent.xdebug_debug_ports && !Array.isArray(phpDebugGeneralComponent.xdebug_debug_ports)) {
25
+ hasChanges = true;
26
+ phpDebugGeneralComponent.xdebug_debug_ports = [phpDebugGeneralComponent.xdebug_debug_ports];
27
+ } else if (!phpDebugGeneralComponent.xdebug_debug_ports) {
28
+ hasChanges = true;
29
+ phpDebugGeneralComponent.xdebug_debug_ports = [];
30
+ }
31
+
32
+ if (!(xdebugDebugPortKey in phpDebugGeneralComponent)) {
33
+ hasChanges = true;
34
+ phpDebugGeneralComponent[xdebugDebugPortKey] = xdebug.v3Port;
35
+ }
36
+
37
+ const missingXDebugPorts = [xdebug.v3Port, xdebug.v2Port].filter(
38
+ (port) => !phpDebugGeneralComponent.xdebug_debug_ports.some((xPort) => xPort[portKey] === port)
39
+ );
40
+
41
+ if (missingXDebugPorts.length > 0) {
42
+ hasChanges = true;
43
+ missingXDebugPorts.forEach((port) => {
44
+ phpDebugGeneralComponent.xdebug_debug_ports.push({
45
+ [portKey]: port
46
+ });
47
+ });
48
+ }
49
+ } else {
50
+ hasChanges = true;
51
+ workspaceConfigs.push({
52
+ [nameKey]: PHP_DEBUG_GENERAL_COMPONENT_NAME,
53
+ [xdebugDebugPortKey]: xdebug.v3Port,
54
+ [ignoreConnectionsThroughUnregisteredServersKey]: 'true',
55
+ xdebug_debug_ports: [xdebug.v3Port, xdebug.v2Port].map((port) => ({
56
+ [portKey]: port
57
+ }))
58
+ });
59
+ }
60
+
61
+ return hasChanges;
62
+ };
63
+
64
+ module.exports = setupPHPDebugGeneral;
@@ -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;