-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (47 loc) · 1.63 KB
/
index.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
#!/usr/bin/env node
const arg = require('arg');
const cloneDeep = require('clone-deep');
const fs = require('fs');
const glob = require("glob");
const path = require("path");
const YAML = require('yaml');
const patterns = require('./patterns');
const ignores = require('./ignores');
const ignore = '--ignore';
const labels = '--label';
const args = arg({
[ignore]: [String],
[labels]: [String]
});
if (args[ignore] !== undefined) {
args[ignore].forEach(entry => ignores.push(entry));
}
const labelsConfig = args[labels] === undefined ? {} : {labels: args[labels]};
const configs = [];
Object.keys(patterns).forEach(pattern => {
const patternConfig = patterns[pattern];
const matches = glob.sync(`**/${pattern}`, {
dot: true,
ignore: ignores
});
matches.forEach(match => {
const directory = path.dirname(match);
const config = {
...cloneDeep(patternConfig),
...cloneDeep(labelsConfig),
directory: directory === '.' ? '/' : directory,
'open-pull-requests-limit': 10,
};
configs.push(config);
});
});
const doc = new YAML.Document();
const arguments = process.argv.slice(2).join(' ');
doc.commentBefore = (' Generated with https://github.com/charleskorn/dependabot-config-generator\n Re-generate this file with: npx github:charleskorn/dependabot-config-generator ' + arguments).trimEnd();
doc.contents = {version: 2, updates: configs};
const directory = '.github';
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory);
}
const filePath = path.join(directory, 'dependabot.yml');
fs.writeFileSync(filePath, doc.toString());