@scandipwa/magento-scripts 2.0.0-alpha.7 → 2.0.0-alpha.8

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.
package/exec.js ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env node
2
+
3
+ const getLatestVersion = require('@scandipwa/scandipwa-dev-utils/latest-version');
4
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
5
+ const semver = require('semver');
6
+ const isInstalledGlobally = require('is-installed-globally');
7
+ const isRunningRoot = require('./lib/util/is-running-root');
8
+ const { executeTask } = require('./lib/tasks/execute');
9
+
10
+ if (isRunningRoot()) {
11
+ logger.error('Root privileges detected!');
12
+ console.log(`
13
+ We detected that you are running ${ logger.style.misc('magento-scripts') } as root user.
14
+ We cannot allow you to run ${ logger.style.misc('magento-scripts') } with root privileges, this will only cause more problems.
15
+
16
+ If you are experiencing problems with ${ logger.style.misc('Docker') } or ${ logger.style.misc('Magento') } setup, running ${ logger.style.misc('magento-scripts') } as root will not solve those problems.
17
+ `);
18
+
19
+ process.exit(1);
20
+ }
21
+
22
+ process.title = 'magento-scripts';
23
+
24
+ const newVersionIsAPatch = (latestVersion, currentVersion) => {
25
+ const latestVersionParsed = semver.parse(latestVersion);
26
+ const currentVersionParsed = semver.parse(currentVersion);
27
+
28
+ return latestVersionParsed.major === currentVersionParsed.major
29
+ && latestVersionParsed.minor === currentVersionParsed.minor
30
+ && latestVersionParsed.patch !== currentVersionParsed.patch;
31
+ };
32
+
33
+ (async () => {
34
+ const { version: currentVersion, name } = require('./package.json');
35
+ try {
36
+ const latestVersion = await getLatestVersion(name);
37
+
38
+ if (semver.gt(latestVersion, currentVersion)) {
39
+ const isNewVersionAPath = newVersionIsAPatch(latestVersion, currentVersion);
40
+
41
+ let message = [];
42
+
43
+ if (isNewVersionAPath) {
44
+ message = [
45
+ `A patch for ${ logger.style.misc(name) } is available!`,
46
+ `We recommend to update to latest version ${ logger.style.misc(latestVersion) }!`,
47
+ `-> ${ logger.style.command(`npm i ${ isInstalledGlobally ? '-g ' : '' }${ name }@${ latestVersion }`) }`
48
+ ];
49
+ } else {
50
+ message = [
51
+ `${ isInstalledGlobally ? 'Global module' : 'Module' } ${ logger.style.misc(name) } (${currentVersion}) is out-dated.`,
52
+ `Please upgrade it to latest version ${ logger.style.misc(latestVersion) }.`,
53
+ `You can do it by running the following command: ${ logger.style.command(`npm i ${ isInstalledGlobally ? '-g ' : '' }${ name }@${ latestVersion }`) }.`
54
+ ];
55
+ }
56
+
57
+ process.isOutOfDateVersion = true;
58
+ process.isOutOfDateVersionMessage = message;
59
+ }
60
+ } catch (e) {
61
+ logger.warn(`Package ${ logger.style.misc(name) } is not yet published.`);
62
+ logger.log(); // add empty line
63
+ }
64
+
65
+ const [containername, ...commands] = process.argv.slice(2);
66
+
67
+ return executeTask({
68
+ containername,
69
+ commands
70
+ });
71
+ })();
package/index.js CHANGED
@@ -13,7 +13,7 @@ if (isRunningRoot()) {
13
13
  We detected that you are running ${ logger.style.misc('magento-scripts') } as root user.
14
14
  We cannot allow you to run ${ logger.style.misc('magento-scripts') } with root privileges, this will only cause more problems.
15
15
 
16
- If you are experiencing problems with ${ logger.style.misc('Docker') }, ${ logger.style.misc('PHPBrew') } and ${ logger.style.misc('PHP') } compilation or ${ logger.style.misc('Magento') } setup, running ${ logger.style.misc('magento-scripts') } as root will not solve those problems.
16
+ If you are experiencing problems with ${ logger.style.misc('Docker') } or ${ logger.style.misc('Magento') } setup, running ${ logger.style.misc('magento-scripts') } as root will not solve those problems.
17
17
  `);
18
18
 
19
19
  process.exit(1);
@@ -1,11 +1,4 @@
1
- const logger = require('@scandipwa/scandipwa-dev-utils/logger');
2
- const { Listr } = require('listr2');
3
- const checkConfigurationFile = require('../config/check-configuration-file');
4
- const getProjectConfiguration = require('../config/get-project-configuration');
5
- const executeInContainer = require('../tasks/execute');
6
- const getMagentoVersionConfig = require('../config/get-magento-version-config');
7
- const { checkRequirements } = require('../tasks/requirements');
8
- const { getCachedPorts } = require('../config/get-port-config');
1
+ const { executeTask } = require('../tasks/execute');
9
2
 
10
3
  /**
11
4
  * @param {import('yargs')} yargs
@@ -26,55 +19,7 @@ Available containers:
26
19
  - sslTerminator`);
