@scandipwa/magento-scripts 1.16.0-alpha.3 → 1.16.0-alpha.4

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.
@@ -1,8 +1,8 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
- const os = require('os');
4
3
  const pathExists = require('../../../util/path-exists');
5
4
  const UnknownError = require('../../../errors/unknown-error');
5
+ const phpbrewConfig = require('../../phpbrew');
6
6
 
7
7
  /**
8
8
  * @type {import('../../../../typings/index').PHPExtension}
@@ -12,9 +12,7 @@ module.exports = {
12
12
  hooks: {
13
13
  postInstall: async ({ php }) => {
14
14
  const sodiumDynamicLibraryPath = path.join(
15
- os.homedir(),
16
- '.phpbrew',
17
- 'php',
15
+ phpbrewConfig.phpPath,
18
16
  `php-${php.version}`,
19
17
  'var',
20
18
  'db',
@@ -1,5 +1,5 @@
1
1
  const path = require('path');
2
- const os = require('os');
2
+ const phpbrewConfig = require('./phpbrew');
3
3
 
4
4
  module.exports = (app, config) => {
5
5
  const { php } = app;
@@ -7,9 +7,7 @@ module.exports = (app, config) => {
7
7
  const { cacheDir } = config;
8
8
 
9
9
  const phpVersionDir = path.join(
10
- os.homedir(),
11
- '.phpbrew',
12
- 'php',
10
+ phpbrewConfig.phpPath,
13
11
  `php-${ php.version }`
14
12
  );
15
13
 
@@ -1,6 +1,8 @@
1
1
  /* eslint-disable max-len */
2
2
  const { execAsyncSpawn } = require('../../util/exec-async-command');
3
+ const sleep = require('../../util/sleep');
3
4
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
5
+ const KnownError = require('../../errors/known-error');
4
6
 
5
7
  /**
6
8
  * @param {Object} options
@@ -164,6 +166,41 @@ const getContainerStatus = async (containerName) => {
164
166
  }
165
167
  };
166
168
 
169
+ /**
170
+ * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
171
+ */
172
+ const checkContainersAreRunning = () => ({
173
+ title: 'Checking container statuses',
174
+ task: async (ctx, task) => {
175
+ const { config: { docker }, ports } = ctx;
176
+ const containers = Object.values(docker.getContainers(ports));
177
+ let tries = 0;
178
+ while (tries < 3) {
179
+ const containersWithStatus = await Promise.all(
180
+ containers.map(async (container) => ({
181
+ ...container,
182
+ status: await getContainerStatus(container.name)
183
+ }))
184
+ );
185
+
186
+ if (containersWithStatus.some((c) => c.status.Status !== 'running')) {
187
+ if (tries === 2) {
188
+ throw new KnownError(`${containersWithStatus.filter((c) => c.status.Status !== 'running').map((c) => c._).join(', ')} containers are not running! Please check container logs for more details!`);
189
+ } else {
190
+ task.output = `${containersWithStatus.filter((c) => c.status.Status !== 'running').map((c) => c._).join(', ')} are not running, waiting if something will change...`;
191
+ await sleep(2000);
192
+ tries++;
193
+ }
194
+ } else {
195
+ break;
196
+ }
197
+ }
198
+ },
199
+ options: {
200
+ bottomBar: 10
201
+ }
202
+ });
203
+
167
204
  /**
168
205
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
169
206
  */
@@ -188,5 +225,7 @@ module.exports = {
188
225
  startContainers,
189
226
  stopContainers,
190
227
  pullContainers,
191
- statusContainers
228
+ statusContainers,
229
+ checkContainersAreRunning,
230
+ getContainerStatus
192
231
  };
@@ -19,7 +19,8 @@ const startServices = () => ({
19
19
  ctx
20
20
  })
21
21
  },
