@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
@@ -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 adjustFullPageCache = require('../magento/setup-magento/adjust-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
+ adjustFullPageCache(),
57
57
  ...(isPageBuilderInstalled && Number(isPagebuilderEnabled) ? [disablePageBuilder()] : []),
58
58
  buildTheme(theme)
59
59
  ]);
@@ -1,4 +1,5 @@
1
1
  const path = require('path');
2
+ const KnownError = require('../../errors/known-error');
2
3
  const getJsonfileData = require('../../util/get-jsonfile-data');
3
4
  const pathExists = require('../../util/path-exists');
4
5
 
@@ -26,7 +27,7 @@ const retrieveThemeData = (themePath) => ({
26
27
  const composerData = await getJsonfileData(path.join(absoluteThemePath, 'composer.json'));
27
28
 
28
29
  if (!composerData) {
29
- throw new Error(`composer.json file not found in "${themePath}"`);
30
+ throw new KnownError(`composer.json file not found in "${themePath}"`);
30
31
  }
31
32
 
32
33
  ctx.themePath = themePath;
@@ -1,4 +1,5 @@
1
1
  const path = require('path');
2
+ const UnknownError = require('../../errors/unknown-error');
2
3
  const envPhpToJson = require('../../util/env-php-json');
3
4
  const getJsonfileData = require('../../util/get-jsonfile-data');
4
5
  const runMagentoCommand = require('../../util/run-magento');
@@ -8,7 +9,7 @@ const runMagentoCommand = require('../../util/run-magento');
8
9
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
9
10
  */
10
11
  const persistedQuerySetup = () => ({
11
- title: 'Setting up redis configuration for persisted queries',
12
+ title: 'Setting up Redis configuration for persisted queries',
12
13
  task: async (ctx, task) => {
13
14
  const { ports, magentoVersion, verbose = false } = ctx;
14
15
  const composerLockData = await getJsonfileData(path.join(process.cwd(), 'composer.lock'));
@@ -29,8 +30,8 @@ const persistedQuerySetup = () => ({
29
30
  if (
30
31
  persistedQueryConfig
31
32
  && persistedQueryConfig.redis
32
- && persistedQueryConfig.redis.port === ports.redis
33
- && persistedQueryConfig.redis.localhost === 'localhost'
33
+ && persistedQueryConfig.redis.port === `${ ports.redis }`
34
+ && persistedQueryConfig.redis.host === 'localhost'
34
35
  ) {
35
36
  task.skip();
36
37
  return;
@@ -51,7 +52,7 @@ const persistedQuerySetup = () => ({
51
52
  magentoVersion
52
53
  });
53
54
  } catch (e) {
54
- throw new Error(
55
+ throw new UnknownError(
55
56
  `Unexpected error while setting redis for pq!.
56
57
  See ERROR log below.\n\n${e}`
57
58
  );
@@ -5,16 +5,24 @@ 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 adjustFullPageCache = require('../magento/setup-magento/adjust-full-page-cache');
9
9
  const buildTheme = require('./build-theme');
10
+ const KnownError = require('../../errors/known-error');
10
11
 
11
12
  /**
12
13
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
13
14
  */
14
15
  const setupThemes = () => ({
16
+ title: 'Setting up themes',
15
17
  task: async (ctx, task) => {
16
18
  const { config: { baseConfig } } = ctx;
17
19
  const composerData = await getJsonfileData(path.join(baseConfig.magentoDir, 'composer.json'));
20
+
21
+ if (!composerData.repositories) {
22
+ task.skip();
23
+ return;
24
+ }
25
+
18
26
  const composerLocalPaths = Array.isArray(composerData.repositories)
19
27
  ? composerData.repositories.filter((repo) => repo.type === 'path')
20
28
  : Object.values(composerData.repositories).filter((repo) => repo.type === 'path');
@@ -60,7 +68,7 @@ const setupThemes = () => ({
60
68
  const composerData = await getJsonfileData(path.join(absoluteThemePath, 'composer.json'));
61
69
 
62
70
  if (!composerData) {
63
- throw new Error(`composer.json file not found in "${themePath}"`);
71
+ throw new KnownError(`composer.json file not found in "${themePath}"`);
64
72
  }
65
73
 
66
74
  return {
@@ -80,7 +88,7 @@ const setupThemes = () => ({
80
88
  ])
81
89
  })).concat([
82
90
  upgradeMagento(),
83
- disablePageCache(),
91
+ adjustFullPageCache(),
84
92
  setupPersistedQuery()
85
93
  ])
86
94
  );
@@ -1,24 +1,46 @@
1
+ const path = require('path');
2
+ const UnknownError = require('../../errors/unknown-error');
3
+ const getJsonfileData = require('../../util/get-jsonfile-data');
1
4
  const runComposerCommand = require('../../util/run-composer');
2
5
 
3
6
  /**
4
7
  * @type {(theme: import('../../../typings/theme').Theme) => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
5
8
  */
6
- const symlinkTheme = ({ absoluteThemePath }) => ({
9
+ const symlinkTheme = (theme) => ({
7
10
  title: 'Setting symbolic link for theme in composer.json',
8
- task: async ({ magentoVersion, verbose = false }, task) => {
11
+ task: async (ctx, task) => {
12
+ const { magentoVersion, verbose = false } = ctx;
13
+ const composerJsonData = await getJsonfileData(path.join(process.cwd(), 'composer.json'));
14
+
15
+ if (!composerJsonData.repositories) {
16
+ task.skip();
17
+ return;
18
+ }
19
+
20
+ const repositories = Array.isArray(composerJsonData.repositories)
21
+ ? composerJsonData.repositories.reduce((acc, repo, index) => ({ ...acc, [`${index}`]: repo }), {})
22
+ : composerJsonData.repositories;
23
+
24
+ if (Object.values(repositories).some((value) => value.url === theme.themePath)) {
25
+ task.skip();
26
+ return;
27
+ }
28
+
9
29
  try {
10
- await runComposerCommand(`config repo.scandipwa path ${absoluteThemePath}`, {
30
+ await runComposerCommand(`config repo.scandipwa path ${theme.absoluteThemePath}`, {
11
31
  magentoVersion,
12
32
  callback: !verbose ? undefined : (t) => {
13
33
  task.output = t;
14
34
  }
15
35
  });
16
36
  } catch (e) {
17
- throw new Error(
37
+ throw new UnknownError(
18
38
  `Unexpected error while configuring theme symbolic link.
19
39
  See ERROR log above.\n\n${e}`
20
40
  );
21
41
  }
42
+
43
+ ctx.isSetupUpgradeNeeded = true;
22
44
  }
23
45
  });
24
46
 
@@ -6,6 +6,10 @@ const getCSAThemes = async ({ cwd = process.cwd() } = {}) => {
6
6
  path.join(cwd, 'composer.json')
7
7
  );
8
8
 
9
+ if (!composerData.repositories) {
10
+ return [];
11
+ }
12
+
9
13
  const pathRepositories = Object.entries(composerData.repositories)
10
14
  .filter(([_, repoOptions]) => repoOptions.type === 'path');
11
15
 
@@ -0,0 +1,337 @@
1
+ const os = require('os');
2
+ const { request } = require('smol-request');
3
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
4
+ const generateUUID = require('@tilework/mosaic-dev-utils/uuid');
5
+ const { getSystemConfigSync } = require('../config/system-config');
6
+ const { getExternalIpAddress } = require('./ip');
7
+ const pkg = require('../../package.json');
8
+
9
+ const GA_TRACKING_ID = process.env.GA_TRACKING_ID || 'UA-127741417-8';
10
+ const UNKNOWN = 'unknown';
11
+
12
+ const anonymizeError = (text) => text.replace(new RegExp(`${os.homedir()}`, 'gi'), '/home/magento-scripts-user');
13
+
14
+ /**
15
+ * Google Analytics Parameters
16
+ * @typedef {Object} GAParameters
17
+ * @property {String} version
18
+ * @property {String} trackingID
19
+ * @property {String} [dataSource]
20
+ * @property {Object} [user]
21
+ * @property {String} [user.clientID]
22
+ * @property {String} [user.userID]
23
+ * @property {Object} [session]
24
+ * @property {String} [session.sessionControl]
25
+ * @property {String} [session.ipOverride]
26
+ * @property {String} [session.userAgentOverride]
27
+ * @property {Object} [systemInfo]
28
+ * @property {String} [systemInfo.userLanguage]
29
+ * @property {Object} [contentInformation]
30
+ * @property {String} [contentInformation.documentLocationUrl]
31
+ * @property {String} [contentInformation.documentPath]
32
+ * @property {String} [contentInformation.documentHostName]
33
+ * @property {Object} [timing]
34
+ * @property {String} [timing.userTimingCategory]
35
+ * @property {String} [timing.userTimingVariableName]
36
+ * @property {String} [timing.userTimingTime]
37
+ * @property {String} [timing.userTimingLabel]
38
+ * @property {Object} [hit]
39
+ * @property {String} [hit.type]
40
+ * @property {Object} [exception]
41
+ * @property {String} [exception.description]
42
+ * @property {Boolean} [exception.fatal]
43
+ * @property {Object} [event]
44
+ * @property {String} event.category
45
+ * @property {String} event.action
46
+ * @property {String} [event.label]
47
+ * @property {String} [event.value]
48
+ * @property {Object} [app]
49
+ * @property {String} [app.name]
50
+ * @property {String} [app.id]
51
+ * @property {String} [app.version]
52
+ * @property {String} [app.installedID]
53
+ * @property {Record<string, string>} [customDimension]
54
+ */
55
+
56
+ /**
57
+ * @type {GAParameters}
58
+ */
59
+ const gaParametersMapping = {
60
+ version: 'v',
61
+ trackingID: 'tid',
62
+ user: {
63
+ clientID: 'cid',
64
+ userID: 'uid'
65
+ },
66
+ session: {
67
+ sessionControl: 'sc',
68
+ ipOverride: 'uip',
69
+ userAgentOverride: 'ua'
70
+ },
71
+ systemInfo: {
72
+ userLanguage: 'ul'
73
+ },
74
+ contentInformation: {
75
+ documentLocationUrl: 'dl',
76
+ documentPath: 'dp',
77
+ documentHostName: 'dh'
78
+ },
79
+ timing: {
80
+ userTimingCategory: 'utc',
81
+ userTimingVariableName: 'utv',
82
+ userTimingTime: 'utt',
83
+ userTimingLabel: 'utl'
84
+ },
85
+ hit: {
86
+ type: 't'
87
+ },
88
+ exception: {
89
+ description: 'exd',
90
+ fatal: 'exf'
91
+ },
92
+ event: {
93
+ category: 'ec',
94
+ action: 'ea',
95
+ label: 'el',
96
+ value: 'ev'
97
+ },
98
+ app: {
99
+ name: 'an',
100
+ id: 'aid',
101
+ version: 'av',
102
+ installedID: 'aiid'
103
+ },
104
+ customDimension: Array.from({ length: 200 }, (_, i) => i + 1).reduce((acc, val) => ({
105
+ ...acc,
106
+ [`customDimension${val}`]: `cd${val}`
107
+ }), {})
108
+ };
109
+
110
+ const getAppData = () => ({
111
+ name: pkg.name,
112
+ version: pkg.version
113
+ });
114
+
115
+ /**
116
+ * @param {GAParameters} parameters
117
+ */
118
+ const collectAnalyticsParameters = (parameters) => {
119
+ const parsedParameters = {};
120
+
121
+ for (const [firstLevelKey, firstLevelValue] of Object.entries(gaParametersMapping)) {
122
+ if (typeof firstLevelValue === 'object' && firstLevelValue !== null) {
123
+ for (const [secondLevelKey, secondLevelValue] of Object.entries(firstLevelValue)) {
124
+ if (parameters[firstLevelKey] && parameters[firstLevelKey][secondLevelKey]) {
125
+ parsedParameters[secondLevelValue] = parameters[firstLevelKey][secondLevelKey];
126
+ }
127
+ }
128
+ } else if (parameters[firstLevelKey]) {
129
+ parsedParameters[firstLevelValue] = parameters[firstLevelKey];
130
+ }
131
+ }
132
+
133
+ return parsedParameters;
134
+ };
135
+
136
+ class Analytics {
137
+ constructor() {
138
+ this.isGaDisabled = this.getIsGaDisabled();
139
+ this.gaTrackingId = GA_TRACKING_ID;
140
+ this.clientIdentifier = UNKNOWN;
141
+ this.currentUrl = UNKNOWN;
142
+ this.lang = UNKNOWN;
143
+
144
+ try {
145
+ this.setClientIdentifier(
146
+ generateUUID()
147
+ );
148
+ } catch (e) {
149
+ this.setClientIdentifier(
150
+ Date.now()
151
+ );
152
+ }
153
+ }
154
+
155
+ setLang(lang) {
156
+ this.lang = lang;
157
+ }
158
+
159
+ setCurrentUrl(currentUrl) {
160
+ this.currentUrl = currentUrl;
161
+ }
162
+
163
+ setClientIdentifier(id) {
164
+ this.clientIdentifier = id;
165
+ }
166
+
167
+ setGaTrackingId(id) {
168
+ this.gaTrackingId = id;
169
+ }
170
+
171
+ getIsGaDisabled() {
172
+ const { analytics } = getSystemConfigSync({ validate: false });
173
+
174
+ return !analytics;
175
+ }
176
+
177
+ /**
178
+ * @param {GAParameters} data
179
+ */
180
+ async _collect(data) {
181
+ if (this.isGaDisabled) {
182
+ // skip GA
183
+ return;
184
+ }
185
+
186
+ /**
187
+ * @type {GAParameters}
188
+ */
189
+ const analyticsParameters = {
190
+ ...data,
191
+ version: '1',
192
+ trackingID: this.gaTrackingId,
193
+ user: {
194
+ clientID: this.clientIdentifier
195
+ },
196
+ app: getAppData()
197
+ };
198
+
199
+ try {
200
+ analyticsParameters.systemInfo = {
201
+ ipOverride: await getExternalIpAddress()
202
+ };
203
+ } catch (e) {
204
+ console.log(e);
205
+ // Do nothing
206
+ }
207
+
208
+ if (this.lang !== UNKNOWN) {
209
+ // get system language here
210
+ analyticsParameters.systemInfo = {
211
+ userLanguage: this.lang
212
+ };
213
+ }
214
+
215
+ if (this.currentUrl !== UNKNOWN) {
216
+ const {
217
+ hostname,
218
+ pathname
219
+ } = new URL(this.currentUrl);
220
+
221
+ analyticsParameters.contentInformation = {
222
+ documentLocationUrl: this.currentUrl,
223
+ documentPath: pathname,
224
+ documentHostName: hostname
225
+ };
226
+ }
227
+
228
+ const params = new URLSearchParams(collectAnalyticsParameters(analyticsParameters)).toString();
229
+
230
+ try {
231
+ if (!process.env.GA_DEBUG) {
232
+ await request(
233
+ `https://www.google-analytics.com/collect?${ params }`,
234
+ {
235
+ headers: { 'User-Agent': 'Google-Cloud-Functions' },
236
+ responseType: 'headers'
237
+ }
238
+ );
239
+
240
+ return;
241
+ }
242
+
243
+ const { data: jsonResponse } = await request(
244
+ `https://www.google-analytics.com/debug/collect?${ params }`,
245
+ {
246
+ headers: { 'User-Agent': 'Google-Cloud-Functions' },
247
+ responseType: 'json'
248
+ }
249
+ );
250
+
251
+ logger.log(analyticsParameters);
252
+ logger.log(JSON.stringify(jsonResponse, null, 2));
253
+
254
+ // eslint-disable-next-line no-empty
255
+ } catch (e) {
256
+ console.log('Failed to report telemetry data');
257
+ }
258
+ }
259
+
260
+ trackError(error, isFatal = true) {
261
+ // return; // nothing
262
+ return this._collect({
263
+ hit: {
264
+ type: 'exception'
265
+ },
266
+ exception: {
267
+ description: anonymizeError(typeof error === 'string' ? error : error.message),
268
+ fatal: isFatal
269
+ }
270
+ });
271
+ // return this._collect({
272
+ // t: 'exception',
273
+ // exd: anonymizeError(typeof error === 'string' ? error : error.message),
274
+ // exf: isFatal
275
+ // });
276
+ }
277
+
278
+ trackTiming(label, time, category = UNKNOWN) {
279
+ return this._collect({
280
+ hit: {
281
+ type: 'timing'
282
+ },
283
+ timing: {
284
+ userTimingCategory: category,
285
+ userTimingVariableName: label,
286
+ userTimingLabel: this.currentUrl,
287
+ userTimingTime: Math.round(time)
288
+ }
289
+ });
290
+ // return this._collect({
291
+ // t: 'timing',
292
+ // utc: category,
293
+ // utv: label,
294
+ // utl: this.currentUrl,
295
+ // utt: Math.round(time)
296
+ // });
297
+ }
298
+
299
+ trackPageView() {
300
+ return this._collect({
301
+ hit: {
302
+ type: 'pageview'
303
+ }
304
+ });
305
+ }
306
+
307
+ trackEvent(action, label, value, category = UNKNOWN) {
308
+ return this._collect({
309
+ hit: {
310
+ type: 'event'
311
+ },
312
+ event: {
313
+ category,
314
+ action,
315
+ label,
316
+ value
317
+ }
318
+ });
319
+ // return this._collect({
320
+ // t: 'event',
321
+ // ec: category,
322
+ // ea: action,
323
+ // el: label,
324
+ // ev: value
325
+ // });
326
+ }
327
+
328
+ printAboutAnalytics() {
329
+ if (!this.isGaDisabled) {
330
+ logger.log('We collect analytics data to make our products more stable and reliable!');
331
+ logger.log('If you want to know more go here https://docs.scandipwa.com/about/data-analytics');
332
+ logger.logN();
333
+ }
334
+ }
335
+ }
336
+
337
+ module.exports = new Analytics();
package/lib/util/arch.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const macosVersion = require('macos-version');
2
2
  const { execSync } = require('child_process');
3
- const { execAsync } = require('./exec-async-command');
3
+ const { execAsync } = require('./exec-async');
4
4
 
5
5
  /**
6
6
  * Get actual system arch
@@ -1,12 +1,13 @@
1
1
  const Joi = require('joi');
2
2
  const semver = require('semver');
3
+ const KnownError = require('../errors/known-error');
3
4
  const pathExistsSync = require('./path-exists-sync');
4
5
 
5
6
  const fileExistsValidator = (value) => {
6
7
  const fileExists = pathExistsSync(value);
7
8
 
8
9
  if (!fileExists) {
9
- throw new Error(`File "${value}" does not exists!`);
10
+ throw new KnownError(`File "${value}" does not exists!`);
10
11
  }
11
12
 
12
13
  return undefined;
@@ -72,6 +73,15 @@ const nginxConfigurationSchema = Joi.object({
72
73
  configTemplate: Joi.string().optional().custom(fileExistsValidator)
73
74
  });
74
75
 
76
+ /**
77
+ * @type {Joi.ObjectSchema<import('../../typings').NginxConfiguration>}
78
+ */
79
+ const varnishConfigurationSchema = Joi.object({
80
+ enabled: Joi.boolean().optional(),
81
+ version: Joi.string().optional(),
82
+ configTemplate: Joi.string().optional().custom(fileExistsValidator)
83
+ });
84
+
75
85
  /**
76
86
  * @type {Joi.ObjectSchema<import('../../typings').ServiceWithVersion>}
77
87
  */
@@ -101,7 +111,9 @@ const configurationSchema = Joi.object({
101
111
  mysql: serviceConfigurationSchema.optional(),
102
112
  elasticsearch: serviceConfigurationSchema.optional(),
103
113
  redis: serviceConfigurationSchema.optional(),
104
- composer: composerConfigurationSchema.optional()
114
+ composer: composerConfigurationSchema.optional(),
115
+ varnish: varnishConfigurationSchema.optional(),
116
+ sslTerminator: nginxConfigurationSchema.optional()
105
117
  });
106
118
 
107
119
  /**
@@ -0,0 +1,20 @@
1
+ const path = require('path');
2
+ const UnknownError = require('../errors/unknown-error');
3
+ const runPhpCode = require('./run-php');
4
+
5
+ const configPhpToJson = async (projectPath = process.cwd(), { magentoVersion }) => {
6
+ const { code, result } = await runPhpCode(`-r "echo json_encode(require '${path.join(projectPath, 'app', 'etc', 'config.php')}');"`, {
7
+ magentoVersion
8
+ });
9
+
10
+ if (code !== 0) {
11
+ throw new UnknownError(`Received non-zero code during converting app/etc/config.php to json:\n\n${result}`);
12
+ }
13
+ try {
14
+ return JSON.parse(result);
15
+ } catch (e) {
16
+ throw new UnknownError(`Ooops! Something went wrong when trying to parse app/etc/config.php file!\n\n${e}\n\nFile result: ${result}`);
17
+ }
18
+ };
19
+
20
+ module.exports = configPhpToJson;
@@ -1,4 +1,5 @@
1
1
  const path = require('path');
2
+ const UnknownError = require('../errors/unknown-error');
2
3
  const runPhpCode = require('./run-php');
3
4
 
4
5
  const envPhpToJson = async (projectPath = process.cwd(), { magentoVersion }) => {
@@ -7,12 +8,12 @@ const envPhpToJson = async (projectPath = process.cwd(), { magentoVersion }) =>
7
8
  });
8
9
 
9
10
  if (code !== 0) {
10
- throw new Error(result);
11
+ throw new UnknownError(`Received non-zero code during converting app/etc/env.php to json:\n\n${result}`);
11
12
  }
12
13
  try {
13
14
  return JSON.parse(result);
14
15
  } catch (e) {
15
- throw new Error(`Ooops! Something went wrong when trying to parse app/etc/env.php file!\n\n${e}\n\nFile result: ${result}`);
16
+ throw new UnknownError(`Ooops! Something went wrong when trying to parse app/etc/env.php file!\n\n${e}\n\nFile result: ${result}`);
16
17
  }
17
18
  };
18
19
 
@@ -9,6 +9,8 @@ interface ExecAsyncSpawnOptions<T extends boolean> {
9
9
  logOutput?: boolean
10
10
  cwd?: string
11
11
  withCode?: T
12
+ // only for mac
13
+ useRosetta2?: boolean
12
14
  }
13
15
 
14
16
  /**
@@ -1,25 +1,42 @@
1
+ const os = require('os');
1
2
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
2
- const { exec, spawn } = require('child_process');
3
-
4
- const execAsync = (command, options) => new Promise((resolve, reject) => {
5
- exec(command, options, (err, stdout) => (err ? reject(err) : resolve(stdout)));
6
- });
3
+ const { spawn } = require('child_process');
4
+ const { getArchSync } = require('./arch');
5
+ const compileOptions = require('../tasks/php/compile-options');
7
6
 
8
7
  const execAsyncSpawn = (command, {
9
8
  callback = () => {},
10
9
  pipeInput,
11
10
  logOutput = false,
12
11
  cwd,
13
- withCode = false
12
+ withCode = false,
13
+ useRosetta2 = false
14
14
  } = {}) => {
15
- const childProcess = spawn(
16
- 'bash',
17
- ['-c', command],
18
- {
19
- stdio: pipeInput ? ['inherit', 'pipe', 'pipe'] : 'pipe',
20
- cwd
21
- }
22
- );
15
+ const spawnOptions = {
16
+ stdio: pipeInput ? ['inherit', 'pipe', 'pipe'] : 'pipe',
17
+ cwd
18
+ };
19
+ let childProcess;
20
+ if (useRosetta2 && os.platform() === 'darwin' && getArchSync() === 'arm64') {
21
+ childProcess = spawn(
22
+ 'arch',
23
+ // eslint-disable-next-line max-len
24
+ ['-x86_64', 'bash', '-c', command],
25
+ {
26
+ ...spawnOptions,
27
+ env: {
28
+ ...process.env,
29
+ PATH: compileOptions.darwin.env.PATH
30
+ }
31
+ }
32
+ );
33
+ } else {
34
+ childProcess = spawn(
35
+ 'bash',
36
+ ['-c', command],
37
+ spawnOptions
38
+ );
39
+ }
23
40
 
24
41
  return new Promise((resolve, reject) => {
25
42
  let stdout = '';
@@ -71,7 +88,6 @@ const execCommandTask = (command, options = {}) => ({
71
88
  });
72
89
 
73
90
  module.exports = {
74
- execAsync,
75
91
  execAsyncSpawn,
76
92
  execCommandTask
77
93
  };