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

create-webhook-files.js 2.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
  1. #!/usr/bin/env node
  2. const fs = require('fs')
  3. const mkdirp = require('mkdirp').sync
  4. const path = require('path')
  5. const program = require('commander')
  6. const allVersions = require('../../lib/all-versions')
  7. const payloadsDir = 'lib/webhooks/static'
  8. // [start-readme]
  9. //
  10. // This script creates new static webhook payload files for a new version.
  11. //
  12. // [end-readme]
  13. program
  14. .description('Create new payload files in lib/webhooks/static/<new_version> based on an existing version.')
  15. .option('-n, --newVersion <version>', 'The version to copy the payloads to. Must be in <plan@release> format.')
  16. .option('-o, --oldVersion <version>', 'The version to copy the payloads from. Must be in <plan@release> format.')
  17. .parse(process.argv)
  18. const newVersion = program.opts().newVersion
  19. const oldVersion = program.opts().oldVersion
  20. if (!(newVersion && oldVersion)) {
  21. console.log('Error! You must provide --newVersion and --oldVersion.')
  22. process.exit(1)
  23. }
  24. if (!(Object.keys(allVersions).includes(newVersion) && Object.keys(allVersions).includes(oldVersion))) {
  25. console.log('Error! You must provide the full name of a currently supported version, e.g., enterprise-server@2.22.')
  26. process.exit(1)
  27. }
  28. const newVersionDirName = allVersions[newVersion].miscVersionName
  29. const oldVersionDirName = allVersions[oldVersion].miscVersionName
  30. const srcDir = path.join(payloadsDir, oldVersionDirName)
  31. const destDir = path.join(payloadsDir, newVersionDirName)
  32. // create the new directory
  33. mkdirp(destDir)
  34. // copy the files
  35. fs.readdirSync(srcDir).forEach(file => {
  36. const srcFile = path.join(srcDir, file)
  37. const destFile = path.join(destDir, file)
  38. fs.copyFileSync(srcFile, destFile)
  39. })
  40. // check that it worked
  41. if (!fs.existsSync(destDir)) {
  42. console.log(`Error! A new directory was not successfully created at ${destDir}.`)
  43. process.exit(1)
  44. }
  45. if (!fs.readdirSync(destDir).length) {
  46. console.log(`Error! The directory created at ${destDir} is empty.`)
  47. process.exit(1)
  48. }
  49. // print success message
  50. console.log(`Done! Copied ${srcDir} to ${destDir}.`)
Tip!

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

Comments

Loading...