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

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 (179) 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/commands/logs.js +1 -0
  5. package/lib/commands/start.js +18 -5
  6. package/lib/config/cma-config.js +16 -0
  7. package/lib/config/dependencies-for-platforms.js +15 -3
  8. package/lib/config/docker.js +89 -15
  9. package/lib/config/get-port-config.js +9 -3
  10. package/lib/config/index.js +2 -1
  11. package/lib/config/php/extensions/libsodium.js +2 -1
  12. package/lib/config/port-config.js +3 -1
  13. package/lib/config/scandipwa-versions.js +2 -1
  14. package/lib/config/ssl-terminator/index.js +10 -0
  15. package/lib/config/system-config.js +34 -5
  16. package/lib/config/templates/magentorc.template +3 -5
  17. package/lib/config/templates/nginx.template.conf +0 -14
  18. package/lib/config/templates/php.template.ini +6 -4
  19. package/lib/config/templates/ssl-terminator.template.conf +27 -0
  20. package/lib/config/templates/varnish.template.vcl +255 -0
  21. package/lib/config/varnish/varnish-6-0.js +11 -0
  22. package/lib/config/varnish/varnish-6-6.js +11 -0
  23. package/lib/config/varnish/varnish-7-0.js +11 -0
  24. package/lib/config/versions/magento-2.3.0.js +9 -1
  25. package/lib/config/versions/magento-2.3.1.js +9 -1
  26. package/lib/config/versions/magento-2.3.2-p2.js +9 -1
  27. package/lib/config/versions/magento-2.3.2.js +9 -1
  28. package/lib/config/versions/magento-2.3.3-p1.js +9 -1
  29. package/lib/config/versions/magento-2.3.3.js +9 -1
  30. package/lib/config/versions/magento-2.3.4-p2.js +9 -1
  31. package/lib/config/versions/magento-2.3.4.js +9 -1
  32. package/lib/config/versions/magento-2.3.5-p1.js +9 -1
  33. package/lib/config/versions/magento-2.3.5-p2.js +9 -1
  34. package/lib/config/versions/magento-2.3.5.js +9 -1
  35. package/lib/config/versions/magento-2.3.6-p1.js +9 -1
  36. package/lib/config/versions/magento-2.3.6.js +9 -1
  37. package/lib/config/versions/magento-2.3.7-p1.js +9 -1
  38. package/lib/config/versions/magento-2.3.7-p2.js +9 -1
  39. package/lib/config/versions/magento-2.3.7-p3.js +9 -1
  40. package/lib/config/versions/magento-2.3.7.js +9 -1
  41. package/lib/config/versions/magento-2.4.0-p1.js +9 -1
  42. package/lib/config/versions/magento-2.4.0.js +9 -1
  43. package/lib/config/versions/magento-2.4.1-p1.js +9 -1
  44. package/lib/config/versions/magento-2.4.1.js +9 -1
  45. package/lib/config/versions/magento-2.4.2-p1.js +9 -1
  46. package/lib/config/versions/magento-2.4.2-p2.js +9 -1
  47. package/lib/config/versions/magento-2.4.2.js +9 -1
  48. package/lib/config/versions/magento-2.4.3-p1.js +9 -1
  49. package/lib/config/versions/magento-2.4.3-p2.js +9 -1
  50. package/lib/config/versions/magento-2.4.3.js +9 -1
  51. package/lib/config/versions/magento-2.4.4.js +9 -1
  52. package/lib/config/xml-parser.js +5 -3
  53. package/lib/errors/known-error.js +15 -0
  54. package/lib/errors/unknown-error.js +15 -0
  55. package/lib/tasks/cli/create-bashrc-config.js +7 -3
  56. package/lib/tasks/composer/index.js +5 -3
  57. package/lib/tasks/composer/local-auth-json.js +4 -2
  58. package/lib/tasks/docker/containers.js +13 -8
  59. package/lib/tasks/docker/network.js +2 -1
  60. package/lib/tasks/docker/volumes.js +4 -4
  61. package/lib/tasks/file-system/create-nginx-config.js +9 -40
  62. package/lib/tasks/file-system/create-php-config.js +2 -1
  63. package/lib/tasks/file-system/create-php-fpm-config.js +2 -1
  64. package/lib/tasks/file-system/create-phpstorm-config/database-config.js +5 -4
  65. package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +12 -10
  66. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +0 -3
  67. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +0 -3
  68. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +1 -1
  69. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +0 -3
  70. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +0 -3
  71. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +1 -4
  72. package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +1 -4
  73. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +1 -11
  74. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +1 -6
  75. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +1 -11
  76. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +2 -3
  77. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +1 -4
  78. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +2 -4
  79. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +1 -11
  80. package/lib/tasks/file-system/create-ssl-terminator-config.js +96 -0
  81. package/lib/tasks/file-system/create-varnish-config.js +53 -0
  82. package/lib/tasks/file-system/create-vscode-config.js +3 -2
  83. package/lib/tasks/file-system/index.js +5 -1
  84. package/lib/tasks/magento/enable-magento-composer-plugins.js +3 -2
  85. package/lib/tasks/magento/install-magento.js +7 -5
  86. package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +26 -0
  87. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +1 -1
  88. package/lib/tasks/magento/setup-magento/delete-admin-users.js +1 -1
  89. package/lib/tasks/magento/setup-magento/delete-customers.js +7 -4
  90. package/lib/tasks/magento/setup-magento/delete-orders.js +6 -4
  91. package/lib/tasks/magento/setup-magento/disable-2fa.js +4 -12
  92. package/lib/tasks/magento/setup-magento/flush-redis-config.js +2 -1
  93. package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +14 -16
  94. package/lib/tasks/magento/setup-magento/index.js +3 -1
  95. package/lib/tasks/magento/setup-magento/install-magento.js +2 -1
  96. package/lib/tasks/magento/setup-magento/migrate-database.js +24 -11
  97. package/lib/tasks/magento/setup-magento/set-base-url.js +7 -2
  98. package/lib/tasks/magento/setup-magento/upgrade-magento.js +27 -3
  99. package/lib/tasks/magento/setup-magento/varnish-config.js +69 -0
  100. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +41 -0
  101. package/lib/tasks/mysql/connect-to-mysql.js +2 -1
  102. package/lib/tasks/mysql/fix-db.js +2 -2
  103. package/lib/tasks/mysql/import-dump-to-mysql.js +13 -2
  104. package/lib/tasks/mysql/import-remote-db/index.js +2 -1
  105. package/lib/tasks/mysql/import-remote-db/ssh/index.js +2 -1
  106. package/lib/tasks/mysql/import-remote-db/ssh/regular-server.js +2 -1
  107. package/lib/tasks/php/bundled-extensions.js +28 -0
  108. package/lib/tasks/php/compile-options.js +27 -54
  109. package/lib/tasks/php/compile.js +6 -4
  110. package/lib/tasks/php/configure.js +7 -66
  111. package/lib/tasks/php/extensions/disable.js +2 -1
  112. package/lib/tasks/php/extensions/enable.js +2 -1
  113. package/lib/tasks/php/extensions/index.js +74 -0
  114. package/lib/tasks/php/extensions/install.js +3 -3
  115. package/lib/tasks/php/index.js +8 -7
  116. package/lib/tasks/php/install-sodium.js +93 -0
  117. package/lib/tasks/php/update-env-php.js +16 -1
  118. package/lib/tasks/php/update-env.php +56 -12
  119. package/lib/tasks/php/update-phpbrew.js +7 -3
  120. package/lib/tasks/php/validate-php.js +67 -0
  121. package/lib/tasks/php-fpm/start-php-fpm.js +4 -2
  122. package/lib/tasks/requirements/composer.js +7 -5
  123. package/lib/tasks/requirements/dependency/arch.js +2 -1
  124. package/lib/tasks/requirements/dependency/centos.js +2 -1
  125. package/lib/tasks/requirements/dependency/fedora.js +2 -1
  126. package/lib/tasks/requirements/dependency/mac.js +18 -3
  127. package/lib/tasks/requirements/docker/index.js +96 -40
  128. package/lib/tasks/requirements/docker/install-on-mac.js +29 -0
  129. package/lib/tasks/requirements/docker/install.js +13 -12
  130. package/lib/tasks/requirements/docker/running-status.js +138 -0
  131. package/lib/tasks/requirements/docker/version.js +3 -0
  132. package/lib/tasks/requirements/index.js +8 -5
  133. package/lib/tasks/requirements/node-version.js +2 -1
  134. package/lib/tasks/requirements/php-version.js +29 -25
  135. package/lib/tasks/requirements/phpbrew/index.js +2 -1
  136. package/lib/tasks/requirements/phpbrew/install.js +14 -2
  137. package/lib/tasks/requirements/phpbrew/version.js +2 -1
  138. package/lib/tasks/requirements/platform.js +5 -3
  139. package/lib/tasks/requirements/rosetta.js +32 -0
  140. package/lib/tasks/start.js +8 -9
  141. package/lib/tasks/status/index.js +25 -9
  142. package/lib/tasks/theme/build-theme.js +27 -8
  143. package/lib/tasks/theme/install-theme.js +18 -5
  144. package/lib/tasks/theme/link-theme.js +2 -2
  145. package/lib/tasks/theme/retrieve-theme-data.js +2 -1
  146. package/lib/tasks/theme/setup-persisted-query.js +5 -4
  147. package/lib/tasks/theme/setup-themes.js +11 -3
  148. package/lib/tasks/theme/symlink-theme.js +26 -4
  149. package/lib/util/CSA-theme.js +4 -0
  150. package/lib/util/analytics.js +337 -0
  151. package/lib/util/arch.js +1 -1
  152. package/lib/util/config-file-validator.js +14 -2
  153. package/lib/util/config-php-json.js +20 -0
  154. package/lib/util/env-php-json.js +3 -2
  155. package/lib/util/exec-async-command.d.ts +2 -0
  156. package/lib/util/exec-async-command.js +31 -15
  157. package/lib/util/exec-async.js +9 -0
  158. package/lib/util/get-brew-bin-path.js +64 -0
  159. package/lib/util/get-installed-magento-version.js +3 -2
  160. package/lib/util/get-jsonfile-data.js +2 -1
  161. package/lib/util/install-dependencies-task.js +15 -5
  162. package/lib/util/instance-metadata.js +4 -3
  163. package/lib/util/ip.js +45 -1
  164. package/lib/util/is-running-root.js +3 -0
  165. package/lib/util/magento-task.js +20 -9
  166. package/lib/util/match-filesystem.js +2 -1
  167. package/lib/util/php-task.js +7 -3
  168. package/lib/util/request.js +0 -0
  169. package/lib/util/resolve-configuration-with-overrides.js +2 -1
  170. package/lib/util/run-composer.js +5 -3
  171. package/lib/util/run-magento.js +3 -2
  172. package/lib/util/run-php.js +14 -3
  173. package/lib/util/systemctl.js +46 -0
  174. package/lib/util/wait-for-it.js +3 -2
  175. package/package.json +4 -3
  176. package/typings/context.d.ts +6 -1
  177. package/typings/index.d.ts +32 -1
  178. package/lib/tasks/magento/setup-magento/adjust-magento-configuration.js +0 -27
  179. package/lib/tasks/magento/setup-magento/disable-page-cache.js +0 -11