27
20
  },
28
21
  async (argv) => {
29
- const tasks = new Listr([
30
- checkRequirements(),
31
- getMagentoVersionConfig(),
32
- checkConfigurationFile(),
33
- getProjectConfiguration(),
34
- getCachedPorts()
35
- ], {
36
- concurrent: false,
37
- exitOnError: true,
38
- ctx: { throwMagentoVersionMissing: true },
39
- rendererOptions: { collapse: false, clearOutput: true }
40
- });
41
-
42
- let ctx;
43
- try {
44
- ctx = await tasks.run();
45
- } catch (e) {
46
- logger.error(e.message || e);
47
- process.exit(1);
48
- }
49
- const containers = ctx.config.docker.getContainers(ctx.ports);
50
- const services = Object.keys(containers);
51
-
52
- if (services.includes(argv.containername) || services.some((service) => service.includes(argv.containername))) {
53
- const container = containers[argv.containername]
54
- ? containers[argv.containername]
55
- : Object.entries(containers).find(([key]) => key.includes(argv.containername))[1];
56
-
57
- if (argv.commands.length === 0) {
58
- // if we have default connect command then use it
59
- if (container.connectCommand) {
60
- // eslint-disable-next-line no-param-reassign
61
- argv.commands = container.connectCommand;
62
- } else {
63
- // otherwise fall back to bash (if it exists inside container)
64
- argv.commands.push('bash');
65
- }
66
- }
67
-
68
- logger.logN(`Executing container ${logger.style.misc(container._)} (command: ${logger.style.command(argv.commands[0])})`);
69
- await executeInContainer({
70
- containerName: container.name,
71
- commands: argv.commands
72
- });
73
-
74
- return;
75
- }
76
-
77
- logger.error(`No container found "${argv.containername}"`);
22
+ await executeTask(argv);
78
23
  }
79
24
  );
80
25
  };
@@ -2,16 +2,16 @@ RED='\033[0;31m'
2
2
  GREEN='\033[0;32m'
3
3
  NC='\033[0m' # No Color
4
4
 
5
- alias php="npm run exec php php"
5
+ alias php="node ./node_modules/.bin/magento-scripts-exec php php"
6
6
  alias magento="php bin/magento"
7
7
  alias magneto="echo -e 'Not ${RED}magneto${NC} but ${GREEN}magento${NC} please! or at least ${GREEN}m${NC}!' && magento"
8
8
  alias m="magento"
9
- alias composer="npm run exec php composer"
9
+ alias composer="node ./node_modules/.bin/magento-scripts-exec php composer"
10
10
  alias c="composer"
11
11
  <% if (it.varnishEnabled) { %>
12
- alias cvc="npm run exec varnish varnishadm ban req.url '~ /' && echo 'Varnish cache cleared!'"
12
+ alias cvc="node ./node_modules/.bin/magento-scripts-exec varnish varnishadm ban req.url '~ /' && echo 'Varnish cache cleared!'"
13
13
  <% } %>
14
- alias mariadb="npm run exec mariadb 'mysql -umagento -pmagento'"
15
- alias mariadbroot="npm run exec mariadb 'mysql -uroot -pscandipwa'"
14
+ alias mariadb="node ./node_modules/.bin/magento-scripts-exec mariadb 'mysql -umagento -pmagento'"
15
+ alias mariadbroot="node ./node_modules/.bin/magento-scripts-exec mariadb 'mysql -uroot -pscandipwa'"
16
16
 
17
17
  export BASH_SILENCE_DEPRECATION_WARNING=1
