@scandipwa/magento-scripts 2.0.0-alpha.2 → 2.0.0-alpha.20

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 (144) hide show
  1. package/exec.js +71 -0
  2. package/index.js +1 -1
  3. package/lib/commands/cli.js +14 -1
  4. package/lib/commands/execute.js +2 -57
  5. package/lib/commands/start.js +24 -3
  6. package/lib/commands/status.js +9 -1
  7. package/lib/config/config.js +20 -2
  8. package/lib/config/docker.js +86 -53
  9. package/lib/config/get-project-configuration.js +5 -0
  10. package/lib/config/index.js +10 -3
  11. package/lib/config/php/versions/php-7.2.js +1 -0
  12. package/lib/config/php/versions/php-7.3.js +1 -0
  13. package/lib/config/php/versions/php-7.4.js +1 -0
  14. package/lib/config/php/versions/php-8.1.js +1 -0
  15. package/lib/config/php-config.js +4 -3
  16. package/lib/config/port-config.js +3 -1
  17. package/lib/config/services/composer/versions/composer-1.js +13 -0
  18. package/lib/config/services/composer/versions/composer-2.js +8 -0
  19. package/lib/config/services/composer/versions/index.js +4 -0
  20. package/lib/config/services/maildev/index.js +7 -0
  21. package/lib/config/services/nginx/versions/index.js +3 -0
  22. package/lib/config/services/nginx/versions/nginx-1.18.js +11 -0
  23. package/lib/config/{ssl-terminator → services/ssl-terminator}/index.js +3 -0
  24. package/lib/config/templates/magentorc.template +6 -5
  25. package/lib/config/templates/php-debug.template.ini +31 -0
  26. package/lib/config/templates/php-fpm.template.conf +1 -2
  27. package/lib/config/templates/php.template.ini +5 -201
  28. package/lib/config/templates/ssl-terminator.template.conf +10 -3
  29. package/lib/config/templates/varnish.template.vcl +20 -13
  30. package/lib/config/varnish/varnish-6-0.js +4 -0
  31. package/lib/config/varnish/varnish-6-6.js +4 -0
  32. package/lib/config/varnish/varnish-7-0.js +4 -0
  33. package/lib/config/versions/magento-2.2.10.js +41 -0
  34. package/lib/config/versions/magento-2.3.0.js +8 -10
  35. package/lib/config/versions/magento-2.3.1.js +8 -10
  36. package/lib/config/versions/magento-2.3.2-p1.js +8 -10
  37. package/lib/config/versions/magento-2.3.2-p2.js +8 -10
  38. package/lib/config/versions/magento-2.3.2.js +8 -10
  39. package/lib/config/versions/magento-2.3.3-p1.js +8 -10
  40. package/lib/config/versions/magento-2.3.3.js +8 -10
  41. package/lib/config/versions/magento-2.3.4-p1.js +8 -10
  42. package/lib/config/versions/magento-2.3.4-p2.js +8 -10
  43. package/lib/config/versions/magento-2.3.4.js +8 -10
  44. package/lib/config/versions/magento-2.3.5-p1.js +8 -10
  45. package/lib/config/versions/magento-2.3.5-p2.js +8 -10
  46. package/lib/config/versions/magento-2.3.5.js +8 -10
  47. package/lib/config/versions/magento-2.3.6-p1.js +8 -10
  48. package/lib/config/versions/magento-2.3.6.js +8 -10
  49. package/lib/config/versions/magento-2.3.7-p1.js +8 -10
  50. package/lib/config/versions/magento-2.3.7-p2.js +8 -10
  51. package/lib/config/versions/magento-2.3.7-p3.js +8 -10
  52. package/lib/config/versions/magento-2.3.7-p4.js +42 -0
  53. package/lib/config/versions/magento-2.3.7.js +8 -10
  54. package/lib/config/versions/magento-2.4.0-p1.js +8 -10
  55. package/lib/config/versions/magento-2.4.0.js +8 -10
  56. package/lib/config/versions/magento-2.4.1-p1.js +8 -10
  57. package/lib/config/versions/magento-2.4.1.js +8 -10
  58. package/lib/config/versions/magento-2.4.2-p1.js +8 -10
  59. package/lib/config/versions/magento-2.4.2-p2.js +8 -10
  60. package/lib/config/versions/magento-2.4.2.js +8 -10
  61. package/lib/config/versions/magento-2.4.3-p1.js +8 -10
  62. package/lib/config/versions/magento-2.4.3-p2.js +8 -10
  63. package/lib/config/versions/magento-2.4.3-p3.js +44 -0
  64. package/lib/config/versions/magento-2.4.3.js +8 -10
  65. package/lib/config/versions/magento-2.4.4-p1.js +44 -0
  66. package/lib/config/versions/magento-2.4.4.js +8 -10
  67. package/lib/config/versions/magento-2.4.5.js +44 -0
  68. package/lib/tasks/cli/create-bashrc-config.js +1 -1
  69. package/lib/tasks/composer/local-auth-json.js +1 -1
  70. package/lib/tasks/database/connect-to-database.js +6 -3
  71. package/lib/tasks/database/create-magento-database.js +5 -2
  72. package/lib/tasks/database/create-magento-user.js +50 -0
  73. package/lib/tasks/database/default-magento-database.js +3 -0
  74. package/lib/tasks/database/default-magento-user.js +7 -0
  75. package/lib/tasks/database/import-dump-to-database.js +3 -2
  76. package/lib/tasks/docker/api.d.ts +25 -1
  77. package/lib/tasks/docker/api.js +31 -1
  78. package/lib/tasks/docker/containers/container-api.d.ts +21 -0
  79. package/lib/tasks/docker/containers/container-api.js +82 -17
  80. package/lib/tasks/docker/containers/tasks.js +44 -13
  81. package/lib/tasks/docker/convert-composer-home-to-composer-cache-volume.js +52 -0
  82. package/lib/tasks/docker/convert-mysql-to-mariadb.js +2 -2
  83. package/lib/tasks/docker/image/image-api.d.ts +44 -0
  84. package/lib/tasks/docker/image/image-api.js +30 -2
  85. package/lib/tasks/docker/index.js +6 -1
  86. package/lib/tasks/docker/project-image-builder.js +36 -13
  87. package/lib/tasks/docker/system/index.js +5 -0
  88. package/lib/tasks/docker/system/system-api.d.ts +71 -0
  89. package/lib/tasks/docker/system/system-api.js +29 -0
  90. package/lib/tasks/docker/volume/index.js +2 -1
  91. package/lib/tasks/docker/volume/tasks.js +67 -9
  92. package/lib/tasks/docker/volume/volume-api.d.ts +40 -0
  93. package/lib/tasks/docker/volume/volume-api.js +54 -1
  94. package/lib/tasks/execute.js +100 -0
  95. package/lib/tasks/file-system/create-nginx-config.js +3 -5
  96. package/lib/tasks/file-system/create-php-config.js +2 -23
  97. package/lib/tasks/file-system/create-php-debug-config.js +45 -0
  98. package/lib/tasks/file-system/create-php-fpm-config.js +2 -4
  99. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +13 -3
  100. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-workspace-project-configuration-config.js +1 -1
  101. package/lib/tasks/file-system/create-ssl-terminator-config.js +4 -7
  102. package/lib/tasks/file-system/create-varnish-config.js +4 -7
  103. package/lib/tasks/file-system/index.js +2 -0
  104. package/lib/tasks/magento/enable-magento-composer-plugins.js +85 -30
  105. package/lib/tasks/magento/install-magento-project.js +3 -2
  106. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +2 -4
  107. package/lib/tasks/magento/setup-magento/flush-redis-config.js +3 -6
  108. package/lib/tasks/magento/setup-magento/index.js +2 -0
  109. package/lib/tasks/magento/setup-magento/install-magento.js +8 -10
  110. package/lib/tasks/magento/setup-magento/set-base-url.js +1 -1
  111. package/lib/tasks/magento/setup-magento/set-mail-config.js +26 -0
  112. package/lib/tasks/magento/setup-magento/varnish-config.js +4 -9
  113. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +17 -16
  114. package/lib/tasks/php/php-container.js +7 -3
  115. package/lib/tasks/php/update-env-php.js +3 -4
  116. package/lib/tasks/{prefix → project-config}/index.js +6 -6
  117. package/lib/tasks/requirements/composer-credentials.js +7 -3
  118. package/lib/tasks/requirements/docker/context.js +88 -0
  119. package/lib/tasks/requirements/docker/index.js +114 -20
  120. package/lib/tasks/requirements/docker/install.js +21 -7
  121. package/lib/tasks/requirements/docker/permissions.js +2 -11
  122. package/lib/tasks/requirements/docker/running-status.js +94 -24
  123. package/lib/tasks/requirements/docker/version.js +1 -0
  124. package/lib/tasks/requirements/index.js +0 -2
  125. package/lib/tasks/requirements/php-version.js +4 -2
  126. package/lib/tasks/start.js +27 -8
  127. package/lib/tasks/status/index.js +29 -20
  128. package/lib/tasks/stop.js +2 -0
  129. package/lib/tasks/theme/retrieve-theme-data.js +11 -1
  130. package/lib/util/config-file-validator.js +15 -2
  131. package/lib/util/execute-in-container.js +62 -0
  132. package/lib/util/instance-metadata.js +14 -2
  133. package/lib/util/systemctl.js +62 -13
  134. package/package.json +4 -3
  135. package/typings/context.d.ts +11 -0
  136. package/typings/index.d.ts +42 -1
  137. package/lib/tasks/execute/index.js +0 -26
  138. package/lib/tasks/requirements/dependency/arch.js +0 -50
  139. package/lib/tasks/requirements/dependency/centos.js +0 -36
  140. package/lib/tasks/requirements/dependency/fedora.js +0 -36
  141. package/lib/tasks/requirements/dependency/index.js +0 -33
  142. package/lib/tasks/requirements/dependency/mac.js +0 -124
  143. package/lib/tasks/requirements/dependency/ubuntu.js +0 -83
  144. package/yarn-error.log +0 -9660
