|
1 |
| -const { globSync } = require('glob'); |
| 1 | +const { glob } = require('glob'); |
2 | 2 | const isEqual = require('lodash/isEqual');
|
3 | 3 | const prettier = require('prettier');
|
4 |
| -const { readFileSync, writeFileSync } = require('fs'); |
| 4 | +const { readFile, writeFile } = require('fs/promises'); |
5 | 5 | const { memoTagsCleanup } = require('./utils');
|
6 | 6 | const { wordReplacements, tagTransforms } = require('./tags-transforms.json');
|
7 | 7 |
|
8 | 8 | const tagsCleanup = memoTagsCleanup(wordReplacements, tagTransforms);
|
9 |
| -const paths = globSync('content/videos/**/index.json'); |
10 |
| -let count = 0; |
11 | 9 |
|
12 |
| -for (let path of paths) { |
13 |
| - const raw = readFileSync(path); |
14 |
| - const o = JSON.parse(raw); |
| 10 | +(async () => { |
| 11 | + const paths = await glob('content/videos/**/index.json'); |
| 12 | + let count = 0; |
15 | 13 |
|
16 |
| - const languages = tagsCleanup(o.languages); |
17 |
| - const topics = tagsCleanup(o.topics); |
| 14 | + for (const path of paths) { |
| 15 | + const raw = await readFile(path); |
| 16 | + const o = JSON.parse(raw); |
18 | 17 |
|
19 |
| - if (!isEqual(languages, o.languages) || !isEqual(topics, o.topics)) { |
20 |
| - o.languages = languages; |
21 |
| - o.topics = topics; |
| 18 | + const languages = tagsCleanup(o.languages); |
| 19 | + const topics = tagsCleanup(o.topics); |
22 | 20 |
|
23 |
| - const udpatedSource = prettier.format(JSON.stringify(o), { |
24 |
| - parser: 'json' |
25 |
| - }); |
| 21 | + if (!isEqual(languages, o.languages) || !isEqual(topics, o.topics)) { |
| 22 | + o.languages = languages; |
| 23 | + o.topics = topics; |
26 | 24 |
|
27 |
| - writeFileSync(path, udpatedSource); |
| 25 | + const udpatedSource = await prettier.format(JSON.stringify(o), { |
| 26 | + parser: 'json' |
| 27 | + }); |
28 | 28 |
|
29 |
| - count++; |
| 29 | + await writeFile(path, udpatedSource); |
| 30 | + |
| 31 | + count++; |
| 32 | + } |
30 | 33 | }
|
31 |
| -} |
32 | 34 |
|
33 |
| -console.log( |
34 |
| - `${count} of ${paths.length} video JSON files were modified to transform language and topic tags` |
35 |
| -); |
| 35 | + console.log( |
| 36 | + `${count} of ${paths.length} video JSON files were modified to transform language and topic tags` |
| 37 | + ); |
| 38 | +})(); |
0 commit comments