@scandipwa/magento-scripts 1.14.1-alpha.0 → 1.14.1-alpha.11

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 (146) 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/dependencies-for-platforms.js +12 -2
  7. package/lib/config/docker.js +89 -15
  8. package/lib/config/get-port-config.js +9 -3
  9. package/lib/config/index.js +2 -1
  10. package/lib/config/php/extensions/libsodium.js +2 -1
  11. package/lib/config/port-config.js +3 -1
  12. package/lib/config/scandipwa-versions.js +2 -1
  13. package/lib/config/ssl-terminator/index.js +10 -0
  14. package/lib/config/system-config.js +34 -5
  15. package/lib/config/templates/magentorc.template +3 -5
  16. package/lib/config/templates/nginx.template.conf +0 -14
  17. package/lib/config/templates/php.template.ini +6 -4
  18. package/lib/config/templates/ssl-terminator.template.conf +27 -0
  19. package/lib/config/templates/varnish.template.vcl +250 -0
  20. package/lib/config/varnish/varnish-6-0.js +11 -0
  21. package/lib/config/varnish/varnish-6-6.js +11 -0
  22. package/lib/config/varnish/varnish-7-0.js +11 -0
  23. package/lib/config/versions/magento-2.3.0.js +9 -1
  24. package/lib/config/versions/magento-2.3.1.js +9 -1
  25. package/lib/config/versions/magento-2.3.2-p2.js +9 -1
  26. package/lib/config/versions/magento-2.3.2.js +9 -1
  27. package/lib/config/versions/magento-2.3.3-p1.js +9 -1
  28. package/lib/config/versions/magento-2.3.3.js +9 -1
  29. package/lib/config/versions/magento-2.3.4-p2.js +9 -1
  30. package/lib/config/versions/magento-2.3.4.js +9 -1
  31. package/lib/config/versions/magento-2.3.5-p1.js +9 -1
  32. package/lib/config/versions/magento-2.3.5-p2.js +9 -1
  33. package/lib/config/versions/magento-2.3.5.js +9 -1
  34. package/lib/config/versions/magento-2.3.6-p1.js +9 -1
  35. package/lib/config/versions/magento-2.3.6.js +9 -1
  36. package/lib/config/versions/magento-2.3.7-p1.js +9 -1
  37. package/lib/config/versions/magento-2.3.7-p2.js +9 -1
  38. package/lib/config/versions/magento-2.3.7-p3.js +9 -1
  39. package/lib/config/versions/magento-2.3.7.js +9 -1
  40. package/lib/config/versions/magento-2.4.0-p1.js +9 -1
  41. package/lib/config/versions/magento-2.4.0.js +9 -1
  42. package/lib/config/versions/magento-2.4.1-p1.js +9 -1
  43. package/lib/config/versions/magento-2.4.1.js +9 -1
  44. package/lib/config/versions/magento-2.4.2-p1.js +9 -1
  45. package/lib/config/versions/magento-2.4.2-p2.js +9 -1
  46. package/lib/config/versions/magento-2.4.2.js +9 -1
  47. package/lib/config/versions/magento-2.4.3-p1.js +9 -1
  48. package/lib/config/versions/magento-2.4.3-p2.js +9 -1
  49. package/lib/config/versions/magento-2.4.3.js +9 -1
  50. package/lib/config/versions/magento-2.4.4.js +9 -1
  51. package/lib/errors/known-error.js +15 -0
  52. package/lib/errors/unknown-error.js +15 -0
  53. package/lib/tasks/cli/create-bashrc-config.js +7 -3
  54. package/lib/tasks/composer/index.js +5 -3
  55. package/lib/tasks/composer/local-auth-json.js +4 -2
  56. package/lib/tasks/docker/containers.js +13 -8
  57. package/lib/tasks/docker/network.js +2 -1
  58. package/lib/tasks/docker/volumes.js +4 -4
  59. package/lib/tasks/file-system/create-nginx-config.js +9 -40
  60. package/lib/tasks/file-system/create-php-config.js +2 -1
  61. package/lib/tasks/file-system/create-php-fpm-config.js +2 -1
  62. package/lib/tasks/file-system/create-php-storm-config.js +6 -5
  63. package/lib/tasks/file-system/create-ssl-terminator-config.js +96 -0
  64. package/lib/tasks/file-system/create-varnish-config.js +53 -0
  65. package/lib/tasks/file-system/create-vscode-config.js +3 -2
  66. package/lib/tasks/file-system/index.js +5 -1
  67. package/lib/tasks/magento/enable-magento-composer-plugins.js +3 -2
  68. package/lib/tasks/magento/install-magento.js +7 -5
  69. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +1 -1
  70. package/lib/tasks/magento/setup-magento/disable-2fa.js +4 -12
  71. package/lib/tasks/magento/setup-magento/disable-full-page-cache.js +20 -0
  72. package/lib/tasks/magento/setup-magento/flush-redis-config.js +2 -1
  73. package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +14 -16
  74. package/lib/tasks/magento/setup-magento/index.js +3 -1
  75. package/lib/tasks/magento/setup-magento/install-magento.js +2 -1
  76. package/lib/tasks/magento/setup-magento/migrate-database.js +24 -11
  77. package/lib/tasks/magento/setup-magento/set-base-url.js +7 -2
  78. package/lib/tasks/magento/setup-magento/upgrade-magento.js +27 -3
  79. package/lib/tasks/magento/setup-magento/varnish-config.js +69 -0
  80. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +41 -0
  81. package/lib/tasks/mysql/connect-to-mysql.js +2 -1
  82. package/lib/tasks/mysql/fix-db.js +2 -2
  83. package/lib/tasks/mysql/import-dump-to-mysql.js +4 -2
  84. package/lib/tasks/mysql/import-remote-db/index.js +2 -1
  85. package/lib/tasks/mysql/import-remote-db/ssh/index.js +2 -1
  86. package/lib/tasks/mysql/import-remote-db/ssh/regular-server.js +2 -1
  87. package/lib/tasks/php/bundled-extensions.js +28 -0
  88. package/lib/tasks/php/compile-options.js +18 -48
  89. package/lib/tasks/php/compile.js +4 -3
  90. package/lib/tasks/php/configure.js +7 -66
  91. package/lib/tasks/php/extensions/index.js +71 -0
  92. package/lib/tasks/php/index.js +8 -7
  93. package/lib/tasks/php/update-env-php.js +16 -1
  94. package/lib/tasks/php/update-env.php +56 -12
  95. package/lib/tasks/php/update-phpbrew.js +2 -1
  96. package/lib/tasks/php/validate-php.js +67 -0
  97. package/lib/tasks/php-fpm/start-php-fpm.js +2 -1
  98. package/lib/tasks/requirements/composer.js +5 -3
  99. package/lib/tasks/requirements/dependency/arch.js +2 -1
  100. package/lib/tasks/requirements/dependency/centos.js +2 -1
  101. package/lib/tasks/requirements/dependency/fedora.js +2 -1
  102. package/lib/tasks/requirements/docker/index.js +7 -4
  103. package/lib/tasks/requirements/docker/install.js +13 -12
  104. package/lib/tasks/requirements/docker/running-status.js +138 -0
  105. package/lib/tasks/requirements/docker/version.js +3 -0
  106. package/lib/tasks/requirements/index.js +5 -5
  107. package/lib/tasks/requirements/node-version.js +2 -1
  108. package/lib/tasks/requirements/php-version.js +8 -4
  109. package/lib/tasks/requirements/phpbrew/index.js +2 -1
  110. package/lib/tasks/requirements/phpbrew/install.js +2 -1
  111. package/lib/tasks/requirements/phpbrew/version.js +2 -1
  112. package/lib/tasks/requirements/platform.js +3 -2
  113. package/lib/tasks/start.js +11 -10
  114. package/lib/tasks/status/index.js +25 -9
  115. package/lib/tasks/theme/build-theme.js +27 -8
  116. package/lib/tasks/theme/install-theme.js +18 -5
  117. package/lib/tasks/theme/link-theme.js +2 -2
  118. package/lib/tasks/theme/retrieve-theme-data.js +2 -1
  119. package/lib/tasks/theme/setup-persisted-query.js +5 -4
  120. package/lib/tasks/theme/setup-themes.js +5 -3
  121. package/lib/tasks/theme/symlink-theme.js +20 -4
  122. package/lib/util/analytics.js +337 -0
  123. package/lib/util/config-file-validator.js +14 -2
  124. package/lib/util/config-php-json.js +20 -0
  125. package/lib/util/env-php-json.js +3 -2
  126. package/lib/util/get-installed-magento-version.js +3 -2
  127. package/lib/util/get-jsonfile-data.js +2 -1
  128. package/lib/util/install-dependencies-task.js +4 -4
  129. package/lib/util/instance-metadata.js +11 -4
  130. package/lib/util/ip.js +45 -1
  131. package/lib/util/is-running-root.js +3 -0
  132. package/lib/util/magento-task.js +20 -9
  133. package/lib/util/match-filesystem.js +2 -1
  134. package/lib/util/php-task.js +6 -2
  135. package/lib/util/request.js +0 -0
  136. package/lib/util/resolve-configuration-with-overrides.js +2 -1
  137. package/lib/util/run-composer.js +3 -2
  138. package/lib/util/run-magento.js +3 -2
  139. package/lib/util/run-php.js +10 -3
  140. package/lib/util/systemctl.js +46 -0
  141. package/lib/util/wait-for-it.js +3 -2
  142. package/package.json +4 -3
  143. package/typings/context.d.ts +5 -1
  144. package/typings/index.d.ts +32 -1
  145. package/lib/tasks/magento/setup-magento/adjust-magento-configuration.js +0 -27
  146. package/lib/tasks/magento/setup-magento/disable-page-cache.js +0 -11