@@ -37,3 +37,43 @@ export function create(
37
37
  options?: VolumeCreateOptions,
38
38
  execOptions?: ExecAsyncSpawnOptions<false>
39
39
  ): Promise<string>
40
+
41
+ export interface VolumeRmOptions {
42
+ force?: boolean
43
+ volumes: string[]
44
+ }
45
+
46
+ export function rm(
47
+ options?: VolumeRmOptions,
48
+ execOptions?: ExecAsyncSpawnOptions<false>
49
+ ): Promise<string>
50
+
51
+ export interface VolumeInspectOptions<T extends boolean = false> {
52
+ volume: string
53
+ format?: string
54
+ formatToJSON?: T
55
+ }
56
+
57
+ export interface VolumeInspectResult {
58
+ CreatedAt: string
59
+ Driver: string
60
+ Labels: unknown
61
+ Mountpoint: string
62
+ Name: string
63
+ Options: unknown
64
+ Scope: string
65
+ CreatedTime: number
66
+ Containers: Record<string, {
67
+ Name: string
68
+ Destination: string
69
+ }>
70
+ }
71
+
72
+ export function inspect(
73
+ options?: VolumeInspectOptions,
74
+ execOptions?: ExecAsyncSpawnOptions<false>
75
+ ): Promise<string>
76
+ export function inspect(
77
+ options?: VolumeInspectOptions<true>,
78
+ execOptions?: ExecAsyncSpawnOptions<false>
79
+ ): Promise<VolumeInspectResult>
@@ -60,7 +60,60 @@ const ls = async (options, execOptions = {}) => {
60
60
  return execAsyncSpawn(`docker volume ls ${args}`, execOptions);
61
61
  };
