Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade deps (Gatsby 5.11) and minor improvements #1243

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 24 additions & 21 deletions node-scripts/tags-transforms.js
Original file line number Diff line number Diff line change
@@ -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`
);
})();