Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
LizBaker committed Jun 17, 2022
1 parent cd30b11 commit 1c5bcd1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@
"db:clean": "./scripts/actions/translation_workflow/testing/cleanup.sh",
"i18n-utility": "npx ts-node ./scripts/i18n_utility/cli.ts",
"image-codemod": "./codemods/convertMDXImages/runImageWorkflow.sh",
"generate-nav-titles": " node scripts/getNavforTranslation.js"
"generate-nav-titles": " node scripts/getNavforTranslation.js",
"delete-unused-images": " node scripts/removeUnusedImages.js"
},
"husky": {
"hooks": {
Expand Down
32 changes: 32 additions & 0 deletions scripts/removeUnusedImages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const fs = require('fs');
const path = require('path');

const isFile = (filepath) => fs.statSync(filepath).isFile();
const isDirectory = (filepath) => fs.statSync(filepath).isDirectory();
const pathJoin = (base) => (filepath) => path.join(base, filepath);

const getDirectories = (filepath) =>
fs.readdirSync(filepath).map(pathJoin(filepath)).filter(isDirectory);

const getFiles = (filepath) =>
fs.readdirSync(filepath).map(pathJoin(filepath)).filter(isFile);

const getFilesRecursively = (filepath) =>
getDirectories(filepath)
.flatMap(getFilesRecursively)
.reduce((acc, file) => [...acc, file], getFiles(filepath));

const getAllDocsFiles = () => {
const files = getFilesRecursively('src/content/docs/synthetics');
const regex = new RegExp('^import.+', 'gm');
const filteredFiles = files
.flatMap((file) => {
const textfile = fs.readFileSync(file, 'utf-8');
return textfile.match(regex)?.split('/')?.[1];
})
.filter(Boolean);

console.log(filteredFiles);
};

getAllDocsFiles();

0 comments on commit 1c5bcd1

Please sign in to comment.