Skip to content

Commit

Permalink
Merge pull request #1243 from fturmel/PR/upgrade-deps-and-minor-impro…
Browse files Browse the repository at this point in the history
…vements

Upgrade deps (Gatsby 5.11) and minor improvements
  • Loading branch information
shiffman committed Oct 22, 2023
2 parents ae6796e + f205889 commit 2abf881
Show file tree
Hide file tree
Showing 5 changed files with 4,825 additions and 3,202 deletions.
45 changes: 24 additions & 21 deletions node-scripts/tags-transforms.js
@@ -1,35 +1,38 @@
const { globSync } = require('glob');
const { glob } = require('glob');
const isEqual = require('lodash/isEqual');
const prettier = require('prettier');
const { readFileSync, writeFileSync } = require('fs');
const { readFile, writeFile } = require('fs/promises');
const { memoTagsCleanup } = require('./utils');
const { wordReplacements, tagTransforms } = require('./tags-transforms.json');

const tagsCleanup = memoTagsCleanup(wordReplacements, tagTransforms);
const paths = globSync('content/videos/**/index.json');
let count = 0;

for (let path of paths) {
const raw = readFileSync(path);
const o = JSON.parse(raw);
(async () => {
const paths = await glob('content/videos/**/index.json');
let count = 0;

const languages = tagsCleanup(o.languages);
const topics = tagsCleanup(o.topics);
for (const path of paths) {
const raw = await readFile(path);
const o = JSON.parse(raw);

if (!isEqual(languages, o.languages) || !isEqual(topics, o.topics)) {
o.languages = languages;
o.topics = topics;
const languages = tagsCleanup(o.languages);
const topics = tagsCleanup(o.topics);

const udpatedSource = prettier.format(JSON.stringify(o), {
parser: 'json'
});
if (!isEqual(languages, o.languages) || !isEqual(topics, o.topics)) {
o.languages = languages;
o.topics = topics;

writeFileSync(path, udpatedSource);
const udpatedSource = await prettier.format(JSON.stringify(o), {
parser: 'json'
});

count++;
await writeFile(path, udpatedSource);

count++;
}
}
}

console.log(
`${count} of ${paths.length} video JSON files were modified to transform language and topic tags`
);
console.log(
`${count} of ${paths.length} video JSON files were modified to transform language and topic tags`
);
})();

0 comments on commit 2abf881

Please sign in to comment.