@@ -0,0 +1,98 @@
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 = require('../util/execute-in-container');
9
+ const { containerApi } = require('./docker/containers');
10
+ const { runPHPContainerCommand } = require('./php/php-container');
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
+ ], {
26
+ concurrent: false,
27
+ exitOnError: true,
28
+ ctx: { throwMagentoVersionMissing: true },
29
+ rendererOptions: { collapse: false, clearOutput: true }
30
+ });
31
+
32
+ let ctx;
33
+ try {
34
+ ctx = await tasks.run();
35
+ } catch (e) {
36
+ logger.error(e.message || e);
37
+ process.exit(1);
38
+ }
39
+ const containers = ctx.config.docker.getContainers(ctx.ports);
40
+ const services = Object.keys(containers);
41
+
42
+ if (services.includes(argv.containername) || services.some((service) => service.includes(argv.containername))) {
43
+ /**
44
+ * @type {import('./docker/containers/container-api').ContainerRunOptions}
45
+ */
46
+ const container = containers[argv.containername]
47
+ ? containers[argv.containername]
48
+ : Object.entries(containers).find(([key]) => key.includes(argv.containername))[1];
49
+
50
+ if (argv.commands.length === 0) {
51
+ // if we have default connect command then use it
52
+ if (container.connectCommand) {
53
+ // eslint-disable-next-line no-param-reassign
54
+ argv.commands = container.connectCommand;
55
+ } else {
56
+ // otherwise fall back to bash (if it exists inside container)
57
+ argv.commands.push('bash');
58
+ }
59
+ }
60
+
61
+ const containerList = await containerApi.ls({
62
+ formatToJSON: true,
63
+ all: true,
64
+ filter: `name=${container.name}`
65
+ });
66
+
67
+ if (containerList.length > 0) {
68
+ logger.logN(`Executing container ${logger.style.misc(container._)} (command: ${logger.style.command(argv.commands.join(' '))})`);
69
+ const result = await executeInContainer({
70
+ containerName: container.name,
71
+ commands: argv.commands
72
+ });
73
+
74
+ return result;
75
+ }
76
+
77
+ if (container.name.endsWith('php')) {
78
+ logger.logN(`Starting container ${logger.style.misc(container._)} with command: ${logger.style.command(argv.commands.join(' '))}`);
79
+ const result = await runPHPContainerCommand(
80
+ ctx,
81
+ argv.commands.join(' '),
82
+ {
83
+ logOutput: true
84
+ }
85
+ );
86
+
87
+ return result;
88
+ }
89
+
90
+ throw new KnownError(`Container ${container.name} is not running!`);
91
+ }
92
+
93
+ logger.error(`No container found "${argv.containername}"`);
94
+ };
95
+
96
+ module.exports = {
97
+ executeTask
98
+ };
@@ -10,9 +10,13 @@ const { containerApi } = require('../docker/containers');
10
10
  const runPHPContainerCommand = async (ctx, command, options = {}) => {
11
11
  const { php } = ctx.config.docker.getContainers(ctx.ports);
12
12
 
13
- const containers = await containerApi.ls({ formatToJSON: true, all: true });
13
+ const containers = await containerApi.ls({
14
+ formatToJSON: true,
15
+ all: true,
16
+ filter: `name=${php.name}`
17
+ });
14
18
 
15
- if (containers.some((c) => c.Names === php.name)) {
19
+ if (containers.length > 0) {
16
20
  return execPHPContainerCommand(ctx, command, options);
17
21
  }
18
22
 
@@ -1,6 +1,9 @@
1
1
  const os = require('os');
2
2
  const { spawn } = require('child_process');
3
3
 
4
+ /**
5
+ * @param {{ containerName: string, commands: string[] }} param0
6
+ */
4
7
  const executeInContainer = ({ containerName, commands }) => {
5
8
  if (!process.stdin.isTTY) {
6
9
  process.stderr.write('This app works only in TTY mode');
@@ -14,7 +17,10 @@ const executeInContainer = ({ containerName, commands }) => {
14
17
  '-it',
15
18
  userArg,
16
19
  containerName
17
- ].filter(Boolean).concat(...commands.map((command) => command.split(' '))), {
20
+ ]
21
+ .filter(Boolean)
22
+ .concat(...commands.map((command) => command.split(' ')).flat()),
23
+ {
18
24
  stdio: [0, 1, 2]
19
25
  });
20
26
 
package/package.json CHANGED
@@ -3,12 +3,13 @@
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": "2.0.0-alpha.7",
6
+ "version": "2.0.0-alpha.8",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
10
10
  "bin": {
11
- "magento-scripts": "./index.js"
11
+ "magento-scripts": "./index.js",
12
+ "magento-scripts-exec": "./exec.js"
12
13
  },
13
14
  "engines": {
14
15
  "node": ">=12"
@@ -53,5 +54,5 @@
53
54
  "mysql",
54
55
  "scandipwa"
55
56
  ],
56
- "gitHead": "c965b81745323f4b3dce11965d49b2de32a4d79c"
57
+ "gitHead": "a7d43251a35fd62dcf74503e2547aa0a0dd080c7"
57
58
  }