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

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 (110) hide show
  1. package/index.js +13 -0
  2. package/lib/commands/cli.js +28 -1
  3. package/lib/commands/execute.js +2 -1
  4. package/lib/config/docker.js +45 -9
  5. package/lib/config/get-port-config.js +2 -1
  6. package/lib/config/port-config.js +1 -0
  7. package/lib/config/templates/magentorc.template +3 -5
  8. package/lib/config/templates/php.template.ini +6 -4
  9. package/lib/config/templates/varnish.template.vcl +241 -0
  10. package/lib/config/versions/magento-2.3.0.js +9 -0
  11. package/lib/config/versions/magento-2.3.1.js +9 -0
  12. package/lib/config/versions/magento-2.3.2-p2.js +9 -0
  13. package/lib/config/versions/magento-2.3.2.js +9 -0
  14. package/lib/config/versions/magento-2.3.3-p1.js +9 -0
  15. package/lib/config/versions/magento-2.3.3.js +9 -0
  16. package/lib/config/versions/magento-2.3.4-p2.js +9 -0
  17. package/lib/config/versions/magento-2.3.4.js +9 -0
  18. package/lib/config/versions/magento-2.3.5-p1.js +9 -0
  19. package/lib/config/versions/magento-2.3.5-p2.js +9 -0
  20. package/lib/config/versions/magento-2.3.5.js +9 -0
  21. package/lib/config/versions/magento-2.3.6-p1.js +9 -0
  22. package/lib/config/versions/magento-2.3.6.js +9 -0
  23. package/lib/config/versions/magento-2.3.7-p1.js +9 -0
  24. package/lib/config/versions/magento-2.3.7-p2.js +9 -0
  25. package/lib/config/versions/magento-2.3.7-p3.js +9 -0
  26. package/lib/config/versions/magento-2.3.7.js +9 -0
  27. package/lib/config/versions/magento-2.4.0-p1.js +9 -0
  28. package/lib/config/versions/magento-2.4.0.js +9 -0
  29. package/lib/config/versions/magento-2.4.1-p1.js +9 -0
  30. package/lib/config/versions/magento-2.4.1.js +9 -0
  31. package/lib/config/versions/magento-2.4.2-p1.js +9 -0
  32. package/lib/config/versions/magento-2.4.2-p2.js +9 -0
  33. package/lib/config/versions/magento-2.4.2.js +9 -0
  34. package/lib/config/versions/magento-2.4.3-p1.js +9 -0
  35. package/lib/config/versions/magento-2.4.3-p2.js +9 -0
  36. package/lib/config/versions/magento-2.4.3.js +9 -0
  37. package/lib/config/versions/magento-2.4.4.js +9 -0
  38. package/lib/tasks/cli/create-bashrc-config.js +5 -2
  39. package/lib/tasks/docker/containers.js +10 -8
  40. package/lib/tasks/docker/volumes.js +4 -4
  41. package/lib/tasks/file-system/create-nginx-config.js +5 -0
  42. package/lib/tasks/file-system/create-php-storm-config.js +82 -0
  43. package/lib/tasks/file-system/create-varnish-config.js +51 -0
  44. package/lib/tasks/file-system/index.js +4 -2
  45. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +1 -1
  46. package/lib/tasks/magento/setup-magento/disable-2fa.js +4 -12
  47. package/lib/tasks/magento/setup-magento/disable-full-page-cache.js +20 -0
  48. package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +14 -16
  49. package/lib/tasks/magento/setup-magento/migrate-database.js +21 -6
  50. package/lib/tasks/magento/setup-magento/varnish-config.js +63 -0
  51. package/lib/tasks/mysql/fix-db.js +2 -2
  52. package/lib/tasks/php/index.js +1 -1
  53. package/lib/tasks/php/update-env-php.js +16 -1
  54. package/lib/tasks/php/update-env.php +54 -12
  55. package/lib/tasks/requirements/docker/index.js +2 -0
  56. package/lib/tasks/requirements/docker/install.js +11 -11
  57. package/lib/tasks/requirements/docker/running-status.js +137 -0
  58. package/lib/tasks/requirements/docker/version.js +2 -0
  59. package/lib/tasks/requirements/index.js +5 -5
  60. package/lib/tasks/requirements/php-version.js +3 -1
  61. package/lib/tasks/start.js +2 -6
  62. package/lib/tasks/status/index.js +1 -1
  63. package/lib/tasks/theme/link-theme.js +2 -2
  64. package/lib/tasks/theme/setup-persisted-query.js +3 -3
  65. package/lib/tasks/theme/setup-themes.js +2 -2
  66. package/lib/util/config-file-validator.js +11 -1
  67. package/lib/util/config-php-json.js +19 -0
  68. package/lib/util/instance-metadata.js +1 -7
  69. package/lib/util/is-running-root.js +3 -0
  70. package/lib/util/php-task.js +6 -2
  71. package/lib/util/run-php.js +7 -1
  72. package/lib/util/systemctl.js +46 -0
  73. package/package.json +2 -3
  74. package/typings/context.d.ts +1 -2
  75. package/typings/index.d.ts +19 -0
  76. package/lib/config/xml-parser.js +0 -61
  77. package/lib/tasks/file-system/create-phpstorm-config/database-config.js +0 -248
  78. package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +0 -83
  79. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +0 -154
  80. package/lib/tasks/file-system/create-phpstorm-config/index.js +0 -27
  81. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +0 -29
  82. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/config.js +0 -54
  83. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +0 -31
  84. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +0 -42
  85. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/eslint-inspection-config.js +0 -37
  86. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/index.js +0 -80
  87. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +0 -29
  88. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +0 -145
  89. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/paths.js +0 -20
  90. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-fixer-validation-inspection-config.js +0 -60
  91. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +0 -119
  92. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/stylelint-inspection-config.js +0 -37
  93. package/lib/tasks/file-system/create-phpstorm-config/keys.js +0 -14
  94. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +0 -67
  95. package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +0 -57
  96. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +0 -76
  97. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +0 -63
  98. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +0 -69
  99. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +0 -77
  100. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +0 -98
  101. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/format-setting-config.js +0 -57
  102. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +0 -66
  103. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +0 -64
  104. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +0 -60
  105. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +0 -51
  106. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +0 -74
  107. package/lib/tasks/file-system/create-phpstorm-config/xml-utils.js +0 -5
  108. package/lib/tasks/magento/setup-magento/adjust-magento-configuration.js +0 -27
  109. package/lib/tasks/magento/setup-magento/disable-page-cache.js +0 -11
  110. package/typings/phpstorm.d.ts +0 -33
