u2a 3.4.16 → 3.4.19

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/README.md CHANGED
@@ -41,7 +41,7 @@ U2A is a command-line utility that allows you to transform any web URL into a st
41
41
  > Full support for MacOs and Linux apps not guaranteed.
42
42
 
43
43
  ---
44
- Brought to you by [@douxxtech](https://github.com/douxxtech)
44
+ Brought to you by the [U2A Team](https://github.com/orgs/url2app/people) <3
45
45
 
46
46
  ---
47
47
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "u2a",
3
- "version": "3.4.16",
3
+ "version": "3.4.19",
4
4
  "description": "URL to App - Turn any URL into a desktop application",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -16,6 +16,8 @@ const { setupConfig } = require('./utils/config');
16
16
  const { checkNotRoot } = require('./utils/noroot');
17
17
  const { checkVersion } = require('./utils/versionCheck');
18
18
 
19
+ setupConfig();
20
+
19
21
  (async () => {
20
22
 
21
23
  program
@@ -63,7 +65,4 @@ const { checkVersion } = require('./utils/versionCheck');
63
65
 
64
66
  await checkNotRoot(options.allowroot).catch(() => {});
65
67
  await checkVersion().catch(() => {});
66
-
67
- setupConfig();
68
-
69
68
  })();
@@ -40,8 +40,8 @@ class Logger {
40
40
  this._writeToFile(formattedMessage);
41
41
  }
42
42
 
43
- error(message, error = null) {
44
- const formattedMessage = this._format('ERROR', `${message} ${error}`);
43
+ error(message, error = '') {
44
+ const formattedMessage = this._format('ERROR', `${message}${error ? ' ' + error : ''}`);
45
45
  console.log(chalk.red(formattedMessage));
46
46
  this._writeToFile(formattedMessage);
47
47
 
@@ -4,42 +4,70 @@ const Logger = require('./logger');
4
4
 
5
5
  const logger = new Logger('version-check');
6
6
 
7
+ // types of updates based on pattern arount lines 90 of this file
8
+ const UPDATE_TYPES = {
9
+ NONE: 'none',
10
+ SECURITY: 'security',
11
+ CORE: 'core',
12
+ FEATURE: 'feature'
13
+ };
14
+
7
15
  async function checkVersion(silent = false) {
8
16
  try {
9
-
10
17
  logger.debug('Started version check');
11
18
  const response = await axios.get('https://urltoapp.xyz/api/v1/getlastest', {
12
19
  timeout: 1000
13
20
  });
14
21
 
15
22
  const latestVersion = response.data.trim();
16
- logger.debug(`Version retrived: ${latestVersion}`);
23
+ logger.debug(`Version retrieved: ${latestVersion}`);
17
24
 
18
- const needsUpdate = compareVersions(version, latestVersion) <= 0;
25
+ const versionComparison = compareVersions(version, latestVersion);
26
+ const updateType = getUpdateType(version, latestVersion);
27
+ const needsUpdate = versionComparison < 0;
19
28
 
20
- if (!silent && needsUpdate && latestVersion !== version) {
21
- logger.debug(`New update available: ${latestVersion}`);
29
+ if (!silent && needsUpdate) {
30
+ logger.debug(`New update available: ${latestVersion} (${updateType})`);
22
31
  console.log('');
23
- logger.warn(`A new update (${latestVersion}) is available ! Current version: ${version}`);
32
+
33
+ const updateMessages = {
34
+ [UPDATE_TYPES.SECURITY]: `CRITICAL: Security update (${latestVersion}) available!`,
35
+ [UPDATE_TYPES.CORE]: `IMPORTANT: Core update (${latestVersion}) available!`,
36
+ [UPDATE_TYPES.FEATURE]: `NEW: Feature update (${latestVersion}) available!`
37
+ };
38
+
39
+ if (updateType === UPDATE_TYPES.SECURITY) {
40
+ logger.error(updateMessages[UPDATE_TYPES.SECURITY]); //using .error cuz im lazy to do other variations, sorry ! :)
41
+ } else {
42
+ logger.warn(updateMessages[updateType] || `A new update (${latestVersion}) is available!`);
43
+ }
44
+
45
+ logger.warn(`Current version: ${version}`);
24
46
  logger.warn(`Update u2a with: npm install -g u2a@${latestVersion}`);
47
+
48
+ if (updateType === UPDATE_TYPES.SECURITY) {
49
+ logger.error('This update fixes SECURITY VULNERABILITIES and should be installed immediately!');
50
+ }
25
51
  }
26
52
 
27
53
  return {
28
54
  current: version,
29
55
  latest: latestVersion,
30
- needsUpdate: needsUpdate && latestVersion !== version
56
+ needsUpdate,
57
+ updateType,
58
+ updateDetails: needsUpdate ? getUpdateDetails(version, latestVersion) : null
31
59
  };
32
60
  } catch (error) {
33
61
  return {
34
62
  current: version,
35
63
  latest: null,
36
64
  needsUpdate: false,
65
+ updateType: UPDATE_TYPES.NONE,
37
66
  error: error.message
38
67
  };
39
68
  }
40
69
  }
41
70
 
42
-
43
71
  function compareVersions(v1, v2) {
44
72
  const parts1 = v1.split('.').map(Number);
45
73
  const parts2 = v2.split('.').map(Number);
@@ -55,6 +83,48 @@ function compareVersions(v1, v2) {
55
83
  return 0;
56
84
  }
57
85
 
86
+ function getUpdateType(currentVersion, latestVersion) {
87
+ if (currentVersion === latestVersion) {
88
+ return UPDATE_TYPES.NONE;
89
+ }
90
+
91
+ const current = currentVersion.split('.').map(Number);
92
+ const latest = latestVersion.split('.').map(Number);
93
+
94
+ /*
95
+ a.b.c format where:
96
+ a: security version
97
+ b: core version
98
+ c: feature version
99
+ eg, 3.4.18 -> security version: 3, core version: 4, feature version: 18
100
+ */
101
+
102
+ if (latest[0] > current[0]) {
103
+ return UPDATE_TYPES.SECURITY;
104
+ } else if (latest[1] > current[1]) {
105
+ return UPDATE_TYPES.CORE;
106
+ } else if (latest[2] > current[2]) {
107
+ return UPDATE_TYPES.FEATURE;
108
+ }
109
+
110
+ return UPDATE_TYPES.NONE; //current is newer or same
111
+ }
112
+
113
+
114
+ function getUpdateDetails(currentVersion, latestVersion) {
115
+ const current = currentVersion.split('.').map(Number);
116
+ const latest = latestVersion.split('.').map(Number);
117
+
118
+ return {
119
+ securityChanges: latest[0] - current[0],
120
+ coreChanges: latest[1] - current[1],
121
+ featureChanges: latest[2] - current[2],
122
+ fromVersion: currentVersion,
123
+ toVersion: latestVersion
124
+ }; //hard maths up here
125
+ }
126
+
58
127
  module.exports = {
59
- checkVersion
128
+ checkVersion,
129
+ UPDATE_TYPES
60
130
  };