62
62
 
63
+ /**
64
+ * @param {import('./volume-api').VolumeRmOptions} options
65
+ * @param {import('../../../util/exec-async-command').ExecAsyncSpawnOptions} execOptions
66
+ */
67
+ const rm = async (options, execOptions = {}) => {
68
+ const {
69
+ force,
70
+ volumes
71
+ } = options;
72
+
73
+ const forceArg = force && '--force';
74
+
75
+ const command = [
76
+ 'docker',
77
+ 'volume',
78
+ 'rm',
79
+ forceArg,
80
+ ...volumes
81
+ ].filter(Boolean).join(' ');
82
+
83
+ return execAsyncSpawn(command, execOptions);
84
+ };
85
+
86
+ /**
87
+ * @param {import('./volume-api').VolumeInspectOptions} options
88
+ * @param {import('../../../util/exec-async-command').ExecAsyncSpawnOptions} execOptions
89
+ */
90
+ const inspect = async (options, execOptions = {}) => {
91
+ const {
92
+ volume,
93
+ format,
94
+ formatToJSON = false
95
+ } = options;
96
+
97
+ const formatArg = !formatToJSON && format
98
+ ? `--format=${format}`
99
+ : formatToJSON && '--format=\'{{json .}}\'';
100
+
101
+ const args = [
102
+ formatArg,
103
+ volume
104
+ ].filter(Boolean).join(' ');
105
+
106
+ if (formatToJSON) {
107
+ const result = await execAsyncSpawn(`docker volume inspect ${args}`, execOptions);
108
+ return JSON.parse(result);
109
+ }
110
+
111
+ return execAsyncSpawn(`docker volume inspect ${args}`, execOptions);
112
+ };
113
+
63
114
  module.exports = {
64
115
  create,
65
- ls
116
+ ls,
117
+ rm,
118
+ inspect
66
119
  };
