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

get-new-version-path.js 1.5 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
  1. #!/usr/bin/env node
  2. const path = require('path')
  3. const assert = require('assert')
  4. const patterns = require('../lib/patterns')
  5. const { deprecated } = require('../lib/enterprise-server-releases')
  6. const { getNewVersionedPath, getOldVersionFromOldPath } = require('../lib/old-versions-utils')
  7. const usage = 'must provide a path like "/github/getting-started" or "/enterprise/2.20/user/github/getting-started", with or without language code'
  8. // [start-readme]
  9. //
  10. // Helper script that returns a "new" versioned path given an "old" versioned path.
  11. //
  12. // Examples:
  13. //
  14. // Given: /github/getting-started-with-github/using-github
  15. // Returns: /free-pro-team@latest/github/getting-started-with-github/using-github
  16. //
  17. // Given: /enterprise/admin/installation/upgrading-github-enterprise
  18. // Returns: /enterprise-server@2.22/admin/installation/upgrading-github-enterprise
  19. //
  20. //
  21. // [end-readme]
  22. let oldPath = process.argv.slice(2)[0]
  23. assert(oldPath, usage)
  24. // add '/' to the original string if not included
  25. if (!oldPath.startsWith('/')) {
  26. oldPath = path.join('/', oldPath)
  27. }
  28. // do not transform deprecated versions
  29. const oldVersion = getOldVersionFromOldPath(oldPath)
  30. if (deprecated.includes(oldVersion)) {
  31. console.log('This is a deprecated Enterprise path! It does not redirect.\n')
  32. process.exit()
  33. }
  34. // get the new path
  35. const newPath = patterns.hasLanguageCode.test(oldPath)
  36. ? getNewVersionedPath(oldPath, oldPath.match(patterns.getLanguageCode)[1])
  37. : getNewVersionedPath(oldPath)
  38. // print the result
  39. console.log(`New versioned path:\n\n${newPath}\n`)
Tip!

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

Comments

Loading...