@scandipwa/magento-scripts 1.14.0 → 1.14.1-alpha.2
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.
- package/lib/config/templates/php-fpm.template.conf +1 -0
- package/lib/config/versions/magento-2.3.7-p2.js +47 -0
- package/lib/config/versions/magento-2.3.7-p3.js +47 -0
- package/lib/config/versions/magento-2.4.3-p2.js +51 -0
- package/lib/config/versions/magento-2.4.4.js +51 -0
- package/lib/config/xml-parser.js +61 -0
- package/lib/tasks/file-system/create-phpstorm-config/database-config.js +248 -0
- package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +85 -0
- package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +154 -0
- package/lib/tasks/file-system/create-phpstorm-config/index.js +27 -0
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +29 -0
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/config.js +54 -0
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +31 -0
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +42 -0
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/eslint-inspection-config.js +37 -0
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/index.js +80 -0
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +29 -0
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +145 -0
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/paths.js +20 -0
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-fixer-validation-inspection-config.js +60 -0
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +119 -0
- package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/stylelint-inspection-config.js +37 -0
- package/lib/tasks/file-system/create-phpstorm-config/keys.js +14 -0
- package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +67 -0
- package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +57 -0
- package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +76 -0
- package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +63 -0
- package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +69 -0
- package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +77 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +98 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/format-setting-config.js +57 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +66 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +64 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +60 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +51 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +74 -0
- package/lib/tasks/file-system/create-phpstorm-config/xml-utils.js +5 -0
- package/lib/tasks/file-system/index.js +1 -1
- package/lib/tasks/start.js +6 -2
- package/lib/util/instance-metadata.js +7 -1
- package/package.json +13 -2
- package/typings/context.d.ts +2 -0
- package/typings/phpstorm.d.ts +33 -0
- package/lib/tasks/file-system/create-php-storm-config.js +0 -82
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const {
|
|
2
|
+
classes: {
|
|
3
|
+
PHP_CS_FIXER_VALIDATION_INSPECTION
|
|
4
|
+
}
|
|
5
|
+
} = require('./config');
|
|
6
|
+
const { classKey } = require('../keys');
|
|
7
|
+
const setupCodingStandardOption = require('./coding-standard-config');
|
|
8
|
+
const setupCustomRuleSetPathOption = require('./custom-ruleset-path-config');
|
|
9
|
+
const setupDefaultProperties = require('./default-properties-config');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {Array} inspectionToolsData
|
|
13
|
+
* @returns {Promise<Boolean>}
|
|
14
|
+
*/
|
|
15
|
+
const setupPhpCSFixerValidationInspection = async (inspectionToolsData) => {
|
|
16
|
+
let hasChanges = false;
|
|
17
|
+
const phpCSFixerConfig = inspectionToolsData.find(
|
|
18
|
+
(inspectionToolData) => inspectionToolData[classKey] === PHP_CS_FIXER_VALIDATION_INSPECTION
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (phpCSFixerConfig) {
|
|
22
|
+
const hasChangesInProperties = setupDefaultProperties(phpCSFixerConfig);
|
|
23
|
+
if (hasChangesInProperties) {
|
|
24
|
+
hasChanges = true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (phpCSFixerConfig.option) {
|
|
28
|
+
const hasCodingStandardChanges = await setupCodingStandardOption(phpCSFixerConfig);
|
|
29
|
+
if (hasCodingStandardChanges) {
|
|
30
|
+
hasChanges = true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const hasCustomRuleSetChanges = await setupCustomRuleSetPathOption(phpCSFixerConfig);
|
|
34
|
+
if (hasCustomRuleSetChanges) {
|
|
35
|
+
hasChanges = true;
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
hasChanges = true;
|
|
39
|
+
phpCSFixerConfig.option = [];
|
|
40
|
+
await setupCodingStandardOption(phpCSFixerConfig);
|
|
41
|
+
await setupCustomRuleSetPathOption(phpCSFixerConfig);
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
hasChanges = true;
|
|
45
|
+
const phpCSFixerConfig = {
|
|
46
|
+
[classKey]: PHP_CS_FIXER_VALIDATION_INSPECTION,
|
|
47
|
+
option: []
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
setupDefaultProperties(phpCSFixerConfig);
|
|
51
|
+
await setupCodingStandardOption(phpCSFixerConfig);
|
|
52
|
+
await setupCustomRuleSetPathOption(phpCSFixerConfig);
|
|
53
|
+
|
|
54
|
+
inspectionToolsData.push(phpCSFixerConfig);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return hasChanges;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
module.exports = setupPhpCSFixerValidationInspection;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
const {
|
|
2
|
+
classes: {
|
|
3
|
+
PHP_CS_VALIDATION_INSPECTION
|
|
4
|
+
},
|
|
5
|
+
options: {
|
|
6
|
+
CODING_STANDARD_OPTION_NAME,
|
|
7
|
+
MAGENTO2_CODING_STANDARD_OPTION_VALUE,
|
|
8
|
+
EXTENSIONS_OPTION_NAME,
|
|
9
|
+
WARNING_HIGHLIGHT_LEVEL_NAME_OPTION_NAME,
|
|
10
|
+
WARNING_HIGHLIGHT_LEVEL_NAME_OPTION_VALUE,
|
|
11
|
+
SHOW_SNIFF_NAMES_OPTION_NAME
|
|
12
|
+
}
|
|
13
|
+
} = require('./config');
|
|
14
|
+
const {
|
|
15
|
+
classKey,
|
|
16
|
+
nameKey,
|
|
17
|
+
valueKey
|
|
18
|
+
} = require('../keys');
|
|
19
|
+
const setupDefaultProperties = require('./default-properties-config');
|
|
20
|
+
const setupMagento2CodingStandardOption = require('./magento-coding-standard-config');
|
|
21
|
+
|
|
22
|
+
const phpCSConfigDefaultOptions = [
|
|
23
|
+
{
|
|
24
|
+
[nameKey]: CODING_STANDARD_OPTION_NAME,
|
|
25
|
+
[valueKey]: MAGENTO2_CODING_STANDARD_OPTION_VALUE
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
[nameKey]: WARNING_HIGHLIGHT_LEVEL_NAME_OPTION_NAME,
|
|
29
|
+
[valueKey]: WARNING_HIGHLIGHT_LEVEL_NAME_OPTION_VALUE
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
[nameKey]: SHOW_SNIFF_NAMES_OPTION_NAME,
|
|
33
|
+
[valueKey]: 'true'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
[nameKey]: EXTENSIONS_OPTION_NAME,
|
|
37
|
+
[valueKey]: 'php'
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const setupPhpCSValidationInspection = async (inspectionToolsData) => {
|
|
42
|
+
let hasChanges = false;
|
|
43
|
+
const phpCSConfig = inspectionToolsData.find(
|
|
44
|
+
(inspectionToolData) => inspectionToolData[classKey] === PHP_CS_VALIDATION_INSPECTION
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
if (phpCSConfig) {
|
|
48
|
+
const hasChangesInProperties = setupDefaultProperties(phpCSConfig);
|
|
49
|
+
if (hasChangesInProperties) {
|
|
50
|
+
hasChanges = true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (phpCSConfig.option) {
|
|
54
|
+
const hasCodingStandardChanges = await setupMagento2CodingStandardOption(phpCSConfig);
|
|
55
|
+
if (hasCodingStandardChanges) {
|
|
56
|
+
hasChanges = true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const warningHighlightLevelNameOption = phpCSConfig.option.find(
|
|
60
|
+
(option) => option[nameKey] === WARNING_HIGHLIGHT_LEVEL_NAME_OPTION_NAME
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (!warningHighlightLevelNameOption) {
|
|
64
|
+
hasChanges = true;
|
|
65
|
+
phpCSConfig.option.push({
|
|
66
|
+
[nameKey]: WARNING_HIGHLIGHT_LEVEL_NAME_OPTION_NAME,
|
|
67
|
+
[valueKey]: WARNING_HIGHLIGHT_LEVEL_NAME_OPTION_VALUE
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const showSniffNamesOption = phpCSConfig.option.find(
|
|
72
|
+
(option) => option[nameKey] === SHOW_SNIFF_NAMES_OPTION_NAME
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
if (!showSniffNamesOption) {
|
|
76
|
+
hasChanges = true;
|
|
77
|
+
phpCSConfig.option.push({
|
|
78
|
+
[nameKey]: SHOW_SNIFF_NAMES_OPTION_NAME,
|
|
79
|
+
[valueKey]: 'true'
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// we want php code sniffer to lint only php files
|
|
84
|
+
// for other files (js, css, scss) we have separate linter setups
|
|
85
|
+
const extensionsOption = phpCSConfig.option.find(
|
|
86
|
+
(option) => option[nameKey] === EXTENSIONS_OPTION_NAME
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
if (extensionsOption && extensionsOption[valueKey] !== 'php') {
|
|
90
|
+
hasChanges = true;
|
|
91
|
+
extensionsOption[valueKey] = 'php';
|
|
92
|
+
} else if (!extensionsOption) {
|
|
93
|
+
hasChanges = true;
|
|
94
|
+
phpCSConfig.option.push({
|
|
95
|
+
[nameKey]: EXTENSIONS_OPTION_NAME,
|
|
96
|
+
[valueKey]: 'php'
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
hasChanges = true;
|
|
101
|
+
phpCSConfig.option = phpCSConfigDefaultOptions;
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
hasChanges = true;
|
|
105
|
+
|
|
106
|
+
const phpCSConfig = {
|
|
107
|
+
[classKey]: PHP_CS_VALIDATION_INSPECTION,
|
|
108
|
+
option: phpCSConfigDefaultOptions
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
setupDefaultProperties(phpCSConfig);
|
|
112
|
+
|
|
113
|
+
inspectionToolsData.push(phpCSConfig);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return hasChanges;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
module.exports = setupPhpCSValidationInspection;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const {
|
|
2
|
+
classes: {
|
|
3
|
+
STYLELINT_INSPECTION
|
|
4
|
+
}
|
|
5
|
+
} = require('./config');
|
|
6
|
+
const { classKey } = require('../keys');
|
|
7
|
+
const setupDefaultProperties = require('./default-properties-config');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Set up Styelint configuration
|
|
11
|
+
*
|
|
12
|
+
* *function is async so it will be properly handled in Promise.all*
|
|
13
|
+
* @param {Array} inspectionToolsData
|
|
14
|
+
* @returns {Promise<Boolean>}
|
|
15
|
+
*/
|
|
16
|
+
const setupStyleLintInspection = async (inspectionToolsData) => {
|
|
17
|
+
let hasChanges = false;
|
|
18
|
+
const stylelintConfig = inspectionToolsData.find(
|
|
19
|
+
(inspectionToolData) => inspectionToolData[classKey] === STYLELINT_INSPECTION
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
if (stylelintConfig) {
|
|
23
|
+
hasChanges = setupDefaultProperties(stylelintConfig);
|
|
24
|
+
} else {
|
|
25
|
+
hasChanges = true;
|
|
26
|
+
inspectionToolsData.push({
|
|
27
|
+
[classKey]: STYLELINT_INSPECTION,
|
|
28
|
+
'@_enabled': 'true',
|
|
29
|
+
'@_level': 'ERROR',
|
|
30
|
+
'@_enabled_by_default': 'true'
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return hasChanges;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
module.exports = setupStyleLintInspection;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// xml property key names
|
|
2
|
+
const classKey = '@_class';
|
|
3
|
+
const nameKey = '@_name';
|
|
4
|
+
const valueKey = '@_value';
|
|
5
|
+
const toolPathKey = '@_tool_path';
|
|
6
|
+
const standardsKey = '@_standards';
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
classKey,
|
|
10
|
+
nameKey,
|
|
11
|
+
valueKey,
|
|
12
|
+
toolPathKey,
|
|
13
|
+
standardsKey
|
|
14
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { loadXmlFile, buildXmlFile } = require('../../../../config/xml-parser');
|
|
2
|
+
const pathExists = require('../../../../util/path-exists');
|
|
3
|
+
const setupMessDetector = require('./mess-detector-config');
|
|
4
|
+
const setupPHPCodeSniffer = require('./php-code-sniffer-config');
|
|
5
|
+
const setupPHPCSFixer = require('./php-cs-fixer-config');
|
|
6
|
+
const setupPHPProjectSharedConfiguration = require('./php-project-shared-configuration-config');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @type {() => import('listr2').ListrTask<import('../../../../../typings/context').ListrContext>}
|
|
10
|
+
*/
|
|
11
|
+
const setupPhpConfig = () => ({
|
|
12
|
+
title: 'Set up PHP configuration',
|
|
13
|
+
task: async (ctx, task) => {
|
|
14
|
+
const {
|
|
15
|
+
config: {
|
|
16
|
+
phpStorm,
|
|
17
|
+
phpStorm: {
|
|
18
|
+
php: {
|
|
19
|
+
phpLanguageLevel
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
} = ctx;
|
|
24
|
+
|
|
25
|
+
if (await pathExists(phpStorm.php.path)) {
|
|
26
|
+
const phpConfigContent = await loadXmlFile(phpStorm.php.path);
|
|
27
|
+
const phpConfigs = phpConfigContent.project.component;
|
|
28
|
+
const hasChanges = await Promise.all([
|
|
29
|
+
setupMessDetector(phpConfigs),
|
|
30
|
+
setupPHPCodeSniffer(phpConfigs),
|
|
31
|
+
setupPHPCSFixer(phpConfigs),
|
|
32
|
+
setupPHPProjectSharedConfiguration(phpConfigs, phpLanguageLevel)
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
if (hasChanges.includes(true)) {
|
|
36
|
+
await buildXmlFile(phpStorm.php.path, phpConfigContent);
|
|
37
|
+
} else {
|
|
38
|
+
task.skip();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const phpConfigContent = {
|
|
45
|
+
'?xml': {
|
|
46
|
+
'@_version': '1.0',
|
|
47
|
+
'@_encoding': 'UTF-8'
|
|
48
|
+
},
|
|
49
|
+
project: {
|
|
50
|
+
'@_version': '4',
|
|
51
|
+
component: []
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const phpConfigs = phpConfigContent.project.component;
|
|
55
|
+
|
|
56
|
+
await Promise.all([
|
|
57
|
+
setupMessDetector(phpConfigs),
|
|
58
|
+
setupPHPCodeSniffer(phpConfigs),
|
|
59
|
+
setupPHPCSFixer(phpConfigs),
|
|
60
|
+
setupPHPProjectSharedConfiguration(phpConfigs, phpLanguageLevel)
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
await buildXmlFile(phpStorm.php.path, phpConfigContent);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
module.exports = setupPhpConfig;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const pathExists = require('../../../../util/path-exists');
|
|
3
|
+
const { nameKey, toolPathKey } = require('../keys');
|
|
4
|
+
const { formatPathForPHPStormConfig } = require('../xml-utils');
|
|
5
|
+
|
|
6
|
+
const phpMDBinaryPath = path.join(process.cwd(), 'vendor', 'bin', 'phpmd');
|
|
7
|
+
const phpMDBinaryFormattedPath = formatPathForPHPStormConfig(phpMDBinaryPath);
|
|
8
|
+
|
|
9
|
+
const defaultMessDetectorSetting = {
|
|
10
|
+
MessDetectorConfiguration: {
|
|
11
|
+
[toolPathKey]: phpMDBinaryFormattedPath
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {Array} phpConfigs
|
|
17
|
+
* @returns {Promise<Boolean>}
|
|
18
|
+
*/
|
|
19
|
+
const setupMessDetector = async (phpConfigs) => {
|
|
20
|
+
let hasChanges = false;
|
|
21
|
+
const messDetectorComponent = phpConfigs.find(
|
|
22
|
+
(phpConfig) => phpConfig[nameKey] === 'MessDetector'
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const isPhpMDBinPathExists = await pathExists(phpMDBinaryPath);
|
|
26
|
+
|
|
27
|
+
if (messDetectorComponent && isPhpMDBinPathExists) {
|
|
28
|
+
if (!Array.isArray(messDetectorComponent.phpmd_settings)) {
|
|
29
|
+
hasChanges = true;
|
|
30
|
+
messDetectorComponent.phpmd_settings = [messDetectorComponent.phpmd_settings];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const messDetectorConfiguration = messDetectorComponent.phpmd_settings.find(
|
|
34
|
+
(phpmdSetting) => phpmdSetting.MessDetectorConfiguration
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (messDetectorConfiguration && messDetectorConfiguration[toolPathKey] !== phpMDBinaryFormattedPath) {
|
|
38
|
+
hasChanges = true;
|
|
39
|
+
messDetectorConfiguration[toolPathKey] = phpMDBinaryFormattedPath;
|
|
40
|
+
} else if (!messDetectorConfiguration) {
|
|
41
|
+
hasChanges = true;
|
|
42
|
+
messDetectorComponent.phpmd_settings.push(defaultMessDetectorSetting);
|
|
43
|
+
}
|
|
44
|
+
} else if (isPhpMDBinPathExists) {
|
|
45
|
+
hasChanges = true;
|
|
46
|
+
phpConfigs.push({
|
|
47
|
+
[nameKey]: 'MessDetector',
|
|
48
|
+
phpmd_settings: [
|
|
49
|
+
defaultMessDetectorSetting
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return hasChanges;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
module.exports = setupMessDetector;
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
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 {
|
|
60
|
+
hasChanges = true;
|
|
61
|
+
phpCodeSnifferComponent.phpcs_settings.push(defaultPHPCSSetting);
|
|
62
|
+
}
|
|
63
|
+
} else if (isAllPHPCSBinsExists) {
|
|
64
|
+
hasChanges = true;
|
|
65
|
+
phpConfigs.push({
|
|
66
|
+
[nameKey]: PHP_CODE_SNIFFER_COMPONENT_NAME,
|
|
67
|
+
phpcs_settings: [
|
|
68
|
+
defaultPHPCSSetting
|
|
69
|
+
]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return hasChanges;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
module.exports = setupPHPCodeSniffer;
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
if (phpCSFixerConfiguration[toolPathKey] !== phpCSFixerBinaryFormattedPath) {
|
|
43
|
+
hasChanges = true;
|
|
44
|
+
phpCSFixerConfiguration[toolPathKey] = phpCSFixerBinaryFormattedPath;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
hasChanges = true;
|
|
48
|
+
phpCSFixerComponent.phpcsfixer_settings.push(defaultPHPCSFixerSettings);
|
|
49
|
+
}
|
|
50
|
+
} else if (isPhpCSFixerBinPathExists) {
|
|
51
|
+
hasChanges = true;
|
|
52
|
+
phpConfigs.push({
|
|
53
|
+
[nameKey]: PHP_CS_FIXER_COMPONENT_NAME,
|
|
54
|
+
phpcsfixer_settings: [
|
|
55
|
+
defaultPHPCSFixerSettings
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return hasChanges;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
module.exports = setupPHPCSFixer;
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
if (phpProjectSharedConfigurationComponent[phpLanguageLevelKey] !== currentPhpLanguageLevel) {
|
|
38
|
+
hasChanges = true;
|
|
39
|
+
phpProjectSharedConfigurationComponent[phpLanguageLevelKey] = currentPhpLanguageLevel;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const suggestedChangeDefaultLanguageLevelOption = phpProjectSharedConfigurationComponent.option.find(
|
|
43
|
+
(phpProjectSharedConfigOption) => phpProjectSharedConfigOption[nameKey] === SUGGESTED_CHANGE_DEFAULT_LANGUAGE_LEVEL_OPTION_NAME
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (suggestedChangeDefaultLanguageLevelOption) {
|
|
47
|
+
if (suggestedChangeDefaultLanguageLevelOption[valueKey] !== 'false') {
|
|
48
|
+
hasChanges = true;
|
|
49
|
+
suggestedChangeDefaultLanguageLevelOption[valueKey] = 'false';
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
hasChanges = true;
|
|
53
|
+
phpProjectSharedConfigurationComponent.option.push(defaultSuggestChangeDefaultLanguageLevelOption);
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
hasChanges = true;
|
|
57
|
+
phpConfigs.push({
|
|
58
|
+
[nameKey]: PHP_PROJECT_SHARED_CONFIGURATION_COMPONENT_NAME,
|
|
59
|
+
[phpLanguageLevelKey]: currentPhpLanguageLevel,
|
|
60
|
+
option: [
|
|
61
|
+
defaultSuggestChangeDefaultLanguageLevelOption
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return hasChanges;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
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;
|