@@ -0,0 +1,100 @@
1
+ const { Listr } = require('listr2');
2
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
3
+ const { checkRequirements } = require('./requirements');
4
+ const getMagentoVersionConfig = require('../config/get-magento-version-config');
5
+ const checkConfigurationFile = require('../config/check-configuration-file');
6
+ const getProjectConfiguration = require('../config/get-project-configuration');
7
+ const { getCachedPorts } = require('../config/get-port-config');
8
+ const { executeInContainer, runInContainer } = require('../util/execute-in-container');
9
+ const { containerApi } = require('./docker/containers');
10
+ const dockerNetwork = require('./docker/network');
11
+ const KnownError = require('../errors/known-error');
12
+
13
+ /**
14
+ *
15
+ * @param {{ containername: string, commands?: string[] }} argv
16
+ * @returns
17
+ */
18
+ const executeTask = async (argv) => {
19
+ const tasks = new Listr([
20
+ checkRequirements(),
21
+ getMagentoVersionConfig(),
22
+ checkConfigurationFile(),
23
+ getProjectConfiguration(),
24
+ getCachedPorts(),
25
+ dockerNetwork.tasks.createNetwork()
26
+ ], {
27
+ concurrent: false,
28
+ exitOnError: true,
29
+ ctx: { throwMagentoVersionMissing: true },
30
+ rendererOptions: { collapse: false, clearOutput: true }
31
+ });
32
+
33
+ let ctx;
34
+ try {
35
+ ctx = await tasks.run();
36
+ } catch (e) {
37
+ logger.error(e.message || e);
38
+ process.exit(1);
39
+ }
40
+ const containers = ctx.config.docker.getContainers(ctx.ports);
41
+ const services = Object.keys(containers);
42
+
43
+ if (services.includes(argv.containername) || services.some((service) => service.includes(argv.containername))) {
44
+ /**
45
+ * @type {import('./docker/containers/container-api').ContainerRunOptions}
46
+ */
47
+ const container = containers[argv.containername]
48
+ ? containers[argv.containername]
49
+ : Object.entries(containers).find(([key]) => key.includes(argv.containername))[1];
50
+
51
+ if (argv.commands.length === 0) {
52
+ // if we have default connect command then use it
53
+ if (container.connectCommand) {
54
+ // eslint-disable-next-line no-param-reassign
55
+ argv.commands = container.connectCommand;
56
+ } else {
57
+ // otherwise fall back to bash (if it exists inside container)
58
+ argv.commands.push('bash');
59
+ }
60
+ }
61
+
62
+ const containerList = await containerApi.ls({
63
+ formatToJSON: true,
64
+ all: true,
65
+ filter: `name=${container.name}`
66
+ });
67
+
68
+ if (containerList.length > 0) {
69
+ logger.logN(`Executing container ${logger.style.misc(container._)} (command: ${logger.style.command(argv.commands.join(' '))})`);
70
+ const result = await executeInContainer({
71
+ containerName: container.name,
72
+ commands: argv.commands,
73
+ user: container.user
74
+ });
75
+
76
+ return result;
77
+ }
78
+
79
+ if (container.name.endsWith('php')) {
80
+ logger.logN(`Starting container ${logger.style.misc(container._)} with command: ${logger.style.command(argv.commands.join(' '))}`);
81
+ const result = await runInContainer(
82
+ {
83
+ ...container,
84
+ name: `${container.name}_exec-${Date.now()}`
85
+ },
86
+ argv.commands
87
+ );
88
+
89
+ return result;
90
+ }
91
+
92
+ throw new KnownError(`Container ${container.name} is not running!`);
93
+ }
94
+
95
+ logger.error(`No container found "${argv.containername}"`);
96
+ };
97
+
98
+ module.exports = {
99
+ executeTask
100
+ };
@@ -14,7 +14,7 @@ const createNginxConfig = () => ({
14
14
  overridenConfiguration,
15
15
  baseConfig
16
16
  },
17
- isWsl
17
+ isDockerDesktop
18
18
  } = ctx;
19
19
 
