forked from jsdoc/jsdoc
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Herebyfile.js
122 lines (101 loc) · 3.18 KB
/
Herebyfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
Copyright 2023 the JSDoc Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import path from 'node:path';
import { execa } from 'execa';
import { task } from 'hereby';
import { LicenseChecker } from 'js-green-licenses';
const BIN_DIR = 'node_modules/.bin';
const JSDOC_BIN = 'packages/jsdoc/jsdoc.js';
const NODE_BIN = process.execPath;
const sourceGlob = ['*.cjs', '*.js', 'packages/**/*/*.cjs', 'packages/**/*.js'];
function bin(name) {
return path.join(BIN_DIR, name);
}
export const coverage = task({
name: 'coverage',
run: async () => {
await execa(bin('c8'), [
'--exclude=Herebyfile.js',
"--exclude='**/test{,s}/**'",
'--reporter=html',
bin('hereby'),
'test',
]);
},
});
export const dependencyLicenses = task({
name: 'dependency-licenses',
run: () => {
const checker = new LicenseChecker({ verbose: false });
const log = console.log;
return new Promise((resolve, reject) => {
// Temporarily silence console.log() to prevent unnecessary output.
console.log = () => {}; // eslint-disable-line no-empty-function
checker.on('end', () => {
console.log = log;
resolve();
});
checker.on('error', (e) => {
const message =
`Error while processing ${e.packageName}@${e.versionSpec}: ${e.err}. ` +
`Parent packages: ${JSON.stringify(e.parentPackages, null, 0)}`;
console.log = log;
reject(new Error(message));
});
checker.on('non-green-license', (e) => {
const message =
`${e.packageName}@${e.version} has an invalid license: ${e.licenseName}. ` +
`Parent packages: ${JSON.stringify(e.parentPackages, null, 0)}`;
console.log = log;
reject(new Error(message));
});
checker.checkLocalDirectory('.');
});
},
});
export const format = task({
name: 'format',
run: async () => {
await execa(bin('prettier'), ['--write', './']);
},
});
export const licenseHeaders = task({
name: 'license-headers',
run: async () => {
await execa(bin('license-check-and-add'), ['check', '-f', '.license-check.json']);
},
});
export const licenseCheck = task({
name: 'license-check',
dependencies: [dependencyLicenses, licenseHeaders],
});
export const lint = task({
name: 'lint',
run: async () => {
await execa(bin('eslint'), [...sourceGlob], { stdout: 'inherit', stderr: 'inherit' });
},
});
export const test = task({
name: 'test',
run: async () => {
await execa(NODE_BIN, [JSDOC_BIN, '-T'], {
stdout: process.stdout,
stderr: process.stderr,
});
},
});
const lintAndTest = task({
name: 'lint-and-test',
dependencies: [lint, test],
});
export default lintAndTest;