@scandipwa/magento-scripts 1.14.1-alpha.3 → 1.14.1-alpha.6

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 (73) hide show
  1. package/lib/commands/cli.js +28 -1
  2. package/lib/commands/execute.js +2 -1
  3. package/lib/config/docker.js +46 -9
  4. package/lib/config/get-port-config.js +2 -1
  5. package/lib/config/port-config.js +1 -0
  6. package/lib/config/templates/magentorc.template +3 -5
  7. package/lib/config/templates/php.template.ini +6 -4
  8. package/lib/config/templates/varnish.template.vcl +241 -0
  9. package/lib/config/versions/magento-2.3.0.js +9 -0
  10. package/lib/config/versions/magento-2.3.1.js +9 -0
  11. package/lib/config/versions/magento-2.3.2-p2.js +9 -0
  12. package/lib/config/versions/magento-2.3.2.js +9 -0
  13. package/lib/config/versions/magento-2.3.3-p1.js +9 -0
  14. package/lib/config/versions/magento-2.3.3.js +9 -0
  15. package/lib/config/versions/magento-2.3.4-p2.js +9 -0
  16. package/lib/config/versions/magento-2.3.4.js +9 -0
  17. package/lib/config/versions/magento-2.3.5-p1.js +9 -0
  18. package/lib/config/versions/magento-2.3.5-p2.js +9 -0
  19. package/lib/config/versions/magento-2.3.5.js +9 -0
  20. package/lib/config/versions/magento-2.3.6-p1.js +9 -0
  21. package/lib/config/versions/magento-2.3.6.js +9 -0
  22. package/lib/config/versions/magento-2.3.7-p1.js +9 -0
  23. package/lib/config/versions/magento-2.3.7-p2.js +9 -0
  24. package/lib/config/versions/magento-2.3.7-p3.js +9 -0
  25. package/lib/config/versions/magento-2.3.7.js +9 -0
  26. package/lib/config/versions/magento-2.4.0-p1.js +9 -0
  27. package/lib/config/versions/magento-2.4.0.js +9 -0
  28. package/lib/config/versions/magento-2.4.1-p1.js +9 -0
  29. package/lib/config/versions/magento-2.4.1.js +9 -0
  30. package/lib/config/versions/magento-2.4.2-p1.js +9 -0
  31. package/lib/config/versions/magento-2.4.2-p2.js +9 -0
  32. package/lib/config/versions/magento-2.4.2.js +9 -0
  33. package/lib/config/versions/magento-2.4.3-p1.js +9 -0
  34. package/lib/config/versions/magento-2.4.3-p2.js +9 -0
  35. package/lib/config/versions/magento-2.4.3.js +9 -0
  36. package/lib/config/versions/magento-2.4.4.js +9 -0
  37. package/lib/tasks/cli/create-bashrc-config.js +5 -2
  38. package/lib/tasks/docker/containers.js +10 -8
  39. package/lib/tasks/docker/volumes.js +4 -4
  40. package/lib/tasks/file-system/create-nginx-config.js +5 -0
  41. package/lib/tasks/file-system/create-varnish-config.js +51 -0
  42. package/lib/tasks/file-system/index.js +3 -1
  43. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +1 -1
  44. package/lib/tasks/magento/setup-magento/disable-2fa.js +4 -12
  45. package/lib/tasks/magento/setup-magento/disable-full-page-cache.js +20 -0
  46. package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +14 -16
  47. package/lib/tasks/magento/setup-magento/migrate-database.js +24 -11
  48. package/lib/tasks/magento/setup-magento/upgrade-magento.js +17 -3
  49. package/lib/tasks/magento/setup-magento/varnish-config.js +63 -0
  50. package/lib/tasks/mysql/fix-db.js +2 -2
  51. package/lib/tasks/php/index.js +1 -1
  52. package/lib/tasks/php/update-env-php.js +16 -1
  53. package/lib/tasks/php/update-env.php +54 -12
  54. package/lib/tasks/requirements/index.js +5 -5
  55. package/lib/tasks/requirements/php-version.js +3 -1
  56. package/lib/tasks/start.js +3 -8
  57. package/lib/tasks/status/index.js +1 -1
  58. package/lib/tasks/theme/build-theme.js +26 -8
  59. package/lib/tasks/theme/install-theme.js +16 -4
  60. package/lib/tasks/theme/link-theme.js +2 -2
  61. package/lib/tasks/theme/setup-persisted-query.js +3 -3
  62. package/lib/tasks/theme/setup-themes.js +3 -2
  63. package/lib/tasks/theme/symlink-theme.js +18 -3
  64. package/lib/util/config-file-validator.js +11 -1
  65. package/lib/util/config-php-json.js +19 -0
  66. package/lib/util/match-filesystem.js +2 -1
  67. package/lib/util/php-task.js +6 -2
  68. package/lib/util/run-php.js +7 -1
  69. package/package.json +2 -2
  70. package/typings/context.d.ts +2 -0
  71. package/typings/index.d.ts +19 -0
  72. package/lib/tasks/magento/setup-magento/adjust-magento-configuration.js +0 -27
  73. package/lib/tasks/magento/setup-magento/disable-page-cache.js +0 -11