20
20
  const {
@@ -23,10 +23,8 @@ const createNginxConfig = () => ({
23
23
  }
24
24
  } = overridenConfiguration;
25
25
 
26
- const isLinux = ctx.platform === 'linux';
27
- const isNativeLinux = isLinux && !isWsl;
28
- const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
29
- const hostPort = isNativeLinux ? ports.app : 80;
26
+ const hostMachine = !isDockerDesktop ? '127.0.0.1' : 'host.docker.internal';
27
+ const hostPort = !isDockerDesktop ? ports.app : 80;
30
28
 
31
29
  try {
32
30
  await setConfigFile({
@@ -1,7 +1,5 @@
1
- const semver = require('semver');
2
1
  const UnknownError = require('../../errors/unknown-error');
3
2
  const setConfigFile = require('../../util/set-config');
4
- const { getEnabledExtensionsFromImage } = require('../docker/project-image-builder');
5
3
 
6
4
  /**
7
5
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
@@ -9,32 +7,13 @@ const { getEnabledExtensionsFromImage } = require('../docker/project-image-build
9
7
  const createPhpConfig = () => ({
10
8
  title: 'Setting PHP config',
11
9
  task: async (ctx) => {
12
- const {
13
- config: {
14
- php,
15
- baseConfig
16
- },
17
- debug
18
- } = ctx;
19
- const containers = ctx.config.docker.getContainers(ctx.ports);
20
- const phpExtensions = await getEnabledExtensionsFromImage(containers.php.debugImage);
21
- const isXDebug2 = semver.satisfies(phpExtensions.xdebug, '2');
22
-
23
- const isLinux = ctx.platform === 'linux';
24
- const isNativeLinux = isLinux && !ctx.isWsl;
25
- const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
10
+ const { config: { php } } = ctx;
26
11
 
27
12
  try {
28
13
  await setConfigFile({
29
14
  configPathname: php.iniPath,
30
15
  template: php.iniTemplatePath,
31
- overwrite: true,
32
- templateArgs: {
33
- debug,
34
- mageRoot: baseConfig.containerMagentoDir,
35
- isXDebug2,
36
- hostMachine
37
- }
16
+ overwrite: true
38
17
  });
39
18
  } catch (e) {
40
19
  throw new UnknownError(`Unexpected error accrued during php.ini config creation\n\n${e}`);
@@ -0,0 +1,45 @@
1
+ const semver = require('semver');
2
+ const UnknownError = require('../../errors/unknown-error');
3
+ const setConfigFile = require('../../util/set-config');
4
+ const { getEnabledExtensionsFromImage } = require('../docker/project-image-builder');
5
+
6
+ /**
7
+ * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
8
+ */
9
+ const createPhpDebugConfig = () => ({
10
+ title: 'Setting PHP XDebug config',
11
+ skip: (ctx) => !ctx.debug,
12
+ task: async (ctx) => {
13
+ const {
14
+ config: {
15
+ php,
16
+ baseConfig
17
+ },
18
+ debug,
19
+ isDockerDesktop
20
+ } = ctx;
21
+ const containers = ctx.config.docker.getContainers(ctx.ports);
22
+ const phpExtensions = await getEnabledExtensionsFromImage(containers.php.debugImage);
23
+ const isXDebug2 = semver.satisfies(phpExtensions.xdebug, '2');
24
+
25
+ const hostMachine = !isDockerDesktop ? '127.0.0.1' : 'host.docker.internal';
26
+
27
+ try {
28
+ await setConfigFile({
29
+ configPathname: php.debugIniPath,
30
+ template: php.debugTemplatePath,
31
+ overwrite: true,
32
+ templateArgs: {
33
+ debug,
34
+ mageRoot: baseConfig.containerMagentoDir,
35
+ isXDebug2,
36
+ hostMachine
37
+ }
38
+ });
39
+ } catch (e) {
40
+ throw new UnknownError(`Unexpected error accrued during xdebug.ini config creation\n\n${e}`);
41
+ }
42
+ }
43
+ });
44
+
45
+ module.exports = createPhpDebugConfig;
@@ -7,10 +7,8 @@ const setConfigFile = require('../../util/set-config');
7
7
  const createPhpFpmConfig = () => ({
8
8
  title: 'Setting php-fpm config',
9
9
  task: async (ctx) => {
10
- const { config: { php } } = ctx;
11
- const isLinux = ctx.platform === 'linux';
12
- const isNativeLinux = isLinux && !ctx.isWsl;
13
- const port = isNativeLinux ? ctx.ports.fpm : 9000;
10
+ const { config: { php }, isDockerDesktop } = ctx;
11
+ const port = !isDockerDesktop ? ctx.ports.fpm : 9000;
14
12
 
15
13
  try {
16
14
  await setConfigFile({
@@ -26,11 +26,21 @@ const mustBeIncludedPaths = [
26
26
  /**
27
27
  * Will retrieve project config file path from module.xml
28
28
  *
29
- * @returns {Promise<String>}
29
+ * @returns {Promise<String | null>}
30
30
  */
31
31
  const getProjectConfigFilePath = async () => {
32
32
  const modulesConfigData = await loadXmlFile(pathToModulesConfig);
33
- return modulesConfigData.project.component.modules.module['@_filepath'].replace('$PROJECT_DIR$', process.cwd());
33
+ const {
34
+ project: {
35
+ component: {
36
+ modules: {
37
+ module
38
+ } = {}
39
+ } = {}
40
+ } = {}
41
+ } = modulesConfigData || {};
42
+ const filePath = module && module['@_filepath'];
43
+ return filePath ? filePath.replace('$PROJECT_DIR$', process.cwd()) : null;
34
44
  };
35
45
 
36
46
  const setupDefaultsForExcludedFoldersConfig = (projectConfigData) => {
@@ -138,7 +148,7 @@ const setupExcludedFoldersConfig = () => ({
138
148
  task: async (ctx, task) => {
139
149
  if (await pathExists(pathToModulesConfig)) {
140
150
  const projectFilePath = await getProjectConfigFilePath();
141
- if (await pathExists(projectFilePath)) {
151
+ if (projectFilePath && await pathExists(projectFilePath)) {
142
152
  const projectConfigData = await loadXmlFile(projectFilePath);
143
153
  setupDefaultsForExcludedFoldersConfig(projectConfigData);
144
154
  const hasChanges = setupExcludedFolders(projectConfigData);
@@ -31,7 +31,7 @@ const setupPHPWorkspaceProjectConfiguration = async (workspaceConfigs, ctx) => {
31
31
  hasChanges = true;
32
32
  workspaceConfigs.push({
33
33
  [nameKey]: PHP_WORKSPACE_PROJECT_CONFIGURATION_COMPONENT_NAME,
34
- [currentInterpreterImage]: currentInterpreterImage,
34
+ [interpreterNameKey]: currentInterpreterImage,
35
35
  include_path: []
36
36
  });
37
37
  }
@@ -1,4 +1,3 @@
1
- const os = require('os');
2
1
  const path = require('path');
3
2
  const fs = require('fs');
4
3
  const setConfigFile = require('../../util/set-config');
@@ -19,8 +18,8 @@ const createSSLTerminatorConfig = () => ({
19
18
  overridenConfiguration,
20
19
  baseConfig
21
20
  },
22
- isWsl,
23
- debug
21
+ debug,
22
+ isDockerDesktop
24
23
  } = ctx;
25
24
 
26
25
  const {
@@ -65,10 +64,8 @@ const createSSLTerminatorConfig = () => ({
65
64
  }
66
65
 
67
66
  const networkToBindTo = isIpAddress(host) ? host : '127.0.0.1';
68
- const isLinux = os.platform() === 'linux';
69
- const isNativeLinux = isLinux && !isWsl;
70
- const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
71
- const hostPort = isNativeLinux ? ports.sslTerminator : 80;
67
+ const hostMachine = !isDockerDesktop ? '127.0.0.1' : 'host.docker.internal';
68
+ const hostPort = !isDockerDesktop ? ports.sslTerminator : 80;
72
69
 
73
70
  try {
74
71
  await setConfigFile({
@@ -17,8 +17,7 @@ const createVarnishConfig = () => ({
17
17
  cacheDir
18
18
  }
19
19
  },
20
- isWsl,
21
- platform
20
+ isDockerDesktop
22
21
  } = ctx;
23
22
 
24
23
  const {
@@ -27,9 +26,6 @@ const createVarnishConfig = () => ({
27
26
  }
28
27
  } = overridenConfiguration;
29
28
 
30
- const isLinux = platform === 'linux';
31
- const isNativeLinux = isLinux && !isWsl;
32
-
33
29
  try {
34
30
  await setConfigFile({
35
31
  configPathname: path.join(
@@ -40,8 +36,9 @@ const createVarnishConfig = () => ({
40
36
  template: varnish.configTemplate,
41
37
  overwrite: true,
42
38
  templateArgs: {
43
- hostMachine: isNativeLinux ? '127.0.0.1' : 'host.docker.internal',
44
- nginxPort: ports.app
39
+ hostMachine: !isDockerDesktop ? '127.0.0.1' : 'host.docker.internal',
40
+ nginxPort: ports.app,
41
+ healthCheck: varnish.healthCheck
45
42
  }
46
43
  });
47
44
  } catch (e) {
@@ -1,6 +1,7 @@
1
1
  const createMariaDBConfig = require('./create-mariadb-config');
2
2
  const createNginxConfig = require('./create-nginx-config');
3
3
  const createPhpConfig = require('./create-php-config');
4
+ const createPhpDebugConfig = require('./create-php-debug-config');
4
5
  const createPhpFpmConfig = require('./create-php-fpm-config');
5
6
  const createPhpStormConfig = require('./create-phpstorm-config');
6
7
  const createSSLTerminatorConfig = require('./create-ssl-terminator-config');
@@ -17,6 +18,7 @@ const prepareFileSystem = () => ({
17
18
  createNginxConfig(),
18
19
  createPhpFpmConfig(),
19
20
  createPhpConfig(),
21
+ createPhpDebugConfig(),
20
22
  createPhpStormConfig(),
21
23
  createVSCodeConfig(),
22
24
  createVarnishConfig(),
@@ -4,7 +4,6 @@ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
4
4
  const semver = require('semver');
5
5
  const pathExists = require('../../util/path-exists');
6
6
  const getJsonfileData = require('../../util/get-jsonfile-data');
7
- const KnownError = require('../../errors/known-error');
8
7
 
9
8
  const vendorPath = path.join(process.cwd(), 'vendor');
10
9
  const composerJsonPath = path.join(process.cwd(), 'composer.json');
@@ -86,29 +85,80 @@ const enableMagentoComposerPlugins = () => ({
86
85
  } = composerJsonData;
87
86
  const allowPluginsKeys = Object.keys(allowPlugins);
88
87
 
88
+ const missingPluginsFromAllowPlugins = composerPlugins.filter((plugin) => {
89
+ const [pluginVendor, pluginName] = plugin.split('/');
90
+ return !allowPluginsKeys.some((allowedPlugin) => {
91
+ const [allowedPluginVendor, allowedPluginName] = allowedPlugin.split('/');
92
+ if (allowedPluginVendor === pluginVendor) {
93
+ if (allowedPluginName === '*') {
94
+ return true;
95
+ }
96
+
97
+ return allowedPluginName === pluginName;
98
+ }
99
+
100
+ return false;
101
+ });
102
+ });
103
+
89
104
  if (
90
105
  allowPluginsKeys.length === 0
91
- || composerPlugins.some((p) => !allowPluginsKeys.includes(p))
106
+ || missingPluginsFromAllowPlugins.length > 0
92
107
  ) {
93
- const missingPlugins = composerPlugins.filter((p) => !allowPluginsKeys.includes(p));
108
+ const missingVendors = missingPluginsFromAllowPlugins.reduce((acc, val) => {
109
+ const [pluginVendor] = val.split('/');
110
+
111
+ if (acc.length === 0) {
112
+ return [pluginVendor];
113
+ }
114
+
115
+ if (!acc.includes(pluginVendor)) {
116
+ return [...acc, pluginVendor];
117
+ }
118
+
119
+ return acc;
120
+ }, []);
121
+
122
+ const pluginOptions = [
123
+ {
124
+ name: 'all-individual',
125
+ message: 'Enable all individually'
126
+ },
127
+ {
128
+ name: 'manual',
129
+ message: 'Configure manually'
130
+ },
131
+ {
132
+ name: 'skip',
133
+ message: 'Skip this step'
134
+ }
135
+ ];
136
+
137
+ if (missingVendors.length === 1) {
138
+ pluginOptions.unshift({
139
+ name: 'all',
140
+ message: `Enable all (${logger.style.code(`"${missingVendors[0]}/*"`)})`
141
+ });
142
+ }
143
+
94
144
  const answerForEnablingPlugins = await task.prompt({
95
145
  type: 'Select',
96
146
  message: `Composer 2.2 requires manually allowing composer-plugins to run.
97
147
  Magento requires the following plugins to correctly operate:
98
148
 
99
- ${missingPlugins.map((p) => logger.style.code(p)).join('\n')}
149
+ ${missingPluginsFromAllowPlugins.map((p) => logger.style.code(p)).join('\n')}
100
150
 
101
151
  Do you want to enable them all or disable some of them?`,
102
- choices: ['Enable all', 'Configure manually', 'Skip this step']
152
+ choices: pluginOptions
103
153
  });
104
154
 
105
155
  switch (answerForEnablingPlugins.toLowerCase()) {
106
- case 'enable all': {
156
+ case 'all': {
107
157
  composerJsonData.config = {
108
158
  ...(composerJsonData.config || {}),
109
159
  'allow-plugins': {
110
160
  ...allowPlugins,
111
- ...missingPlugins.reduce((acc, val) => ({ ...acc, [val]: true }), {})
161
+ [`${missingVendors[0]}/*`]: true
112
162
  }
113
163
  };
114
164
 
@@ -117,36 +167,41 @@ Do you want to enable them all or disable some of them?`,
117
167
  });
118
168
  break;
119
169
  }
120
- case 'configure manually': {
170
+ case 'all-individual': {
171
+ composerJsonData.config = {
172
+ ...(composerJsonData.config || {}),
173
+ 'allow-plugins': {
174
+ ...allowPlugins,
175
+ ...missingPluginsFromAllowPlugins.reduce((acc, val) => ({ ...acc, [val]: true }), {})
176
+ }
177
+ };
178
+
179
+ await fs.promises.writeFile(composerJsonPath, JSON.stringify(composerJsonData, null, 4), {
180
+ encoding: 'utf-8'
181
+ });
182
+ break;
183
+ }
184
+ case 'manual': {
121
185
  const userEnabledPlugins = await task.prompt({
122
186
  type: 'MultiSelect',
123
187
  message: 'Please pick plugins you want to enable!',
124
- choices: missingPlugins.map((p) => ({ name: p }))
188
+ choices: missingPluginsFromAllowPlugins.map((p) => ({ name: p }))
125
189
  });
126
190
 
127
- const userConfirmation = await task.prompt({
128
- type: 'Confirm',
129
- message: `Please confirm enabling of the following plugins:\n\n${userEnabledPlugins.map((p) => logger.style.code(p)).join('\n')}\n`
130
- });
191
+ const disabledPlugins = composerPlugins.filter((p) => !userEnabledPlugins.includes(p));
131
192
 
132
- if (userConfirmation) {
133
- const disabledPlugins = composerPlugins.filter((p) => !userEnabledPlugins.includes(p));
134
-
135
- composerJsonData.config = {
136
- ...(composerJsonData.config || {}),
137
- 'allow-plugins': {
138
- ...allowPlugins,
139
- ...disabledPlugins.reduce((acc, val) => ({ ...acc, [val]: false }), {}),
140
- ...userEnabledPlugins.reduce((acc, val) => ({ ...acc, [val]: true }), {})
141
- }
142
- };
193
+ composerJsonData.config = {
194
+ ...(composerJsonData.config || {}),
195
+ 'allow-plugins': {
196
+ ...allowPlugins,
197
+ ...disabledPlugins.reduce((acc, val) => ({ ...acc, [val]: false }), {}),
198
+ ...userEnabledPlugins.reduce((acc, val) => ({ ...acc, [val]: true }), {})
199
+ }
200
+ };
143
201
 
144
- await fs.promises.writeFile(composerJsonPath, JSON.stringify(composerJsonData, null, 4), {
145
- encoding: 'utf-8'
146
- });
147
- } else {
148
- throw new KnownError('Please confirm your choice or choose other option.');
149
- }
202
+ await fs.promises.writeFile(composerJsonPath, JSON.stringify(composerJsonData, null, 4), {
203
+ encoding: 'utf-8'
204
+ });
150
205
 
151
206
  break;
152
207
  }
@@ -97,8 +97,9 @@ const createMagentoProject = async (ctx, task, {
97
97
  `"${tempDir}"`
98
98
  ];
99
99
 
100
- await runPHPContainerCommand(ctx, `composer ${installCommand.join(' ')} \n
101
- && mv ${tempDir}/composer.json ${ctx.config.baseConfig.containerMagentoDir}/composer.json`);
100
+ await runPHPContainerCommand(ctx, `bash -c 'mkdir ${tempDir} && \
101
+ composer ${installCommand.join(' ')} && \
102
+ mv ${tempDir}/composer.json ${ctx.config.baseConfig.containerMagentoDir}/composer.json'`);
102
103
  };
103
104
 
104
105
  /**
@@ -7,10 +7,8 @@ module.exports = () => ({
7
7
  title: 'Configuring Elasticsearch',
8
8
  skip: async (ctx) => !(await isTableExists('magento', 'core_config_data', ctx)),
9
9
  task: async (ctx, task) => {
10
- const { ports, databaseConnection } = 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
+ const { ports, databaseConnection, isDockerDesktop } = ctx;
11
+ const hostMachine = !isDockerDesktop ? '127.0.0.1' : 'host.docker.internal';
14
12
  await updateTableValues('core_config_data', [
15
13
  { path: 'catalog/search/engine', value: 'elasticsearch7' },
16
14
  { path: 'catalog/search/elasticsearch7_server_hostname', value: hostMachine },
@@ -1,18 +1,15 @@
1
1
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
2
- const os = require('os');
3
2
  const UnknownError = require('../../../errors/unknown-error');
4
3
 
5
- const isLinux = os.platform() === 'linux';
6
-
7
4
  /**
8
5
  * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
9
6
  */
10
7
  module.exports = () => ({
11
8
  title: 'Flushing Magento redis cache',
12
- task: async ({ ports, config: { docker } }) => {
9
+ task: async ({ ports, config: { docker }, isDockerDesktop }) => {
13
10
  const { redis: { name } } = docker.getContainers(ports);
14
- const host = isLinux ? 'localhost' : 'host.docker.internal';
15
- const port = isLinux ? '6379' : ports.redis;
11
+ const host = !isDockerDesktop ? 'localhost' : 'host.docker.internal';
12
+ const port = !isDockerDesktop ? '6379' : ports.redis;
16
13
  const result = await execAsyncSpawn(`docker exec ${ name } redis-cli -h ${ host } -p ${ port } -n 0 flushdb`);
17
14
 
18
15
  if (!result.trim().includes('OK')) {