@iobroker/repochecker 3.0.0-alpha.1 → 3.0.0-alpha.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 +1 -1
- package/lib/M000_PackageJson.js +401 -0
- package/lib/M100_IOPackageJson.js +658 -0
- package/lib/M200_Npm.js +94 -0
- package/lib/M300_Testing.js +62 -0
- package/lib/M400_Repository.js +247 -0
- package/lib/M500_Code.js +440 -0
- package/lib/M600_Readme.js +105 -0
- package/lib/M700_License.js +83 -0
- package/lib/M800_Github.js +56 -0
- package/lib/M900_GitNpmIgnore.js +174 -0
- package/lib/common.js +109 -0
- package/lib/config.js +450 -0
- package/package.json +3 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/*
|
|
3
|
+
This module is a support module for iobroker.repochecker
|
|
4
|
+
|
|
5
|
+
Area checked: .gitignore, .npmignore
|
|
6
|
+
Numbering : 900 - 998
|
|
7
|
+
|
|
8
|
+
NOTE: requires filesList to be loaded
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
TODO:
|
|
13
|
+
- something is wrong with undefined 'check' variable
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// const common = require('./common.js');
|
|
17
|
+
|
|
18
|
+
function paddingNum(num) {
|
|
19
|
+
if (num >= 10) return num;
|
|
20
|
+
return '0' + num;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 900 - ???
|
|
24
|
+
async function checkGitIgnore(context) {
|
|
25
|
+
|
|
26
|
+
const checkFiles = [
|
|
27
|
+
'.idea',
|
|
28
|
+
'tmp',
|
|
29
|
+
'node_modules',
|
|
30
|
+
'iob_npm.done',
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
// https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/.gitignore
|
|
34
|
+
console.log('\ncheckGitIgnore [E9xx]');
|
|
35
|
+
|
|
36
|
+
if (!context.filesList) {
|
|
37
|
+
throw('FATAL:context.fileslist is undefined');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!context.filesList.includes('.gitignore')) {
|
|
41
|
+
context.errors.push(`[E901] .gitignore not found`);
|
|
42
|
+
} else {
|
|
43
|
+
const rules = (context['/.gitignore'] || '').split('\n').map(line => line.trim().replace('\r', '')).filter(line => line);
|
|
44
|
+
rules.forEach((name, i) => {
|
|
45
|
+
if (name.includes('*')) {
|
|
46
|
+
rules[i] = new RegExp(name
|
|
47
|
+
.replace('.', '\\.')
|
|
48
|
+
.replace('/', '\\/')
|
|
49
|
+
.replace('**', '.*')
|
|
50
|
+
.replace('*', '[^\\/]*')
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/* TODO: something is wrong with undefined 'check' variable
|
|
56
|
+
if (!rules.includes('node_modules') && !rules.includes('/node_modules') && !rules.includes('/node_modules/*') && !rules.includes('node_modules/*')) {
|
|
57
|
+
!check && context.errors.push(`[E902] node_modules not found in .npmignore`);
|
|
58
|
+
}
|
|
59
|
+
if (!rules.includes('iob_npm.done') && !rules.includes('/iob_npm.done')) {
|
|
60
|
+
!check && context.errors.push(`[E903] iob_npm.done not found in .gitignore`);
|
|
61
|
+
}
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
checkFiles.forEach(file => {
|
|
65
|
+
if (context.filesList.includes(file)) {
|
|
66
|
+
// maybe it is with regex
|
|
67
|
+
const check = rules.some(rule => {
|
|
68
|
+
if (typeof rule === 'string') {
|
|
69
|
+
return rule === file || rule === file.replace(/\/$/, '');
|
|
70
|
+
} else {
|
|
71
|
+
return rule.test(file);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
!check && context.errors.push(`[E904] file ${file} found in repository, but not found in .gitignore`);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return context;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 950 - ???
|
|
84
|
+
async function checkNpmIgnore(context) {
|
|
85
|
+
const checkFiles = [
|
|
86
|
+
'node_modules/',
|
|
87
|
+
'test/',
|
|
88
|
+
'src/',
|
|
89
|
+
'appveyor.yml',
|
|
90
|
+
'.travis.yml',
|
|
91
|
+
'tsconfig.json',
|
|
92
|
+
'tsconfig.build.json',
|
|
93
|
+
'iob_npm.done',
|
|
94
|
+
// '.git/',
|
|
95
|
+
// '.github/',
|
|
96
|
+
// '.idea/',
|
|
97
|
+
// '.gitignore',
|
|
98
|
+
// '.npmignore',
|
|
99
|
+
// '.travis.yml',
|
|
100
|
+
// '.babelrc',
|
|
101
|
+
// '.editorconfig',
|
|
102
|
+
// '.eslintignore',
|
|
103
|
+
// '.eslintrc.js',
|
|
104
|
+
// '.fimbullinter.yaml',
|
|
105
|
+
// '.lgtm.yml',
|
|
106
|
+
// '.prettierignore',
|
|
107
|
+
// '.prettierignore',
|
|
108
|
+
// '.prettierrc.js',
|
|
109
|
+
// '.vscode/',
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
// https://raw.githubusercontent.com/userName/ioBroker.adaptername/${context.branch}/.npmignore
|
|
113
|
+
console.log('\ncheckNpmIgnore [E95x]');
|
|
114
|
+
if (context.packageJson.files && context.packageJson.files.length) {
|
|
115
|
+
if (context.filesList.includes('.npmignore')) {
|
|
116
|
+
context.warnings.push(`[E951] .npmignore found but "files" is used at package.json. Please remove .npmignore.`);
|
|
117
|
+
} else {
|
|
118
|
+
context.checks.push('package.json "files" already used.');
|
|
119
|
+
}
|
|
120
|
+
return Promise.resolve(context);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// package.json files section is NOT used
|
|
124
|
+
if (!context.filesList.includes('.npmignore')) {
|
|
125
|
+
context.warnings.push(`[E952] .npmignore not found`);
|
|
126
|
+
} else {
|
|
127
|
+
context.warnings.push(`[W953] .npmignore found - consider using package.json object "files" instead.`);
|
|
128
|
+
|
|
129
|
+
const rules = (context['/.npmignore'] || '').split('\n').map(line => line.trim().replace('\r', '')).filter(line => line);
|
|
130
|
+
let tooComplexToCheck = false;
|
|
131
|
+
rules.forEach((name, i) => {
|
|
132
|
+
if (name.includes('*')) {
|
|
133
|
+
rules[i] = new RegExp(name
|
|
134
|
+
.replace('.', '\\.')
|
|
135
|
+
.replace('/', '\\/')
|
|
136
|
+
.replace('**', '.*')
|
|
137
|
+
.replace('*', '[^\\/]*')
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
if (name.startsWith('!')) {
|
|
141
|
+
tooComplexToCheck = true;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// 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.
|
|
146
|
+
/*if (!rules.includes('node_modules') && !rules.includes('/node_modules') && !rules.includes('/node_modules/*') && !rules.includes('node_modules/*')) {
|
|
147
|
+
!check && context.errors.push(`[E954] node_modules not found in `.npmignore``);
|
|
148
|
+
}*/
|
|
149
|
+
if (!tooComplexToCheck) {
|
|
150
|
+
if (!rules.includes('iob_npm.done') && !rules.includes('/iob_npm.done')) {
|
|
151
|
+
/*!check &&*/ context.errors.push(`[E953] iob_npm.done not found in .npmignore`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
checkFiles.forEach((file, i) => {
|
|
155
|
+
if (context.filesList.includes(file)) {
|
|
156
|
+
// maybe it is with regex
|
|
157
|
+
const check = rules.some(rule => {
|
|
158
|
+
if (typeof rule === 'string') {
|
|
159
|
+
return rule === file || rule === file.replace(/\/$/, '');
|
|
160
|
+
} else {
|
|
161
|
+
return rule.test(file);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
!check && context.errors.push(`[E9${paddingNum(i + 61)}] file ${file} found in repository, but not found in .npmignore`);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return context;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
exports.checkGitIgnore = checkGitIgnore;
|
|
174
|
+
exports.checkNpmIgnore = checkNpmIgnore;
|
package/lib/common.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/*
|
|
3
|
+
This module contains genaral utility routines for iobroker.repochecker
|
|
4
|
+
|
|
5
|
+
*/
|
|
6
|
+
const axios = require('axios');
|
|
7
|
+
|
|
8
|
+
// disable axios caching
|
|
9
|
+
axios.defaults.headers = {
|
|
10
|
+
'Cache-Control': 'no-cache',
|
|
11
|
+
'Pragma': 'no-cache',
|
|
12
|
+
'Expires': '0',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
let gDebug = false;
|
|
16
|
+
function setDebug(flag){
|
|
17
|
+
gDebug = flag;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function debug(msg) {
|
|
21
|
+
console.log(`[DEBUG] ${msg}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function checkLanguages(langObj, languages) {
|
|
25
|
+
return languages.filter(lang => !langObj[lang]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function downloadFile(githubUrl, path, binary, noError) {
|
|
29
|
+
|
|
30
|
+
console.log(`Download ${githubUrl}${path || ''}`);
|
|
31
|
+
|
|
32
|
+
const options = {};
|
|
33
|
+
if (binary) {
|
|
34
|
+
options.responseType = 'arraybuffer';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const response = await axios(githubUrl + (path || ''), options);
|
|
39
|
+
debug(`download succeded`);
|
|
40
|
+
return(response.data);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
(!noError || gDebug) && console.error(`Cannot download ${githubUrl}${path || ''} ${e}`);
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getDependencyArray(deps) {
|
|
49
|
+
return deps
|
|
50
|
+
.map(dep => typeof dep === 'object' ? Object.keys(dep) : [dep])
|
|
51
|
+
.reduce((acc, dep) => acc.concat(dep), []);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// dependencies might be:
|
|
55
|
+
// [
|
|
56
|
+
// {"js-controller":">=1.2.3"}
|
|
57
|
+
// ]
|
|
58
|
+
// or
|
|
59
|
+
// [
|
|
60
|
+
// {"js-controller":">=1.2.3"},
|
|
61
|
+
// {"vis":">=1.2.3"}
|
|
62
|
+
// ]
|
|
63
|
+
// or
|
|
64
|
+
// [
|
|
65
|
+
// {
|
|
66
|
+
// "js-controller":">=1.2.3",
|
|
67
|
+
// "vis":">=1.2.3"
|
|
68
|
+
// }
|
|
69
|
+
// ]
|
|
70
|
+
// or
|
|
71
|
+
// [
|
|
72
|
+
// {"js-controller":">=1.2.3"},
|
|
73
|
+
// "vis"
|
|
74
|
+
// ]
|
|
75
|
+
function getDependencies(deps) {
|
|
76
|
+
const ret = {};
|
|
77
|
+
console.log(`deps: ${JSON.stringify(deps)}, type ${typeof deps}`);
|
|
78
|
+
for (const dep of deps ) {
|
|
79
|
+
if (typeof dep === 'object') {
|
|
80
|
+
for (const key in dep ) {
|
|
81
|
+
ret[key] = dep[key];
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
ret[ dep ] = '>=0';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
console.log(`ret: ${JSON.stringify(ret)}`);
|
|
88
|
+
return ret;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
return the greater of two semver versions
|
|
93
|
+
*/
|
|
94
|
+
function maxVersion(v1, v2) {
|
|
95
|
+
if (compareVersions.compareVersions(v1, v2) > 0) {
|
|
96
|
+
return v1;
|
|
97
|
+
}
|
|
98
|
+
return v2;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
exports.setDebug=setDebug;
|
|
102
|
+
exports.debug=debug;
|
|
103
|
+
|
|
104
|
+
exports.checkLanguages=checkLanguages;
|
|
105
|
+
exports.downloadFile=downloadFile;
|
|
106
|
+
exports.getDependencyArray=getDependencyArray;
|
|
107
|
+
exports.getDependencies=getDependencies;
|
|
108
|
+
exports.maxVersion=maxVersion;
|
|
109
|
+
|