@scandipwa/magento-scripts 1.16.0-alpha.4 → 2.0.0-alpha.0

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 (190) hide show
  1. package/lib/commands/cli.js +2 -4
  2. package/lib/commands/execute.js +28 -3
  3. package/lib/commands/start.js +37 -15
  4. package/lib/commands/status.js +2 -0
  5. package/lib/config/docker.js +65 -42
  6. package/lib/config/get-project-configuration.js +3 -1
  7. package/lib/config/index.js +10 -7
  8. package/lib/config/magento/required-php-extensions/index.js +29 -0
  9. package/lib/config/magento/required-php-extensions/magento-2.3.js +19 -0
  10. package/lib/config/magento/required-php-extensions/magento-2.4.js +29 -0
  11. package/lib/config/php/base-repo.js +3 -0
  12. package/lib/config/php/extensions/apcu.js +12 -0
  13. package/lib/config/php/extensions/bcmath.js +7 -0
  14. package/lib/config/php/extensions/curl.js +11 -0
  15. package/lib/config/php/extensions/gd.js +14 -0
  16. package/lib/config/php/extensions/index.js +18 -2
  17. package/lib/config/php/extensions/intl.js +10 -0
  18. package/lib/config/php/extensions/opcache.js +10 -0
  19. package/lib/config/php/extensions/pdo_mysql.js +7 -0
  20. package/lib/config/php/extensions/soap.js +10 -0
  21. package/lib/config/php/extensions/sodium.js +10 -0
  22. package/lib/config/php/extensions/xdebug.js +8 -5
  23. package/lib/config/php/extensions/xsl.js +10 -0
  24. package/lib/config/php/extensions/zip.js +10 -0
  25. package/lib/config/php/{releases → versions}/index.js +0 -0
  26. package/lib/config/php/versions/php-7.2.js +23 -0
  27. package/lib/config/php/versions/php-7.3.js +23 -0
  28. package/lib/config/php/versions/php-7.4.js +23 -0
  29. package/lib/config/php/versions/php-8.1.js +23 -0
  30. package/lib/config/php-config.js +8 -12
  31. package/lib/config/port-config.js +1 -5
  32. package/lib/config/templates/magentorc.template +3 -3
  33. package/lib/config/templates/php-fpm.template.conf +3 -3
  34. package/lib/config/templates/php.template.ini +12 -6
  35. package/lib/config/templates/ssl-terminator.template.conf +1 -1
  36. package/lib/config/templates/vscode-launch.template.json +3 -1
  37. package/lib/config/versions/magento-2.3.0.js +8 -2
  38. package/lib/config/versions/magento-2.3.1.js +8 -2
  39. package/lib/config/versions/magento-2.3.2-p1.js +44 -0
  40. package/lib/config/versions/magento-2.3.2-p2.js +8 -2
  41. package/lib/config/versions/magento-2.3.2.js +8 -2
  42. package/lib/config/versions/magento-2.3.3-p1.js +8 -2
  43. package/lib/config/versions/magento-2.3.3.js +8 -2
  44. package/lib/config/versions/magento-2.3.4-p1.js +44 -0
  45. package/lib/config/versions/magento-2.3.4-p2.js +8 -2
  46. package/lib/config/versions/magento-2.3.4.js +8 -2
  47. package/lib/config/versions/magento-2.3.5-p1.js +8 -2
  48. package/lib/config/versions/magento-2.3.5-p2.js +8 -2
  49. package/lib/config/versions/magento-2.3.5.js +8 -2
  50. package/lib/config/versions/magento-2.3.6-p1.js +8 -2
  51. package/lib/config/versions/magento-2.3.6.js +8 -2
  52. package/lib/config/versions/magento-2.3.7-p1.js +8 -2
  53. package/lib/config/versions/magento-2.3.7-p2.js +8 -2
  54. package/lib/config/versions/magento-2.3.7-p3.js +8 -2
  55. package/lib/config/versions/magento-2.3.7.js +8 -2
  56. package/lib/config/versions/magento-2.4.0-p1.js +9 -3
  57. package/lib/config/versions/magento-2.4.0.js +9 -3
  58. package/lib/config/versions/magento-2.4.1-p1.js +6 -5
  59. package/lib/config/versions/magento-2.4.1.js +9 -2
  60. package/lib/config/versions/magento-2.4.2-p1.js +6 -5
  61. package/lib/config/versions/magento-2.4.2-p2.js +6 -6
  62. package/lib/config/versions/magento-2.4.2.js +6 -6
  63. package/lib/config/versions/magento-2.4.3-p1.js +7 -7
  64. package/lib/config/versions/magento-2.4.3-p2.js +7 -7
  65. package/lib/config/versions/magento-2.4.3.js +7 -7
  66. package/lib/config/versions/magento-2.4.4.js +9 -2
  67. package/lib/tasks/cleanup.js +2 -2
  68. package/lib/tasks/composer/index.js +14 -104
  69. package/lib/tasks/docker/api.d.ts +71 -0
  70. package/lib/tasks/docker/api.js +30 -0
  71. package/lib/tasks/docker/containers/container-api.d.ts +128 -0
  72. package/lib/tasks/docker/containers/container-api.js +153 -0
  73. package/lib/tasks/docker/containers/index.js +19 -0
  74. package/lib/tasks/docker/containers/tasks.js +215 -0
  75. package/lib/tasks/docker/convert-legacy-volumes.js +7 -3
  76. package/lib/tasks/docker/image/image-api.d.ts +34 -0
  77. package/lib/tasks/docker/image/image-api.js +49 -0
  78. package/lib/tasks/docker/image/index.js +5 -0
  79. package/lib/tasks/docker/index.js +1 -13
  80. package/lib/tasks/docker/network/index.js +7 -0
  81. package/lib/tasks/docker/network/network-api.d.ts +103 -0
  82. package/lib/tasks/docker/network/network-api.js +99 -0
  83. package/lib/tasks/docker/{network.js → network/tasks.js} +17 -10
  84. package/lib/tasks/docker/project-image-builder.js +167 -0
  85. package/lib/tasks/docker/volumes.js +1 -1
  86. package/lib/tasks/file-system/create-nginx-config.js +2 -3
  87. package/lib/tasks/file-system/create-php-config.js +20 -5
  88. package/lib/tasks/file-system/create-php-fpm-config.js +8 -4
  89. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +41 -29
  90. package/lib/tasks/file-system/create-phpstorm-config/index.js +2 -0
  91. package/lib/tasks/file-system/create-phpstorm-config/keys.js +15 -1
  92. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +4 -1
  93. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-config.js +3 -3
  94. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-interpreters-config.js +81 -0
  95. package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/index.js +42 -0
  96. package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/php-docker-settings-config.js +9 -0
  97. package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/setup-php-docker-container-settings-config.js +66 -0
  98. package/lib/tasks/file-system/create-phpstorm-config/setup-xml-structure.js +11 -9
  99. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +2 -1
  100. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +15 -30
  101. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +24 -5
  102. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/mess-detector-project-configuration-config.js +50 -0
  103. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-code-sniffer-project-configuration-config.js +50 -0
  104. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-cs-fixer-project-configuration-config.js +50 -0
  105. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +15 -15
  106. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +29 -3
  107. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-stan-project-configuration-config.js.js +50 -0
  108. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-workspace-project-configuration-config.js +42 -0
  109. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/psalm-project-configuration-config.js.js +50 -0
  110. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/workspace-config.js +0 -2
  111. package/lib/tasks/file-system/create-ssl-terminator-config.js +4 -2
  112. package/lib/tasks/file-system/create-vscode-config.js +57 -42
  113. package/lib/tasks/file-system/index.js +2 -1
  114. package/lib/tasks/link.js +1 -2
  115. package/lib/tasks/magento/install-magento-project.js +39 -64
  116. package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +4 -4
  117. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +6 -2
  118. package/lib/tasks/magento/setup-magento/create-admin.js +5 -6
  119. package/lib/tasks/magento/setup-magento/disable-2fa.js +3 -5
  120. package/lib/tasks/magento/setup-magento/disable-maintenance-mode.js +3 -4
  121. package/lib/tasks/magento/setup-magento/index.js +1 -3
  122. package/lib/tasks/magento/setup-magento/install-magento.js +57 -11
  123. package/lib/tasks/magento/setup-magento/migrate-database.js +12 -11
  124. package/lib/tasks/magento/setup-magento/set-deployment-mode.js +4 -4
  125. package/lib/tasks/magento/setup-magento/varnish-config.js +7 -5
  126. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +128 -3
  127. package/lib/tasks/mysql/connect-to-mysql.js +44 -19
  128. package/lib/tasks/mysql/import-dump-to-mysql.js +161 -25
  129. package/lib/tasks/php/php-container.js +108 -0
  130. package/lib/tasks/php/update-env-php.js +35 -19
  131. package/lib/tasks/php/update-env.php +61 -56
  132. package/lib/tasks/php/working_health_check.php +85 -0
  133. package/lib/tasks/requirements/{composer.js → composer-credentials.js} +3 -1
  134. package/lib/tasks/requirements/docker/index.js +15 -12
  135. package/lib/tasks/requirements/docker/performance.js +54 -0
  136. package/lib/tasks/requirements/docker/version.js +8 -8
  137. package/lib/tasks/requirements/index.js +7 -10
  138. package/lib/tasks/requirements/php-version.js +8 -116
  139. package/lib/tasks/requirements/platform.js +12 -25
  140. package/lib/tasks/start.js +41 -48
  141. package/lib/tasks/status/index.js +4 -10
  142. package/lib/tasks/stop.js +0 -2
  143. package/lib/tasks/theme/install-theme.js +1 -1
  144. package/lib/tasks/theme/symlink-theme.js +2 -3
  145. package/lib/util/config-php-json.js +13 -4
  146. package/lib/util/dockerfile-builder/build-instructions.js +197 -0
  147. package/lib/util/dockerfile-builder/index.js +276 -0
  148. package/lib/util/dockerfile-builder/types.d.ts +123 -0
  149. package/lib/util/env-php-json.js +10 -6
  150. package/lib/util/exec-async-command.js +3 -9
  151. package/lib/util/macos-version.js +20 -0
  152. package/lib/util/magento-task.js +3 -4
  153. package/lib/util/nginx-logs-parser.js +122 -0
  154. package/lib/util/php-task.js +3 -6
  155. package/lib/util/prefix.js +1 -1
  156. package/lib/util/run-composer.js +6 -14
  157. package/lib/util/run-container-image.js +17 -0
  158. package/lib/util/run-magento.js +6 -14
  159. package/lib/util/run-php.js +6 -17
  160. package/package.json +9 -9
  161. package/typings/context.d.ts +3 -9
  162. package/typings/index.d.ts +38 -57
  163. package/lib/config/composer.js +0 -11
  164. package/lib/config/php/extensions/libsodium.js +0 -36
  165. package/lib/config/php/releases/php-7.2.js +0 -25
  166. package/lib/config/php/releases/php-7.3.js +0 -25
  167. package/lib/config/php/releases/php-7.4.js +0 -23
  168. package/lib/config/php/releases/php-8.1.js +0 -25
  169. package/lib/config/phpbrew.js +0 -12
  170. package/lib/tasks/composer/install-prestissimo.js +0 -88
  171. package/lib/tasks/docker/containers.js +0 -231
  172. package/lib/tasks/php/bundled-extensions.js +0 -27
  173. package/lib/tasks/php/compile-options.js +0 -56
  174. package/lib/tasks/php/compile.js +0 -55
  175. package/lib/tasks/php/configure.js +0 -89
  176. package/lib/tasks/php/extensions/disable.js +0 -49
  177. package/lib/tasks/php/extensions/enable.js +0 -52
  178. package/lib/tasks/php/extensions/index.js +0 -80
  179. package/lib/tasks/php/extensions/install.js +0 -54
  180. package/lib/tasks/php/index.js +0 -79
  181. package/lib/tasks/php/install-sodium.js +0 -93
  182. package/lib/tasks/php/update-phpbrew.js +0 -45
  183. package/lib/tasks/php/validate-php.js +0 -67
  184. package/lib/tasks/php-fpm/get-process-id.js +0 -14
  185. package/lib/tasks/php-fpm/index.js +0 -4
  186. package/lib/tasks/php-fpm/start-php-fpm.js +0 -49
  187. package/lib/tasks/php-fpm/stop-php-fpm.js +0 -48
  188. package/lib/tasks/requirements/phpbrew/index.js +0 -61
  189. package/lib/tasks/requirements/phpbrew/install.js +0 -159
  190. package/lib/tasks/requirements/phpbrew/version.js +0 -28