@@ -1,7 +1,10 @@
1
1
  const runPhpCode = require('./run-php');
2
2
 
3
3
  /**
4
- * @type {(command: string, options: { noTitle: boolean }) => import('listr2').ListrTask<import('../../typings/context').ListrContext>}
4
+ * @type {(
5
+ * command: string,
6
+ * options: { noTitle: boolean, env: Record<string, string> }
7
+ * ) => import('listr2').ListrTask<import('../../typings/context').ListrContext>}
5
8
  */
6
9
  const phpTask = (command, options = {}) => ({
7
10
  title: !options.noTitle ? `Running command 'php ${command}` : undefined,
@@ -10,7 +13,8 @@ const phpTask = (command, options = {}) => ({
10
13
  task.output = t;
11
14
  },
12
15
  throwNonZeroCode: true,
13
- magentoVersion
16
+ magentoVersion,
17
+ env: options.env
14
18
  })
15
19
  });
16
20
 
File without changes
@@ -1,4 +1,5 @@
1
1
  const path = require('path');
2
+ const UnknownError = require('../errors/unknown-error');
2
3
  const { configFileSchema } = require('./config-file-validator');
3
4
  const { deepmerge } = require('./deepmerge');
4
5
  const pathExists = require('./path-exists');
@@ -11,7 +12,7 @@ const resolveConfigurationWithOverrides = async (configuration, baseConfig, proj
11
12
  try {
12
13
  await configFileSchema.validateAsync(userConfiguration);
13
14
  } catch (e) {
14
- throw new Error(`Configuration file validation error!\n\n${e.message}`);
15
+ throw new UnknownError(`Configuration file validation error!\n\n${e.message}`);
15
16
  }
16
17
 
17
18
  const overridenConfiguration = deepmerge(configuration, userConfiguration);
@@ -1,5 +1,6 @@
1
1
  const { execAsyncSpawn } = require('./exec-async-command');
2
2
  const { getConfigFromMagentoVersion, defaultConfiguration } = require('../config');
3
+ const UnknownError = require('../errors/unknown-error');
3
4
  /**
4
5
  * Execute composer command
5
6
  * @param {String} command composer command
@@ -24,8 +25,8 @@ const runComposerCommand = async (command, options = {}) => {
24
25
  });
25
26
 
26
27
  if (throwNonZeroCode && code !== 0) {
27
- throw new Error(`Code: ${code}
28
- Response: ${result}`);
28
+ throw new UnknownError(`Code: ${code}
29
+ Response: ${result}`);
29
30
  }
30
31
 
31
32
  return { code, result };
@@ -1,5 +1,6 @@
1
1
  const { execAsyncSpawn } = require('./exec-async-command');
2
2
  const { getConfigFromMagentoVersion, defaultConfiguration, magento } = require('../config');
3
+ const UnknownError = require('../errors/unknown-error');
3
4
  /**
4
5
  * Execute magento command
5
6
  * @param {String} command magento command
@@ -27,8 +28,8 @@ const runMagentoCommand = async (command, options = {}) => {
27
28
  });
28
29
 
29
30
  if (throwNonZeroCode && code !== 0) {
30
- throw new Error(`Code: ${code}
31
- Response: ${result}`);
31
+ throw new UnknownError(`Code: ${code}
32
+ Response: ${result}`);
32
33
  }
33
34
 
34
35
  return { code, result };
@@ -1,5 +1,6 @@
1
1
  const { execAsyncSpawn } = require('./exec-async-command');
2
2
  const { getConfigFromMagentoVersion, defaultConfiguration } = require('../config');
3
+ const UnknownError = require('../errors/unknown-error');
3
4
  /**
4
5
  * Execute PHP code
5
6
  * @param {String} command magento command
@@ -10,6 +11,7 @@ const { getConfigFromMagentoVersion, defaultConfiguration } = require('../config
10
11
  * @param {() => {}} options.callback
11
12
  * @param {Boolean} options.throwNonZeroCode Throw if command return non 0 code.
12
13
  * @param {String} options.magentoVersion Magento version for config
14
+ * @param {Record<string, string>} options.env Environment variables
13
15
  */
14
16
  const runPhpCode = async (command, options = {}) => {
15
17
  const {
@@ -17,14 +19,19 @@ const runPhpCode = async (command, options = {}) => {
17
19
  magentoVersion = defaultConfiguration.magentoVersion
18
20
  } = options;
19
21
  const { php } = await getConfigFromMagentoVersion(magentoVersion);
20
- const { code, result } = await execAsyncSpawn(`${php.binPath} -c ${php.iniPath} ${command}`, {
22
+ let spawnCommand = `${php.binPath} -c ${php.iniPath} ${command}`;
23
+ if (options.env && Object.keys(options.env).length > 0) {
24
+ const env = Object.entries(options.env).map(([key, value]) => `${key}=${value}`).join(' ');
25
+ spawnCommand = `${env} ${spawnCommand}`;
26
+ }
27
+ const { code, result } = await execAsyncSpawn(spawnCommand, {
21
28
  ...options,
22
29
  withCode: true
23
30
  });
24
31
 
25
32
  if (throwNonZeroCode && code !== 0) {
26
- throw new Error(`Code: ${code}
27
- Response: ${result}`);
33
+ throw new UnknownError(`Code: ${code}
34
+ Response: ${result}`);
28
35
  }
29
36
 
30
37
  return { code, result };
@@ -0,0 +1,46 @@
1
+ const { execAsyncSpawn } = require('./exec-async-command');
2
+
3
+ /**
4
+ * @param {String} cmd
5
+ * @param {String} serviceName
6
+ * @param {{ now: boolean }} options
7
+ */
8
+ const run = (cmd, serviceName, options = {}) => execAsyncSpawn(
9
+ `systemctl ${ cmd }${ serviceName ? ` ${ serviceName }` : '' }${ options.now ? ' --now' : ''}`,
10
+ {
11
+ withCode: true
12
+ }
13
+ );
14
+
15
+ const daemonReload = () => run('daemon-reload');
16
+
17
+ const systemctlControl = (serviceName) => ({
18
+ disable: () => run('disable', serviceName),
19
+ enable: () => run('enable', serviceName),
20
+ enableAndStart: () => run('enable', serviceName, { now: true }),
21
+ restart: () => run('restart', serviceName),
22
+ start: () => run('start', serviceName),
23
+ stop: () => run('stop', serviceName),
24
+ isEnabled: async () => {
25
+ try {
26
+ const { result } = await run('is-enabled', serviceName);
27
+ return result.includes('enabled');
28
+ } catch (e) {
29
+ return false;
30
+ }
31
+ },
32
+ isRunning: async () => {
33
+ try {
34
+ const { result } = await run('status', serviceName);
35
+
36
+ return result.includes('active (running)');
37
+ } catch (e) {
38
+ return false;
39
+ }
40
+ }
41
+ });
42
+
43
+ module.exports = {
44
+ systemctlControl,
45
+ daemonReload
46
+ };
@@ -1,4 +1,5 @@
1
1
  const net = require('net');
2
+ const UnknownError = require('../errors/unknown-error');
2
3
  const sleep = require('./sleep');
3
4
 
4
5
  const connectToHostPort = ({ host, port }) => new Promise((resolve, reject) => {
@@ -14,7 +15,7 @@ const connectToHostPort = ({ host, port }) => new Promise((resolve, reject) => {
14
15
  });
15
16
  socket.on('timeout', () => {
16
17
  socket.end();
17
- reject(new Error('Connection timeout'));
18
+ reject(new UnknownError('Connection timeout'));
18
19
  });
19
20
  });
20
21
 
@@ -29,7 +30,7 @@ const waitForIt = async ({
29
30
  // eslint-disable-next-line no-await-in-loop
30
31
  await Promise.race([
31
32
  sleep(300).then(() => {
32
- throw new Error('Connection timeout');
33
+ throw new UnknownError('Connection timeout');
33
34
  }),
34
35
  connectToHostPort({ host, port })
35
36
  ]);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Scripts and configuration used by CMA.",
4
4
  "homepage": "https://docs.create-magento-app.com/",
5
5
  "repository": "github:scandipwa/create-magento-app",
6
- "version": "1.14.1-alpha.0",
6
+ "version": "1.14.1-alpha.11",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -22,7 +22,7 @@
22
22
  "arm64"
23
23
  ],
24
24
  "dependencies": {
25
- "@scandipwa/scandipwa-dev-utils": "0.1.12",
25
+ "@scandipwa/scandipwa-dev-utils": "0.1.13",
26
26
  "conf": "10.1.1",
27
27
  "enquirer": "2.3.6",
28
28
  "eta": "1.12.3",
@@ -35,6 +35,7 @@
35
35
  "mysql2": "2.3.2",
36
36
  "node-ssh": "12.0.0",
37
37
  "semver": "7.3.5",
38
+ "smol-request": "2.1.1",
38
39
  "systeminformation": "5.11.7",
39
40
  "yargs": "17.3.1"
40
41
  },
@@ -51,5 +52,5 @@
51
52
  "mysql",
52
53
  "scandipwa"
53
54
  ],
54
- "gitHead": "055ef1bd01035af8eaf80dffa087e77c67938fa8"
55
+ "gitHead": "3e86a5870f29d0b24ac3f65ff5fdbe96ef5bd025"
55
56
  }
@@ -12,9 +12,12 @@ export interface ListrContext {
12
12
  mysql: number
13
13
  redis: number
14
14
  elasticsearch: number
15
+ varnish: number
16
+ sslTerminator: number
15
17
  }
16
18
  arch: 'arm64' | 'x64'
17
19
  isArm: boolean
20
+ isWsl: boolean
18
21
  platform?: NodeJS.Platform
19
22
  platformVersion?: string
20
23
  /**
@@ -51,7 +54,7 @@ export interface ListrContext {
51
54
  o: string
52
55
  }
53
56
  }>
54
- getContainers(): Record<'nginx' | 'redis' | 'mysql' | 'elasticsearch', {
57
+ getContainers(): Record<'nginx' | 'redis' | 'mysql' | 'elasticsearch' | 'varnish', {
55
58
  _: string
56
59
  ports: string[]
57
60
  healthCheck: {
@@ -88,4 +91,5 @@ export interface ListrContext {
88
91
  useNonOverlappingPorts: boolean
89
92
  }
90
93
  mysqlConnection: mysql2.Connection
94
+ isSetupUpgradeNeeded?: boolean
91
95
  }
@@ -10,7 +10,14 @@ export interface ServiceWithVersion {
10
10
  version: string
11
11
  }
12
12
 
13
- // export inter/
13
+ export interface SSLTerminatorConfiguration extends ServiceWithVersion {
14
+ /**
15
+ * Configuration file location
16
+ *
17
+ * @example ./my-ssl-terminator-config.conf
18
+ */
19
+ configTemplate: string
20
+ }
14
21
 
15
22
  export interface NginxConfiguration extends ServiceWithVersion {
16
23
  /**
@@ -21,6 +28,20 @@ export interface NginxConfiguration extends ServiceWithVersion {
21
28
  configTemplate: string
22
29
  }
23
30
 
31
+ export interface VarnishConfiguration extends ServiceWithVersion {
32
+ /**
33
+ * Enable or disable Varnish in the project
34
+ */
35
+ enabled: boolean
36
+
37
+ /**
38
+ * Configuration file location
39
+ *
40
+ * @example ./my-varnish-config.vcl
41
+ */
42
+ configTemplate: string
43
+ }
44
+
24
45
  export interface PHPExtension extends Record<string, unknown> {
25
46
  version?: string
26
47
  /**
@@ -175,6 +196,16 @@ export interface CMAConfiguration {
175
196
  * Composer configuration
176
197
  */
177
198
  composer: ServiceWithVersion
199
+
200
+ /**
201
+ * Varnish configuration
202
+ */
203
+ varnish: VarnishConfiguration
204
+
205
+ /**
206
+ * SSL Terminator configuration
207
+ */
208
+ sslTerminator: SSLTerminatorConfiguration
178
209
  }
179
210
  /**
180
211
  * Magento configuration
@@ -1,27 +0,0 @@
1
- const { isTableExists } = require('../../../util/database');
2
-
3
- /**
4
- * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
5
- */
6
- const adjustMagentoConfiguration = () => ({
7
- title: 'Adjusting Magento Database Configuration',
8
- skip: async (ctx) => !(await isTableExists('magento', 'core_config_data', ctx)),
9
- task: async (ctx) => {
10
- const { mysqlConnection } = ctx;
11
-
12
- // delete varnish configuration if exists
13
- await mysqlConnection.query(`
14
- DELETE FROM core_config_data WHERE path LIKE '%varnish%';
15
- `);
16
-
17
- // update cache policy to not use varnish
18
- // 0 - magento cache, 2 - varnish cache
19
- await mysqlConnection.query(`
20
- UPDATE core_config_data
21
- SET value = ?
22
- WHERE path = ?;
23
- `, ['0', 'system/full_page_cache/caching_application']);
24
- }
25
- });
26
-
27
- module.exports = adjustMagentoConfiguration;
@@ -1,11 +0,0 @@
1
- const magentoTask = require('../../../util/magento-task');
2
-
3
- /**
4
- * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
5
- */
6
- const disablePageCache = () => ({
7
- title: 'Disabling full_page cache in Magento',
8
- task: (ctx, task) => task.newListr(magentoTask('cache:disable full_page'))
9
- });
10
-
11
- module.exports = disablePageCache;