From 7d9c117bb6db0d3c4d074ee24be7b8b2f8bad5de Mon Sep 17 00:00:00 2001 From: MagicLegend Date: Thu, 19 May 2022 19:07:19 +0300 Subject: [PATCH] Added skip-phpstorm-config option to the start command Prevent magento-scripts from constantly overwriting the PHPStorm configurations at every start --- .../magento-scripts/lib/commands/start.js | 6 + .../file-system/create-php-storm-config.js | 129 +++++++++--------- 2 files changed, 73 insertions(+), 62 deletions(-) diff --git a/build-packages/magento-scripts/lib/commands/start.js b/build-packages/magento-scripts/lib/commands/start.js index f4ccd037..a360d405 100644 --- a/build-packages/magento-scripts/lib/commands/start.js +++ b/build-packages/magento-scripts/lib/commands/start.js @@ -65,6 +65,12 @@ module.exports = (yargs) => { describe: 'Enable verbose logging', type: 'boolean', default: false + }) + .option('skip-phpstorm-config', { + alias: 'c', + describe: 'Skip setting PHPStorm config', + type: 'boolean', + default: false }), async (args = {}) => { /** diff --git a/build-packages/magento-scripts/lib/tasks/file-system/create-php-storm-config.js b/build-packages/magento-scripts/lib/tasks/file-system/create-php-storm-config.js index 0c3add5b..7f9cabf7 100644 --- a/build-packages/magento-scripts/lib/tasks/file-system/create-php-storm-config.js +++ b/build-packages/magento-scripts/lib/tasks/file-system/create-php-storm-config.js @@ -4,79 +4,84 @@ const path = require('path'); const fs = require('fs'); const createPhpStormConfig = () => ({ - title: 'Setting PHPStorm config', - task: async ({ config: { phpStorm }, ports }) => { - const { phpLanguageLevel } = phpStorm.php; - const jdbcUrl = `jdbc:mysql://localhost:${ports.mysql}/magento`; + task: (ctx, task) => task.newListr([ + { + title: 'Setting PHPStorm config', + skip: (ctx) => ctx.skipPhpstormConfig, + task: async ({ config: { phpStorm }, ports }) => { + const { phpLanguageLevel } = phpStorm.php; + const jdbcUrl = `jdbc:mysql://localhost:${ports.mysql}/magento`; - try { - await setConfigFile({ - configPathname: phpStorm.xdebug.path, - template: phpStorm.xdebug.templatePath, - overwrite: true, - templateArgs: { - phpStorm + try { + await setConfigFile({ + configPathname: phpStorm.xdebug.path, + template: phpStorm.xdebug.templatePath, + overwrite: true, + templateArgs: { + phpStorm + } + }); + } catch (e) { + throw new Error(`Unexpected error accrued during workspace.xml config creation\n\n${e}`); } - }); - } catch (e) { - throw new Error(`Unexpected error accrued during workspace.xml config creation\n\n${e}`); - } - try { - await setConfigFile({ - configPathname: phpStorm.php.path, - template: phpStorm.php.templatePath, - overwrite: true, - templateArgs: { - phpLanguageLevel + try { + await setConfigFile({ + configPathname: phpStorm.php.path, + template: phpStorm.php.templatePath, + overwrite: true, + templateArgs: { + phpLanguageLevel + } + }); + } catch (e) { + throw new Error(`Unexpected error accrued during php.xml config creation\n\n${e}`); } - }); - } catch (e) { - throw new Error(`Unexpected error accrued during php.xml config creation\n\n${e}`); - } - try { - await setConfigFile({ - configPathname: phpStorm.database.dataSourcesLocal.path, - template: phpStorm.database.dataSourcesLocal.templatePath, - overwrite: true, - templateArgs: { - phpStorm + try { + await setConfigFile({ + configPathname: phpStorm.database.dataSourcesLocal.path, + template: phpStorm.database.dataSourcesLocal.templatePath, + overwrite: true, + templateArgs: { + phpStorm + } + }); + } catch (e) { + throw new Error(`Unexpected error accrued during dataSources.local.xml config creation\n\n${e}`); } - }); - } catch (e) { - throw new Error(`Unexpected error accrued during dataSources.local.xml config creation\n\n${e}`); - } - try { - await setConfigFile({ - configPathname: phpStorm.database.dataSources.path, - template: phpStorm.database.dataSources.templatePath, - overwrite: true, - templateArgs: { - phpStorm, - jdbcUrl + try { + await setConfigFile({ + configPathname: phpStorm.database.dataSources.path, + template: phpStorm.database.dataSources.templatePath, + overwrite: true, + templateArgs: { + phpStorm, + jdbcUrl + } + }); + } catch (e) { + throw new Error(`Unexpected error accrued during dataSources.xml config creation\n\n${e}`); } - }); - } catch (e) { - throw new Error(`Unexpected error accrued during dataSources.xml config creation\n\n${e}`); - } - if (!await pathExists(path.resolve('./.idea/dataSources'))) { - await fs.promises.mkdir(path.resolve('./.idea/dataSources')); - } + if (!await pathExists(path.resolve('./.idea/dataSources'))) { + await fs.promises.mkdir(path.resolve('./.idea/dataSources')); + } - try { - await setConfigFile({ - configPathname: phpStorm.inspectionTools.path, - template: phpStorm.inspectionTools.templatePath, - overwrite: true, - templateArgs: {} - }); - } catch (e) { - throw new Error(`Unexpected error accrued during Project_Default.xml config creation\n\n${e}`); + try { + await setConfigFile({ + configPathname: phpStorm.inspectionTools.path, + template: phpStorm.inspectionTools.templatePath, + overwrite: true, + templateArgs: {} + }); + } catch (e) { + throw new Error(`Unexpected error accrued during Project_Default.xml config creation\n\n${e}`); + } + } } - } + ]) }); module.exports = createPhpStormConfig;