-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
delete-unused-files.js
60 lines (44 loc) · 1.34 KB
/
delete-unused-files.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
const { readdirSync, rmSync } = require('fs');
const walkSync = require('walk-sync');
const files = readdirSync('rev-index');
const plurals = {
namespace: 'namespaces',
class: 'classes',
module: 'modules',
}
function deleteUnusedFilesForRevIndex(file) {
const json = require(file);
let project;
if(json.data.id.match(/^ember-\d/)) {
project = 'ember';
} else if (json.data.id.match(/^ember-data-\d/)) {
project = 'ember-data';
} else {
console.log('error figuring out project for', file);
return;
}
const version = json.data.attributes.version;
const knownFiles = [];
['module', 'class', 'namespace'].forEach(entity => {
for (const key in json.meta[entity]) {
knownFiles.push(`${plurals[entity]}/${json.meta[entity][key]}.json`);
}
})
const paths = walkSync(`json-docs/${project}/${version}`, { directories: false});
paths.forEach(file => {
if (file.startsWith('project-versions/')) {
// ignore project-versions folder
return;
}
if (file.startsWith('missings/')) {
// I have no idea what a "missings" is but tests fail if we don't ignore them
return;
}
if(!knownFiles.includes(file)) {
rmSync(`json-docs/${project}/${version}/${file}`)
}
})
}
files.forEach(file => {
deleteUnusedFilesForRevIndex(`./rev-index/${file}`)
});