-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathtags-transforms.js
More file actions
38 lines (29 loc) · 1.06 KB
/
tags-transforms.js
File metadata and controls
38 lines (29 loc) · 1.06 KB
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
const { glob } = require('glob');
const isEqual = require('lodash/isEqual');
const prettier = require('prettier');
const { readFile, writeFile } = require('fs/promises');
const { memoTagsCleanup } = require('./utils');
const { wordReplacements, tagTransforms } = require('./tags-transforms.json');
const tagsCleanup = memoTagsCleanup(wordReplacements, tagTransforms);
(async () => {
const paths = await glob('content/videos/**/index.json');
let count = 0;
for (const path of paths) {
const raw = await readFile(path);
const o = JSON.parse(raw);
const languages = tagsCleanup(o.languages);
const topics = tagsCleanup(o.topics);
if (!isEqual(languages, o.languages) || !isEqual(topics, o.topics)) {
o.languages = languages;
o.topics = topics;
const updatedSource = await prettier.format(JSON.stringify(o), {
parser: 'json'
});
await writeFile(path, updatedSource);
count++;
}
}
console.log(
`${count} of ${paths.length} video JSON files were modified to transform language and topic tags`
);
})();