unused-files.mjs 821 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env node
  2. 'use strict'
  3. import { globSync } from 'glob'
  4. import { fileURLToPath } from 'node:url'
  5. import path from 'node:path'
  6. import { readFileSync } from 'node:fs'
  7. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  8. let foundFiles = []
  9. globSync(path.join(__dirname, `../preview/**/*.{html,md}`)).forEach((file) => {
  10. let fileContent = readFileSync(file)
  11. fileContent.toString().replace(/\{% include(_cached)? ([a-z0-9\/_-]+\.html)/g, (f, c, filename) => {
  12. filename = path.join(__dirname, `../preview/_includes/${filename}`)
  13. if (!foundFiles.includes(filename)) {
  14. foundFiles.push(filename)
  15. }
  16. })
  17. })
  18. let includeFiles = globSync(path.join(__dirname, `../preview/_includes/**/*.html`))
  19. includeFiles.forEach((file) => {
  20. if (!foundFiles.includes(file)) {
  21. console.log('file', file)
  22. }
  23. })