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

update-versioning-in-files.js 2.2 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  1. #!/usr/bin/env node
  2. const fs = require('fs')
  3. const path = require('path')
  4. const walk = require('walk-sync')
  5. const frontmatter = require('../lib/read-frontmatter')
  6. const contentPath = path.join(process.cwd(), 'content')
  7. const dataPath = path.join(process.cwd(), 'data')
  8. const contentFiles = walk(contentPath, { includeBasePath: true, directories: false })
  9. .filter(file => file.endsWith('.md'))
  10. .filter(file => !file.endsWith('README.md'))
  11. const dataFiles = walk(dataPath, { includeBasePath: true, directories: false })
  12. .filter(file => file.includes('data/reusables') || file.includes('data/variables'))
  13. .filter(file => !file.endsWith('README.md'))
  14. dataFiles
  15. .forEach(file => {
  16. const content = fs.readFileSync(file, 'utf8')
  17. // Update Liquid in data files
  18. const newContent = updateLiquid(content)
  19. fs.writeFileSync(file, newContent)
  20. })
  21. contentFiles
  22. .forEach(file => {
  23. const { data, content } = frontmatter(fs.readFileSync(file, 'utf8'))
  24. // Update Liquid in content files
  25. const newContent = content ? updateLiquid(content) : ''
  26. // Update versions frontmatter
  27. if (data) {
  28. if (!data.versions && data.productVersions) {
  29. data.versions = data.productVersions
  30. Object.keys(data.versions).forEach(version => {
  31. // update dotcom, actions, rest, etc.
  32. if (version !== 'enterprise') {
  33. data.versions['free-pro-team'] = data.versions[version]
  34. delete data.versions[version]
  35. } else {
  36. data.versions['enterprise-server'] = data.versions.enterprise
  37. delete data.versions.enterprise
  38. }
  39. })
  40. }
  41. delete data.productVersions
  42. // Update Liquid in frontmatter props
  43. Object.keys(data)
  44. // Only process a subset of props
  45. .filter(key => key === 'title' || key === 'intro' || key === 'product')
  46. .forEach(key => {
  47. data[key] = updateLiquid(data[key])
  48. })
  49. }
  50. fs.writeFileSync(file, frontmatter.stringify(newContent, data, { lineWidth: 10000 }))
  51. })
  52. function updateLiquid (content) {
  53. return content
  54. .replace(/page.version/g, 'currentVersion')
  55. .replace(/["'](?:')?dotcom["'](?:')?/g, '"free-pro-team@latest"')
  56. .replace(/["'](?:')?(2\.\d{2})["'](?:')?/g, '"enterprise-server@$1"')
  57. }
Tip!

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

Comments

Loading...