@iobroker/repochecker 3.1.4 → 3.2.0

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/lib/common.js CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  */
6
6
  const axios = require('axios');
7
+ const fs = require('node:fs/promises');
7
8
  const compareVersions = require('compare-versions');
8
9
 
9
10
  // disable axios caching
@@ -14,41 +15,55 @@ axios.defaults.headers = {
14
15
  };
15
16
 
16
17
  let gDebug = false;
17
- function setDebug(flag){
18
+ function setDebug(flag) {
18
19
  gDebug = flag;
20
+ debug('debug messages have been enabled');
19
21
  }
20
22
 
21
23
  function debug(msg) {
22
- console.log(`[DEBUG] ${msg}`);
24
+ gDebug && console.log(`[DEBUG] ${msg}`);
23
25
  }
24
26
 
25
- function checkLanguages(langObj, languages) {
26
- return languages.filter(lang => !langObj[lang]);
27
+ let gLocal = false;
28
+ function setLocal(flag) {
29
+ gLocal = flag;
30
+ console.log(`[INFO] running in LOCAL mode`);
27
31
  }
28
32
 
29
- async function downloadFile(githubUrl, path, binary, noError) {
30
-
31
- console.log(`Download ${githubUrl}${path || ''}`);
33
+ function isLocal() {
34
+ return gLocal;
35
+ }
32
36
 
33
- const options = {};
34
- if (binary) {
35
- options.responseType = 'arraybuffer';
36
- }
37
+ function checkLanguages(langObj, languages) {
38
+ return languages.filter((lang) => !langObj[lang]);
39
+ }
37
40
 
38
- try {
39
- const response = await axios(githubUrl + (path || ''), options);
40
- debug(`download succeded`);
41
- return(response.data);
42
- } catch (e) {
43
- (!noError || gDebug) && console.error(`Cannot download ${githubUrl}${path || ''} ${e}`);
44
- throw e;
41
+ async function downloadFile(githubUrl, path, binary, noError) {
42
+ if (!isLocal()) {
43
+ console.log(`Download ${githubUrl}${path || ''}`);
44
+ const options = {};
45
+ if (binary) {
46
+ options.responseType = 'arraybuffer';
47
+ }
48
+ try {
49
+ const response = await axios(githubUrl + (path || ''), options);
50
+ debug(`download succeded`);
51
+ return response.data;
52
+ } catch (e) {
53
+ (!noError || gDebug) && console.error(`Cannot download ${githubUrl}${path || ''} ${e}`);
54
+ throw e;
55
+ }
56
+ } else {
57
+ console.log(`Download local ${path || ''}`);
58
+ // remove first / from path
59
+ path = path.replace(/^\/+/, '');
60
+ const file = await fs.readFile(path, binary ? null : 'utf8');
61
+ return file;
45
62
  }
46
-
47
63
  }
48
-
49
64
  function getDependencyArray(deps) {
50
65
  return deps
51
- .map(dep => typeof dep === 'object' ? Object.keys(dep) : [dep])
66
+ .map((dep) => (typeof dep === 'object' ? Object.keys(dep) : [dep]))
52
67
  .reduce((acc, dep) => acc.concat(dep), []);
53
68
  }
54
69
 
@@ -77,13 +92,13 @@ function getDependencies(deps) {
77
92
  const ret = {};
78
93
  console.log(`deps: ${JSON.stringify(deps)}, type ${typeof deps}`);
79
94
  if (deps instanceof Array) {
80
- for (const dep of deps ) {
95
+ for (const dep of deps) {
81
96
  if (typeof dep === 'object') {
82
- for (const key in dep ) {
97
+ for (const key in dep) {
83
98
  ret[key] = dep[key];
84
99
  }
85
100
  } else {
86
- ret[ dep ] = '>=0';
101
+ ret[dep] = '>=0';
87
102
  }
88
103
  }
89
104
  }
@@ -101,12 +116,13 @@ function maxVersion(v1, v2) {
101
116
  return v2;
102
117
  }
103
118
 
104
- exports.setDebug=setDebug;
105
- exports.debug=debug;
106
-
107
- exports.checkLanguages=checkLanguages;
108
- exports.downloadFile=downloadFile;
109
- exports.getDependencyArray=getDependencyArray;
110
- exports.getDependencies=getDependencies;
111
- exports.maxVersion=maxVersion;
119
+ exports.setDebug = setDebug;
120
+ exports.debug = debug;
121
+ exports.setLocal = setLocal;
122
+ exports.isLocal = isLocal;
112
123
 
124
+ exports.checkLanguages = checkLanguages;
125
+ exports.downloadFile = downloadFile;
126
+ exports.getDependencyArray = getDependencyArray;
127
+ exports.getDependencies = getDependencies;
128
+ exports.maxVersion = maxVersion;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.1.4",
2
+ "version": "3.2.0",
3
3
  "name": "@iobroker/repochecker",
4
4
  "dependencies": {
5
5
  "axios": "^1.7.7",