@@ -0,0 +1,9 @@
1
+ const { exec } = require('child_process');
2
+
3
+ const execAsync = (command, options) => new Promise((resolve, reject) => {
4
+ exec(command, options, (err, stdout) => (err ? reject(err) : resolve(stdout)));
5
+ });
6
+
7
+ module.exports = {
8
+ execAsync
9
+ };
@@ -0,0 +1,64 @@
1
+ const { getArch, getArchSync } = require('./arch');
2
+
3
+ const BREW_BIN_PATH_INTEL = '/usr/local/bin/brew';
4
+ const BREW_BIN_PATH_ARM_ROSETTA = '/usr/local/homebrew/bin/brew';
5
+ // native is not used ATM
6
+ const BREW_BIN_PATH_ARM_NATIVE = '/opt/homebrew/bin/brew';
7
+
8
+ const getBrewBinPath = async () => {
9
+ const arch = await getArch();
10
+
11
+ if (arch === 'arm64') {
12
+ return BREW_BIN_PATH_ARM_ROSETTA;
13
+ }
14
+
15
+ return BREW_BIN_PATH_INTEL;
16
+ };
17
+
18
+ const getBrewBinPathSync = () => {
19
+ const arch = getArchSync();
20
+
21
+ if (arch === 'arm64') {
22
+ return BREW_BIN_PATH_ARM_ROSETTA;
23
+ }
24
+
25
+ return BREW_BIN_PATH_INTEL;
26
+ };
27
+
28
+ const getBrewCommand = async ({ native } = { native: false }) => {
29
+ const arch = await getArch();
30
+
31
+ if (arch === 'arm64') {
32
+ if (native) {
33
+ return `arch -arm64 ${BREW_BIN_PATH_ARM_NATIVE}`;
34
+ }
35
+
36
+ return `arch -x86_64 ${BREW_BIN_PATH_ARM_ROSETTA}`;
37
+ }
38
+
39
+ return BREW_BIN_PATH_INTEL;
40
+ };
41
+
42
+ const getBrewCommandSync = ({ native } = { native: false }) => {
43
+ const arch = getArchSync();
44
+
45
+ if (arch === 'arm64') {
46
+ if (native) {
47
+ return `arch -arm64 ${BREW_BIN_PATH_ARM_NATIVE}`;
48
+ }
49
+
50
+ return `arch -x86_64 ${BREW_BIN_PATH_ARM_ROSETTA}`;
51
+ }
52
+
53
+ return BREW_BIN_PATH_INTEL;
54
+ };
55
+
56
+ module.exports = {
57
+ getBrewBinPath,
58
+ getBrewBinPathSync,
59
+ getBrewCommand,
60
+ getBrewCommandSync,
61
+ BREW_BIN_PATH_INTEL,
62
+ BREW_BIN_PATH_ARM_ROSETTA,
63
+ BREW_BIN_PATH_ARM_NATIVE
64
+ };
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
+ const KnownError = require('../errors/known-error');
3
4
  const pathExists = require('./path-exists');