@@ -1,31 +1,27 @@
1
1
  const path = require('path');
2
- const os = require('os');
2
+ const fs = require('fs');
3
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
3
4
  const runComposerCommand = require('../../util/run-composer');
4
5
  const matchFilesystem = require('../../util/match-filesystem');
5
- const moveFile = require('../../util/move-file');
6
6
  const pathExists = require('../../util/path-exists');
7
7
  const getJsonFileData = require('../../util/get-jsonfile-data');
8
- const rmdirSafe = require('../../util/rmdir-safe');
9
8
  const KnownError = require('../../errors/known-error');
10
9
  const UnknownError = require('../../errors/unknown-error');
11
- const logger = require('@scandipwa/scandipwa-dev-utils/logger');
10
+ const { runPHPContainerCommand } = require('../php/php-container');
12
11
 
13
12
  const magentoProductEnterpriseEdition = 'magento/product-enterprise-edition';
14
13
  const magentoProductCommunityEdition = 'magento/product-community-edition';
15
14
 
16
15
  /**
17
- * Adjust composer.json file configuration for magento
16
+ * @param {import('../../../typings/context').ListrContext} ctx
17
+ * @param {import('listr2').ListrTaskWrapper<import('../../../typings/context').ListrContext>} task
18
18
  */
19
- const adjustComposerJson = async ({
20
- baseConfig,
19
+ const adjustComposerJson = async (ctx, task, {
21
20
  magentoEdition,
22
21
  magentoProductSelectedEdition,
23
- magentoVersion,
24
- magentoPackageVersion,
25
- task,
26
- verbose
22
+ magentoPackageVersion
27
23
  }) => {
28
- const composerData = await getJsonFileData(path.join(baseConfig.magentoDir, 'composer.json'));
24
+ const composerData = await getJsonFileData(path.join(ctx.config.baseConfig.magentoDir, 'composer.json'));
29
25
 
30
26
  // fix composer magento repository
31
27
  if (composerData && (!composerData.repositories
@@ -36,9 +32,8 @@ const adjustComposerJson = async ({
36
32
  && !Object.values(composerData.repositories).some((repo) => repo.type === 'composer' && repo.url.includes('repo.magento.com')))
37
33
  )) {
38
34
  task.output = 'No Magento repository is set in composer.json! Setting up...';
39
- await runComposerCommand('config repo.0 composer https://repo.magento.com', {
40
- magentoVersion,
41
- callback: !verbose ? undefined : (t) => {
35
+ await runComposerCommand(ctx, 'config repo.0 composer https://repo.magento.com', {
36
+ callback: !ctx.verbose ? undefined : (t) => {
42
37
  task.output = t;
43
38
  }
44
39
  });
@@ -47,10 +42,9 @@ const adjustComposerJson = async ({
47
42
  // if composer-root-update-plugin is not installed in composer, install it.
48
43
  if (composerData && !composerData.require['magento/composer-root-update-plugin']) {
49
44
  task.output = 'Installing magento/composer-root-update-plugin!';
50
- await runComposerCommand('require magento/composer-root-update-plugin:^1',
45
+ await runComposerCommand(ctx, 'require magento/composer-root-update-plugin:^1',
51
46
  {
52
- magentoVersion,
53
- callback: !verbose ? undefined : (t) => {
47
+ callback: !ctx.verbose ? undefined : (t) => {
54
48
  task.output = t;
55
49
  }
56
50
  });
@@ -61,7 +55,8 @@ const adjustComposerJson = async ({
61
55
  && composerData.require[magentoProductCommunityEdition]
62
56
  && composerData.require[magentoProductEnterpriseEdition]
63
57
  ) {
64
- throw new KnownError('Somehow, both Magento editions are installed!\nPlease choose only one edition an modify your composer.json manually!');
58
+ throw new KnownError(`Somehow, both Magento editions are installed!
59
+ Please choose only one edition an modify your composer.json manually!`);
65
60
  }
66
61
 
67
62
  const oppositeEdition = [magentoProductCommunityEdition, magentoProductEnterpriseEdition]
@@ -75,13 +70,11 @@ Change magento edition in config file or manually reinstall correct magento edit
75
70
  }
76
71
 
77
72
  // if magento package is not installed in composer, require it.
78
-
79
73
  if (composerData && !composerData.require[magentoProductSelectedEdition]) {
80
74
  task.output = `Installing ${magentoProductSelectedEdition}=${magentoPackageVersion}!`;
81
- await runComposerCommand(`require ${magentoProductSelectedEdition}:${magentoPackageVersion}`,
75
+ await runComposerCommand(ctx, `require ${magentoProductSelectedEdition}:${magentoPackageVersion}`,
82
76
  {
83
- magentoVersion,
84
- callback: !verbose ? undefined : (t) => {
77
+ callback: !ctx.verbose ? undefined : (t) => {
85
78
  task.output = t;
86
79
  }
87
80
  });
@@ -89,16 +82,14 @@ Change magento edition in config file or manually reinstall correct magento edit
89
82
  };
90
83
 
91
84
  /**
92
- * Create Magento Project
85
+ * @param {import('../../../typings/context').ListrContext} ctx
86
+ * @param {import('listr2').ListrTaskWrapper<import('../../../typings/context').ListrContext>} task
93
87
  */
94
- const createMagentoProject = async ({
88
+ const createMagentoProject = async (ctx, task, {
95
89
  magentoProject,
96
- magentoPackageVersion,
97
- magentoVersion,
98
- task,
99
- verbose
90
+ magentoPackageVersion
100
91
  }) => {
101
- const tempDir = path.join(os.tmpdir(), `magento-tmpdir-${Date.now()}`);
92
+ const tempDir = `/tmp/magento-tmpdir-${Date.now()}`;
102
93
  const installCommand = [
103
94
  'create-project',
104
95
  `--repository=https://repo.magento.com/ ${magentoProject}=${magentoPackageVersion}`,
@@ -106,31 +97,17 @@ const createMagentoProject = async ({
106
97
  `"${tempDir}"`
107
98
  ];
108
99
 
109
- await runComposerCommand(
110
- installCommand.join(' '),
111
- {
112
- magentoVersion,
113
- callback: !verbose ? undefined : (t) => {
114
- task.output = t;
115
- }
116
- }
117
- );
118
-
119
- await moveFile({
120
- from: path.join(tempDir, 'composer.json'),
121
- to: path.join(process.cwd(), 'composer.json')
122
- });
123
-
124
- await rmdirSafe(tempDir);
100
+ await runPHPContainerCommand(ctx, `composer ${installCommand.join(' ')} \n
101
+ && mv ${tempDir}/composer.json /var/www/html/composer.json`);
125
102
  };
126
103
 
127
104
  /**
128
105
  * @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
129
106
  */
130
107
  const installMagentoProject = () => ({
131
- title: 'Installing Magento',
108
+ title: 'Installing Magento Project',
132
109
  task: async (ctx, task) => {
133
- const { magentoVersion, config: { baseConfig, overridenConfiguration }, verbose } = ctx;
110
+ const { config: { baseConfig, overridenConfiguration } } = ctx;
134
111
  const {
135
112
  magento: { edition: magentoEdition },
136
113
  magentoVersion: magentoPackageVersion
@@ -140,15 +117,10 @@ const installMagentoProject = () => ({
140
117
  const magentoProject = `magento/project-${magentoEdition}-edition`;
141
118
 
142
119
  if (await pathExists(path.join(baseConfig.magentoDir, 'composer.json'))) {
143
- await adjustComposerJson({
144
- baseConfig,
145
- isEnterprise,
120
+ await adjustComposerJson(ctx, task, {
146
121
  magentoEdition,
147
122
  magentoPackageVersion,
148
- magentoProductSelectedEdition,
149
- magentoVersion,
150
- task,
151
- verbose
123
+ magentoProductSelectedEdition
152
124
  });
153
125
  }
154
126
 
@@ -172,26 +144,29 @@ const installMagentoProject = () => ({
172
144
  task.output = 'Creating Magento project';
173
145
 
174
146
  if (!await pathExists(path.join(process.cwd(), 'composer.json'))) {
175
- await createMagentoProject({
147
+ await createMagentoProject(ctx, task, {
176
148
  magentoProject,
177
- magentoPackageVersion,
178
- magentoVersion,
179
- task,
180
- verbose
149
+ magentoPackageVersion
150
+ });
151
+ }
152
+
153
+ if (!await pathExists(path.join(process.cwd(), 'app', 'etc'))) {
154
+ await fs.promises.mkdir(path.join(process.cwd(), 'app', 'etc'), {
155
+ recursive: true
181
156
  });
182
157
  }
158
+
183
159
  try {
184
- await runComposerCommand('install',
160
+ await runComposerCommand(ctx, 'install',
185
161
  {
186
- magentoVersion,
187
- callback: !verbose ? undefined : (t) => {
162
+ callback: !ctx.verbose ? undefined : (t) => {
188
163
  task.output = t;
189
164
  }
190
165
  });
191
166
  } catch (e) {
192
167
  if (e.message.includes('man-in-the-middle attack')) {
193
168
  throw new KnownError(`Probably you haven't setup pubkeys in composer.
194
- Please run ${logger.style.command('composer diagnose')} in cli to get mode.\n\n${e}`);
169
+ Please run ${logger.style.command('composer diagnose')} in cli to get mode.\n\n${e}`);
195
170
  }
196
171
 
197
172
  throw new UnknownError(`Unexpected error during composer install.\n\n${e}`);
@@ -6,15 +6,15 @@ const magentoTask = require('../../../util/magento-task');
6
6
  */
7
7
  const disableFullPageCache = () => ({
8
8
  title: 'Adjusting full_page cache setting',
9
- task: async ({ magentoVersion, config }, task) => {
10
- const { cache_types } = await envPhpToJson(process.cwd(), { magentoVersion });
9
+ task: async (ctx, task) => {
10
+ const { cache_types } = await envPhpToJson(ctx);
11
11
  if (cache_types && typeof cache_types.full_page === 'number') {
12
- if (cache_types.full_page !== 0 && !config.overridenConfiguration.configuration.varnish.enabled) {
12
+ if (cache_types.full_page !== 0 && !ctx.config.overridenConfiguration.configuration.varnish.enabled) {
13
13
  task.title = 'Disabling full_page cache in Magento';
14
14
  return task.newListr(magentoTask('cache:disable full_page'));
15
15
  }
16
16
 
17
- if (config.overridenConfiguration.configuration.varnish.enabled && cache_types.full_page !== 1) {
17
+ if (ctx.config.overridenConfiguration.configuration.varnish.enabled && cache_types.full_page !== 1) {
18
18
  task.title = 'Enabling full_page cache in Magento (Varnish is enabled)';
19
19
  return task.newListr(magentoTask('cache:enable full_page'));
20
20
  }
@@ -6,10 +6,14 @@ const { updateTableValues, isTableExists } = require('../../../util/database');
6
6
  module.exports = () => ({
7
7
  title: 'Configuring Elasticsearch',
8
8
  skip: async (ctx) => !(await isTableExists('magento', 'core_config_data', ctx)),
9
- task: async ({ ports, mysqlConnection }, task) => {
9
+ task: async (ctx, task) => {
10
+ const { ports, mysqlConnection } = ctx;
11
+ const isLinux = ctx.platform === 'linux';
12
+ const isNativeLinux = isLinux && !ctx.isWsl;
13
+ const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
10
14
  await updateTableValues('core_config_data', [
11
15
  { path: 'catalog/search/engine', value: 'elasticsearch7' },
12
- { path: 'catalog/search/elasticsearch7_server_hostname', value: '127.0.0.1' },
16
+ { path: 'catalog/search/elasticsearch7_server_hostname', value: hostMachine },
13
17
  { path: 'catalog/search/elasticsearch7_server_port', value: `${ports.elasticsearch}` }
14
18
  ], { mysqlConnection, task });
15
19
  }
@@ -5,8 +5,9 @@ const runMagentoCommand = require('../../../util/run-magento');
5
5
  */
6
6
  module.exports = () => ({
7
7
  title: 'Creating admin user',
8
- task: async ({ magentoVersion, mysqlConnection, config: { magentoConfiguration } }, task) => {
9
- const [[{ userCount }]] = await mysqlConnection.query(`
8
+ task: async (ctx, task) => {
9
+ const { config: { magentoConfiguration } } = ctx;
10
+ const [[{ userCount }]] = await ctx.mysqlConnection.query(`
10
11
  SELECT count(*) AS userCount
11
12
  FROM admin_user
12
13
  WHERE username = ?;
@@ -17,13 +18,11 @@ module.exports = () => ({
17
18
  return;
18
19
  }
19
20
 
20
- await runMagentoCommand(`admin:user:create \
21
+ await runMagentoCommand(ctx, `admin:user:create \
21
22
  --admin-firstname='${ magentoConfiguration.first_name }' \
22
23
  --admin-lastname='${ magentoConfiguration.last_name }' \
23
24
  --admin-email='${ magentoConfiguration.email }' \
24
25
  --admin-user='${ magentoConfiguration.user }' \
25
- --admin-password='${ magentoConfiguration.password }'`, {
26
- magentoVersion
27
- });
26
+ --admin-password='${ magentoConfiguration.password }'`);
28
27
  }
29
28
  });
@@ -6,13 +6,11 @@ const runMagentoCommand = require('../../../util/run-magento');
6
6
  */
7
7
  module.exports = () => ({
8
8
  title: 'Disabling 2fa for admin',
9
- task: async ({ magentoVersion }, task) => {
10
- const { modules } = await configPhpToJson(process.cwd(), { magentoVersion });
9
+ task: async (ctx, task) => {
10
+ const { modules } = await configPhpToJson(ctx);
11
11
 
12
12
  if (modules.Magento_TwoFactorAuth !== undefined && modules.Magento_TwoFactorAuth !== 0) {
13
- await runMagentoCommand('module:disable Magento_TwoFactorAuth', {
14
- magentoVersion
15
- });
13
+ await runMagentoCommand(ctx, 'module:disable Magento_TwoFactorAuth');
16
14
 
17
15
  return;
18
16
  }
@@ -5,9 +5,8 @@ const runMagentoCommand = require('../../../util/run-magento');
5
5
  */
6
6
  const disableMaintenanceMode = () => ({
7
7
  title: 'Disabling maintenance mode',
8
- task: async ({ magentoVersion }, task) => {
9
- const { result } = await runMagentoCommand('maintenance:status', {
10
- magentoVersion,
8
+ task: async (ctx, task) => {
9
+ const { result } = await runMagentoCommand(ctx, 'maintenance:status', {
11
10
  throwNonZeroCode: false
12
11
  });
13
12
 
@@ -16,7 +15,7 @@ const disableMaintenanceMode = () => ({
16
15
  return;
17
16
  }
18
17
 
19
- await runMagentoCommand('maintenance:disable', { magentoVersion });
18
+ await runMagentoCommand(ctx, 'maintenance:disable');
20
19
  }
21
20
  });
22
21
 
@@ -10,7 +10,6 @@ const setUrlRewrite = require('./set-url-rewrite');
10
10
  const increaseAdminSessionLifetime = require('./increase-admin-session-lifetime');
11
11
  const magentoTask = require('../../../util/magento-task');
12
12
  const urnHighlighter = require('./urn-highlighter');
13
- const waitingForVarnish = require('./waiting-for-varnish');
14
13
  const adjustFullPageCache = require('./adjust-full-page-cache');
15
14
 
16
15
  /**
@@ -50,8 +49,7 @@ const setupMagento = (options = {}) => ({
50
49
  disable2fa(),
51
50
  urnHighlighter(),
52
51
  adjustFullPageCache(),
53
- magentoTask('cache:flush'),
54
- waitingForVarnish()
52
+ magentoTask('cache:flush')
55
53
  ], {
56
54
  concurrent: false,
57
55
  exitOnError: true,
@@ -12,7 +12,7 @@ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
12
12
  * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
13
13
  */
14
14
  const installMagento = ({ isDbEmpty = false } = {}) => ({
15
- title: 'Installing magento',
15
+ title: 'Installing Magento in Database',
16
16
  task: async (ctx, task) => {
17
17
  if (isDbEmpty) {
18
18
  task.output = 'No Magento is installed in DB!\nInstalling...';
@@ -23,12 +23,59 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
23
23
  docker,
24
24
  magentoConfiguration
25
25
  },
26
- ports
26
+ ports,
27
+ mysqlConnection
27
28
  } = ctx;
29
+
30
+ const isLinux = ctx.platform === 'linux';
31
+ const isNativeLinux = isLinux && !ctx.isWsl;
32
+ const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
33
+
34
+ const [tableResponse] = await mysqlConnection.query(
35
+ 'SELECT * FROM information_schema.tables WHERE table_schema = \'magento\' AND table_name = \'admin_user\' LIMIT 1;'
36
+ );
37
+
38
+ if (tableResponse.length > 0) {
39
+ const response = await mysqlConnection.query(
40
+ 'select * from admin_user where username=\'admin\';'
41
+ );
42
+
43
+ const usersWithUsernameAdmin = response && response.length > 0 && response[0];
44
+
45
+ if (usersWithUsernameAdmin && usersWithUsernameAdmin.length > 0) {
46
+ const confirmDeleteAdminUsers = await task.prompt({
47
+ type: 'Select',
48
+ message: `In order to install Magento in database you will need to delete admin user with username ${logger.style.command('admin')}`,
49
+ choices: [
50
+ {
51
+ name: 'delete-all',
52
+ message: `Delete all admin users (${logger.style.code('Recommended')})`
53
+ },
54
+ {
55
+ name: 'delete-only-admin',
56
+ message: `Delete only admin user with ${logger.style.command('admin')} username`
57
+ }
58
+ ]
59
+ });
60
+
61
+ await mysqlConnection.query('SET FOREIGN_KEY_CHECKS = 0;');
62
+
63
+ if (confirmDeleteAdminUsers === 'delete-all') {
64
+ await mysqlConnection.query(`
65
+ TRUNCATE TABLE admin_user;
66
+ `);
67
+ } else {
68
+ await mysqlConnection.query(`
69
+ DELETE FROM admin_user WHERE username='admin';
70
+ `);
71
+ }
72
+
73
+ await mysqlConnection.query('SET FOREIGN_KEY_CHECKS = 1;');
74
+ }
75
+ }
76
+
28
77
  const { mysql: { env } } = docker.getContainers(ports);
29
- const envPhpData = await envPhpToJson(process.cwd(), {
30
- magentoVersion: ctx.magentoVersion
31
- });
78
+ const envPhpData = await envPhpToJson(ctx);
32
79
 
33
80
  const envPhpHaveEncryptionKey = envPhpData && envPhpData.crypt && envPhpData.crypt.key && envPhpData.crypt.key;
34
81
 
@@ -50,7 +97,7 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
50
97
 
51
98
  const elasticsearchConfiguration = ` \
52
99
  --search-engine='elasticsearch7' \
53
- --elasticsearch-host='127.0.0.1' \
100
+ --elasticsearch-host='${ hostMachine }' \
54
101
  --elasticsearch-port='${ ports.elasticsearch }'`;
55
102
 
56
103
  /**
@@ -69,25 +116,24 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
69
116
  ${ !isMagento23 ? elasticsearchConfiguration : '' } \
70
117
  ${encryptionKeyOption || ''} \
71
118
  --session-save=redis \
72
- --session-save-redis-host='127.0.0.1' \
119
+ --session-save-redis-host='${ hostMachine }' \
73
120
  --session-save-redis-port='${ ports.redis }' \
74
121
  --session-save-redis-log-level='3' \
75
122
  --session-save-redis-max-concurrency='30' \
76
123
  --session-save-redis-db='1' \
77
124
  --session-save-redis-disable-locking='1' \
78
125
  --cache-backend='redis' \
79
- --cache-backend-redis-server='127.0.0.1' \
126
+ --cache-backend-redis-server='${ hostMachine }' \
80
127
  --cache-backend-redis-port='${ ports.redis }' \
81
128
  --cache-backend-redis-db='0't \
82
- --db-host='127.0.0.1:${ ports.mysql }' \
129
+ --db-host='${ hostMachine }:${ ports.mysql }' \
83
130
  --db-name='${ env.MYSQL_DATABASE }' \
84
131
  --db-user='${ env.MYSQL_USER }' \
85
132
  --db-password='${ env.MYSQL_PASSWORD }' \
86
133
  --backend-frontname='${ magentoConfiguration.adminuri }' \
87
134
  --no-interaction`;
88
135
 
89
- await runMagentoCommand(command, {
90
- magentoVersion,
136
+ await runMagentoCommand(ctx, command, {
91
137
  throwNonZeroCode: true,
92
138
  callback: !ctx.verbose ? undefined : (t) => {
93
139
  task.output = t;
@@ -17,10 +17,7 @@ const updateEnvPHP = require('../../php/update-env-php');
17
17
  const migrateDatabase = (options = {}) => ({
18
18
  title: 'Migrating database',
19
19
  task: async (ctx, task) => {
20
- const {
21
- magentoVersion,
22
- mysqlConnection
23
- } = ctx;
20
+ const { mysqlConnection } = ctx;
24
21
 
25
22
  const [[{ tableCount }]] = await mysqlConnection.query(`
26
23
  SELECT count(*) AS tableCount
@@ -35,12 +32,14 @@ const migrateDatabase = (options = {}) => ({
35
32
  ) {
36
33
  if (options.onlyInstallMagento) {
37
34
  ctx.isSetupUpgradeNeeded = false;
38
- return task.newListr(
35
+ return task.newListr([
36
+ updateEnvPHP(),
39
37
  installMagento({ isDbEmpty: true })
40
- );
38
+ ]);
41
39
  }
42
40
 
43
41
  return task.newListr([
42
+ updateEnvPHP(),
44
43
  installMagento({ isDbEmpty: true }),
45
44
  updateEnvPHP(),
46
45
  varnishConfigSetup(),
@@ -57,8 +56,7 @@ const migrateDatabase = (options = {}) => ({
57
56
  });
58
57
  }
59
58
 
60
- const { code } = await runMagentoCommand('setup:db:status', {
61
- magentoVersion,
59
+ const { code } = await runMagentoCommand(ctx, 'setup:db:status', {
62
60
  throwNonZeroCode: false
63
61
  });
64
62
 
@@ -82,14 +80,17 @@ const migrateDatabase = (options = {}) => ({
82
80
  case 1: {
83
81
  if (options.onlyInstallMagento) {
84
82
  ctx.isSetupUpgradeNeeded = false;
85
- return task.newListr(
86
- installMagentoProject()
87
- );
83
+ return task.newListr([
84
+ installMagentoProject(),
85
+ installMagento()
86
+ ]);
88
87
  }
89
88
 
90
89
  return task.newListr([
91
90
  installMagentoProject(),
92
91
  updateEnvPHP(),
92
+ installMagento(),
93
+ updateEnvPHP(),
93
94
  varnishConfigSetup(),
94
95
  configureElasticsearch(),
95
96
  upgradeMagento(),
@@ -6,10 +6,10 @@ const runMagentoCommand = require('../../../util/run-magento');
6
6
  */
7
7
  module.exports = () => ({
8
8
  title: 'Switching Magento mode',
9
- task: async ({ magentoVersion, config: { magentoConfiguration: { mode } } }, task) => {
10
- const { result } = await runMagentoCommand('deploy:mode:show', {
11
- throwNonZeroCode: false,
12
- magentoVersion
9
+ task: async (ctx, task) => {
10
+ const { config: { magentoConfiguration: { mode } } } = ctx;
11
+ const { result } = await runMagentoCommand(ctx, 'deploy:mode:show', {
12
+ throwNonZeroCode: false
13
13
  });
14
14
 
15
15
  if (result.includes(mode)) {
@@ -6,7 +6,7 @@ const getIsWsl = require('../../../util/is-wsl');
6
6
  * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
7
7
  */
8
8
  const varnishConfigSetup = () => ({
9
- title: 'Varnish setup',
9
+ title: 'Varnish Database setup',
10
10
  task: async (ctx, task) => {
11
11
  const {
12
12
  config: {
@@ -19,17 +19,19 @@ const varnishConfigSetup = () => ({
19
19
  }
20
20
  },
21
21
  mysqlConnection,
22
- ports
22
+ ports,
23
+ debug
23
24
  } = ctx;
24
25
 
25
26
  const isLinux = os.platform() === 'linux';
26
27
  const isWsl = await getIsWsl();
28
+ const isNativeLinux = isLinux && !isWsl;
27
29
 
28
- if (varnishEnabled) {
30
+ if (!debug && varnishEnabled) {
29
31
  await updateTableValues('core_config_data', [
30
32
  {
31
33
  path: 'system/full_page_cache/varnish/backend_host',
32
- value: 'localhost'
34
+ value: !isNativeLinux ? 'host.docker.internal' : 'localhost'
33
35
  },
34
36
  {
35
37
  path: 'system/full_page_cache/varnish/backend_port',
@@ -37,7 +39,7 @@ const varnishConfigSetup = () => ({
37
39
  },
38
40
  {
39
41
  path: 'system/full_page_cache/varnish/access_list',
40
- value: (!isLinux || isWsl) ? 'host.docker.internal,localhost' : 'localhost'
42
+ value: !isNativeLinux ? 'host.docker.internal,localhost' : 'localhost'
41
43
  },
42
44
  {
43
45
  path: 'system/full_page_cache/caching_application',