@@ -0,0 +1,137 @@
1
+ const os = require('os');
2
+ const { execAsyncSpawn } = require('../../../util/exec-async-command');
3
+ const getIsWsl = require('../../../util/is-wsl');
4
+ const pathExists = require('../../../util/path-exists');
5
+ const sleep = require('../../../util/sleep');
6
+ const { systemctlControl } = require('../../../util/systemctl');
7
+
8
+ const pathToDockerApplication = '/Applications/Docker.app';
9
+
10
+ const getDockerVersion = () => execAsyncSpawn('docker version --format {{.Server.Version}}', {
11
+ withCode: true
12
+ });
13
+
14
+ /**
15
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
16
+ */
17
+ const checkDockerStatusMacOS = () => ({
18
+ title: 'Checking Docker status on MacOS',
19
+ task: async (ctx, task) => {
20
+ const { result, code } = await getDockerVersion();
21
+
22
+ if (code !== 0 && result.includes('Is the docker daemon running?')) {
23
+ const dockerOpenAppConfirmation = await task.prompt({
24
+ type: 'Confirm',
25
+ message: 'Looks like Docker is not running, would you like us to open a Docker for Mac application and wait for it to start up?'
26
+ });
27
+
28
+ if (dockerOpenAppConfirmation && await pathExists(pathToDockerApplication)) {
29
+ await execAsyncSpawn(`open ${pathToDockerApplication}`);
30
+ let ready = false;
31
+ let attempts = 0;
32
+ while (!ready) {
33
+ if (attempts > 24 && !ready) {
34
+ throw new Error('Docker haven\'t started in 2 mins, exiting...');
35
+ }
36
+ try {
37
+ const { code: startupCode } = await getDockerVersion();
38
+ if (startupCode !== 0) {
39
+ task.output = `Waiting for Docker to startup for ${attempts * 5} seconds...`;
40
+ attempts++;
41
+ await sleep(5000);
42
+ } else {
43
+ ready = true;
44
+ }
45
+ } catch (e) {
46
+ //
47
+ }
48
+ }
49
+
50
+ return;
51
+ }
52
+
53
+ task.skip('User skipped running Docker');
54
+ }
55
+ },
56
+ options: {
57
+ bottomBar: 10
58
+ }
59
+ });
60
+
61
+ /**
62
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
63
+ */
64
+ const checkDockerStatusWSL = () => ({
65
+ title: 'Checking Docker status on Windows WSL',
66
+ task: async () => {
67
+ const { result, code } = await getDockerVersion();
68
+
69
+ if (code !== 0 && result.includes('Is the docker daemon running?')) {
70
+ throw new Error(`Docker is not running!
71
+
72
+ Please open Docker Desktop application for Windows and make sure that Docker is running. Then you can try again!`);
73
+ }
74
+ }
75
+ });
76
+
77
+ /**
78
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
79
+ */
80
+ const checkDockerStatusLinux = () => ({
81
+ title: 'Checking Docker status on Linux',
82
+ task: async (ctx, task) => {
83
+ const dockerService = systemctlControl('docker');
84
+
85
+ const isRunning = await dockerService.isRunning();
86
+ const isEnabled = await dockerService.isEnabled();
87
+
88
+ if (!isEnabled && !isRunning) {
89
+ const dockerStartConfirmation = await task.prompt({
90
+ type: 'Confirm',
91
+ message: `Looks like Docker is not enabled and not running, would you like to enable and run it?
92
+
93
+ This action requires root privileges.`
94
+ });
95
+
96
+ if (dockerStartConfirmation) {
97
+ await dockerService.enableAndStart();
98
+
99
+ return;
100
+ }
101
+ task.skip('User skipped running Docker');
102
+ } else if (!isRunning) {
103
+ const dockerStartConfirmation = await task.prompt({
104
+ type: 'Confirm',
105
+ message: `Looks like Docker is not running, would you like to run it?
106
+
107
+ This action requires root privileges.`
108
+ });
109
+
110
+ if (dockerStartConfirmation) {
111
+ await dockerService.start();
112
+
113
+ return;
114
+ }
115
+ task.skip('User skipped running Docker');
116
+ }
117
+ }
118
+ });
119
+
120
+ /**
121
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
122
+ */
123
+ const checkDockerStatus = () => ({
124
+ title: 'Checking Docker status',
125
+ task: async (ctx, task) => {
126
+ if (os.platform() === 'darwin') {
127
+ return task.newListr(checkDockerStatusMacOS());
128
+ }
129
+ if (!await getIsWsl()) {
130
+ return task.newListr(checkDockerStatusLinux());
131
+ }
132
+
133
+ return task.newListr(checkDockerStatusWSL());
134
+ }
135
+ });
136
+
137
+ module.exports = checkDockerStatus;
@@ -13,6 +13,8 @@ const getDockerVersion = () => ({
13
13
  const dockerVersion = result.split('').filter((c) => /[\d.]/i.test(c)).join('') || result;
14
14
 
15
15
  ctx.dockerVersion = dockerVersion;
16
+ } else {
17
+ throw new Error(`Got unexpected result during Docker version retrieval!\n\n${ result }`);
16
18
  }
17
19
  }