4
5
 
5
6
  const getComposerData = async (composerPath) => {
@@ -16,7 +17,7 @@ const getInstalledMagentoVersion = async (projectPath = process.cwd()) => {
16
17
  const composerData = await getComposerData(path.join(projectPath, 'composer.json'));
17
18
 
18
19
  if (!composerData) {
19
- throw new Error('composer.json not found');
20
+ throw new KnownError('composer.json not found');
20
21
  }
21
22
  const magentoDependency = [
22
23
  'magento/product-community-edition',
@@ -24,7 +25,7 @@ const getInstalledMagentoVersion = async (projectPath = process.cwd()) => {
24
25
  ].find((magentoEdition) => composerData.require[magentoEdition]);
25
26
 
26
27
  if (!magentoDependency) {
27
- throw new Error('No Magento dependency found in composer.json');
28
+ throw new KnownError('No Magento dependency found in composer.json');
28
29
  }
29
30
 
30
31
  return composerData.require[magentoDependency].replace(/\^/i, '');
@@ -1,4 +1,5 @@
1
1
  const fs = require('fs');
2
+ const UnknownError = require('../errors/unknown-error');
2
3
  const pathExists = require('./path-exists');
3
4
 
4
5
  const getJsonfileData = async (filePath) => {
@@ -11,7 +12,7 @@ const getJsonfileData = async (filePath) => {
11
12
  try {
12
13
  return JSON.parse(await fs.promises.readFile(filePath, 'utf-8'));
13
14
  } catch (e) {
14
- throw new Error(`Ooops! Something went wrong when trying to json parse ${filePath} file!\n\n${e}`);
15
+ throw new UnknownError(`Ooops! Something went wrong when trying to json parse ${filePath} file!\n\n${e}`);
15
16
  }
16
17
  };
17
18
 
@@ -3,19 +3,30 @@ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
3
3
  const sleep = require('./sleep');
4
4
  const { execCommandTask } = require('./exec-async-command');
5
5
  const dependenciesForPlatforms = require('../config/dependencies-for-platforms');
6
+ const KnownError = require('../errors/known-error');
6
7
 
7
8
  /**
8
9
  * Install dependencies
9
10
  * @param {object} options
10
11
  * @param {keyof dependenciesForPlatforms} options.platform Platform
11
12
  * @param {string[]} options.dependenciesToInstall List of dependencies to install
13
+ * @param {boolean} options.useMacNativeEnvironment Use Mac native environment
12
14
  * @returns {import('listr2').ListrTask<import('../../typings/context').ListrContext>}
13
15
  */
14
16
  const installDependenciesTask = (options) => ({
15
17
  title: 'Installing missing dependencies',
16
18
  task: async (ctx, task) => {
17
19
  const { dependenciesToInstall, platform } = options;
18
- const cmd = dependenciesForPlatforms[platform].installCommand(dependenciesToInstall.join(' '));
20
+ let cmd;
21
+ if (os.platform() === 'darwin') {
22
+ if (options.useMacNativeEnvironment) {
23
+ cmd = dependenciesForPlatforms[platform].installCommand(dependenciesToInstall.join(' '), { native: true });
24
+ } else {
25
+ cmd = dependenciesForPlatforms[platform].installCommand(dependenciesToInstall.join(' '));
26
+ }
27
+ } else {
28
+ cmd = dependenciesForPlatforms[platform].installCommand(dependenciesToInstall.join(' '));
29
+ }
19
30
  const installCommand = logger.style.code(cmd);
20
31
  const dependenciesWordFormatter = `dependenc${dependenciesToInstall.length > 1 ? 'ies' : 'y'}`;
21
32
  task.title = `Installing missing dependencies: ${ logger.style.code(dependenciesToInstall.join(', ')) }`;
@@ -56,15 +67,14 @@ const installDependenciesTask = (options) => ({
56
67
  promptSkipper = true;
57
68
 
58
69
  if (installAnswer === 'timeout') {
59
- throw new Error(`Timeout!
70
+ throw new KnownError(`Timeout!
60
71
 
61
72
  To install missing ${ dependenciesWordFormatter } manually, run the following command: ${ installCommand }`);
62
73
  }
63
74
 
64
75
  if (installAnswer === 'not-install') {
65
- throw new Error(`Okay, skipping ${ dependenciesWordFormatter } installation for now.
66
-
67
- To install missing ${ dependenciesWordFormatter } manually, run the following command: ${ installCommand }`);
76
+ task.skip(`User chose to skip installation of ${ dependenciesWordFormatter }`);
77
+ return;
68
78
  }
69
79
 
70
80
  if (installAnswer === 'install') {
@@ -7,7 +7,8 @@ const WEB_ADMIN_CREDENTIALS_TITLE = 'Panel credentials';
7
7
 
8
8
  const mapDataStyle = ({ title, text }) => ({
9
9
  title,
10
- text: logger.style.link(text)
10
+ text: logger.style.link(text),
11
+ link: text
11
12
  });
12
13
 
13
14
  /**
@@ -38,7 +39,7 @@ const getInstanceMetadata = (ctx) => {
38
39
  if (isNgrok) {
39
40
  frontend.push({
40
41
  title: WEB_LOCAL_LOCATION_TITLE,
41
- text: `${ssl.enabled ? 'https' : 'http'}://localhost${ssl.enabled || ports.app === 80 ? '' : `:${ports.app}`}/`
42
+ text: `${ssl.enabled ? 'https' : 'http'}://localhost${ssl.enabled || ports.sslTerminator === 80 ? '' : `:${ports.sslTerminator}`}/`
42
43
  });
43
44
  frontend.push({
44
45
  title: WEB_LOCATION_TITLE,
@@ -47,7 +48,7 @@ const getInstanceMetadata = (ctx) => {
47
48
  } else {
48
49
  frontend.push({
49
50
  title: WEB_LOCATION_TITLE,
50
- text: `${ssl.enabled ? 'https' : 'http'}://${host}${ssl.enabled || ports.app === 80 ? '' : `:${ports.app}`}/`
51
+ text: `${ssl.enabled ? 'https' : 'http'}://${host}${ssl.enabled || ports.sslTerminator === 80 ? '' : `:${ports.sslTerminator}`}/`
51
52
  });
52
53
  }
53
54
 
package/lib/util/ip.js CHANGED
@@ -1,8 +1,52 @@
1
+ const { request } = require('smol-request');
2
+
1
3
  const ipRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
2
4
 
3
5
  const isIpAddress = (text) => ipRegex.test(text);
4
6
 
7
+ const externalIpProviders = [
8
+ 'http://api.ipify.org/',
9
+ 'http://icanhazip.com/',
10
+ 'http://ifconfig.io/ip',
11
+ 'http://ip.appspot.com/',
12
+ 'http://ident.me/',
13
+ 'http://whatismyip.akamai.com/',
14
+ 'http://tnx.nl/ip',
15
+ 'http://myip.dnsomatic.com/',
16
+ 'http://ipecho.net/plain',
17
+ 'http://diagnostic.opendns.com/myip',
18
+ 'http://trackip.net/ip'
19
+ ];
20
+
21
+ /**
22
+ * Get an external IP address
23
+ * @returns {Promise<string>}
24
+ */
25
+ const getExternalIpAddress = async () => {
26
+ let ip;
27
+
28
+ for (const ipProvider of externalIpProviders) {
29
+ try {
30
+ const response = await request(ipProvider, {
31
+ responseType: 'text'
32
+ });
33
+
34
+ ip = response.data;
35
+ break;
36
+ } catch (e) {
37
+ //
38
+ }
39
+ }
40
+
41
+ if (!ip) {
42
+ throw new Error('External IP address is not available!');
43
+ }
44
+
45
+ return ip;
46
+ };
47
+
5
48
  module.exports = {
6
49
  ipRegex,
7
- isIpAddress
50
+ isIpAddress,
51
+ getExternalIpAddress
8
52
  };
@@ -0,0 +1,3 @@
1
+ const isRunningRoot = () => process.getuid() === 0; // UID 0 is always root
2
+
3
+ module.exports = isRunningRoot;
@@ -1,17 +1,28 @@
1
1
  const runMagentoCommand = require('./run-magento');
2
2
 
3
3
  /**
4
- * @type {(command: string) => import('listr2').ListrTask<import('../../typings/context').ListrContext>}
4
+ * @param {String} command
5
+ * @param {Object} [options]
6
+ * @param {(e: Error) => void} [options.onError]
7
+ * @returns {import('listr2').ListrTask<import('../../typings/context').ListrContext>}
5
8
  */
6
- const magentoTask = (command) => ({
9
+ const magentoTask = (command, options = {}) => ({
7
10
  title: `Running command 'magento ${command}'`,
8
- task: ({ magentoVersion, verbose }, task) => runMagentoCommand(command, {
9
- callback: !verbose ? undefined : (t) => {
10
- task.output = t;
11
- },
12
- magentoVersion,
13
- throwNonZeroCode: true
14
- }),
11
+ task: async ({ magentoVersion, verbose }, task) => {
12
+ try {
13
+ await runMagentoCommand(command, {
14
+ callback: !verbose ? undefined : (t) => {
15
+ task.output = t;
16
+ },
17
+ magentoVersion,
18
+ throwNonZeroCode: true
19
+ });
20
+ } catch (e) {
21
+ if (options.onError) {
22
+ options.onError(e);
23
+ }
24
+ }
25
+ },
15
26
  options: {
16
27
  bottomBar: 10
17
28
  }
@@ -13,7 +13,8 @@ const matchFilesystem = async (cwd, structure) => {
13
13
  .every((value) => value === true);
14
14
 
15
15
  return ok;
16
- } if (typeof structure === 'object') {
16
+ }
17
+ if (typeof structure === 'object') {
17
18
  const ok = (await Promise.all(Object.entries(structure).map(([key, value]) => {
18
19
  if (typeof value === 'boolean') {
19
20
  return pathExists(path.join(cwd, key));
@@ -1,16 +1,20 @@
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
+ * @param {String} command
5
+ * @param {{ noTitle: boolean, env: Record<string, string> }} options
6
+ * @returns {import('listr2').ListrTask<import('../../typings/context').ListrContext>}
5
7
  */
6
8
  const phpTask = (command, options = {}) => ({
7
9
  title: !options.noTitle ? `Running command 'php ${command}` : undefined,
8
- task: ({ magentoVersion }, task) => runPhpCode(command, {
10
+ task: (ctx, task) => runPhpCode(command, {
9
11
  callback: (t) => {
10
12
  task.output = t;
11
13
  },
12
14
  throwNonZeroCode: true,
13
- magentoVersion
15
+ magentoVersion: ctx.magentoVersion,
16
+ env: options.env,
17
+ useRosettaOnMac: ctx.arch === 'arm64' && ctx.platform === 'darwin'
14
18
  })
15
19
  });
16
20
 
File without changes
@@ -1,4 +1,5 @@
1
1
  const path = require('path');
2
+ const UnknownError = require('../errors/unknown-error');
2
3
  const { configFileSchema } = require('./config-file-validator');
3
4
  const { deepmerge } = require('./deepmerge');
4
5
  const pathExists = require('./path-exists');
@@ -11,7 +12,7 @@ const resolveConfigurationWithOverrides = async (configuration, baseConfig, proj
11
12
  try {
12
13
  await configFileSchema.validateAsync(userConfiguration);
13
14
  } catch (e) {
14
- throw new Error(`Configuration file validation error!\n\n${e.message}`);
15
+ throw new UnknownError(`Configuration file validation error!\n\n${e.message}`);
15
16
  }
16
17
 
17
18
  const overridenConfiguration = deepmerge(configuration, userConfiguration);
@@ -1,5 +1,6 @@
1
1
  const { execAsyncSpawn } = require('./exec-async-command');
2
2
  const { getConfigFromMagentoVersion, defaultConfiguration } = require('../config');
3
+ const UnknownError = require('../errors/unknown-error');
3
4
  /**
4
5
  * Execute composer command
5
6
  * @param {String} command composer command
@@ -20,12 +21,13 @@ const runComposerCommand = async (command, options = {}) => {
20
21
  const { code, result } = await execAsyncSpawn(`${php.binPath} -c ${php.iniPath} ${composer.binPath} ${command}`, {
21
22
  ...options,
22
23
  cwd: magentoDir,
23
- withCode: true
24
+ withCode: true,
25
+ useRosetta2: true
24
26
  });
25
27
 
26
28
  if (throwNonZeroCode && code !== 0) {
27
- throw new Error(`Code: ${code}
28
- Response: ${result}`);
29
+ throw new UnknownError(`Code: ${code}
30
+ Response: ${result}`);
29
31
  }
30
32
 
31
33
  return { code, result };
@@ -1,5 +1,6 @@
1
1
  const { execAsyncSpawn } = require('./exec-async-command');
2
2
  const { getConfigFromMagentoVersion, defaultConfiguration, magento } = require('../config');
3
+ const UnknownError = require('../errors/unknown-error');
3
4
  /**
4
5
  * Execute magento command
5
6
  * @param {String} command magento command
@@ -27,8 +28,8 @@ const runMagentoCommand = async (command, options = {}) => {
27
28
  });
28
29
 
29
30
  if (throwNonZeroCode && code !== 0) {
30
- throw new Error(`Code: ${code}
31
- Response: ${result}`);
31
+ throw new UnknownError(`Code: ${code}
32
+ Response: ${result}`);
32
33
  }
33
34
 
34
35
  return { code, result };
@@ -1,5 +1,6 @@
1
1
  const { execAsyncSpawn } = require('./exec-async-command');
2
2
  const { getConfigFromMagentoVersion, defaultConfiguration } = require('../config');
3
+ const UnknownError = require('../errors/unknown-error');
3
4
  /**
4
5
  * Execute PHP code
5
6
  * @param {String} command magento command
@@ -10,6 +11,8 @@ const { getConfigFromMagentoVersion, defaultConfiguration } = require('../config
10
11
  * @param {() => {}} options.callback
11
12
  * @param {Boolean} options.throwNonZeroCode Throw if command return non 0 code.
12
13
  * @param {String} options.magentoVersion Magento version for config
14
+ * @param {Record<string, string>} options.env Environment variables
15
+ * @param {Boolean} options.useRosettaOnMac Use Rosetta 2 on MacOS
13
16
  */
14
17
  const runPhpCode = async (command, options = {}) => {
15
18
  const {
@@ -17,14 +20,22 @@ const runPhpCode = async (command, options = {}) => {
17
20
  magentoVersion = defaultConfiguration.magentoVersion
18
21
  } = options;
19
22
  const { php } = await getConfigFromMagentoVersion(magentoVersion);
20
- const { code, result } = await execAsyncSpawn(`${php.binPath} -c ${php.iniPath} ${command}`, {
23
+ let spawnCommand = `${php.binPath} -c ${php.iniPath} ${command}`;
24
+ if (options.env && Object.keys(options.env).length > 0) {
25
+ const env = Object.entries(options.env).map(([key, value]) => `${key}=${value}`).join(' ');
26
+ spawnCommand = `${env} ${spawnCommand}`;
27
+ }
28
+ if (options.useRosettaOnMac) {
29
+ spawnCommand = `arch -x86_64 bash -c '${spawnCommand}'`;
30
+ }
31
+ const { code, result } = await execAsyncSpawn(spawnCommand, {
21
32
  ...options,
22
33
  withCode: true
23
34
  });
24
35
 
25
36
  if (throwNonZeroCode && code !== 0) {
26
- throw new Error(`Code: ${code}
27
- Response: ${result}`);
37
+ throw new UnknownError(`Code: ${code}
38
+ Response: ${result}`);
28
39
  }
29
40
 
30
41
  return { code, result };
@@ -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
+ };
@@ -1,4 +1,5 @@
1
1
  const net = require('net');
2
+ const UnknownError = require('../errors/unknown-error');
2
3
  const sleep = require('./sleep');
3
4
 
4
5
  const connectToHostPort = ({ host, port }) => new Promise((resolve, reject) => {
@@ -14,7 +15,7 @@ const connectToHostPort = ({ host, port }) => new Promise((resolve, reject) => {
14
15
  });
15
16
  socket.on('timeout', () => {
16
17
  socket.end();
17
- reject(new Error('Connection timeout'));
18
+ reject(new UnknownError('Connection timeout'));
18
19
  });
19
20
  });
20
21
 
@@ -29,7 +30,7 @@ const waitForIt = async ({
29
30
  // eslint-disable-next-line no-await-in-loop
30
31
  await Promise.race([
31
32
  sleep(300).then(() => {
32
- throw new Error('Connection timeout');
33
+ throw new UnknownError('Connection timeout');
33
34
  }),
34
35
  connectToHostPort({ host, port })
35
36
  ]);
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.12",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -22,7 +22,7 @@
22
22
  "arm64"
23
23
  ],
24
24
  "dependencies": {
25
- "@scandipwa/scandipwa-dev-utils": "0.1.12",
25
+ "@scandipwa/scandipwa-dev-utils": "0.1.13",
26
26
  "conf": "10.1.1",
27
27
  "enquirer": "2.3.6",
28
28
  "eta": "1.12.3",
@@ -36,6 +36,7 @@
36
36
  "mysql2": "2.3.2",
37
37
  "node-ssh": "12.0.0",
38
38
  "semver": "7.3.5",
39
+ "smol-request": "2.1.1",
39
40
  "systeminformation": "5.11.7",
40
41
  "yargs": "17.3.1"
41
42
  },
@@ -52,5 +53,5 @@
52
53
  "mysql",
53
54
  "scandipwa"
54
55
  ],
55
- "gitHead": "cc46e60ca1d44d6e00b151e03af5cc7f56a5e54a"
56
+ "gitHead": "c765f4fe97f9d09cabfd928fc127484eb2cac911"
56
57
  }
@@ -13,9 +13,13 @@ export interface ListrContext {
13
13
  mysql: number
14
14
  redis: number
15
15
  elasticsearch: number
16
+ varnish: number
17
+ sslTerminator: number
16
18
  }
17
19
  arch: 'arm64' | 'x64'
18
20
  isArm: boolean
21
+ isWsl: boolean
22
+ isArmMac: boolean
19
23
  platform?: NodeJS.Platform
20
24
  platformVersion?: string
21
25
  /**
@@ -52,7 +56,7 @@ export interface ListrContext {
52
56
  o: string
53
57
  }
54
58
  }>
55
- getContainers(): Record<'nginx' | 'redis' | 'mysql' | 'elasticsearch', {
59
+ getContainers(): Record<'nginx' | 'redis' | 'mysql' | 'elasticsearch' | 'varnish', {
56
60
  _: string
57
61
  ports: string[]
58
62
  healthCheck: {
@@ -90,4 +94,5 @@ export interface ListrContext {
90
94
  useNonOverlappingPorts: boolean
91
95
  }
92
96
  mysqlConnection: mysql2.Connection
97
+ isSetupUpgradeNeeded?: boolean
93
98
  }
@@ -10,7 +10,14 @@ export interface ServiceWithVersion {
10
10
  version: string
11
11
  }
12
12
 
13
- // export inter/
13
+ export interface SSLTerminatorConfiguration extends ServiceWithVersion {
14
+ /**
15
+ * Configuration file location
16
+ *
17
+ * @example ./my-ssl-terminator-config.conf
18
+ */
19
+ configTemplate: string
20
+ }
14
21
 
15
22
  export interface NginxConfiguration extends ServiceWithVersion {
16
23
  /**
@@ -21,6 +28,20 @@ export interface NginxConfiguration extends ServiceWithVersion {
21
28
  configTemplate: string
22
29
  }
23
30
 
31
+ export interface VarnishConfiguration extends ServiceWithVersion {
32
+ /**
33
+ * Enable or disable Varnish in the project
34
+ */
35
+ enabled: boolean
36
+
37
+ /**
38
+ * Configuration file location
39
+ *
40
+ * @example ./my-varnish-config.vcl
41
+ */
42
+ configTemplate: string
43
+ }
44
+
24
45
  export interface PHPExtension extends Record<string, unknown> {
25
46
  version?: string
26
47
  /**
@@ -175,6 +196,16 @@ export interface CMAConfiguration {
175
196
  * Composer configuration
176
197
  */
177
198
  composer: ServiceWithVersion
199
+
200
+ /**
201
+ * Varnish configuration
202
+ */
203
+ varnish: VarnishConfiguration
204
+
205
+ /**
206
+ * SSL Terminator configuration
207
+ */
208
+ sslTerminator: SSLTerminatorConfiguration
178
209
  }
179
210
  /**
180
211
  * Magento configuration
@@ -1,27 +0,0 @@
1
- const { isTableExists } = require('../../../util/database');
2
-
3
- /**
4
- * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
5
- */
6
- const adjustMagentoConfiguration = () => ({
7
- title: 'Adjusting Magento Database Configuration',
8
- skip: async (ctx) => !(await isTableExists('magento', 'core_config_data', ctx)),
9
- task: async (ctx) => {
10
- const { mysqlConnection } = ctx;
11
-
12
- // delete varnish configuration if exists
13
- await mysqlConnection.query(`
14
- DELETE FROM core_config_data WHERE path LIKE '%varnish%';
15
- `);
16
-
17
- // update cache policy to not use varnish
18
- // 0 - magento cache, 2 - varnish cache
19
- await mysqlConnection.query(`
20
- UPDATE core_config_data
21
- SET value = ?
22
- WHERE path = ?;
23
- `, ['0', 'system/full_page_cache/caching_application']);
24
- }
25
- });
26
-
27
- module.exports = adjustMagentoConfiguration;
@@ -1,11 +0,0 @@
1
- const magentoTask = require('../../../util/magento-task');
2
-
3
- /**
4
- * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
5
- */
6
- const disablePageCache = () => ({
7
- title: 'Disabling full_page cache in Magento',
8
- task: (ctx, task) => task.newListr(magentoTask('cache:disable full_page'))
9
- });
10
-
11
- module.exports = disablePageCache;