@iobroker/repochecker 2.0.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/README.md +47 -0
- package/index.js +1942 -0
- package/package.json +30 -0
package/index.js
ADDED
|
@@ -0,0 +1,1942 @@
|
|
|
1
|
+
/* 1.4.0 2022.04.26
|
|
2
|
+
|
|
3
|
+
___ _ _ _____ _ _
|
|
4
|
+
/ _ \ | | | | / __ \ | | |
|
|
5
|
+
/ /_\ \ __| | __ _ _ __ | |_ ___ _ __ | / \/ |__ ___ ___| | _____ _ __
|
|
6
|
+
| _ |/ _` |/ _` | '_ \| __/ _ \ '__| | | | '_ \ / _ \/ __| |/ / _ \ '__|
|
|
7
|
+
| | | | (_| | (_| | |_) | || __/ | | \__/\ | | | __/ (__| < __/ |
|
|
8
|
+
\_| |_/\__,_|\__,_| .__/ \__\___|_| \____/_| |_|\___|\___|_|\_\___|_|
|
|
9
|
+
| |
|
|
10
|
+
|_|
|
|
11
|
+
|
|
12
|
+
*/
|
|
13
|
+
const unzipper = require('unzipper');
|
|
14
|
+
const util = require('util');
|
|
15
|
+
const stream = require('stream');
|
|
16
|
+
const Writable = stream.Writable;
|
|
17
|
+
const sizeOf = require('image-size');
|
|
18
|
+
const axios = require('axios');
|
|
19
|
+
const compareVersions = require('compare-versions');
|
|
20
|
+
|
|
21
|
+
const version = '1.4.0';
|
|
22
|
+
const recommendedJsControllerVersion = '3.3.22';
|
|
23
|
+
|
|
24
|
+
let https;
|
|
25
|
+
|
|
26
|
+
const memStore = { };
|
|
27
|
+
|
|
28
|
+
/* Writable memory stream */
|
|
29
|
+
function WMStrm(key, options) {
|
|
30
|
+
// allow use without new operator
|
|
31
|
+
if (!(this instanceof WMStrm)) {
|
|
32
|
+
return new WMStrm(key, options);
|
|
33
|
+
}
|
|
34
|
+
Writable.call(this, options); // init super
|
|
35
|
+
this.key = key; // save key
|
|
36
|
+
memStore[key] = Buffer.from(''); // empty
|
|
37
|
+
}
|
|
38
|
+
util.inherits(WMStrm, Writable);
|
|
39
|
+
|
|
40
|
+
WMStrm.prototype._write = function (chunk, enc, cb) {
|
|
41
|
+
// our memory store stores things in buffers
|
|
42
|
+
const buffer = Buffer.isBuffer(chunk) ?
|
|
43
|
+
chunk : // already is Buffer use it
|
|
44
|
+
new Buffer(chunk, enc); // string, convert
|
|
45
|
+
|
|
46
|
+
// concat to the buffer already there
|
|
47
|
+
memStore[this.key] = Buffer.concat([memStore[this.key], buffer]);
|
|
48
|
+
cb();
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function downloadFile(githubUrl, path, binary, noError) {
|
|
52
|
+
console.log('Download ' + githubUrl + (path || ''));
|
|
53
|
+
const options = {};
|
|
54
|
+
if (binary) {
|
|
55
|
+
options.responseType = 'arraybuffer';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return axios(githubUrl + (path || ''), options)
|
|
59
|
+
.then(response => response.data)
|
|
60
|
+
.catch(e => {
|
|
61
|
+
!noError && console.error(`Cannot download ${githubUrl}${path || ''}`);
|
|
62
|
+
throw e;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getDependencyArray(deps) {
|
|
67
|
+
return deps
|
|
68
|
+
.map(dep => typeof dep === 'object' ? Object.keys(dep) : [dep])
|
|
69
|
+
.reduce((acc, dep) => acc.concat(dep), []);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function checkLanguages(langObj) {
|
|
73
|
+
if (Object.keys(langObj).length !== allowedLanguages.length) return false;
|
|
74
|
+
|
|
75
|
+
return Object.keys(langObj).filter(lang => allowedLanguages.includes(lang)).length === allowedLanguages.length;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getGithubApiData(context) {
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
axios.get(context.githubUrlApi)
|
|
81
|
+
.then(response => {
|
|
82
|
+
context.githubApiData = response.data;
|
|
83
|
+
// console.log(`API Data: ${JSON.stringify(context.githubApiData)}`);
|
|
84
|
+
|
|
85
|
+
if (!context.branch) {
|
|
86
|
+
context.branch = context.githubApiData.default_branch; // main vs. master
|
|
87
|
+
console.log(`Branch was not defined by user - checking branch: ${context.branch}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
context.githubUrl = `${context.githubUrlOriginal.replace('https://github.com', 'https://raw.githubusercontent.com')}/${context.branch}`;
|
|
91
|
+
console.log(`Original URL: ${context.githubUrlOriginal}, raw: ${context.githubUrl}, api: ${context.githubUrlApi}`);
|
|
92
|
+
|
|
93
|
+
resolve(context);
|
|
94
|
+
})
|
|
95
|
+
.catch(e => reject(e.toJSON()));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// check package.json
|
|
100
|
+
// E0xx
|
|
101
|
+
function checkPackageJson(context) {
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
if (context.packageJson) {
|
|
104
|
+
return resolve(context.packageJson);
|
|
105
|
+
} else {
|
|
106
|
+
return downloadFile(context.githubUrl, '/package.json')
|
|
107
|
+
.then(packageJson => resolve(packageJson))
|
|
108
|
+
.catch(e => reject(e));
|
|
109
|
+
}
|
|
110
|
+
}).then(packageJson => {
|
|
111
|
+
return new Promise(resolve => {
|
|
112
|
+
context.packageJson = packageJson;
|
|
113
|
+
if (typeof context.packageJson === 'string') {
|
|
114
|
+
try {
|
|
115
|
+
context.packageJson = JSON.parse(context.packageJson);
|
|
116
|
+
} catch (e) {
|
|
117
|
+
context.errors.push('[E001] Cannot parse packet.json: ' + e);
|
|
118
|
+
return resolve(context);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!context.githubUrlOriginal.match(/\/iobroker\./i)) {
|
|
123
|
+
context.errors.push('[E002] No "ioBroker." found in the name of repository');
|
|
124
|
+
} else {
|
|
125
|
+
context.checks.push('"ioBroker" was found in the name of repository');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (context.githubUrlOriginal.includes('/iobroker.')) {
|
|
129
|
+
context.errors.push('[E003] Repository must have name ioBroker.adaptername, but now io"b"roker is in lowercase');
|
|
130
|
+
} else {
|
|
131
|
+
context.checks.push('Repository has name ioBroker.adaptername (not iobroker.adaptername)');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const m = context.githubUrlOriginal.match(/\/ioBroker\.(.*)$/);
|
|
135
|
+
let adapterName = '';
|
|
136
|
+
if (!m || !m[1]) {
|
|
137
|
+
context.errors.push('[E004] No adapter name found in URL: ' + context.githubUrlOriginal);
|
|
138
|
+
} else {
|
|
139
|
+
context.checks.push('Adapter name found in the URL');
|
|
140
|
+
adapterName = m[1].replace(/\/master$/, '').replace(/\/main$/, '');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
context.adapterName = adapterName;
|
|
144
|
+
|
|
145
|
+
if (adapterName.match(/[A-Z]/)) {
|
|
146
|
+
context.errors.push('[E005] Adapter name must be lowercase');
|
|
147
|
+
} else {
|
|
148
|
+
context.checks.push('Adapter name is lowercase');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (adapterName.match(/[^-_a-z0-9]/)) {
|
|
152
|
+
context.errors.push(`[E006] Invalid characters found in adapter name "${adapterName}". Only lowercase chars, digits, "-" and "_" are allowed`);
|
|
153
|
+
} else {
|
|
154
|
+
context.checks.push(`No invalid characters found in "${adapterName}"`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const n = context.githubUrlOriginal.match(/\/([^\/]+)\/iobroker\./i);
|
|
158
|
+
if (!n || !n[1]) {
|
|
159
|
+
context.errors.push('[E007] Cannot find author repo in the URL');
|
|
160
|
+
} else {
|
|
161
|
+
context.authorName = n[1];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (context.packageJson.name !== 'iobroker.' + adapterName.toLowerCase()) {
|
|
165
|
+
context.errors.push('[E020] Name of adapter in package.json must be lowercase and be equal to "iobroker.' + adapterName.toLowerCase() + '". Now is "' + packageJson.name + '"');
|
|
166
|
+
} else {
|
|
167
|
+
context.checks.push('Name of adapter in package.json must be lowercase and be equal to "iobroker.' + adapterName.toLowerCase() + '".');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (!context.packageJson.version) {
|
|
171
|
+
context.errors.push('[E009] No version found in the package.json');
|
|
172
|
+
} else {
|
|
173
|
+
context.checks.push('Version found in package.json');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (!context.packageJson.description) {
|
|
177
|
+
context.errors.push('[E010] No description found in the package.json');
|
|
178
|
+
} else {
|
|
179
|
+
context.checks.push('Description found in package.json');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (context.packageJson.licenses) {
|
|
183
|
+
context.errors.push('[E021] "licenses" in package.json are deprecated. Please use only "license": "NAME" field.');
|
|
184
|
+
} else {
|
|
185
|
+
context.checks.push('No "licenses" found in package.json');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!context.packageJson.author) {
|
|
189
|
+
context.errors.push('[E013] No author found in the package.json');
|
|
190
|
+
} else {
|
|
191
|
+
context.checks.push('Author found in package.json');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (context.packageJson._args) {
|
|
195
|
+
context.errors.push('[E014] NPM information found in package.json. Please remove all attributes starting with "_"');
|
|
196
|
+
} else {
|
|
197
|
+
context.checks.push('No npm generated attributes found in package.json');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (!context.packageJson.license) {
|
|
201
|
+
context.errors.push('[E015] No license found in package.json');
|
|
202
|
+
} else {
|
|
203
|
+
context.checks.push('"license" found in package.json');
|
|
204
|
+
|
|
205
|
+
// check if license valid
|
|
206
|
+
if (!licenses.includes(context.packageJson.license)) {
|
|
207
|
+
context.errors.push('[E016] No SPDX license found in package.json. Please use one of listed here: https://spdx.org/licenses/');
|
|
208
|
+
} else {
|
|
209
|
+
context.checks.push('"license" is valid in package.json');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (!context.packageJson.repository) {
|
|
214
|
+
context.errors.push('[E017] No repository found in the package.json');
|
|
215
|
+
} else {
|
|
216
|
+
context.checks.push('Repository found in package.json');
|
|
217
|
+
|
|
218
|
+
const allowedRepoUrls = [
|
|
219
|
+
context.githubApiData.html_url, // https://github.com/klein0r/ioBroker.luftdaten
|
|
220
|
+
`git+${context.githubApiData.html_url}`, // git+https://github.com/klein0r/ioBroker.luftdaten
|
|
221
|
+
context.githubApiData.git_url, // git://github.com/klein0r/ioBroker.luftdaten.git
|
|
222
|
+
context.githubApiData.ssh_url, // git@github.com:klein0r/ioBroker.luftdaten.git
|
|
223
|
+
context.githubApiData.clone_url, // https://github.com/klein0r/ioBroker.luftdaten.git
|
|
224
|
+
`git+${context.githubApiData.clone_url}` // git+https://github.com/klein0r/ioBroker.luftdaten.git
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
// https://docs.npmjs.com/cli/v7/configuring-npm/package-json#repository
|
|
228
|
+
if (context.packageJson.repository && typeof context.packageJson.repository === 'object') {
|
|
229
|
+
if (context.packageJson.repository.type !== 'git') {
|
|
230
|
+
context.errors.push('[E018] Invalid repository type: ' + context.packageJson.repository.type + '. It should be git');
|
|
231
|
+
} else {
|
|
232
|
+
context.checks.push('Repository type is valid: git');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (!allowedRepoUrls.includes(context.packageJson.repository.url)) {
|
|
236
|
+
context.errors.push(`[E019] Invalid repository URL: ${context.packageJson.repository.url}. Expected: ${context.githubApiData.ssh_url} or ${context.githubApiData.clone_url}`);
|
|
237
|
+
} else {
|
|
238
|
+
context.checks.push('Repository URL is valid in package.json');
|
|
239
|
+
}
|
|
240
|
+
} else if (context.packageJson.repository && typeof context.packageJson.repository === 'string') {
|
|
241
|
+
if (!allowedRepoUrls.includes(context.packageJson.repository)) {
|
|
242
|
+
context.errors.push(`[E019] Invalid repository URL: ${context.packageJson.repository}. Expected: ${context.githubApiData.ssh_url} or ${context.githubApiData.clone_url}`);
|
|
243
|
+
} else {
|
|
244
|
+
context.checks.push('Repository URL is valid in package.json');
|
|
245
|
+
}
|
|
246
|
+
} else {
|
|
247
|
+
context.errors.push('[E019] Invalid repository URL');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (reservedAdapterNames.includes(adapterName)) {
|
|
251
|
+
context.errors.push('[E022] Adapter name is reserved!');
|
|
252
|
+
} else {
|
|
253
|
+
context.checks.push('Adapter name is not reserved');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// max number is E022
|
|
257
|
+
|
|
258
|
+
resolve(context);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const allowedLanguages = [
|
|
264
|
+
'en',
|
|
265
|
+
'de',
|
|
266
|
+
'ru',
|
|
267
|
+
'pt',
|
|
268
|
+
'nl',
|
|
269
|
+
'fr',
|
|
270
|
+
'it',
|
|
271
|
+
'es',
|
|
272
|
+
'pl',
|
|
273
|
+
'zh-cn'
|
|
274
|
+
];
|
|
275
|
+
|
|
276
|
+
const allowedModes = {
|
|
277
|
+
'none': 'this adapter will not be started',
|
|
278
|
+
'daemon': 'always running process (will be restarted if process exits)',
|
|
279
|
+
'subscribe': 'is started when state system.adapter…alive changes to true. Is killed when .alive changes to false and sets .alive to false if process exits (will not be restarted when process exits)',
|
|
280
|
+
'schedule': 'is started by schedule found in system.adapter…common.schedule - reacts on changes of .schedule by rescheduling with new state',
|
|
281
|
+
'once' : 'his adapter will be started every time the system.adapter.. object changed. It will not be restarted after termination.',
|
|
282
|
+
'extension': ''
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const allowedTypes = {
|
|
286
|
+
'alarm': 'security of home, car, boat, ...',
|
|
287
|
+
'climate-control': 'climate, heaters, air filters, water heaters, ...',
|
|
288
|
+
'communication': 'deliver data for other services via RESTapi, websockets',
|
|
289
|
+
'date-and-time': 'schedules, calendars, ...',
|
|
290
|
+
'energy': 'energy metering',
|
|
291
|
+
'metering': 'other, but energy metering (water, gas, oil, ...)',
|
|
292
|
+
'garden': 'mower, springs, ...',
|
|
293
|
+
'general': 'general purpose adapters, like admin, web, discovery, ...',
|
|
294
|
+
'geoposition': 'geo-positioning. These adapters delivers or accepst the position of other objects or persons.',
|
|
295
|
+
'hardware': 'different multi-purpose hardware, arduino, esp, bluetooth, ...',
|
|
296
|
+
'household': 'vacuum-cleaner, kitchen devices, ...',
|
|
297
|
+
'health': 'Fitness sensors, scales, blood pressure, ...',
|
|
298
|
+
'infrastructure': 'Network, printers, phones, NAS, ...',
|
|
299
|
+
'iot-systems': 'Other comprehensive smarthome systems (software and hardware)',
|
|
300
|
+
'lighting': 'light',
|
|
301
|
+
'logic': 'rules, scripts, parsers, scenes, ...',
|
|
302
|
+
'messaging': 'these adapters send and receive messages from message services: telegram, email, whatsapp, ...',
|
|
303
|
+
'misc-data': 'export/import of some unsorted information, contacts, systeminfo, gazoline prises, share curses, currents (EUR=>USD), ...',
|
|
304
|
+
'multimedia': 'TV, AV Receivers, TV play boxes, Android/apple TV boxes, multi-room music, IR controls, speech input/output, ...',
|
|
305
|
+
'network': 'ping, network detectors, UPnP, ...',
|
|
306
|
+
'protocols': 'Communication protocols: MQTT,',
|
|
307
|
+
'storage': 'logging, data protocols, SQL/NoSQL DBs, file storage, ...',
|
|
308
|
+
'utility': 'different help adapters. Like backup, export/import',
|
|
309
|
+
'vehicle': 'cars',
|
|
310
|
+
'visualization': 'visualisation, like vis, material, mobile',
|
|
311
|
+
'visualization-icons': 'icons for visualisation',
|
|
312
|
+
'visualization-widgets': 'iobroker.vis widgets',
|
|
313
|
+
'weather': 'weather info, air quality, environment statistics'
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const reservedAdapterNames = [
|
|
317
|
+
'config',
|
|
318
|
+
'system',
|
|
319
|
+
'alias',
|
|
320
|
+
'design',
|
|
321
|
+
'all',
|
|
322
|
+
'enum',
|
|
323
|
+
'this',
|
|
324
|
+
'self',
|
|
325
|
+
'0_userdata',
|
|
326
|
+
'_design',
|
|
327
|
+
];
|
|
328
|
+
|
|
329
|
+
const licenses = [
|
|
330
|
+
'0BSD',
|
|
331
|
+
'AAL',
|
|
332
|
+
'Abstyles',
|
|
333
|
+
'Adobe-2006',
|
|
334
|
+
'Adobe-Glyph',
|
|
335
|
+
'ADSL',
|
|
336
|
+
'AFL-1.1',
|
|
337
|
+
'AFL-1.2',
|
|
338
|
+
'AFL-2.0',
|
|
339
|
+
'AFL-2.1',
|
|
340
|
+
'AFL-3.0',
|
|
341
|
+
'Afmparse',
|
|
342
|
+
'AGPL-1.0-only',
|
|
343
|
+
'AGPL-1.0-or-later',
|
|
344
|
+
'AGPL-3.0-only',
|
|
345
|
+
'AGPL-3.0-or-later',
|
|
346
|
+
'Aladdin',
|
|
347
|
+
'AMDPLPA',
|
|
348
|
+
'AML',
|
|
349
|
+
'AMPAS',
|
|
350
|
+
'ANTLR-PD',
|
|
351
|
+
'Apache-1.0',
|
|
352
|
+
'Apache-1.1',
|
|
353
|
+
'Apache-2.0',
|
|
354
|
+
'APAFML',
|
|
355
|
+
'APL-1.0',
|
|
356
|
+
'APSL-1.0',
|
|
357
|
+
'APSL-1.1',
|
|
358
|
+
'APSL-1.2',
|
|
359
|
+
'APSL-2.0',
|
|
360
|
+
'Artistic-1.0-cl8',
|
|
361
|
+
'Artistic-1.0-Perl',
|
|
362
|
+
'Artistic-1.0',
|
|
363
|
+
'Artistic-2.0',
|
|
364
|
+
'Bahyph',
|
|
365
|
+
'Barr',
|
|
366
|
+
'Beerware',
|
|
367
|
+
'BitTorrent-1.0',
|
|
368
|
+
'BitTorrent-1.1',
|
|
369
|
+
'Borceux',
|
|
370
|
+
'BSD-1-Clause',
|
|
371
|
+
'BSD-2-Clause-FreeBSD',
|
|
372
|
+
'BSD-2-Clause-NetBSD',
|
|
373
|
+
'BSD-2-Clause-Patent',
|
|
374
|
+
'BSD-2-Clause',
|
|
375
|
+
'BSD-3-Clause-Attribution',
|
|
376
|
+
'BSD-3-Clause-Clear',
|
|
377
|
+
'BSD-3-Clause-LBNL',
|
|
378
|
+
'BSD-3-Clause-No-Nuclear-License-2014',
|
|
379
|
+
'BSD-3-Clause-No-Nuclear-License',
|
|
380
|
+
'BSD-3-Clause-No-Nuclear-Warranty',
|
|
381
|
+
'BSD-3-Clause',
|
|
382
|
+
'BSD-4-Clause-UC',
|
|
383
|
+
'BSD-4-Clause',
|
|
384
|
+
'BSD-Protection',
|
|
385
|
+
'BSD-Source-Code',
|
|
386
|
+
'BSL-1.0',
|
|
387
|
+
'bzip2-1.0.5',
|
|
388
|
+
'bzip2-1.0.6',
|
|
389
|
+
'Caldera',
|
|
390
|
+
'CATOSL-1.1',
|
|
391
|
+
'CC-BY-1.0',
|
|
392
|
+
'CC-BY-2.0',
|
|
393
|
+
'CC-BY-2.5',
|
|
394
|
+
'CC-BY-3.0',
|
|
395
|
+
'CC-BY-4.0',
|
|
396
|
+
'CC-BY-NC-1.0',
|
|
397
|
+
'CC-BY-NC-2.0',
|
|
398
|
+
'CC-BY-NC-2.5',
|
|
399
|
+
'CC-BY-NC-3.0',
|
|
400
|
+
'CC-BY-NC-4.0',
|
|
401
|
+
'CC-BY-NC-ND-1.0',
|
|
402
|
+
'CC-BY-NC-ND-2.0',
|
|
403
|
+
'CC-BY-NC-ND-2.5',
|
|
404
|
+
'CC-BY-NC-ND-3.0',
|
|
405
|
+
'CC-BY-NC-ND-4.0',
|
|
406
|
+
'CC-BY-NC-SA-1.0',
|
|
407
|
+
'CC-BY-NC-SA-2.0',
|
|
408
|
+
'CC-BY-NC-SA-2.5',
|
|
409
|
+
'CC-BY-NC-SA-3.0',
|
|
410
|
+
'CC-BY-NC-SA-4.0',
|
|
411
|
+
'CC-BY-ND-1.0',
|
|
412
|
+
'CC-BY-ND-2.0',
|
|
413
|
+
'CC-BY-ND-2.5',
|
|
414
|
+
'CC-BY-ND-3.0',
|
|
415
|
+
'CC-BY-ND-4.0',
|
|
416
|
+
'CC-BY-SA-1.0',
|
|
417
|
+
'CC-BY-SA-2.0',
|
|
418
|
+
'CC-BY-SA-2.5',
|
|
419
|
+
'CC-BY-SA-3.0',
|
|
420
|
+
'CC-BY-SA-4.0',
|
|
421
|
+
'CC0-1.0',
|
|
422
|
+
'CDDL-1.0',
|
|
423
|
+
'CDDL-1.1',
|
|
424
|
+
'CDLA-Permissive-1.0',
|
|
425
|
+
'CDLA-Sharing-1.0',
|
|
426
|
+
'CECILL-1.0',
|
|
427
|
+
'CECILL-1.1',
|
|
428
|
+
'CECILL-2.0',
|
|
429
|
+
'CECILL-2.1',
|
|
430
|
+
'CECILL-B',
|
|
431
|
+
'CECILL-C',
|
|
432
|
+
'ClArtistic',
|
|
433
|
+
'CNRI-Jython',
|
|
434
|
+
'CNRI-Python-GPL-Compatible',
|
|
435
|
+
'CNRI-Python',
|
|
436
|
+
'Condor-1.1',
|
|
437
|
+
'copyleft-next-0.3.0',
|
|
438
|
+
'copyleft-next-0.3.1',
|
|
439
|
+
'CPAL-1.0',
|
|
440
|
+
'CPL-1.0',
|
|
441
|
+
'CPOL-1.02',
|
|
442
|
+
'Crossword',
|
|
443
|
+
'CrystalStacker',
|
|
444
|
+
'CUA-OPL-1.0',
|
|
445
|
+
'Cube',
|
|
446
|
+
'curl',
|
|
447
|
+
'D-FSL-1.0',
|
|
448
|
+
'diffmark',
|
|
449
|
+
'DOC',
|
|
450
|
+
'Dotseqn',
|
|
451
|
+
'DSDP',
|
|
452
|
+
'dvipdfm',
|
|
453
|
+
'ECL-1.0',
|
|
454
|
+
'ECL-2.0',
|
|
455
|
+
'EFL-1.0',
|
|
456
|
+
'EFL-2.0',
|
|
457
|
+
'eGenix',
|
|
458
|
+
'Entessa',
|
|
459
|
+
'EPL-1.0',
|
|
460
|
+
'EPL-2.0',
|
|
461
|
+
'ErlPL-1.1',
|
|
462
|
+
'EUDatagrid',
|
|
463
|
+
'EUPL-1.0',
|
|
464
|
+
'EUPL-1.1',
|
|
465
|
+
'EUPL-1.2',
|
|
466
|
+
'Eurosym',
|
|
467
|
+
'Fair',
|
|
468
|
+
'Frameworx-1.0',
|
|
469
|
+
'FreeImage',
|
|
470
|
+
'FSFAP',
|
|
471
|
+
'FSFUL',
|
|
472
|
+
'FSFULLR',
|
|
473
|
+
'FTL',
|
|
474
|
+
'GFDL-1.1-only',
|
|
475
|
+
'GFDL-1.1-or-later',
|
|
476
|
+
'GFDL-1.2-only',
|
|
477
|
+
'GFDL-1.2-or-later',
|
|
478
|
+
'GFDL-1.3-only',
|
|
479
|
+
'GFDL-1.3-or-later',
|
|
480
|
+
'Giftware',
|
|
481
|
+
'GL2PS',
|
|
482
|
+
'Glide',
|
|
483
|
+
'Glulxe',
|
|
484
|
+
'gnuplot',
|
|
485
|
+
'GPL-1.0-only',
|
|
486
|
+
'GPL-1.0-or-later',
|
|
487
|
+
'GPL-2.0-only',
|
|
488
|
+
'GPL-2.0-or-later',
|
|
489
|
+
'GPL-3.0-only',
|
|
490
|
+
'GPL-3.0-or-later',
|
|
491
|
+
'gSOAP-1.3b',
|
|
492
|
+
'HaskellReport',
|
|
493
|
+
'HPND',
|
|
494
|
+
'IBM-pibs',
|
|
495
|
+
'ICU',
|
|
496
|
+
'IJG',
|
|
497
|
+
'ImageMagick',
|
|
498
|
+
'iMatix',
|
|
499
|
+
'Imlib2',
|
|
500
|
+
'Info-ZIP',
|
|
501
|
+
'Intel-ACPI',
|
|
502
|
+
'Intel',
|
|
503
|
+
'Interbase-1.0',
|
|
504
|
+
'IPA',
|
|
505
|
+
'IPL-1.0',
|
|
506
|
+
'ISC',
|
|
507
|
+
'JasPer-2.0',
|
|
508
|
+
'JSON',
|
|
509
|
+
'LAL-1.2',
|
|
510
|
+
'LAL-1.3',
|
|
511
|
+
'Latex2e',
|
|
512
|
+
'Leptonica',
|
|
513
|
+
'LGPL-2.0-only',
|
|
514
|
+
'LGPL-2.0-or-later',
|
|
515
|
+
'LGPL-2.1-only',
|
|
516
|
+
'LGPL-2.1-or-later',
|
|
517
|
+
'LGPL-3.0-only',
|
|
518
|
+
'LGPL-3.0-or-later',
|
|
519
|
+
'LGPLLR',
|
|
520
|
+
'Libpng',
|
|
521
|
+
'libtiff',
|
|
522
|
+
'LiLiQ-P-1.1',
|
|
523
|
+
'LiLiQ-R-1.1',
|
|
524
|
+
'LiLiQ-Rplus-1.1',
|
|
525
|
+
'Linux-OpenIB',
|
|
526
|
+
'LPL-1.0',
|
|
527
|
+
'LPL-1.02',
|
|
528
|
+
'LPPL-1.0',
|
|
529
|
+
'LPPL-1.1',
|
|
530
|
+
'LPPL-1.2',
|
|
531
|
+
'LPPL-1.3a',
|
|
532
|
+
'LPPL-1.3c',
|
|
533
|
+
'MakeIndex',
|
|
534
|
+
'MirOS',
|
|
535
|
+
'MIT-0',
|
|
536
|
+
'MIT-advertising',
|
|
537
|
+
'MIT-CMU',
|
|
538
|
+
'MIT-enna',
|
|
539
|
+
'MIT-feh',
|
|
540
|
+
'MIT',
|
|
541
|
+
'MITNFA',
|
|
542
|
+
'Motosoto',
|
|
543
|
+
'mpich2',
|
|
544
|
+
'MPL-1.0',
|
|
545
|
+
'MPL-1.1',
|
|
546
|
+
'MPL-2.0-no-copyleft-exception',
|
|
547
|
+
'MPL-2.0',
|
|
548
|
+
'MS-PL',
|
|
549
|
+
'MS-RL',
|
|
550
|
+
'MTLL',
|
|
551
|
+
'Multics',
|
|
552
|
+
'Mup',
|
|
553
|
+
'NASA-1.3',
|
|
554
|
+
'Naumen',
|
|
555
|
+
'NBPL-1.0',
|
|
556
|
+
'NCSA',
|
|
557
|
+
'Net-SNMP',
|
|
558
|
+
'NetCDF',
|
|
559
|
+
'Newsletr',
|
|
560
|
+
'NGPL',
|
|
561
|
+
'NLOD-1.0',
|
|
562
|
+
'NLPL',
|
|
563
|
+
'Nokia',
|
|
564
|
+
'NOSL',
|
|
565
|
+
'Noweb',
|
|
566
|
+
'NPL-1.0',
|
|
567
|
+
'NPL-1.1',
|
|
568
|
+
'NPOSL-3.0',
|
|
569
|
+
'NRL',
|
|
570
|
+
'NTP',
|
|
571
|
+
'OCCT-PL',
|
|
572
|
+
'OCLC-2.0',
|
|
573
|
+
'ODbL-1.0',
|
|
574
|
+
'ODC-By-1.0',
|
|
575
|
+
'OFL-1.0',
|
|
576
|
+
'OFL-1.1',
|
|
577
|
+
'OGL-UK-1.0',
|
|
578
|
+
'OGL-UK-2.0',
|
|
579
|
+
'OGL-UK-3.0',
|
|
580
|
+
'OGTSL',
|
|
581
|
+
'OLDAP-1.1',
|
|
582
|
+
'OLDAP-1.2',
|
|
583
|
+
'OLDAP-1.3',
|
|
584
|
+
'OLDAP-1.4',
|
|
585
|
+
'OLDAP-2.0.1',
|
|
586
|
+
'OLDAP-2.0',
|
|
587
|
+
'OLDAP-2.1',
|
|
588
|
+
'OLDAP-2.2.1',
|
|
589
|
+
'OLDAP-2.2.2',
|
|
590
|
+
'OLDAP-2.2',
|
|
591
|
+
'OLDAP-2.3',
|
|
592
|
+
'OLDAP-2.4',
|
|
593
|
+
'OLDAP-2.5',
|
|
594
|
+
'OLDAP-2.6',
|
|
595
|
+
'OLDAP-2.7',
|
|
596
|
+
'OLDAP-2.8',
|
|
597
|
+
'OML',
|
|
598
|
+
'OpenSSL',
|
|
599
|
+
'OPL-1.0',
|
|
600
|
+
'OSET-PL-2.1',
|
|
601
|
+
'OSL-1.0',
|
|
602
|
+
'OSL-1.1',
|
|
603
|
+
'OSL-2.0',
|
|
604
|
+
'OSL-2.1',
|
|
605
|
+
'OSL-3.0',
|
|
606
|
+
'PDDL-1.0',
|
|
607
|
+
'PHP-3.0',
|
|
608
|
+
'PHP-3.01',
|
|
609
|
+
'Plexus',
|
|
610
|
+
'PostgreSQL',
|
|
611
|
+
'psfrag',
|
|
612
|
+
'psutils',
|
|
613
|
+
'Python-2.0',
|
|
614
|
+
'Qhull',
|
|
615
|
+
'QPL-1.0',
|
|
616
|
+
'Rdisc',
|
|
617
|
+
'RHeCos-1.1',
|
|
618
|
+
'RPL-1.1',
|
|
619
|
+
'RPL-1.5',
|
|
620
|
+
'RPSL-1.0',
|
|
621
|
+
'RSA-MD',
|
|
622
|
+
'RSCPL',
|
|
623
|
+
'Ruby',
|
|
624
|
+
'SAX-PD',
|
|
625
|
+
'Saxpath',
|
|
626
|
+
'SCEA',
|
|
627
|
+
'Sendmail-8.23',
|
|
628
|
+
'Sendmail',
|
|
629
|
+
'SGI-B-1.0',
|
|
630
|
+
'SGI-B-1.1',
|
|
631
|
+
'SGI-B-2.0',
|
|
632
|
+
'SimPL-2.0',
|
|
633
|
+
'SISSL-1.2',
|
|
634
|
+
'SISSL',
|
|
635
|
+
'Sleepycat',
|
|
636
|
+
'SMLNJ',
|
|
637
|
+
'SMPPL',
|
|
638
|
+
'SNIA',
|
|
639
|
+
'Spencer-86',
|
|
640
|
+
'Spencer-94',
|
|
641
|
+
'Spencer-99',
|
|
642
|
+
'SPL-1.0',
|
|
643
|
+
'SugarCRM-1.1.3',
|
|
644
|
+
'SWL',
|
|
645
|
+
'TCL',
|
|
646
|
+
'TCP-wrappers',
|
|
647
|
+
'TMate',
|
|
648
|
+
'TORQUE-1.1',
|
|
649
|
+
'TOSL',
|
|
650
|
+
'TU-Berlin-1.0',
|
|
651
|
+
'TU-Berlin-2.0',
|
|
652
|
+
'Unicode-DFS-2015',
|
|
653
|
+
'Unicode-DFS-2016',
|
|
654
|
+
'Unicode-TOU',
|
|
655
|
+
'Unlicense',
|
|
656
|
+
'UPL-1.0',
|
|
657
|
+
'Vim',
|
|
658
|
+
'VOSTROM',
|
|
659
|
+
'VSL-1.0',
|
|
660
|
+
'W3C-19980720',
|
|
661
|
+
'W3C-20150513',
|
|
662
|
+
'W3C',
|
|
663
|
+
'Watcom-1.0',
|
|
664
|
+
'Wsuipa',
|
|
665
|
+
'WTFPL',
|
|
666
|
+
'X11',
|
|
667
|
+
'Xerox',
|
|
668
|
+
'XFree86-1.1',
|
|
669
|
+
'xinetd',
|
|
670
|
+
'Xnet',
|
|
671
|
+
'xpp',
|
|
672
|
+
'XSkat',
|
|
673
|
+
'YPL-1.0',
|
|
674
|
+
'YPL-1.1',
|
|
675
|
+
'Zed',
|
|
676
|
+
'Zend-2.0',
|
|
677
|
+
'Zimbra-1.3',
|
|
678
|
+
'Zimbra-1.4',
|
|
679
|
+
'zlib-acknowledgement',
|
|
680
|
+
'Zlib',
|
|
681
|
+
'ZPL-1.1',
|
|
682
|
+
'ZPL-2.0',
|
|
683
|
+
'ZPL-2.1',
|
|
684
|
+
];
|
|
685
|
+
|
|
686
|
+
// E1xx
|
|
687
|
+
function checkIOPackageJson(context) {
|
|
688
|
+
context = context || {};
|
|
689
|
+
return new Promise((resolve, reject) => {
|
|
690
|
+
console.log('checkIOPackageJson [E1xx]');
|
|
691
|
+
if (context.ioPackageJson) {
|
|
692
|
+
return resolve(context.ioPackageJson);
|
|
693
|
+
} else {
|
|
694
|
+
return downloadFile(context.githubUrl, '/io-package.json')
|
|
695
|
+
.then(packageJson => resolve(packageJson))
|
|
696
|
+
.catch(e => reject(e));
|
|
697
|
+
}
|
|
698
|
+
}).then(ioPackageJson => {
|
|
699
|
+
return new Promise(resolve => {
|
|
700
|
+
context.ioPackageJson = ioPackageJson;
|
|
701
|
+
if (typeof context.ioPackageJson === 'string') {
|
|
702
|
+
try {
|
|
703
|
+
context.ioPackageJson = JSON.parse(context.ioPackageJson);
|
|
704
|
+
} catch (e) {
|
|
705
|
+
context.errors.push('[E100] Cannot parse io-package.json: ' + e);
|
|
706
|
+
return resolve(context);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
if (!context.ioPackageJson.native) {
|
|
711
|
+
context.errors.push('[E101] io-package.json must have at least empty "native" attribute');
|
|
712
|
+
} else {
|
|
713
|
+
context.checks.push('"native" found in io-package.json');
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
if (!context.ioPackageJson.common) {
|
|
717
|
+
context.errors.push('[E102] io-package.json must have common object');
|
|
718
|
+
return resolve(context);
|
|
719
|
+
} else {
|
|
720
|
+
context.checks.push('"common" found in io-package.json');
|
|
721
|
+
if (!context.ioPackageJson.common.name || context.ioPackageJson.common.name !== context.adapterName.toLowerCase()) {
|
|
722
|
+
context.errors.push(`[E103] "common.name" in io-package.json must be equal to "${context.adapterName.toLowerCase()}'". Now is ${context.ioPackageJson.common.name}`);
|
|
723
|
+
} else {
|
|
724
|
+
context.checks.push('"common.name" is valid in io-package.json');
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (context.ioPackageJson.common.title) {
|
|
728
|
+
context.warnings.push('[W171] "common.title" is deprecated in io-package.json');
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
if (!context.ioPackageJson.common.titleLang) {
|
|
732
|
+
context.errors.push('[E104] No "common.titleLang" found in io-package.json');
|
|
733
|
+
} else {
|
|
734
|
+
context.checks.push('"common.titleLang" found in io-package.json');
|
|
735
|
+
|
|
736
|
+
if (typeof context.ioPackageJson.common.titleLang !== 'object') {
|
|
737
|
+
context.errors.push('[E105] "common.titleLang" must be an object. Now: ' + JSON.stringify(context.ioPackageJson.common.titleLang));
|
|
738
|
+
} else if (!checkLanguages(context.ioPackageJson.common.titleLang)) {
|
|
739
|
+
context.warnings.push(`[W105] "common.titleLang" should be translated into all supported languages (${allowedLanguages.join(', ')})`);
|
|
740
|
+
} else {
|
|
741
|
+
Object.keys(context.ioPackageJson.common.titleLang).forEach(lang => {
|
|
742
|
+
const text = context.ioPackageJson.common.titleLang[lang];
|
|
743
|
+
if (text.match(/iobroker/i)) {
|
|
744
|
+
context.errors.push('[W105] "common.titleLang" should not have ioBroker in the name. It is clear, for what this adapter was created. Now: ' + JSON.stringify(context.ioPackageJson.common.titleLang));
|
|
745
|
+
} else {
|
|
746
|
+
context.checks.push('"common.titleLang" has no ioBroker in it in io-package.json');
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
if (text.match(/\sadapter|adapter\s/i)) {
|
|
750
|
+
context.errors.push('[E106] "common.titleLang" should not contain word "adapter" in the name. It is clear, that this is adapter. Now: ' + JSON.stringify(context.ioPackageJson.common.titleLang));
|
|
751
|
+
} else {
|
|
752
|
+
context.checks.push('"common.titleLang" has no "adapter" in it in io-package.json');
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
if (!context.ioPackageJson.common.version) {
|
|
759
|
+
context.errors.push('[E107] No "common.version" found in io-package.json');
|
|
760
|
+
} else {
|
|
761
|
+
context.checks.push('"common.version" found in io-package.json');
|
|
762
|
+
|
|
763
|
+
if (!context.packageJson || context.ioPackageJson.common.version !== context.packageJson.version) {
|
|
764
|
+
context.errors.push('[E118] Versions in package.json and in io-package.json are different');
|
|
765
|
+
} else {
|
|
766
|
+
context.checks.push('"common.version" is equal in package.json adn in io-package.json');
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
if (!context.ioPackageJson.common.desc) {
|
|
771
|
+
context.errors.push('[E108] No "common.desc" found in io-package.json');
|
|
772
|
+
} else {
|
|
773
|
+
context.checks.push('"common.desc" found in io-package.json');
|
|
774
|
+
|
|
775
|
+
if (typeof context.ioPackageJson.common.desc !== 'object') {
|
|
776
|
+
context.errors.push('[E109] "common.desc" in io-package.json should be an object for many languages. Found only ' + context.ioPackageJson.common.desc);
|
|
777
|
+
} else if (!checkLanguages(context.ioPackageJson.common.desc)) {
|
|
778
|
+
context.warnings.push(`[W109] "common.desc" should be translated into all supported languages (${allowedLanguages.join(', ')})`);
|
|
779
|
+
} else {
|
|
780
|
+
context.checks.push('"common.desc" is multilingual in io-package.json');
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
if (context.ioPackageJson.common.keywords) {
|
|
785
|
+
const forbiddenKeywords = ['iobroker', 'adapter', 'smart home'];
|
|
786
|
+
if (!Array.isArray(context.ioPackageJson.common.keywords)) {
|
|
787
|
+
context.errors.push('[E169] "common.keywords" must be an array in the io-package.json');
|
|
788
|
+
} else if (forbiddenKeywords.filter(keyword => context.ioPackageJson.common.keywords.map(k => k.toLowerCase()).includes(keyword)).length > 0) {
|
|
789
|
+
context.warnings.push(`[W170] "common.keywords" should not contain "${forbiddenKeywords.join(', ')}" io-package.json`);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
context.checks.push('"common.keywords" found in io-package.json');
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
if (!context.ioPackageJson.common.icon) {
|
|
796
|
+
context.errors.push('[E110] Icon not found in the io-package.json');
|
|
797
|
+
} else {
|
|
798
|
+
context.checks.push('"common.icon" found in io-package.json');
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if (!context.ioPackageJson.common.extIcon) {
|
|
802
|
+
context.errors.push('[E111] extIcon not found in the io-package.json');
|
|
803
|
+
} else {
|
|
804
|
+
context.checks.push('"common.extIcon" found in io-package.json');
|
|
805
|
+
|
|
806
|
+
// extract icon name
|
|
807
|
+
let fileName = context.ioPackageJson.common.extIcon;
|
|
808
|
+
let pos = fileName.indexOf('?');
|
|
809
|
+
|
|
810
|
+
if (pos !== -1) {
|
|
811
|
+
fileName = fileName.substring(0, pos);
|
|
812
|
+
}
|
|
813
|
+
pos = fileName.lastIndexOf('/');
|
|
814
|
+
fileName = fileName.substring(pos + 1, fileName.length);
|
|
815
|
+
|
|
816
|
+
if (fileName !== context.ioPackageJson.common.icon) {
|
|
817
|
+
context.errors.push('[E112] extIcon must be the same as an icon but with github path');
|
|
818
|
+
} else {
|
|
819
|
+
context.checks.push('"common.extIcon" has same path as repo in io-package.json');
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
if (!context.ioPackageJson.common.compact && !context.ioPackageJson.common.onlyWWW) {
|
|
824
|
+
context.warnings.push('[W113] Adapter should support compact mode');
|
|
825
|
+
} else if (!context.ioPackageJson.common.onlyWWW) {
|
|
826
|
+
context.checks.push('"common.compact" found in io-package.json');
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
if (!context.ioPackageJson.common.noConfig) {
|
|
830
|
+
if (!context.ioPackageJson.common.materialize &&
|
|
831
|
+
!(context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'json') &&
|
|
832
|
+
!(context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'materialize')
|
|
833
|
+
) {
|
|
834
|
+
context.errors.push('[E114] No adapter are allowed in the repo without admin support (set "common.noConfig = true" and "common.adminUI.config = none" if adapter has no configuration)');
|
|
835
|
+
} else {
|
|
836
|
+
context.checks.push('"common.materialize" or "common.adminUI.config" found in io-package.json');
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
if (!(context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'json')) {
|
|
840
|
+
context.warnings.push('[W156] Adapter should support admin 5 UI (jsonConfig)');
|
|
841
|
+
}
|
|
842
|
+
} else {
|
|
843
|
+
context.checks.push('adapter has no admin config');
|
|
844
|
+
|
|
845
|
+
if (!context.ioPackageJson.common.adminUI || context.ioPackageJson.common.adminUI.config !== 'none') {
|
|
846
|
+
context.warnings.push('[W164] Adapters without config "common.noConfig = true" should also set "common.adminUI.config = none"');
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
if (!context.ioPackageJson.common.license) {
|
|
851
|
+
context.errors.push('[E115] No license found in io-package.json');
|
|
852
|
+
} else {
|
|
853
|
+
context.checks.push('"common.license" found in io-package.json');
|
|
854
|
+
|
|
855
|
+
// check if license valid
|
|
856
|
+
if (!licenses.includes(context.ioPackageJson.common.license)) {
|
|
857
|
+
context.errors.push('[E116] No SPDX license found. Please use one of listed here: https://spdx.org/licenses/');
|
|
858
|
+
} else {
|
|
859
|
+
context.checks.push('"common.license" is valid in io-package.json');
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
if (!context.packageJson ||
|
|
863
|
+
context.ioPackageJson.common.license !== context.packageJson.license) {
|
|
864
|
+
context.errors.push('[E117] Licenses in package.json and in io-package.json are different');
|
|
865
|
+
} else {
|
|
866
|
+
context.checks.push('"common.license" is equal in pacjage.json and in io-package.json');
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
if (!context.ioPackageJson.common.mode) {
|
|
871
|
+
context.errors.push('[E165] Node mode found in package.json');
|
|
872
|
+
} else {
|
|
873
|
+
context.checks.push('"common.mode" found in io-package.json');
|
|
874
|
+
|
|
875
|
+
if (!allowedModes[context.ioPackageJson.common.mode]) {
|
|
876
|
+
context.errors.push('[E166] Unknown type found in io-package.json');
|
|
877
|
+
} else {
|
|
878
|
+
context.checks.push('"common.mode" has known mode in io-package.json');
|
|
879
|
+
|
|
880
|
+
if (context.ioPackageJson.common.onlyWWW && context.ioPackageJson.common.mode !== 'none') {
|
|
881
|
+
context.errors.push('[E162] onlyWWW should have common.mode "none" in io-package.json');
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
if (context.ioPackageJson.common.mode === 'schedule' && !context.ioPackageJson.common.schedule) {
|
|
885
|
+
context.errors.push('[E167] schedule adapters must have common.schedule property in io-package.json');
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
if (!context.ioPackageJson.common.type) {
|
|
891
|
+
context.errors.push('[E119] No type found in io-package.json');
|
|
892
|
+
} else {
|
|
893
|
+
context.checks.push('"common.type" found in io-package.json');
|
|
894
|
+
|
|
895
|
+
if (!allowedTypes[context.ioPackageJson.common.type]) {
|
|
896
|
+
context.errors.push('[E120] Unknown type found in io-package.json');
|
|
897
|
+
} else {
|
|
898
|
+
context.checks.push('"common.type" has known type in io-package.json');
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
if (!context.ioPackageJson.common.authors) {
|
|
903
|
+
context.errors.push('[E121] No authors found in io-package.json');
|
|
904
|
+
} else {
|
|
905
|
+
context.checks.push('"common.authors" found in io-package.json');
|
|
906
|
+
|
|
907
|
+
if (!(context.ioPackageJson.common.authors instanceof Array)) {
|
|
908
|
+
context.errors.push('[E122] authors must be an Array in io-package.json');
|
|
909
|
+
} else {
|
|
910
|
+
context.checks.push('"common.authors" is array in io-package.json');
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
if (!context.ioPackageJson.common.authors.length) {
|
|
914
|
+
context.errors.push('[E123] Authors may not be empty in io-package.json');
|
|
915
|
+
} else {
|
|
916
|
+
context.checks.push('"common.authors" is not empty in io-package.json');
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
if (context.ioPackageJson.common.localLink) {
|
|
921
|
+
context.warnings.push('[W172] "common.localLink" in io-package.json is deprecated. Please define object "common.localLinks": { "_default": "..." }');
|
|
922
|
+
} else {
|
|
923
|
+
context.checks.push('No "common.localLink" found in io-package.json');
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
if (!context.ioPackageJson.common.news) {
|
|
927
|
+
context.errors.push('[E130] No "common.news" found in io-package.json');
|
|
928
|
+
} else {
|
|
929
|
+
context.checks.push('"common.news" found in io-package.json');
|
|
930
|
+
|
|
931
|
+
if (Object.keys(context.ioPackageJson.common.news).length > 20) {
|
|
932
|
+
context.errors.push('[E130] Too many "common.news" found in io-package.json. Must be less than 20. Please remove old news.');
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
if (!context.ioPackageJson.common.news[context.ioPackageJson.common.version]) {
|
|
936
|
+
context.errors.push(`[E145] No "common.news" found for actual version ${context.ioPackageJson.common.version}`);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
Object.keys(context.ioPackageJson.common.news).forEach(version => {
|
|
940
|
+
if (!checkLanguages(context.ioPackageJson.common.news[version])) {
|
|
941
|
+
context.warnings.push(`[W145] Each "common.news" should be translated into all supported languages (${allowedLanguages.join(', ')})`);
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// now check the package.json again, because it is valid only for onlyWWW
|
|
947
|
+
if (!context.packageJson.main) {
|
|
948
|
+
!context.ioPackageJson.common.onlyWWW && context.errors.push('[E143] No main found in the package.json');
|
|
949
|
+
} else {
|
|
950
|
+
context.checks.push('"main" found in package.json');
|
|
951
|
+
|
|
952
|
+
if (context.ioPackageJson.common.mode !== 'none' && !context.packageJson.main.endsWith('.js')) {
|
|
953
|
+
!context.ioPackageJson.common.onlyWWW && context.errors.push(`[E163] common.mode "${context.ioPackageJson.common.mode}" requires JavaScript file for "main" in package.json`);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
if (context.ioPackageJson.common.installedFrom) {
|
|
958
|
+
context.errors.push('[E144] common.installedFrom field found in io-package.json. Must be removed.');
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
if (context.ioPackageJson.instanceObjects) {
|
|
962
|
+
const instanceObjects = context.ioPackageJson.instanceObjects;
|
|
963
|
+
if (!(instanceObjects instanceof Array)) {
|
|
964
|
+
context.errors.push('[E146] instanceObjects must be an Array in io-package.json');
|
|
965
|
+
} else {
|
|
966
|
+
const allowedObjectTypes = ['state', 'channel', 'device', 'enum', 'host', 'adapter', 'instance', 'meta', 'config', 'script', 'user', 'group', 'chart', 'folder'];
|
|
967
|
+
const allowedStateTypes = ['number', 'string', 'boolean', 'array', 'object', 'mixed', 'file', 'json'];
|
|
968
|
+
|
|
969
|
+
instanceObjects.forEach(instanceObject => {
|
|
970
|
+
if (instanceObject.type !== undefined && !allowedObjectTypes.includes(instanceObject.type)) {
|
|
971
|
+
context.errors.push('[E147] instanceObject type has an invalid type: ' + instanceObject.type);
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
if (instanceObject.common) {
|
|
975
|
+
if (instanceObject.common.type !== undefined) {
|
|
976
|
+
if (typeof instanceObject.common.type !== 'string') {
|
|
977
|
+
context.errors.push(`[E148] instanceObject common.type has an invalid type! Expected "string", received "${typeof instanceObject.common.type}"`);
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
if (instanceObject.type === 'state' && !allowedStateTypes.includes(instanceObject.common.type)) {
|
|
981
|
+
context.errors.push('[E149] instanceObject common.type has an invalid value: ' + instanceObject.common.type);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
if (!context.ioPackageJson.common.connectionType) {
|
|
990
|
+
!context.ioPackageJson.common.onlyWWW && context.errors.push('[E150] No common.connectionType found in io-package.json');
|
|
991
|
+
} else if (!['local', 'cloud', 'none'].includes(context.ioPackageJson.common.connectionType)) {
|
|
992
|
+
context.errors.push(`[E151] common.connectionType type has an invalid value "${context.ioPackageJson.common.connectionType}"`);
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
if (!context.ioPackageJson.common.dataSource) {
|
|
996
|
+
!context.ioPackageJson.common.onlyWWW && context.errors.push('[E152] No common.dataSource found in io-package.json');
|
|
997
|
+
} else if (!['poll', 'push', 'assumption', 'none'].includes(context.ioPackageJson.common.dataSource)) {
|
|
998
|
+
context.errors.push(`[E152] common.dataSource type has an invalid value "${context.ioPackageJson.common.dataSource}"`);
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
let currentJsControllerVersion = undefined;
|
|
1002
|
+
|
|
1003
|
+
if (context.ioPackageJson.common.dependencies) {
|
|
1004
|
+
const dependencyArray = getDependencyArray(context.ioPackageJson.common.dependencies);
|
|
1005
|
+
|
|
1006
|
+
// Admin is not allowed in dependencies (globalDependencies only)
|
|
1007
|
+
if (dependencyArray.includes('admin')) {
|
|
1008
|
+
context.errors.push(`[E160] "admin" is not allowed in common.dependencies`);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
const jsControllerDependency = context.ioPackageJson.common.dependencies.find(dep => Object.keys(dep).find(attr => attr === 'js-controller'));
|
|
1012
|
+
if (jsControllerDependency) {
|
|
1013
|
+
console.log(`Found current js-controller dependency "${jsControllerDependency['js-controller']}"`);
|
|
1014
|
+
|
|
1015
|
+
if (!jsControllerDependency['js-controller'].startsWith('>=')) {
|
|
1016
|
+
context.errors.push(`[E159] common.dependencies "js-controller" dependency should always allow future versions (>=x.x.x) - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1017
|
+
} else {
|
|
1018
|
+
currentJsControllerVersion = jsControllerDependency['js-controller'].replace(/[^\d.]/g, '');
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
if (context.ioPackageJson.common.globalDependencies) {
|
|
1024
|
+
const dependencyArray = getDependencyArray(context.ioPackageJson.common.globalDependencies);
|
|
1025
|
+
|
|
1026
|
+
// js-controller is not allowed in global dependencies (dependencies only)
|
|
1027
|
+
if (dependencyArray.includes('js-controller')) {
|
|
1028
|
+
context.errors.push(`[E161] "js-controller" is not allowed in common.globalDependencies`);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
if (context.packageJson.dependencies && context.packageJson.dependencies['@iobroker/adapter-core']) {
|
|
1033
|
+
/*
|
|
1034
|
+
- adapter-core <2.3 has no special dep requirements
|
|
1035
|
+
- adapter-core 2.3.x requires js-controller 1.5.8+ as dep
|
|
1036
|
+
- adapter-core 2.4.0+ required js-controller 2.0.0+ as dep
|
|
1037
|
+
*/
|
|
1038
|
+
if (context.packageJson.dependencies['@iobroker/adapter-core'].includes('2.3')) {
|
|
1039
|
+
if (!context.ioPackageJson.common.dependencies) {
|
|
1040
|
+
context.errors.push(`[E153] common.dependencies must contain {"js-controller": ">=1.5.8"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1041
|
+
} else {
|
|
1042
|
+
if (currentJsControllerVersion) {
|
|
1043
|
+
if (!compareVersions.compare(currentJsControllerVersion, '1.5.8', '>=')) {
|
|
1044
|
+
context.errors.push(`[E153] common.dependencies must contain {"js-controller": ">=1.5.8"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1045
|
+
} else {
|
|
1046
|
+
context.checks.push('adapter-core 2.3 dependency matches js-controller dependency');
|
|
1047
|
+
}
|
|
1048
|
+
} else {
|
|
1049
|
+
context.errors.push(`[E153] common.dependencies must contain {"js-controller": ">=1.5.8"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
} else if (context.packageJson.dependencies['@iobroker/adapter-core'].includes('2.4') || context.packageJson.dependencies['@iobroker/adapter-core'].includes('2.5') || context.packageJson.dependencies['@iobroker/adapter-core'].includes('2.6')) {
|
|
1053
|
+
if (!context.ioPackageJson.common.dependencies) {
|
|
1054
|
+
context.errors.push(`[E154] common.dependencies must contain {"js-controller": ">=2.0.0"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1055
|
+
} else {
|
|
1056
|
+
if (currentJsControllerVersion) {
|
|
1057
|
+
if (!compareVersions.compare(currentJsControllerVersion, '2.0.0', '>=')) {
|
|
1058
|
+
context.errors.push(`[E154] common.dependencies must contain {"js-controller": ">=2.0.0"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1059
|
+
} else {
|
|
1060
|
+
context.checks.push('adapter-core >=2.4 dependency matches js-controller dependency');
|
|
1061
|
+
}
|
|
1062
|
+
} else {
|
|
1063
|
+
context.errors.push(`[E154] common.dependencies must contain {"js-controller": ">=2.0.0"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
if (context.ioPackageJson.common.protectedNative) {
|
|
1070
|
+
if (!currentJsControllerVersion) {
|
|
1071
|
+
context.errors.push(`[E157] common.protectedNative requires dependency {"js-controller": ">=2.0.2"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1072
|
+
} else if (!compareVersions.compare(currentJsControllerVersion, '2.0.2', '>=')) {
|
|
1073
|
+
context.errors.push(`[E157] common.protectedNative requires dependency {"js-controller": ">=2.0.2"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
if (context.ioPackageJson.common.encryptedNative) {
|
|
1078
|
+
if (!currentJsControllerVersion) {
|
|
1079
|
+
context.errors.push(`[E158] common.encryptedNative requires dependency {"js-controller": ">=3.0.3"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1080
|
+
} else if (!compareVersions.compare(currentJsControllerVersion, '3.0.3', '>=')) {
|
|
1081
|
+
context.errors.push(`[E158] common.encryptedNative requires dependency {"js-controller": ">=3.0.3"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
if (context.ioPackageJson.common.notifications) {
|
|
1086
|
+
if (!currentJsControllerVersion) {
|
|
1087
|
+
context.errors.push(`[E168] common.notifications requires dependency {"js-controller": ">=3.2.0"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1088
|
+
} else if (!compareVersions.compare(currentJsControllerVersion, '3.2.0', '>=')) {
|
|
1089
|
+
context.errors.push(`[E168] common.notifications requires dependency {"js-controller": ">=3.2.0"} or later - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
if (context.ioPackageJson.common.tier && ![1, 2, 3].includes(context.ioPackageJson.common.tier)) {
|
|
1094
|
+
context.errors.push(`[E155] Invalid tier value: ${context.ioPackageJson.common.tier}. Only 1, 2 or 3 are allowed!`);
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
if (context.ioPackageJson.common.extIcon) {
|
|
1098
|
+
return downloadFile(context.ioPackageJson.common.extIcon, null, true)
|
|
1099
|
+
.then(icon => {
|
|
1100
|
+
const image = sizeOf(icon);
|
|
1101
|
+
if (image.width !== image.height) {
|
|
1102
|
+
context.errors.push('[E140] width and height of logo are not equal');
|
|
1103
|
+
} else {
|
|
1104
|
+
context.checks.push('Width and height of logo are equal');
|
|
1105
|
+
if (image.width < 32) {
|
|
1106
|
+
context.errors.push('[E141] logo is too small. It must be greater or equal than 32x32');
|
|
1107
|
+
} else if (image.width > 512) {
|
|
1108
|
+
context.errors.push('[E142] logo is too big. It must be less or equal than 512x512');
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
context.checks.push('"extIcon" could be downloaded');
|
|
1113
|
+
if (!context.ioPackageJson.onlyWWW && context.packageJson.main) {
|
|
1114
|
+
return downloadFile(context.githubUrl, '/' + context.packageJson.main)
|
|
1115
|
+
.then(() => context.checks.push(context.packageJson.main + ' could be downloaded'))
|
|
1116
|
+
.catch(() => context.errors.push(`[E124] Main file not found under URL: ${context.githubUrl}/${context.packageJson.main}`))
|
|
1117
|
+
.then(() => Promise.resolve(context));
|
|
1118
|
+
} else {
|
|
1119
|
+
return Promise.resolve(context);
|
|
1120
|
+
}
|
|
1121
|
+
})
|
|
1122
|
+
.catch(() => context.errors.push(`[E125] External icon not found under URL: ${context.ioPackageJson.common.extIcon}`))
|
|
1123
|
+
.then(() => resolve(context));
|
|
1124
|
+
} else {
|
|
1125
|
+
resolve(context);
|
|
1126
|
+
}
|
|
1127
|
+
// do not put any code behind this line
|
|
1128
|
+
|
|
1129
|
+
// max number is E172
|
|
1130
|
+
}
|
|
1131
|
+
});
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
// E2xx
|
|
1136
|
+
function checkNpm(context) {
|
|
1137
|
+
console.log('checkNpm [E2xx]');
|
|
1138
|
+
return axios('https://api.npms.io/v2/package/iobroker.' + context.adapterName)
|
|
1139
|
+
.catch(() => ({body: null}))
|
|
1140
|
+
.then(async response => {
|
|
1141
|
+
let body = response.data;
|
|
1142
|
+
// bug in NPM some modules could be accessed via normal web page, but not by API
|
|
1143
|
+
if (!body) {
|
|
1144
|
+
try {
|
|
1145
|
+
const _response = await axios('https://www.npmjs.com/package/iobroker.' + context.adapterName);
|
|
1146
|
+
if (!_response.data) {
|
|
1147
|
+
context.errors.push('[E200] Not found on npm. Please publish');
|
|
1148
|
+
return context;
|
|
1149
|
+
} else {
|
|
1150
|
+
body = _response.data;
|
|
1151
|
+
|
|
1152
|
+
context.checks.push('Adapter found on npm');
|
|
1153
|
+
if (!body.includes('href="/~bluefox"') && body.includes('href="/~iobluefox"')) {
|
|
1154
|
+
context.errors.push(`[E201] Bluefox was not found in the collaborators on NPM!. Please execute in adapter directory: "npm owner add bluefox iobroker.${context.adapterName}"`);
|
|
1155
|
+
} else {
|
|
1156
|
+
context.checks.push('Bluefox found in collaborators on NPM');
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
} catch (error) {
|
|
1160
|
+
context.errors.push('[E200] Not found on npm. Please publish');
|
|
1161
|
+
return context;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
context.checks.push('Adapter found on npm');
|
|
1165
|
+
|
|
1166
|
+
if (!body ||
|
|
1167
|
+
!body.collected ||
|
|
1168
|
+
!body.collected.metadata ||
|
|
1169
|
+
!body.collected.metadata.maintainers ||
|
|
1170
|
+
!body.collected.metadata.maintainers.length ||
|
|
1171
|
+
!body.collected.metadata.maintainers.find(user => user.username === 'bluefox' || user.username === 'iobluefox')) {
|
|
1172
|
+
context.errors.push(`[E201] Bluefox was not found in the collaborators on NPM!. Please execute in adapter directory: "npm owner add bluefox iobroker.${context.adapterName}"`);
|
|
1173
|
+
} else {
|
|
1174
|
+
context.checks.push('Bluefox found in collaborators on NPM');
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
if (!body ||
|
|
1178
|
+
!body.collected ||
|
|
1179
|
+
!body.collected.metadata ||
|
|
1180
|
+
!body.collected.metadata.version ||
|
|
1181
|
+
context.packageJson.version !== body.collected.metadata.version) {
|
|
1182
|
+
context.warnings.push(`[W202] Version of package.json (${context.packageJson.version}) doesn't match latest version on NPM (${body.collected.metadata.version})`);
|
|
1183
|
+
} else {
|
|
1184
|
+
context.checks.push('Version of package.json matches latest version on NPM');
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
return context;
|
|
1188
|
+
// max number is E202
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
// E3xx
|
|
1193
|
+
function checkTests(context) {
|
|
1194
|
+
console.log('checkTests [E3xx]');
|
|
1195
|
+
// if found some file in \.github\workflows with test inside => it is OK too
|
|
1196
|
+
if (context && context.filesList.find(name => name.startsWith('.github/workflows/') && name.endsWith('.yml') && name.toLowerCase().includes('test'))) {
|
|
1197
|
+
context.checks.push('Tests found on github actions');
|
|
1198
|
+
return Promise.resolve(context);
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
const travisURL = context.githubUrlOriginal.replace('github.com', 'api.travis-ci.org') + '.png';
|
|
1202
|
+
|
|
1203
|
+
return axios(travisURL)
|
|
1204
|
+
.then(response => {
|
|
1205
|
+
if (!response.data) {
|
|
1206
|
+
context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
|
|
1207
|
+
return context;
|
|
1208
|
+
}
|
|
1209
|
+
if (!response.headers || !response.headers['content-disposition']) {
|
|
1210
|
+
context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
|
|
1211
|
+
return context;
|
|
1212
|
+
}
|
|
1213
|
+
// inline; filename="passing.png"
|
|
1214
|
+
const m = response.headers['content-disposition'].match(/filename="(.+)"$/);
|
|
1215
|
+
if (!m) {
|
|
1216
|
+
context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
|
|
1217
|
+
return context;
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
if (m[1] === 'unknown.png') {
|
|
1221
|
+
context.errors.push('[E300] Not found on travis. Please setup travis or use github actions (preferred)');
|
|
1222
|
+
return context;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
context.checks.push('Found on travis-ci');
|
|
1226
|
+
|
|
1227
|
+
context.warnings.push('[W302] Use github actions instead of travis-ci');
|
|
1228
|
+
|
|
1229
|
+
if (m[1] !== 'passing.png') {
|
|
1230
|
+
context.errors.push('[E301] Tests on Travis-ci.org are broken. Please fix.');
|
|
1231
|
+
} else {
|
|
1232
|
+
context.checks.push('Tests are OK on travis-ci');
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
return context;
|
|
1236
|
+
// max number is E302
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// E4xx
|
|
1241
|
+
function checkRepo(context) {
|
|
1242
|
+
console.log('checkRepo [E4xx]');
|
|
1243
|
+
if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.type) {
|
|
1244
|
+
// download latest repo
|
|
1245
|
+
return axios('https://raw.githubusercontent.com/ioBroker/ioBroker.repositories/master/sources-dist.json')
|
|
1246
|
+
.then(async response => {
|
|
1247
|
+
let body = response.data;
|
|
1248
|
+
if (!body) {
|
|
1249
|
+
context.errors.push('[E400] Cannot download https://raw.githubusercontent.com/ioBroker/ioBroker.repositories/master/sources-dist.json');
|
|
1250
|
+
} else {
|
|
1251
|
+
context.latestRepo = body;
|
|
1252
|
+
if (!context.latestRepo[context.adapterName]) {
|
|
1253
|
+
context.warnings.push('[W400] Cannot find "' + context.adapterName + '" in latest repository');
|
|
1254
|
+
} else {
|
|
1255
|
+
context.checks.push('Adapter found in latest repository');
|
|
1256
|
+
|
|
1257
|
+
if (context.latestRepo[context.adapterName].type !== context.ioPackageJson.common.type) {
|
|
1258
|
+
context.errors.push('[E402] Types of adapter in latest repository and in io-package.json are different "' + context.latestRepo[context.adapterName].type + '" !== "' + context.ioPackageJson.common.type + '"');
|
|
1259
|
+
} else {
|
|
1260
|
+
context.checks.push('Types of adapter in latest repository and in io-package.json are equal: "' + context.latestRepo[context.adapterName].type + '"');
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
if (context.latestRepo[context.adapterName].version) {
|
|
1264
|
+
context.errors.push('[E403] Version set in latest repository');
|
|
1265
|
+
} else {
|
|
1266
|
+
context.checks.push('Version does not set in latest repository');
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
const url = `https://raw.githubusercontent.com/${context.authorName}/ioBroker.${context.adapterName}/${context.branch}/`;
|
|
1270
|
+
|
|
1271
|
+
if (!context.latestRepo[context.adapterName].icon) {
|
|
1272
|
+
context.errors.push('[E404] Icon does not found in latest repository');
|
|
1273
|
+
} else {
|
|
1274
|
+
context.checks.push('Icon found in latest repository');
|
|
1275
|
+
|
|
1276
|
+
if (!context.latestRepo[context.adapterName].icon.startsWith(url)) {
|
|
1277
|
+
context.errors.push('[E405] Icon must be in the following path: ' + url);
|
|
1278
|
+
} else {
|
|
1279
|
+
context.checks.push('Icon found in latest repository');
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
if (!context.latestRepo[context.adapterName].meta) {
|
|
1283
|
+
context.errors.push('[E406] Meta URL (latest) not found in latest repository');
|
|
1284
|
+
} else {
|
|
1285
|
+
context.checks.push('Meta URL(latest) found in latest repository');
|
|
1286
|
+
|
|
1287
|
+
if (context.latestRepo[context.adapterName].meta !== url + 'io-package.json') {
|
|
1288
|
+
context.errors.push(`[E407] Meta URL (latest) must be equal to ${url}io-package.json`);
|
|
1289
|
+
} else {
|
|
1290
|
+
context.checks.push('Meta URL (latest) is OK in latest repository');
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
// download stable repo
|
|
1297
|
+
const _response = await axios('https://raw.githubusercontent.com/ioBroker/ioBroker.repositories/master/sources-dist-stable.json');
|
|
1298
|
+
body = _response.data;
|
|
1299
|
+
if (!body) {
|
|
1300
|
+
context.errors.push('[E420] Cannot download https://raw.githubusercontent.com/ioBroker/ioBroker.repositories/master/sources-dist-stable.json');
|
|
1301
|
+
} else {
|
|
1302
|
+
context.stableRepo = body;
|
|
1303
|
+
if (context.stableRepo[context.adapterName]) {
|
|
1304
|
+
if (context.stableRepo[context.adapterName].type !== context.ioPackageJson.common.type) {
|
|
1305
|
+
context.errors.push('[E422] Types of adapter in stable repository and in io-package.json are different "' + context.stableRepo[context.adapterName].type + '" !== "' + context.ioPackageJson.common.type + '"');
|
|
1306
|
+
} else {
|
|
1307
|
+
context.checks.push('Types of adapter in stable repository and in io-package.json are equal: "' + context.stableRepo[context.adapterName].type + '"');
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
if (!context.latestRepo[context.adapterName]) {
|
|
1311
|
+
context.errors.push('[E423] Adapter was found in stable repository but not in latest repo');
|
|
1312
|
+
} else {
|
|
1313
|
+
context.checks.push('Adapter was found in stable repository and in latest repo');
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
if (!context.stableRepo[context.adapterName].version) {
|
|
1317
|
+
context.errors.push('[E424] No version set in stable repository');
|
|
1318
|
+
} else {
|
|
1319
|
+
context.checks.push('Version found in stable repository');
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
const url = `https://raw.githubusercontent.com/${context.authorName}/ioBroker.${context.adapterName}/${context.branch}/`;
|
|
1323
|
+
|
|
1324
|
+
if (!context.stableRepo[context.adapterName].icon) {
|
|
1325
|
+
context.errors.push('[E425] Icon does not found in stable repository');
|
|
1326
|
+
} else {
|
|
1327
|
+
context.checks.push('Icon found in stable repository');
|
|
1328
|
+
|
|
1329
|
+
if (!context.stableRepo[context.adapterName].icon.startsWith(url)) {
|
|
1330
|
+
context.errors.push('[E426] Icon (stable) must be in the following path: ' + url);
|
|
1331
|
+
} else {
|
|
1332
|
+
context.checks.push('Icon (stable) found in latest repository');
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
if (!context.stableRepo[context.adapterName].meta) {
|
|
1337
|
+
context.errors.push('[E427] Meta URL (stable) not found in latest repository');
|
|
1338
|
+
} else {
|
|
1339
|
+
context.checks.push('Meta URL (stable) found in latest repository');
|
|
1340
|
+
|
|
1341
|
+
if (context.stableRepo[context.adapterName].meta !== url + 'io-package.json') {
|
|
1342
|
+
context.errors.push(`[E428] Meta URL (stable) must be equal to ${url}io-package.json`);
|
|
1343
|
+
} else {
|
|
1344
|
+
context.checks.push('Meta URL (stable) is OK in latest repository');
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
return context;
|
|
1350
|
+
});
|
|
1351
|
+
} else {
|
|
1352
|
+
return Promise.resolve(context);
|
|
1353
|
+
}
|
|
1354
|
+
// max number is E428
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
function extractWords(words) {
|
|
1358
|
+
try {
|
|
1359
|
+
const lines = words.split(/\r\n|\r|\n/g);
|
|
1360
|
+
let i = 0;
|
|
1361
|
+
while (!lines[i].match(/^systemDictionary = {/)) {
|
|
1362
|
+
i++;
|
|
1363
|
+
}
|
|
1364
|
+
lines.splice(0, i);
|
|
1365
|
+
|
|
1366
|
+
// remove last empty lines
|
|
1367
|
+
i = lines.length - 1;
|
|
1368
|
+
while (!lines[i]) {
|
|
1369
|
+
i--;
|
|
1370
|
+
}
|
|
1371
|
+
if (i < lines.length - 1) {
|
|
1372
|
+
lines.splice(i + 1);
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
lines[0] = lines[0].replace('systemDictionary = ', '');
|
|
1376
|
+
lines[lines.length - 1] = lines[lines.length - 1].trim().replace(/};$/, '}');
|
|
1377
|
+
words = lines.join('\n');
|
|
1378
|
+
const resultFunc = new Function('return ' + words + ';');
|
|
1379
|
+
|
|
1380
|
+
return resultFunc();
|
|
1381
|
+
} catch (e) {
|
|
1382
|
+
return null;
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
// E5xx
|
|
1387
|
+
function checkCode(context) {
|
|
1388
|
+
const readFiles = [
|
|
1389
|
+
'.npmignore',
|
|
1390
|
+
'.gitignore',
|
|
1391
|
+
'iob_npm.done',
|
|
1392
|
+
'.travis.yml',
|
|
1393
|
+
'gulpfile.js'
|
|
1394
|
+
];
|
|
1395
|
+
|
|
1396
|
+
if (context.packageJson.main) {
|
|
1397
|
+
readFiles.push(context.packageJson.main);
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
if (!context.ioPackageJson.common.noConfig) {
|
|
1401
|
+
if (context.ioPackageJson.common.materialize || (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'materialize')) {
|
|
1402
|
+
readFiles.push('admin/index_m.html');
|
|
1403
|
+
readFiles.push('admin/words.js');
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
if (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'json') {
|
|
1407
|
+
readFiles.push('admin/jsonConfig.json');
|
|
1408
|
+
allowedLanguages.forEach(lang => {
|
|
1409
|
+
readFiles.push(`admin/i18n/${lang}/translations.json`);
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
if (context.ioPackageJson.common.supportCustoms || context.ioPackageJson.common.jsonCustom || (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.custom === 'json')) {
|
|
1414
|
+
readFiles.push('admin/jsonCustom.json');
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
if (context.ioPackageJson.common.blockly) {
|
|
1419
|
+
readFiles.push('admin/blockly.js');
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
// https://github.com/userName/ioBroker.adaptername/archive/${context.branch}.zip
|
|
1423
|
+
return new Promise((resolve, reject) => {
|
|
1424
|
+
console.log('checkCode [E5xx]');
|
|
1425
|
+
return downloadFile(context.githubUrlOriginal, `/archive/${context.branch}.zip`, true)
|
|
1426
|
+
.then(data => {
|
|
1427
|
+
console.log(`${context.branch}.zip ${data.length} bytes`);
|
|
1428
|
+
let found = false;
|
|
1429
|
+
const bufferStream = new stream.PassThrough();
|
|
1430
|
+
bufferStream.end(data);
|
|
1431
|
+
context.filesList = [];
|
|
1432
|
+
|
|
1433
|
+
const promises = [];
|
|
1434
|
+
|
|
1435
|
+
return new Promise(_resolve => {
|
|
1436
|
+
bufferStream
|
|
1437
|
+
.pipe(unzipper.Parse())
|
|
1438
|
+
.on('entry', entry => {
|
|
1439
|
+
// console.log('Check ' + entry.path);
|
|
1440
|
+
if (!found && entry.type === 'Directory' && entry.path.match(/\/node_modules\/$/)) {
|
|
1441
|
+
console.log('Found ' + entry.path);
|
|
1442
|
+
found = true;
|
|
1443
|
+
context.errors.push('[E500] node_modules found in repo. Please delete it');
|
|
1444
|
+
}
|
|
1445
|
+
// Get list of all files and .npmignore + .gitignore
|
|
1446
|
+
|
|
1447
|
+
const name = entry.path.replace(/^[^\/]+\//, '');
|
|
1448
|
+
context.filesList.push(name);
|
|
1449
|
+
|
|
1450
|
+
if (readFiles.includes(name)) {
|
|
1451
|
+
promises.push(new Promise(resolve => {
|
|
1452
|
+
const wstream = new WMStrm(name);
|
|
1453
|
+
wstream.on('finish', () => {
|
|
1454
|
+
context['/' + name] = memStore[name].toString();
|
|
1455
|
+
resolve(context['/' + name]);
|
|
1456
|
+
});
|
|
1457
|
+
entry.pipe(wstream);
|
|
1458
|
+
}));
|
|
1459
|
+
} else {
|
|
1460
|
+
entry.autodrain();
|
|
1461
|
+
}
|
|
1462
|
+
})
|
|
1463
|
+
.on('error', () => {
|
|
1464
|
+
context.errors.push(`[E501] Cannot get ${context.branch}.zip on github`);
|
|
1465
|
+
return Promise.all(promises).then(() => _resolve(context));
|
|
1466
|
+
})
|
|
1467
|
+
.on('close', () => {
|
|
1468
|
+
return Promise.all(promises).then(() => _resolve(context));
|
|
1469
|
+
});
|
|
1470
|
+
});
|
|
1471
|
+
})
|
|
1472
|
+
.then(context => {
|
|
1473
|
+
if (context.ioPackageJson.common.materialize || (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'materialize')) {
|
|
1474
|
+
if (context['/admin/index_m.html'] && context['/admin/index_m.html'].includes('selectID.js') && !context.filesList.includes('admin/img/info-big.png')) {
|
|
1475
|
+
context.errors.push('[E502] "admin/img/info-big.png" not found, but selectID.js used in index_m.html ');
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
if (context['/admin/words.js']) {
|
|
1479
|
+
// at least 3 languages must be in
|
|
1480
|
+
const words = extractWords(context['/admin/words.js']);
|
|
1481
|
+
if (words) {
|
|
1482
|
+
const problem = Object.keys(words).filter(word => !words[word].de || !words[word].ru);
|
|
1483
|
+
if (problem.length > 3) {
|
|
1484
|
+
context.errors.push(`[E506] More non translated in german or russian words found in admin/words.js. You can use https://translator.iobroker.in/ for translations`);
|
|
1485
|
+
} else {
|
|
1486
|
+
problem.forEach(word => {
|
|
1487
|
+
if (!words[word].de) {
|
|
1488
|
+
context.errors.push(`[E506] Word "${word}" is not translated to german in admin/words.js. You can use https://translator.iobroker.in/ for translations`);
|
|
1489
|
+
}
|
|
1490
|
+
if (!words[word].ru) {
|
|
1491
|
+
context.errors.push(`[E506] Word "${word}" is not translated to russian in admin/words.js. You can use https://translator.iobroker.in/ for translations`);
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
} else {
|
|
1497
|
+
context.checks.push('admin/words.js found.');
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
if (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'json') {
|
|
1502
|
+
if (context['/admin/jsonConfig.json']) {
|
|
1503
|
+
try {
|
|
1504
|
+
JSON.parse(context['/admin/jsonConfig.json']);
|
|
1505
|
+
} catch (e) {
|
|
1506
|
+
context.errors.push('[E507] Cannot parse "admin/jsonConfig.json": ' + e);
|
|
1507
|
+
}
|
|
1508
|
+
} else {
|
|
1509
|
+
context.errors.push(`[E508] "admin/jsonConfig.json" not found, but admin support is declared`);
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
allowedLanguages.forEach(lang => {
|
|
1513
|
+
if (context[`/admin/i18n/${lang}/translations.json`]) {
|
|
1514
|
+
try {
|
|
1515
|
+
JSON.parse(context[`/admin/i18n/${lang}/translations.json`]);
|
|
1516
|
+
} catch (e) {
|
|
1517
|
+
context.errors.push(`[E509] Cannot parse "admin/i18n/${lang}/translations.json": ${e}`);
|
|
1518
|
+
}
|
|
1519
|
+
} else {
|
|
1520
|
+
context.errors.push(`[E510] "/admin/i18n/${lang}/translations.json" not found, but admin support is declared`);
|
|
1521
|
+
}
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
if (context.ioPackageJson.common.supportCustoms || context.ioPackageJson.common.jsonCustom || (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.custom === 'json')) {
|
|
1526
|
+
if (context['/admin/jsonCustom.json']) {
|
|
1527
|
+
try {
|
|
1528
|
+
JSON.parse(context['/admin/jsonCustom.json']);
|
|
1529
|
+
} catch (e) {
|
|
1530
|
+
context.errors.push('[E511] Cannot parse "admin/jsonCustom.json": ' + e);
|
|
1531
|
+
}
|
|
1532
|
+
} else {
|
|
1533
|
+
context.errors.push(`[E512] "admin/jsonCustom.json" not found, but custom support is declared`);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
if (context.ioPackageJson.common.blockly && !context['/admin/blockly.js']) {
|
|
1538
|
+
context.errors.push('[E514] "admin/blockly.js" not found, but blockly support is declared');
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
if (context['/iob_npm.done']) {
|
|
1542
|
+
context.errors.push('[E503] "iob_npm.done" found in repo! Remove that file');
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
if (context['/.travis.yml']) {
|
|
1546
|
+
context.hasTravis = true;
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
if (context['/gulpfile.js']) {
|
|
1550
|
+
context.warnings.push('[W513] "gulpfile.js" found in repo! Think about migrating to @iobroker/adapter-dev package');
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
if (context.packageJson.main && context.packageJson.main.endsWith('.js')) {
|
|
1554
|
+
if (!context['/' + context.packageJson.main]) {
|
|
1555
|
+
context.errors.push(`[E504] "${context.packageJson.main}" found in package.json, but not found as file`);
|
|
1556
|
+
} else {
|
|
1557
|
+
if (context['/' + context.packageJson.main].includes('setInterval(') && !context['/' + context.packageJson.main].includes('clearInterval(')) {
|
|
1558
|
+
if (context.ioPackageJson.compact) {
|
|
1559
|
+
// if compact mode supported, it is critical
|
|
1560
|
+
context.errors.push(`[E504] setInterval found in "${context.packageJson.main}", but no clearInterval detected`);
|
|
1561
|
+
} else {
|
|
1562
|
+
context.warnings.push(`[W504] setInterval found in "${context.packageJson.main}", but no clearInterval detected`);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
if (context['/' + context.packageJson.main].includes('setTimeout(') && !context['/' + context.packageJson.main].includes('clearTimeout(')) {
|
|
1566
|
+
if (context.ioPackageJson.compact) {
|
|
1567
|
+
// if compact mode supported, it is critical
|
|
1568
|
+
context.errors.push(`[E505] setTimeout found in "${context.packageJson.main}", but no clearTimeout detected`);
|
|
1569
|
+
} else {
|
|
1570
|
+
context.warnings.push(`[W505] setTimeout found in "${context.packageJson.main}", but no clearTimeout detected`);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
// max E514
|
|
1576
|
+
resolve(context);
|
|
1577
|
+
})
|
|
1578
|
+
.catch(e => reject(e));
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
function getAuthor(author) {
|
|
1583
|
+
if (author && typeof author === 'object') {
|
|
1584
|
+
return `${author.name} <${author.email}>`;
|
|
1585
|
+
} else {
|
|
1586
|
+
return author;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
function checkCommits(context) {
|
|
1591
|
+
console.log('checkCommits');
|
|
1592
|
+
return downloadFile(context.githubUrlOriginal, `/commits/${context.branch}`)
|
|
1593
|
+
.then(data => {
|
|
1594
|
+
const m = data.match(/Commits on [\w\s\d]+, (\d\d\d\d)/);
|
|
1595
|
+
if (m) {
|
|
1596
|
+
context.lastCommitYear = m[1];
|
|
1597
|
+
}
|
|
1598
|
+
return context;
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
// E8xx
|
|
1603
|
+
function checkGithubRepo(context) {
|
|
1604
|
+
return new Promise((resolve) => {
|
|
1605
|
+
console.log('checkGithubRepo [E8xx]');
|
|
1606
|
+
|
|
1607
|
+
if (!context.githubApiData.description) {
|
|
1608
|
+
context.errors.push(`[E801] No repository about text found. Please go to "${context.githubUrlOriginal}", press the settings button beside the about title and add the description.`);
|
|
1609
|
+
} else {
|
|
1610
|
+
context.checks.push('Github repository about found.');
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
if (!context.githubApiData.topics || context.githubApiData.topics.length === 0) {
|
|
1614
|
+
context.errors.push(`[E802] No topics found in the repository. Please go to "${context.githubUrlOriginal}", press the settings button beside the about title and add some topics.`);
|
|
1615
|
+
} else {
|
|
1616
|
+
context.checks.push('Github repository about found.');
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
if (context.githubApiData.archived) {
|
|
1620
|
+
context.errors.push(`[E803] Archived repositories are not allowed.`);
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
// max E803
|
|
1624
|
+
resolve(context);
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
// E6xx
|
|
1629
|
+
function checkReadme(context) {
|
|
1630
|
+
// https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/README.md
|
|
1631
|
+
return new Promise((resolve, reject) => {
|
|
1632
|
+
console.log('checkReadme [E6xx]');
|
|
1633
|
+
downloadFile(context.githubUrl, '/README.md')
|
|
1634
|
+
.then(data => {
|
|
1635
|
+
if (!data) {
|
|
1636
|
+
context.errors.push('[E601] No README.md found');
|
|
1637
|
+
} else {
|
|
1638
|
+
context.checks.push('README.md found');
|
|
1639
|
+
|
|
1640
|
+
if (!data.includes('## Changelog')) {
|
|
1641
|
+
context.errors.push('[E603] NO "## Changelog" found in README.md');
|
|
1642
|
+
} else {
|
|
1643
|
+
context.checks.push('README.md contains Changelog');
|
|
1644
|
+
|
|
1645
|
+
if (!data.includes(`### ${context.packageJson.version}`) ) {
|
|
1646
|
+
context.errors.push(`[E606] Current adapter version ${context.packageJson.version} not found in README.md`);
|
|
1647
|
+
} else {
|
|
1648
|
+
context.checks.push('README.md contains current adapter version');
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
const pos = data.indexOf('## License');
|
|
1653
|
+
if (pos === -1) {
|
|
1654
|
+
context.errors.push('[E604] No "## License" found in README.md');
|
|
1655
|
+
} else {
|
|
1656
|
+
context.checks.push('## License found in README.md');
|
|
1657
|
+
const text = data.substring(pos);
|
|
1658
|
+
const year = new Date().getFullYear().toString();
|
|
1659
|
+
if (!text.includes(context.lastCommitYear || year)) {
|
|
1660
|
+
const m = text.match(/(\d\d\d\d)-\d\d\d\d/);
|
|
1661
|
+
if (m) {
|
|
1662
|
+
context.errors.push(`[E605] No actual year found in copyright. Please add "Copyright (c) ${m[1]}-${year} ${getAuthor(context.packageJson.author)}" at the end of README.md`);
|
|
1663
|
+
} else {
|
|
1664
|
+
context.errors.push(`[E605] No actual year found in copyright. Please add "Copyright (c) ${year} ${getAuthor(context.packageJson.author)}" at the end of README.md`);
|
|
1665
|
+
}
|
|
1666
|
+
} else {
|
|
1667
|
+
context.checks.push('Valid copyright year found in README.md');
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
// max E606
|
|
1673
|
+
resolve(context);
|
|
1674
|
+
})
|
|
1675
|
+
.catch(e => reject(e));
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
// E7xx
|
|
1680
|
+
function checkLicenseFile(context) {
|
|
1681
|
+
// https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/LICENSE
|
|
1682
|
+
return new Promise((resolve, reject) => {
|
|
1683
|
+
console.log('checkLicenseFile [E7xx]');
|
|
1684
|
+
downloadFile(context.githubUrl, '/LICENSE')
|
|
1685
|
+
.then(data => {
|
|
1686
|
+
if (!data) {
|
|
1687
|
+
context.errors.push('[E701] NO LICENSE file found');
|
|
1688
|
+
} else {
|
|
1689
|
+
context.checks.push('LICENSE file found');
|
|
1690
|
+
|
|
1691
|
+
if (context.packageJson.license === 'MIT') {
|
|
1692
|
+
const year = new Date().getFullYear().toString();
|
|
1693
|
+
if (!data.includes(context.lastCommitYear || year)) {
|
|
1694
|
+
const m = data.match(/(\d\d\d\d)-\d\d\d\d/);
|
|
1695
|
+
if (m) {
|
|
1696
|
+
context.errors.push(`[E701] No actual year found in LICENSE. Please add "Copyright (c) ${m[1]}-${year} ${getAuthor(context.packageJson.author)}" at the start of LICENSE`);
|
|
1697
|
+
} else {
|
|
1698
|
+
context.errors.push(`[E701] No actual year found in LICENSE. Please add "Copyright (c) ${year} ${getAuthor(context.packageJson.author)}" at the start of LICENSE`);
|
|
1699
|
+
}
|
|
1700
|
+
} else {
|
|
1701
|
+
context.checks.push('Valid copyright year found in LICENSE');
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
resolve(context);
|
|
1706
|
+
})
|
|
1707
|
+
.catch(e => reject(e));
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
function paddingNum(num) {
|
|
1712
|
+
if (num >= 10) return num;
|
|
1713
|
+
return '0' + num;
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
// E8xx
|
|
1717
|
+
function checkNpmIgnore(context) {
|
|
1718
|
+
const checkFiles = [
|
|
1719
|
+
'node_modules/',
|
|
1720
|
+
'test/',
|
|
1721
|
+
'src/',
|
|
1722
|
+
'appveyor.yml',
|
|
1723
|
+
'.travis.yml',
|
|
1724
|
+
'tsconfig.json',
|
|
1725
|
+
'tsconfig.build.json',
|
|
1726
|
+
'iob_npm.done',
|
|
1727
|
+
// '.git/',
|
|
1728
|
+
// '.github/',
|
|
1729
|
+
// '.idea/',
|
|
1730
|
+
// '.gitignore',
|
|
1731
|
+
// '.npmignore',
|
|
1732
|
+
// '.travis.yml',
|
|
1733
|
+
// '.babelrc',
|
|
1734
|
+
// '.editorconfig',
|
|
1735
|
+
// '.eslintignore',
|
|
1736
|
+
// '.eslintrc.js',
|
|
1737
|
+
// '.fimbullinter.yaml',
|
|
1738
|
+
// '.lgtm.yml',
|
|
1739
|
+
// '.prettierignore',
|
|
1740
|
+
// '.prettierignore',
|
|
1741
|
+
// '.prettierrc.js',
|
|
1742
|
+
// '.vscode/',
|
|
1743
|
+
];
|
|
1744
|
+
|
|
1745
|
+
// https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/.npmignore
|
|
1746
|
+
return new Promise((resolve, reject) => {
|
|
1747
|
+
console.log('checkNpmIgnore [E8xx]');
|
|
1748
|
+
if (context.packageJson.files && context.packageJson.files.length) {
|
|
1749
|
+
return resolve(context);
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
if (!context.filesList.includes('.npmignore')) {
|
|
1753
|
+
context.warnings.push(`[W801] .npmignore not found`);
|
|
1754
|
+
} else {
|
|
1755
|
+
const rules = (context['/.npmignore'] || '').split('\n').map(line => line.trim().replace('\r', '')).filter(line => line);
|
|
1756
|
+
let tooComplexToCheck = false;
|
|
1757
|
+
rules.forEach((name, i) => {
|
|
1758
|
+
if (name.includes('*')) {
|
|
1759
|
+
rules[i] = new RegExp(name
|
|
1760
|
+
.replace('.', '\\.')
|
|
1761
|
+
.replace('/', '\\/')
|
|
1762
|
+
.replace('**', '.*')
|
|
1763
|
+
.replace('*', '[^\\/]*')
|
|
1764
|
+
);
|
|
1765
|
+
}
|
|
1766
|
+
if (name.startsWith('!')) {
|
|
1767
|
+
tooComplexToCheck = true;
|
|
1768
|
+
}
|
|
1769
|
+
});
|
|
1770
|
+
|
|
1771
|
+
// There's no need to put node_modules in .npmignore. npm will never publish node_modules in the package, except if one of the modules is explicitly mentioned in bundledDependencies.
|
|
1772
|
+
/*if (!rules.includes('node_modules') && !rules.includes('/node_modules') && !rules.includes('/node_modules/*') && !rules.includes('node_modules/*')) {
|
|
1773
|
+
!check && context.errors.push(`[E804] node_modules not found in .npmignore`);
|
|
1774
|
+
}*/
|
|
1775
|
+
if (!tooComplexToCheck) {
|
|
1776
|
+
if (!rules.includes('iob_npm.done') && !rules.includes('/iob_npm.done')) {
|
|
1777
|
+
!check && context.errors.push(`[E803] iob_npm.done not found in .npmignore`);
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
checkFiles.forEach((file, i) => {
|
|
1781
|
+
if (context.filesList.includes(file)) {
|
|
1782
|
+
// may be it is with regex
|
|
1783
|
+
const check = rules.some(rule => {
|
|
1784
|
+
if (typeof rule === 'string') {
|
|
1785
|
+
return rule === file || rule === file.replace(/\/$/, '');
|
|
1786
|
+
} else {
|
|
1787
|
+
return rule.test(file);
|
|
1788
|
+
}
|
|
1789
|
+
});
|
|
1790
|
+
|
|
1791
|
+
!check && context.errors.push(`[E8${paddingNum(i + 11)}] file ${file} found in repository, but not found in .npmignore`);
|
|
1792
|
+
}
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
resolve(context);
|
|
1797
|
+
});
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
// E9xx
|
|
1801
|
+
function checkGitIgnore(context) {
|
|
1802
|
+
const checkFiles = [
|
|
1803
|
+
'.idea',
|
|
1804
|
+
'tmp',
|
|
1805
|
+
'node_modules',
|
|
1806
|
+
'iob_npm.done',
|
|
1807
|
+
];
|
|
1808
|
+
|
|
1809
|
+
// https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/.gitignore
|
|
1810
|
+
return new Promise((resolve, reject) => {
|
|
1811
|
+
console.log('checkGitIgnore [E9xx]');
|
|
1812
|
+
if (!context.filesList.includes('.gitignore')) {
|
|
1813
|
+
context.warnings.push(`[W901] .gitignore not found`);
|
|
1814
|
+
} else {
|
|
1815
|
+
const rules = (context['/.gitignore'] || '').split('\n').map(line => line.trim().replace('\r', '')).filter(line => line);
|
|
1816
|
+
rules.forEach((name, i) => {
|
|
1817
|
+
if (name.includes('*')) {
|
|
1818
|
+
rules[i] = new RegExp(name
|
|
1819
|
+
.replace('.', '\\.')
|
|
1820
|
+
.replace('/', '\\/')
|
|
1821
|
+
.replace('**', '.*')
|
|
1822
|
+
.replace('*', '[^\\/]*')
|
|
1823
|
+
);
|
|
1824
|
+
}
|
|
1825
|
+
});
|
|
1826
|
+
|
|
1827
|
+
if (!rules.includes('node_modules') && !rules.includes('/node_modules') && !rules.includes('/node_modules/*') && !rules.includes('node_modules/*')) {
|
|
1828
|
+
!check && context.errors.push(`[E902] node_modules not found in .npmignore`);
|
|
1829
|
+
}
|
|
1830
|
+
if (!rules.includes('iob_npm.done') && !rules.includes('/iob_npm.done')) {
|
|
1831
|
+
!check && context.errors.push(`[E903] iob_npm.done not found in .gitignore`);
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
checkFiles.forEach((file, i) => {
|
|
1835
|
+
if (context.filesList.includes(file)) {
|
|
1836
|
+
// may be it is with regex
|
|
1837
|
+
const check = rules.some(rule => {
|
|
1838
|
+
if (typeof rule === 'string') {
|
|
1839
|
+
return rule === file || rule === file.replace(/\/$/, '');
|
|
1840
|
+
} else {
|
|
1841
|
+
return rule.test(file);
|
|
1842
|
+
}
|
|
1843
|
+
});
|
|
1844
|
+
|
|
1845
|
+
!check && context.errors.push(`[E9${paddingNum(i + 11)}] file ${file} found in repository, but not found in .gitignore`);
|
|
1846
|
+
}
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
resolve(context);
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
function makeResponse(code, data, headers) {
|
|
1854
|
+
return {
|
|
1855
|
+
statusCode: code || 200,
|
|
1856
|
+
headers: {
|
|
1857
|
+
'Access-Control-Allow-Origin': '*', // Required for CORS support to work
|
|
1858
|
+
'Access-Control-Allow-Credentials': true // Required for cookies, authorization headers with HTTPS
|
|
1859
|
+
},
|
|
1860
|
+
body: typeof data === 'string' ? data : JSON.stringify(data)
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
function check(request, ctx, callback) {
|
|
1865
|
+
console.log('PROCESS: ' + JSON.stringify(request));
|
|
1866
|
+
if (!request.queryStringParameters.url) {
|
|
1867
|
+
return callback(null, makeResponse(500, {error: 'No github URL provided'}));
|
|
1868
|
+
} else {
|
|
1869
|
+
const context = {checks: [], errors: [], warnings: []};
|
|
1870
|
+
let githubUrl = request.queryStringParameters.url;
|
|
1871
|
+
let githubBranch = request.queryStringParameters.branch;
|
|
1872
|
+
|
|
1873
|
+
githubUrl = githubUrl
|
|
1874
|
+
.replace('http://', 'https://')
|
|
1875
|
+
.replace('https://www.github.com', 'https://github.com')
|
|
1876
|
+
.replace('https://raw.githubusercontent.com/', 'https://github.com/');
|
|
1877
|
+
|
|
1878
|
+
if (githubUrl.match(/\/$/)) {
|
|
1879
|
+
githubUrl = githubUrl.substring(0, githubUrl.length - 1);
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
context.githubUrlOriginal = githubUrl;
|
|
1883
|
+
context.githubUrlApi = githubUrl.replace('https://github.com/', 'https://api.github.com/repos/');
|
|
1884
|
+
context.branch = githubBranch || null;
|
|
1885
|
+
|
|
1886
|
+
getGithubApiData(context)
|
|
1887
|
+
.then(context => checkPackageJson(context))
|
|
1888
|
+
.then(context => checkIOPackageJson(context))
|
|
1889
|
+
.then(context => checkNpm(context))
|
|
1890
|
+
.then(context => checkCommits(context))
|
|
1891
|
+
.then(context => checkRepo(context))
|
|
1892
|
+
.then(context => checkCode(context))
|
|
1893
|
+
.then(context => checkTests(context))
|
|
1894
|
+
.then(context => checkGithubRepo(context))
|
|
1895
|
+
.then(context => checkReadme(context))
|
|
1896
|
+
.then(context => checkLicenseFile(context))
|
|
1897
|
+
.then(context => checkNpmIgnore(context))
|
|
1898
|
+
.then(context => checkGitIgnore(context))
|
|
1899
|
+
.then(context => {
|
|
1900
|
+
return callback(null, makeResponse(200, {result: 'OK', checks: context.checks, errors: context.errors, warnings: context.warnings, version, hasTravis: context.hasTravis}));
|
|
1901
|
+
})
|
|
1902
|
+
.catch(err => {
|
|
1903
|
+
console.error(err);
|
|
1904
|
+
|
|
1905
|
+
return callback(err, makeResponse(200, {result: 'Errors found', checks: context.checks, errors: context.errors, warnings: context.warnings, version, hasTravis: context.hasTravis}));
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
if (typeof module !== 'undefined' && module.parent) {
|
|
1911
|
+
exports.handler = check;
|
|
1912
|
+
} else {
|
|
1913
|
+
let repoUrl = 'https://github.com/ioBroker/ioBroker.admin';
|
|
1914
|
+
let repoBranch = null;
|
|
1915
|
+
|
|
1916
|
+
// Get url from parameters if possible
|
|
1917
|
+
if (process.argv.length > 2) {
|
|
1918
|
+
repoUrl = process.argv[2];
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
// Get branch from parameters if possible
|
|
1922
|
+
if (process.argv.length > 3) {
|
|
1923
|
+
repoBranch = process.argv[3];
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
console.log(`Checking repository ${repoUrl} (branch ${repoBranch})`);
|
|
1927
|
+
check({queryStringParameters: {
|
|
1928
|
+
url: repoUrl,
|
|
1929
|
+
branch: repoBranch
|
|
1930
|
+
}}, null, (err, data) => {
|
|
1931
|
+
const context = JSON.parse(data.body);
|
|
1932
|
+
console.log(context.result);
|
|
1933
|
+
|
|
1934
|
+
if (context.errors.length) {
|
|
1935
|
+
console.error(JSON.stringify(context.errors, null, 2));
|
|
1936
|
+
}
|
|
1937
|
+
if (context.warnings.length) {
|
|
1938
|
+
console.warn(JSON.stringify(context.warnings, null, 2));
|
|
1939
|
+
}
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
|