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

remove-version-markup.js 4.0 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  1. #!/usr/bin/env node
  2. const fs = require('fs')
  3. const path = require('path')
  4. const walk = require('walk-sync')
  5. const matter = require('gray-matter')
  6. const program = require('commander')
  7. const { indexOf, nth } = require('lodash')
  8. const removeLiquidStatements = require('../../lib/remove-liquid-statements')
  9. const removeDeprecatedFrontmatter = require('../../lib/remove-deprecated-frontmatter')
  10. const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
  11. const contentPath = path.join(__dirname, '../../content')
  12. const dataPath = path.join(__dirname, '../../data')
  13. const removeUnusedAssetsScript = 'script/remove-unused-assets'
  14. const elseifRegex = /{-?% elsif/
  15. // [start-readme]
  16. //
  17. // Run this script after an Enterprise deprecation to remove Liquid statements and frontmatter that contain the deprecated Enterprise version.
  18. // See the Enterprise deprecation issue template for instructions.
  19. //
  20. // [end-readme]
  21. program
  22. .description('Remove Liquid conditionals and update versions frontmatter for a given Enterprise Server release.')
  23. .option('-r, --release <NUMBER>', 'Enterprise Server release number. Example: 2.19')
  24. .parse(process.argv)
  25. // verify CLI options
  26. if (!program.release) {
  27. console.log(program.description() + '\n')
  28. program.options.forEach(opt => {
  29. console.log(opt.flags)
  30. console.log(opt.description + '\n')
  31. })
  32. process.exit(1)
  33. }
  34. if (!enterpriseServerReleases.all.includes(program.release)) {
  35. console.log(`You specified ${program.release}! Please specify a supported or deprecated release number from lib/enterprise-server-releases.js`)
  36. process.exit(1)
  37. }
  38. const versionToDeprecate = `enterprise-server@${program.release}`
  39. const currentIndex = indexOf(enterpriseServerReleases.all, program.release)
  40. const nextOldestRelease = nth(enterpriseServerReleases.all, currentIndex - 1)
  41. const nextOldestVersion = `enterprise-server@${nextOldestRelease}`
  42. console.log(`Deprecating ${versionToDeprecate}!\n`)
  43. console.log(`Next oldest version: ${nextOldestVersion}\n`)
  44. // gather content and data files
  45. const contentFiles = walk(contentPath, { includeBasePath: true, directories: false })
  46. .filter(file => file.endsWith('.md'))
  47. .filter(file => !(file.endsWith('README.md') || file === 'LICENSE' || file === 'LICENSE-CODE'))
  48. const dataFiles = walk(dataPath, { includeBasePath: true, directories: false })
  49. .filter(file => file.includes('data/reusables') || file.includes('data/variables'))
  50. .filter(file => !file.endsWith('README.md'))
  51. const allFiles = contentFiles.concat(dataFiles)
  52. main()
  53. console.log(`\nRunning ${removeUnusedAssetsScript}...`)
  54. require(path.join(process.cwd(), removeUnusedAssetsScript))
  55. function printElseIfFoundWarning (location) {
  56. console.log(`${location} has an 'elsif' condition! Resolve all elsifs by hand, then rerun the script.`)
  57. }
  58. function main () {
  59. allFiles.forEach(file => {
  60. const oldContents = fs.readFileSync(file, 'utf8')
  61. const { content, data } = matter(oldContents)
  62. // we can't safely handle elseifs programmatically, too many possible outcomes
  63. if (elseifRegex.test(content)) {
  64. printElseIfFoundWarning(`content in ${file}`)
  65. process.exit()
  66. }
  67. Object.keys(data).forEach(key => {
  68. if (elseifRegex.test(data[key])) {
  69. printElseIfFoundWarning(`frontmatter '${key}' in ${file}`)
  70. process.exit()
  71. }
  72. })
  73. // update frontmatter versions prop
  74. removeDeprecatedFrontmatter(file, data.versions, versionToDeprecate, nextOldestVersion)
  75. // update liquid statements in content and data
  76. const newContent = removeLiquidStatements(content, versionToDeprecate, nextOldestVersion)
  77. // make sure any intro fields that exist and are empty return an empty string, not null
  78. if (typeof data.intro !== 'undefined' && !data.intro) {
  79. data.intro = ''
  80. }
  81. // put it all back together
  82. const newContents = matter.stringify(newContent, data, { lineWidth: 10000 })
  83. fs.writeFileSync(file, newContents)
  84. })
  85. console.log(`Removed ${versionToDeprecate} markup from content and data files! Review and run script/test.`)
  86. }
Tip!

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

Comments

Loading...