apify-cli 0.14.2-beta.1 → 0.14.2-beta.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-cli",
3
- "version": "0.14.2-beta.1",
3
+ "version": "0.14.2-beta.2",
4
4
  "description": "Apify command-line interface helps you create, develop, build and run Apify actors, and manage the Apify cloud platform.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,3 +1,5 @@
1
+ const { execSync } = require('child_process');
2
+ const process = require('process');
1
3
  const axios = require('axios');
2
4
  const chalk = require('chalk');
3
5
  const semver = require('semver');
@@ -13,17 +15,43 @@ const {
13
15
  extendLocalState,
14
16
  } = require('./local_state');
15
17
 
18
+ const INSTALLATION_TYPE = {
19
+ HOMEBREW: 'HOMEBREW',
20
+ NPM: 'NPM',
21
+ };
22
+
23
+ const UPDATE_COMMAND = {
24
+ [INSTALLATION_TYPE.HOMEBREW]: 'brew update && brew upgrade apify-cli',
25
+ [INSTALLATION_TYPE.NPM]: 'npm install -g apify-cli@latest',
26
+ };
27
+
28
+ /**
29
+ * Detect through which package manager the Apify CLI was installed.
30
+ * @returns {INSTALLATION_TYPE} The installation type of the CLI.
31
+ */
32
+ const detectInstallationType = () => {
33
+ // The path of the alias to the `src/bin/run` file is in process.argv[1]
34
+ const commandPath = process.argv[1];
35
+
36
+ if (commandPath) {
37
+ // If the real command path is like `/opt/homebrew/Cellar/apify-cli/...` or `/home/linuxbrew/.linuxbrew/Cellar/apify-cli/...`,
38
+ // then the CLI is installed via Homebrew
39
+ if (process.platform === 'linux' || process.platform === 'darwin') {
40
+ const realCommandPath = execSync(`realpath "${commandPath}"`);
41
+ if (realCommandPath.includes('homebrew/Cellar') || realCommandPath.includes('linuxbrew/Cellar')) {
42
+ return INSTALLATION_TYPE.HOMEBREW;
43
+ }
44
+ }
45
+ // Add more install types here once we have the CLI in other package managers
46
+ }
47
+
48
+ // If we didn't detect otherwise, assume the CLI was installed through NPM
49
+ return INSTALLATION_TYPE.NPM;
50
+ };
51
+
16
52
  const getLatestNpmVersion = async () => {
17
- const response = await axios({
18
- url: 'https://registry.npmjs.org/apify-cli/',
19
- headers: {
20
- // This is necessary so that NPM returns the abbreviated version of the metadata
21
- // See https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md
22
- accept: 'application/vnd.npm.install-v1+json',
23
- },
24
- });
25
- const packageMetadata = response.data;
26
- const latestVersion = packageMetadata['dist-tags'].latest;
53
+ const response = await axios({ url: 'https://registry.npmjs.org/apify-cli/latest' });
54
+ const latestVersion = response.data.version;
27
55
  return latestVersion;
28
56
  };
29
57
 
@@ -72,9 +100,11 @@ const checkLatestVersion = async (enforeUpdate = false) => {
72
100
  const currentNpmVersion = require('../../package.json').version; // eslint-disable-line
73
101
 
74
102
  if (latestNpmVersion && semver.gt(latestNpmVersion, currentNpmVersion)) {
103
+ const installationType = detectInstallationType();
104
+ const updateCommand = `' ${UPDATE_COMMAND[installationType]} '`;
75
105
  console.log('');
76
106
  warning('You are using an old version of Apify CLI. We strongly recommend you always use the latest available version.');
77
- console.log(` ↪ Run ${chalk.bgWhite(chalk.black(' npm install apify-cli@latest -g '))} to install it! 👍 \n`);
107
+ console.log(` ↪ Run ${chalk.bgWhite(chalk.black(updateCommand))} to update! 👍 \n`);
78
108
  } else if (shouldGetCurrentVersion) {
79
109
  // In this case the version was refreshed from the NPM which took a while and "Info: Making sure that Apify ..." was printed
80
110
  // so also print the state.