Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

move-unique-image-assets.js 1.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  1. #!/usr/bin/env node
  2. const fs = require('fs')
  3. const path = require('path')
  4. const walk = require('walk-sync')
  5. // iterate through enterprise images from most recent to oldest
  6. // for each asset and move any images from /assets/enterprise,
  7. // with file paths that don't already exist, to the /assets/images
  8. // directory. Then the existing Markdown will just work.
  9. async function main () {
  10. const directories = [
  11. path.join('assets/enterprise/3.0'),
  12. path.join('assets/enterprise/github-ae'),
  13. path.join('assets/enterprise/2.22'),
  14. path.join('assets/enterprise/2.21'),
  15. path.join('assets/enterprise/2.20')
  16. ]
  17. for (const directory of directories) {
  18. const files = walk(path.join(process.cwd(), directory), { includeBasePath: true, directories: false })
  19. for (const file of files) {
  20. // get the /assets/images path from the enterprise asset path
  21. const enterpriseRegex = /\/assets\/enterprise\/(2\.20|2\.21|2\.22|3\.0|github-ae)/
  22. const existingFileToCompare = file.replace(enterpriseRegex, '')
  23. if (!fs.existsSync(existingFileToCompare)) {
  24. const newDirectoryName = path.dirname(existingFileToCompare)
  25. if (!fs.existsSync(newDirectoryName)) {
  26. fs.mkdirSync(newDirectoryName, { recursive: true })
  27. }
  28. fs.renameSync(file, existingFileToCompare)
  29. }
  30. }
  31. }
  32. }
  33. main()
  34. .catch(console.error)
  35. .finally(() => console.log('Done!'))
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...