18
20
  });
@@ -13,17 +13,17 @@ const checkRequirements = () => ({
13
13
  task: (ctx, task) => task.newListr([
14
14
  // checking if user is on supported platform
15
15
  checkPlatform(),
16
+ // check the Docker installation
17
+ checkDocker(),
18
+ // check for Node.js version
19
+ checkNodeVersion(),
16
20
  // check the PHPBrew installation
17
21
  checkPHPbrew(),
18
22
  // check installed PHP version
19
23
  checkPHPVersion(),
20
- // check the Docker installation
21
- checkDocker(),
22
24
  // check for COMPOSER_AUTH or auth.json
23
25
  // localAuthJson(),
24
- checkComposer(),
25
- // check for Node.js version
26
- checkNodeVersion()
26
+ checkComposer()
27
27
  ], {
28
28
  concurrent: false,
29
29
  exitOnError: true,
@@ -99,7 +99,7 @@ const checkPHPVersion = () => ({
99
99
  task: async (ctx, task) => {
100
100
  const phpVersionResponse = await execAsyncSpawn('php --version');
101
101
 
102
- const phpVersionResponseResult = phpVersionResponse.match(/PHP\s(\d\.\d\.\d)/i);
102
+ const phpVersionResponseResult = phpVersionResponse.match(/PHP\s(\d+\.\d+\.\d+)/i);
103
103
 
104
104
  if (phpVersionResponseResult && phpVersionResponseResult.length > 0) {
105
105
  const phpVersion = phpVersionResponseResult[1];
@@ -123,6 +123,8 @@ To fix that we will build special PHP version that will be used by PHPBrew, plea
123
123
  );
124
124
  }
125
125
  }
126
+
127
+ task.title = `Using PHP version ${phpVersion} in system`;
126
128
  }
127
129
  }
128
130
  });
@@ -29,7 +29,6 @@ const convertLegacyVolumes = require('./docker/convert-legacy-volumes');
29
29
  const enableMagentoComposerPlugins = require('./magento/enable-magento-composer-plugins');
30
30
  const getIsWsl = require('../util/is-wsl');
31
31
  const checkForXDGOpen = require('../util/xdg-open-exists');
32
- const { getInstanceMetadata, constants: { WEB_LOCATION_TITLE } } = require('../util/instance-metadata');
33
32
 
34
33
  /**
35
34
  * @type {() => import('listr2').ListrTask<import('../../typings/context').ListrContext>}
@@ -190,11 +189,8 @@ const start = () => ({
190
189
 
191
190
  return false;
192
191
  },
193
- task: (ctx) => {
194
- const instanceMetadata = getInstanceMetadata(ctx);
195
- const locationOnTheWeb = instanceMetadata.frontend.find(({ title }) => title === WEB_LOCATION_TITLE);
196
-
197
- openBrowser(locationOnTheWeb.text);
192
+ task: ({ ports, config: { overridenConfiguration: { host, ssl } } }) => {
193
+ openBrowser(`${ssl.enabled ? 'https' : 'http'}://${host}${ssl.enabled || ports.app === 80 ? '' : `:${ports.app}`}/`);
198
194
  },
199
195
  options: {
200
196
  showTimer: false
@@ -91,7 +91,7 @@ const prettyStatus = async (ctx) => {
91
91
  .addLine(`Image: ${logger.style.file(container.image)}`)
92
92
  .addLine(`Network: ${logger.style.link(container.network)}`);
93
93
 
94
- if (container.ports.length > 0) {
94
+ if (container.ports && container.ports.length > 0) {
95
95
  block.addLine('Port forwarding:');
96
96
  container.ports.forEach((port) => {
97
97
  const { host, hostPort, containerPort } = parsePort(port);
@@ -1,6 +1,6 @@
1
1
  const symlinkTheme = require('./symlink-theme');
2
2
  const installTheme = require('./install-theme');
3
- const disablePageCache = require('../magento/setup-magento/disable-page-cache');
3
+ const disableFullPageCache = require('../magento/setup-magento/disable-full-page-cache');
4
4
  const disablePageBuilder = require('../magento/setup-magento/disable-page-builder');
5
5
  const buildTheme = require('./build-theme');
6
6
  const upgradeMagento = require('../magento/setup-magento/upgrade-magento');
@@ -53,7 +53,7 @@ const linkTheme = () => ({
53
53
  updateEnvPHP(),
54
54
  setupPersistedQuery(),
55
55
  upgradeMagento(),
56
- disablePageCache(),
56
+ disableFullPageCache(),
57
57
  ...(isPageBuilderInstalled && Number(isPagebuilderEnabled) ? [disablePageBuilder()] : []),
58
58
  buildTheme(theme)
59
59
  ]);
@@ -8,7 +8,7 @@ const runMagentoCommand = require('../../util/run-magento');
8
8
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
9
9
  */
10
10
  const persistedQuerySetup = () => ({
11
- title: 'Setting up redis configuration for persisted queries',
11
+ title: 'Setting up Redis configuration for persisted queries',
12
12
  task: async (ctx, task) => {
13
13
  const { ports, magentoVersion, verbose = false } = ctx;
14
14
  const composerLockData = await getJsonfileData(path.join(process.cwd(), 'composer.lock'));
@@ -29,8 +29,8 @@ const persistedQuerySetup = () => ({
29
29
  if (
30
30
  persistedQueryConfig
31
31
  && persistedQueryConfig.redis
32
- && persistedQueryConfig.redis.port === ports.redis
33
- && persistedQueryConfig.redis.localhost === 'localhost'
32
+ && persistedQueryConfig.redis.port === `${ ports.redis }`
33
+ && persistedQueryConfig.redis.host === 'localhost'
34
34
  ) {
35
35
  task.skip();
36
36
  return;
@@ -5,7 +5,7 @@ const symlinkTheme = require('./symlink-theme');
5
5
  const installTheme = require('./install-theme');
6
6
  const setupPersistedQuery = require('./setup-persisted-query');
7
7
  const upgradeMagento = require('../magento/setup-magento/upgrade-magento');
8
- const disablePageCache = require('../magento/setup-magento/disable-page-cache');
8
+ const disableFullPageCache = require('../magento/setup-magento/disable-full-page-cache');
9
9
  const buildTheme = require('./build-theme');
10
10
 
11
11
  /**
@@ -80,7 +80,7 @@ const setupThemes = () => ({
80
80
  ])
81
81
  })).concat([
82
82
  upgradeMagento(),
83
- disablePageCache(),
83
+ disableFullPageCache(),
84
84
  setupPersistedQuery()
85
85
  ])
86
86
  );
@@ -72,6 +72,15 @@ const nginxConfigurationSchema = Joi.object({
72
72
  configTemplate: Joi.string().optional().custom(fileExistsValidator)
73
73
  });
74
74
 
75
+ /**
76
+ * @type {Joi.ObjectSchema<import('../../typings').NginxConfiguration>}
77
+ */
78
+ const varnishConfigurationSchema = Joi.object({
79
+ enabled: Joi.boolean().optional(),
80
+ version: Joi.string().optional(),
81
+ configTemplate: Joi.string().optional().custom(fileExistsValidator)
82
+ });
83
+
75
84
  /**
76
85
  * @type {Joi.ObjectSchema<import('../../typings').ServiceWithVersion>}
77
86
  */
@@ -101,7 +110,8 @@ const configurationSchema = Joi.object({
101
110
  mysql: serviceConfigurationSchema.optional(),
102
111
  elasticsearch: serviceConfigurationSchema.optional(),
103
112
  redis: serviceConfigurationSchema.optional(),
104
- composer: composerConfigurationSchema.optional()
113
+ composer: composerConfigurationSchema.optional(),
114
+ varnish: varnishConfigurationSchema.optional()
105
115
  });
106
116
 
107
117
  /**
@@ -0,0 +1,19 @@
1
+ const path = require('path');
2
+ const runPhpCode = require('./run-php');
3
+
4
+ const configPhpToJson = async (projectPath = process.cwd(), { magentoVersion }) => {
5
+ const { code, result } = await runPhpCode(`-r "echo json_encode(require '${path.join(projectPath, 'app', 'etc', 'config.php')}');"`, {
6
+ magentoVersion
7
+ });
8
+
9
+ if (code !== 0) {
10
+ throw new Error(result);
11
+ }
12
+ try {
13
+ return JSON.parse(result);
14
+ } catch (e) {
15
+ throw new Error(`Ooops! Something went wrong when trying to parse app/etc/config.php file!\n\n${e}\n\nFile result: ${result}`);
16
+ }
17
+ };
18
+
19
+ module.exports = configPhpToJson;
@@ -70,11 +70,5 @@ const getInstanceMetadata = (ctx) => {
70
70
  };
71
71
 
72
72
  module.exports = {
73
- getInstanceMetadata,
74
- constants: {
75
- WEB_LOCAL_LOCATION_TITLE,
76
- WEB_LOCATION_TITLE,
77
- WEB_ADMIN_LOCATION_TITLE,
78
- WEB_ADMIN_CREDENTIALS_TITLE
79
- }
73
+ getInstanceMetadata
80
74
  };
@@ -0,0 +1,3 @@
1
+ const isRunningRoot = () => process.getuid() === 0; // UID 0 is always root
2
+
3
+ module.exports = isRunningRoot;
@@ -1,7 +1,10 @@
1
1
  const runPhpCode = require('./run-php');
2
2
 
3
3
  /**
4
- * @type {(command: string, options: { noTitle: boolean }) => import('listr2').ListrTask<import('../../typings/context').ListrContext>}
4
+ * @type {(
5
+ * command: string,
6
+ * options: { noTitle: boolean, env: Record<string, string> }
7
+ * ) => import('listr2').ListrTask<import('../../typings/context').ListrContext>}
5
8
  */
6
9
  const phpTask = (command, options = {}) => ({
7
10
  title: !options.noTitle ? `Running command 'php ${command}` : undefined,
@@ -10,7 +13,8 @@ const phpTask = (command, options = {}) => ({
10
13
  task.output = t;
11
14
  },
12
15
  throwNonZeroCode: true,
13
- magentoVersion
16
+ magentoVersion,
17
+ env: options.env
14
18
  })
15
19
  });
16
20
 
@@ -10,6 +10,7 @@ const { getConfigFromMagentoVersion, defaultConfiguration } = require('../config
10
10
  * @param {() => {}} options.callback
11
11
  * @param {Boolean} options.throwNonZeroCode Throw if command return non 0 code.
12
12
  * @param {String} options.magentoVersion Magento version for config
13
+ * @param {Record<string, string>} options.env Environment variables
13
14
  */
14
15
  const runPhpCode = async (command, options = {}) => {
15
16
  const {
@@ -17,7 +18,12 @@ const runPhpCode = async (command, options = {}) => {
17
18
  magentoVersion = defaultConfiguration.magentoVersion
18
19
  } = options;
19
20
  const { php } = await getConfigFromMagentoVersion(magentoVersion);
20
- const { code, result } = await execAsyncSpawn(`${php.binPath} -c ${php.iniPath} ${command}`, {
21
+ let spawnCommand = `${php.binPath} -c ${php.iniPath} ${command}`;
22
+ if (options.env && Object.keys(options.env).length > 0) {
23
+ const env = Object.entries(options.env).map(([key, value]) => `${key}=${value}`).join(' ');
24
+ spawnCommand = `${env} ${spawnCommand}`;
25
+ }
26
+ const { code, result } = await execAsyncSpawn(spawnCommand, {
21
27
  ...options,
22
28
  withCode: true
23
29
  });
@@ -0,0 +1,46 @@
1
+ const { execAsyncSpawn } = require('./exec-async-command');
2
+
3
+ /**
4
+ * @param {String} cmd
5
+ * @param {String} serviceName
6
+ * @param {{ now: boolean }} options
7
+ */
8
+ const run = (cmd, serviceName, options = {}) => execAsyncSpawn(
9
+ `systemctl ${ cmd }${ serviceName ? ` ${ serviceName }` : '' }${ options.now ? ' --now' : ''}`,
10
+ {
11
+ withCode: true
12
+ }
13
+ );
14
+
15
+ const daemonReload = () => run('daemon-reload');
16
+
17
+ const systemctlControl = (serviceName) => ({
18
+ disable: () => run('disable', serviceName),
19
+ enable: () => run('enable', serviceName),
20
+ enableAndStart: () => run('enable', serviceName, { now: true }),
21
+ restart: () => run('restart', serviceName),
22
+ start: () => run('start', serviceName),
23
+ stop: () => run('stop', serviceName),
24
+ isEnabled: async () => {
25
+ try {
26
+ const { result } = await run('is-enabled', serviceName);
27
+ return result.includes('enabled');
28
+ } catch (e) {
29
+ return false;
30
+ }
31
+ },
32
+ isRunning: async () => {
33
+ try {
34
+ const { result } = await run('status', serviceName);
35
+
36
+ return result.includes('active (running)');
37
+ } catch (e) {
38
+ return false;
39
+ }
40
+ }
41
+ });
42
+
43
+ module.exports = {
44
+ systemctlControl,
45
+ daemonReload
46
+ };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Scripts and configuration used by CMA.",
4
4
  "homepage": "https://docs.create-magento-app.com/",
5
5
  "repository": "github:scandipwa/create-magento-app",
6
- "version": "1.14.1-alpha.1",
6
+ "version": "1.14.1-alpha.4",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -26,7 +26,6 @@
26
26
  "conf": "10.1.1",
27
27
  "enquirer": "2.3.6",
28
28
  "eta": "1.12.3",
29
- "fast-xml-parser": "^4.0.7",
30
29
  "hjson": "^3.2.2",
31
30
  "is-installed-globally": "0.4.0",
32
31
  "joi": "17.6.0",
@@ -52,5 +51,5 @@
52
51
  "mysql",
53
52
  "scandipwa"
54
53
  ],
55
- "gitHead": "cc46e60ca1d44d6e00b151e03af5cc7f56a5e54a"
54
+ "gitHead": "41436e9871ef44477f79f93c751b5d7315de8187"
56
55
  }
@@ -1,7 +1,6 @@
1
1
  import mysql2 from 'mysql2';
2
2
 
3
3
  import { CMAConfiguration, PHPExtensions } from './index';
4
- import { PHPStormConfig } from './phpstorm';
5
4
 
6
5
  export interface ListrContext {
7
6
  magentoVersion: string
@@ -13,6 +12,7 @@ export interface ListrContext {
13
12
  mysql: number
14
13
  redis: number
15
14
  elasticsearch: number
15
+ varnish: number
16
16
  }
17
17
  arch: 'arm64' | 'x64'
18
18
  isArm: boolean
@@ -83,7 +83,6 @@ export interface ListrContext {
83
83
  overridenConfiguration: Omit<CMAConfiguration, 'prefix' | 'useNonOverlappingPorts'>
84
84
  userConfiguration: Omit<CMAConfiguration, 'prefix' | 'useNonOverlappingPorts'>
85
85
  nonOverridenConfiguration: Omit<CMAConfiguration, 'prefix' | 'useNonOverlappingPorts'>
86
- phpStorm: PHPStormConfig
87
86
  }
88
87
  systemConfiguration: {
89
88
  analytics: boolean
@@ -21,6 +21,20 @@ export interface NginxConfiguration extends ServiceWithVersion {
21
21
  configTemplate: string
22
22
  }
23
23
 
24
+ export interface VarnishConfiguration extends ServiceWithVersion {
25
+ /**
26
+ * Enable or disable Varnish in the project
27
+ */
28
+ enabled: boolean
29
+
30
+ /**
31
+ * Configuration file location
32
+ *
33
+ * @example ./my-varnish-config.vcl
34
+ */
35
+ configTemplate: string
36
+ }
37
+
24
38
  export interface PHPExtension extends Record<string, unknown> {
25
39
  version?: string
26
40
  /**
@@ -175,6 +189,11 @@ export interface CMAConfiguration {
175
189
  * Composer configuration
176
190
  */
177
191
  composer: ServiceWithVersion
192
+
193
+ /**
194
+ * Varnish configuration
195
+ */
196
+ varnish: VarnishConfiguration
178
197
  }
179
198
  /**
180
199
  * Magento configuration
@@ -1,61 +0,0 @@
1
- const { XMLParser, XMLBuilder } = require('fast-xml-parser');
2
- const fs = require('fs');
3
- const path = require('path');
4
- const pathExists = require('../util/path-exists');
5
-
6
- /**
7
- * @type {import('fast-xml-parser').X2jOptions}
8
- */
9
- const xmlParserConfig = {
10
- ignoreAttributes: false,
11
- parseAttributeValue: false,
12
- trimValues: true,
13
- allowBooleanAttributes: true
14
- };
15
-
16
- /**
17
- * @type {Partial<import('fast-xml-parser').XmlBuilderOptions>}
18
- */
19
- const xmlBuilderConfig = {
20
- ...xmlParserConfig,
21
- format: true,
22
- suppressEmptyNode: true,
23
- suppressBooleanAttributes: false
24
- };
25
-
26
- const parser = new XMLParser(xmlParserConfig);
27
- const builder = new XMLBuilder(xmlBuilderConfig);
28
-
29
- /**
30
- * Load xml file to js object
31
- * @param {String} filePath
32
- */
33
- const loadXmlFile = async (filePath) => {
34
- const fileData = await fs.promises.readFile(filePath, 'utf-8');
35
-
36
- return parser.parse(fileData);
37
- };
38
-
39
- /**
40
- * Build xml from js object and write it to file
41
- * @param {String} filePath
42
- * @param {String} fileData
43
- */
44
- const buildXmlFile = async (filePath, fileData) => {
45
- const xmlFileData = builder.build(fileData);
46
-
47
- const { dir } = path.parse(filePath);
48
-
49
- if (!await pathExists(dir)) {
50
- await fs.promises.mkdir(dir, {
51
- recursive: true
52
- });
53
- }
54
-
55
- await fs.promises.writeFile(filePath, xmlFileData, 'utf-8');
56
- };
57
-
58
- module.exports = {
59
- loadXmlFile,
60
- buildXmlFile
61
- };