@@ -5,13 +5,14 @@ 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 disableFullPageCache = require('../magento/setup-magento/disable-full-page-cache');
9
9
  const buildTheme = require('./build-theme');
10
10
 
11
11
  /**
12
12
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
13
13
  */
14
14
  const setupThemes = () => ({
15
+ title: 'Setting up themes',
15
16
  task: async (ctx, task) => {
16
17
  const { config: { baseConfig } } = ctx;
17
18
  const composerData = await getJsonfileData(path.join(baseConfig.magentoDir, 'composer.json'));
@@ -80,7 +81,7 @@ const setupThemes = () => ({
80
81
  ])
81
82
  })).concat([
82
83
  upgradeMagento(),
83
- disablePageCache(),
84
+ disableFullPageCache(),
84
85
  setupPersistedQuery()
85
86
  ])
86
87
  );
@@ -1,13 +1,26 @@
1
+ const path = require('path');
2
+ const getJsonfileData = require('../../util/get-jsonfile-data');
1
3
  const runComposerCommand = require('../../util/run-composer');
2
4
 
3
5
  /**
4
6
  * @type {(theme: import('../../../typings/theme').Theme) => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
5
7
  */
6
- const symlinkTheme = ({ absoluteThemePath }) => ({
8
+ const symlinkTheme = (theme) => ({
7
9
  title: 'Setting symbolic link for theme in composer.json',
8
- task: async ({ magentoVersion, verbose = false }, task) => {
10
+ task: async (ctx, task) => {
11
+ const { magentoVersion, verbose = false } = ctx;
12
+ const composerJsonData = await getJsonfileData(path.join(process.cwd(), 'composer.json'));
13
+ const repositories = Array.isArray(composerJsonData.repositories)
14
+ ? composerJsonData.repositories.reduce((acc, repo, index) => ({ ...acc, [`${index}`]: repo }), {})
15
+ : composerJsonData.repositories;
16
+
17
+ if (Object.values(repositories).some((value) => value.url === theme.themePath)) {
18
+ task.skip();
19
+ return;
20
+ }
21
+
9
22
  try {
10
- await runComposerCommand(`config repo.scandipwa path ${absoluteThemePath}`, {
23
+ await runComposerCommand(`config repo.scandipwa path ${theme.absoluteThemePath}`, {
11
24
  magentoVersion,
12
25
  callback: !verbose ? undefined : (t) => {
13
26
  task.output = t;
@@ -19,6 +32,8 @@ const symlinkTheme = ({ absoluteThemePath }) => ({
19
32
  See ERROR log above.\n\n${e}`
20
33
  );
21
34
  }
35
+
36
+ ctx.isSetupUpgradeNeeded = true;
22
37
  }
23
38
  });
24
39
 
@@ -72,6 +72,15 @@ const nginxConfigurationSchema = Joi.object({
72
72
  configTemplate: Joi.string().optional().custom(fileExistsValidator)
73
73
  });
74
74
 
75
+ /**
76
+ * @type {Joi.ObjectSchema<import('../../typings').NginxConfiguration>}
77
+ */
78
+ const varnishConfigurationSchema = Joi.object({
79
+ enabled: Joi.boolean().optional(),
80
+ version: Joi.string().optional(),
81
+ configTemplate: Joi.string().optional().custom(fileExistsValidator)
82
+ });
83
+
75
84
  /**
76
85
  * @type {Joi.ObjectSchema<import('../../typings').ServiceWithVersion>}
77
86
  */
@@ -101,7 +110,8 @@ const configurationSchema = Joi.object({
101
110
  mysql: serviceConfigurationSchema.optional(),
102
111
  elasticsearch: serviceConfigurationSchema.optional(),
103
112
  redis: serviceConfigurationSchema.optional(),
104
- composer: composerConfigurationSchema.optional()
113
+ composer: composerConfigurationSchema.optional(),
114
+ varnish: varnishConfigurationSchema.optional()
105
115
  });
106
116
 
107
117
  /**
@@ -0,0 +1,19 @@
1
+ const path = require('path');
2
+ const runPhpCode = require('./run-php');
3
+
4
+ const configPhpToJson = async (projectPath = process.cwd(), { magentoVersion }) => {
5
+ const { code, result } = await runPhpCode(`-r "echo json_encode(require '${path.join(projectPath, 'app', 'etc', 'config.php')}');"`, {
6
+ magentoVersion
7
+ });
8
+
9
+ if (code !== 0) {
10
+ throw new Error(result);
11
+ }
12
+ try {
13
+ return JSON.parse(result);
14
+ } catch (e) {
15
+ throw new Error(`Ooops! Something went wrong when trying to parse app/etc/config.php file!\n\n${e}\n\nFile result: ${result}`);
16
+ }
17
+ };
18
+
19
+ module.exports = configPhpToJson;
@@ -13,7 +13,8 @@ const matchFilesystem = async (cwd, structure) => {
13
13
  .every((value) => value === true);
14
14
 
15
15
  return ok;
16
- } if (typeof structure === 'object') {
16
+ }
17
+ if (typeof structure === 'object') {
17
18
  const ok = (await Promise.all(Object.entries(structure).map(([key, value]) => {
18
19
  if (typeof value === 'boolean') {
19
20
  return pathExists(path.join(cwd, key));
@@ -1,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
 
@@ -10,6 +10,7 @@ const { getConfigFromMagentoVersion, defaultConfiguration } = require('../config
10
10
  * @param {() => {}} options.callback
11
11
  * @param {Boolean} options.throwNonZeroCode Throw if command return non 0 code.
12
12
  * @param {String} options.magentoVersion Magento version for config
13
+ * @param {Record<string, string>} options.env Environment variables
13
14
  */
14
15
  const runPhpCode = async (command, options = {}) => {
15
16
  const {
@@ -17,7 +18,12 @@ const runPhpCode = async (command, options = {}) => {
17
18
  magentoVersion = defaultConfiguration.magentoVersion
18
19
  } = options;
19
20
  const { php } = await getConfigFromMagentoVersion(magentoVersion);
20
- const { code, result } = await execAsyncSpawn(`${php.binPath} -c ${php.iniPath} ${command}`, {
21
+ let spawnCommand = `${php.binPath} -c ${php.iniPath} ${command}`;
22
+ if (options.env && Object.keys(options.env).length > 0) {
23
+ const env = Object.entries(options.env).map(([key, value]) => `${key}=${value}`).join(' ');
24
+ spawnCommand = `${env} ${spawnCommand}`;
25
+ }
26
+ const { code, result } = await execAsyncSpawn(spawnCommand, {
21
27
  ...options,
22
28
  withCode: true
23
29
  });
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.3",
6
+ "version": "1.14.1-alpha.6",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -51,5 +51,5 @@
51
51
  "mysql",
52
52
  "scandipwa"
53
53
  ],
54
- "gitHead": "262eae9eb5d71053f48d177426320182c5b5a9eb"
54
+ "gitHead": "c9e9f8369d2ef70bb16d0a29d29134909ef70884"
55
55
  }
@@ -12,6 +12,7 @@ export interface ListrContext {
12
12
  mysql: number
13
13
  redis: number
14
14
  elasticsearch: number
15
+ varnish: number
15
16
  }
16
17
  arch: 'arm64' | 'x64'
17
18
  isArm: boolean
@@ -88,4 +89,5 @@ export interface ListrContext {
88
89
  useNonOverlappingPorts: boolean
89
90
  }
90
91
  mysqlConnection: mysql2.Connection
92
+ isSetupUpgradeNeeded?: boolean
91
93
  }
@@ -21,6 +21,20 @@ export interface NginxConfiguration extends ServiceWithVersion {
21
21
  configTemplate: string
22
22
  }
23
23
 
24
+ export interface VarnishConfiguration extends ServiceWithVersion {
25
+ /**
26
+ * Enable or disable Varnish in the project
27
+ */
28
+ enabled: boolean
29
+
30
+ /**
31
+ * Configuration file location
32
+ *
33
+ * @example ./my-varnish-config.vcl
34
+ */
35
+ configTemplate: string
36
+ }
37
+
24
38
  export interface PHPExtension extends Record<string, unknown> {
25
39
  version?: string
26
40
  /**
@@ -175,6 +189,11 @@ export interface CMAConfiguration {
175
189
  * Composer configuration
176
190
  */
177
191
  composer: ServiceWithVersion
192
+
193
+ /**
194
+ * Varnish configuration
195
+ */
196
+ varnish: VarnishConfiguration
178
197
  }
179
198
  /**
180
199
  * 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;