22
- containers.startContainers()
22
+ containers.startContainers(),
23
+ containers.checkContainersAreRunning()
23
24
  ], {
24
25
  concurrent: false,
25
26
  exitOnError: true
@@ -3,6 +3,7 @@ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
3
3
  const { execAsyncSpawn } = require('../../util/exec-async-command');
4
4
  const compileOptions = require('./compile-options');
5
5
  const UnknownError = require('../../errors/unknown-error');
6
+ const { getPHPForPHPBrewBin } = require('../../util/get-php-for-phpbrew');
6
7
 
7
8
  /**
8
9
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
@@ -10,6 +11,7 @@ const UnknownError = require('../../errors/unknown-error');
10
11
  const compilePHP = () => ({
11
12
  title: 'Compiling PHP',
12
13
  task: async ({ config: { php } }, task) => {
14
+ const phpBinForPHPBrew = await getPHPForPHPBrewBin();
13
15
  const platformCompileOptions = compileOptions[process.platform];
14
16
  if (process.platform === 'linux') {
15
17
  const { distro } = await systeminformation.osInfo();
@@ -29,7 +31,11 @@ const compilePHP = () => ({
29
31
  callback: (t) => {
30
32
  task.output = t;
31
33
  },
32
- useRosetta2: true
34
+ useRosetta2: true,
35
+ env: phpBinForPHPBrew ? {
36
+ ...process.env,
37
+ PATH: `${phpBinForPHPBrew}:${process.env.PATH}`
38
+ } : process.env
33
39
  }
34
40
  );
35
41
  } catch (e) {
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable max-len */
2
2
  const phpbrewConfig = require('../../../config/phpbrew');
3
3
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
4
+ const { getPHPForPHPBrewBin } = require('../../../util/get-php-for-phpbrew');
4
5
 
5
6
  /**
6
7
  * @param {String} extensionName
@@ -9,6 +10,7 @@ const { execAsyncSpawn } = require('../../../util/exec-async-command');
9
10
  const disableExtension = (extensionName) => ({
10
11
  title: `Disabling ${extensionName} extension`,
11
12
  task: async (ctx, task) => {
13
+ const phpBinForPHPBrew = await getPHPForPHPBrewBin();
12
14
  const {
13
15
  config,
14
16
  config: { php }
@@ -28,7 +30,11 @@ const disableExtension = (extensionName) => ({
28
30
  callback: (t) => {
29
31
  task.output = t;
30
32
  },
31
- useRosetta2: true
33
+ useRosetta2: true,
34
+ env: phpBinForPHPBrew ? {
35
+ ...process.env,
36
+ PATH: `${phpBinForPHPBrew}:${process.env.PATH}`
37
+ } : process.env
32
38
  });
33
39
  if (hooks && hooks.postDisable) {
34
40
  await Promise.resolve(hooks.postDisable(config));
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable max-len */
2
2
  const phpbrewConfig = require('../../../config/phpbrew');
3
3
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
4
+ const { getPHPForPHPBrewBin } = require('../../../util/get-php-for-phpbrew');
4
5
 
5
6
  /**
6
7
  * @param {String} extensionName
@@ -10,6 +11,7 @@ const { execAsyncSpawn } = require('../../../util/exec-async-command');
10
11
  const enableExtension = (extensionName, extensionOptions) => ({
11
12
  title: `Enabling ${extensionName} extension`,
12
13
  task: async (ctx, task) => {
14
+ const phpBinForPHPBrew = await getPHPForPHPBrewBin();
13
15
  const {
14
16
  config,
15
17
  config: { php }
@@ -30,7 +32,11 @@ const enableExtension = (extensionName, extensionOptions) => ({
30
32
  callback: (t) => {
31
33
  task.output = t;
32
34
  },
33
- useRosetta2: true
35
+ useRosetta2: true,
36
+ env: phpBinForPHPBrew ? {
37
+ ...process.env,
38
+ PATH: `${phpBinForPHPBrew}:${process.env.PATH}`
39
+ } : process.env
34
40
  });
35
41
 
36
42
  if (hooks && hooks.postEnable) {
@@ -4,6 +4,7 @@ const fs = require('fs');
4
4
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
5
5
  const pathExists = require('../../../util/path-exists');
6
6
  const phpbrewConfig = require('../../../config/phpbrew');
7
+ const { getPHPForPHPBrewBin } = require('../../../util/get-php-for-phpbrew');
7
8
 
8
9
  /**
9
10
  * Get enabled extensions list with versions
@@ -11,9 +12,16 @@ const phpbrewConfig = require('../../../config/phpbrew');
11
12
  * @returns {Promise<{[key: string]: string}}>}
12
13
  */
13
14
  const getEnabledExtensions = async ({ php }) => {
15
+ const phpBinForPHPBrew = await getPHPForPHPBrewBin();
14
16
  const output = await execAsyncSpawn(
15
17
  `${ php.binPath } -c ${php.iniPath} -r 'foreach (get_loaded_extensions() as $extension) echo "$extension:" . phpversion($extension) . "\n";'`,
16
- { useRosetta2: true }
18
+ {
19
+ useRosetta2: true,
20
+ env: phpBinForPHPBrew ? {
21
+ ...process.env,
22
+ PATH: `${phpBinForPHPBrew}:${process.env.PATH}`
23
+ } : process.env
24
+ }
17
25
  );
18
26
 
19
27
  return output
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable max-len */
2
2
  const phpbrewConfig = require('../../../config/phpbrew');
3
3
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
4
+ const { getPHPForPHPBrewBin } = require('../../../util/get-php-for-phpbrew');
4
5
 
5
6
  /**
6
7
  * @param {String} extensionName
@@ -10,6 +11,7 @@ const { execAsyncSpawn } = require('../../../util/exec-async-command');
10
11
  const installExtension = (extensionName, extensionOptions) => ({
11
12
  title: `Installing ${extensionName} extension`,
12
13
  task: async (ctx, task) => {
14
+ const phpBinForPHPBrew = await getPHPForPHPBrewBin();
13
15
  const {
14
16
  config,
15
17
  config: { php }
@@ -32,7 +34,11 @@ const installExtension = (extensionName, extensionOptions) => ({
32
34
  callback: (t) => {
33
35
  task.output = t;
34
36
  },
35
- useRosetta2: true
37
+ useRosetta2: true,
38
+ env: phpBinForPHPBrew ? {
39
+ ...process.env,
40
+ PATH: `${phpBinForPHPBrew}:${process.env.PATH}`
41
+ } : process.env
36
42
  });
37
43
 
38
44
  if (hooks && hooks.postInstall) {
@@ -1,5 +1,6 @@
1
1
  const UnknownError = require('../../errors/unknown-error');
2
2
  const { execAsyncSpawn } = require('../../util/exec-async-command');
3
+ const { getPHPForPHPBrewBin } = require('../../util/get-php-for-phpbrew');
3
4
 
4
5
  /**
5
6
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
@@ -7,9 +8,14 @@ const { execAsyncSpawn } = require('../../util/exec-async-command');
7
8
  const updatePhpBrew = () => ({
8
9
  title: 'Updating PHPBrew PHP versions',
9
10
  task: async ({ config: { php } }, task) => {
11
+ const phpBinForPHPBrew = await getPHPForPHPBrewBin();
10
12
  try {
11
13
  const knownPhpVersions = await execAsyncSpawn('phpbrew known', {
12
- useRosetta2: true
14
+ useRosetta2: true,
15
+ env: phpBinForPHPBrew ? {
16
+ ...process.env,
17
+ PATH: `${phpBinForPHPBrew}:${process.env.PATH}`
18
+ } : process.env
13
19
  });
14
20
 
15
21
  if (knownPhpVersions.includes(`${php.version}`)) {
@@ -21,7 +27,11 @@ const updatePhpBrew = () => ({
21
27
  callback: (t) => {
22
28
  task.output = t;
23
29
  },
24
- useRosetta2: true
30
+ useRosetta2: true,
31
+ env: phpBinForPHPBrew ? {
32
+ ...process.env,
33
+ PATH: `${phpBinForPHPBrew}:${process.env.PATH}`
34
+ } : process.env
25
35
  });
26
36
  } catch (e) {
27
37
  throw new UnknownError(`Unexpected error while updating phpbrew known php versions\n\n${e}`);
@@ -1,6 +1,7 @@
1
1
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
2
2
  const KnownError = require('../../../errors/known-error');
3
3
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
4
+ const { getPHPForPHPBrewBin } = require('../../../util/get-php-for-phpbrew');
4
5
  const installPHPBrew = require('./install');
5
6
  const getPHPBrewVersion = require('./version');
6
7
 
@@ -10,8 +11,13 @@ const getPHPBrewVersion = require('./version');
10
11
  const checkPHPBrew = () => ({
11
12
  title: 'Checking phpbrew',
12
13
  task: async (ctx, task) => {
14
+ const phpBinForPHPBrew = await getPHPForPHPBrewBin();
13
15
  const { code } = await execAsyncSpawn('phpbrew --version', {
14
- withCode: true
16
+ withCode: true,
17
+ env: phpBinForPHPBrew ? {
18
+ ...process.env,
19
+ PATH: `${phpBinForPHPBrew}:${process.env.PATH}`
20
+ } : process.env
15
21
  });
16
22
 
17
23
  if (code !== 0) {
@@ -68,7 +68,6 @@ const installPHPBrewBinary = () => ({
68
68
  bottomBar: 10
69
69
  }
70
70
  });
71
-
72
71
  /**
73
72
  * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
74
73
  */
@@ -79,12 +78,19 @@ const addPHPBrewInitiatorLineToConfigFile = () => ({
79
78
  const shellConfigFileName = `.${shellName}rc`;
80
79
 
81
80
  const addLineToShellConfigFIle = await task.prompt({
82
- type: 'Confirm',
81
+ type: 'Select',
83
82
  message: `To finish configuring PHPBrew we need to add ${logger.style.code('[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc')} line to your ${ shellConfigFileName } file.
84
- Do you want to do it now?`
83
+ Do you want to do it now?`,
84
+ choices: [{
85
+ name: 'yes',
86
+ message: 'Yeah, thanks'
87
+ }, {
88
+ name: 'no',
89
+ message: 'No, I will deal with this myself'
90
+ }]
85
91
  });
86
92
 
87
- if (!addLineToShellConfigFIle) {
93
+ if (addLineToShellConfigFIle === 'no') {
88
94
  task.skip();
89
95
  return;
90
96
  }
@@ -101,16 +107,26 @@ Do you want to do it now?`
101
107
  );
102
108
  } else {
103
109
  const continueInstall = await task.prompt({
104
- type: 'Confirm',
110
+ type: 'Select',
105
111
  message: `Unfortunately we cannot automatically add necessary configuration for your shell ${process.env.SHELL}!
106
112
  You will need to that manually!
107
113
 
108
114
  Add following string to your shells configuration file: ${logger.style.code('[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc')}
109
115
 
110
- When you ready, press select Yes and installation will continue.`
116
+ When you ready, press Enter and installation will continue.`,
117
+ choices: [
118
+ {
119
+ name: 'yes',
120
+ message: 'YES'
121
+ },
122
+ {
123
+ name: 'no',
124
+ message: 'Exit installation'
125
+ }
126
+ ]
111
127
  });
112
128
 
113
- if (!continueInstall) {
129
+ if (continueInstall === 'no') {
114
130
  throw new KnownError(`Add following string to your shells configuration file: ${logger.style.code('[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc')}
115
131
 
116
132
  Then you can continue installation.`);
@@ -11,6 +11,7 @@ interface ExecAsyncSpawnOptions<T extends boolean> {
11
11
  withCode?: T
12
12
  // only for mac
13
13
  useRosetta2?: boolean
14
+ env: NodeJS.ProcessEnv
14
15
  }
15
16
 
16
17
  /**
@@ -10,11 +10,16 @@ const execAsyncSpawn = (command, {
10
10
  logOutput = false,
11
11
  cwd,
12
12
  withCode = false,
13
- useRosetta2 = false
13
+ useRosetta2 = false,
14
+ env = process.env
14
15
  } = {}) => {
16
+ /**
17
+ * @type {import('child_process').SpawnOptionsWithoutStdio}
18
+ */
15
19
  const spawnOptions = {
16
20
  stdio: pipeInput ? ['inherit', 'pipe', 'pipe'] : 'pipe',
17
- cwd
21
+ cwd,
22
+ env
18
23
  };
19
24
 
20
25
  /**
@@ -0,0 +1,30 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const phpbrewConfig = require('../config/phpbrew');
4
+ const pathExists = require('./path-exists');
5
+
6
+ const getPHPForPHPBrewBin = async () => {
7
+ if (!await pathExists(phpbrewConfig.phpPath)) {
8
+ return '';
9
+ }
10
+
11
+ const buildedPHPs = await fs.promises.readdir(phpbrewConfig.phpPath, {
12
+ encoding: 'utf-8',
13
+ withFileTypes: true
14
+ });
15
+
16
+ const phpForPHPBrew = buildedPHPs.find((p) => p.isDirectory() && p.name.endsWith('phpbrew'));
17
+
18
+ if (phpForPHPBrew) {
19
+ const phpBinPath = path.join(phpbrewConfig.phpPath, phpForPHPBrew.name, 'bin');
20
+ if (await pathExists(phpBinPath)) {
21
+ return phpBinPath;
22
+ }
23
+ }
24
+
25
+ return '';
26
+ };
27
+
28
+ module.exports = {
29
+ getPHPForPHPBrewBin
30
+ };
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.16.0-alpha.3",
6
+ "version": "1.16.0-alpha.4",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -53,5 +53,5 @@
53
53
  "mysql",
54
54
  "scandipwa"
55
55
  ],
56
- "gitHead": "1801104ed104a124f8d08cc81008d21b792857e4"
56
+ "gitHead": "987f793ba2d0bb3bcabea54d3b996a5204222738"
57
57
  }