deno-types.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * This script downloads the Deno types from the GitHub release page and saves them to the lib directory.
  3. * It is used to provide the Deno types to the Monaco editor in Studio for the Edge Functions AI editor.
  4. *
  5. * Deno Releases: https://github.com/denoland/deno/releases
  6. */
  7. import fs from 'fs/promises'
  8. import path from 'path'
  9. const DENO_VERSION = 'v1.45.0'
  10. const BRIVEN_FUNCTIONS_JS_VERSION = '2.4.4'
  11. const DENO_TYPES_URL = `https://github.com/denoland/deno/releases/download/${DENO_VERSION}/lib.deno.d.ts`
  12. const BRIVEN_FUNCTIONS_JS_TYPES_URL = `https://jsr.io/@supabase/functions-js/${BRIVEN_FUNCTIONS_JS_VERSION}/src/edge-runtime.d.ts`
  13. const OUTPUT_FILE = path.join(path.dirname(__dirname), 'public', 'deno', 'lib.deno.d.ts')
  14. const BRIVEN_FUNCTIONS_JS_OUTPUT_FILE = path.join(
  15. path.dirname(__dirname),
  16. 'public',
  17. 'deno',
  18. 'edge-runtime.d.ts'
  19. )
  20. const OUTPUT_VERSION_FILE = path.join(path.dirname(__dirname), 'public', 'deno', 'deno-version.txt')
  21. const BRIVEN_FUNCTIONS_JS_OUTPUT_VERSION_FILE = path.join(
  22. path.dirname(__dirname),
  23. 'public',
  24. 'deno',
  25. 'briven-functions-js-version.txt'
  26. )
  27. async function downloadTypes() {
  28. console.log('Downloading Deno types')
  29. try {
  30. const response = await fetch(DENO_TYPES_URL)
  31. const data = await response.text()
  32. await fs.writeFile(OUTPUT_FILE, data)
  33. await fs.writeFile(OUTPUT_VERSION_FILE, DENO_VERSION)
  34. console.log('Deno types downloaded successfully')
  35. } catch (error) {
  36. console.error('Error downloading Deno types', error)
  37. process.exit(1)
  38. }
  39. }
  40. async function downloadBrivenFunctionsJsTypes() {
  41. console.log('Downloading Briven Functions JS types')
  42. try {
  43. const response = await fetch(BRIVEN_FUNCTIONS_JS_TYPES_URL)
  44. const data = await response.text()
  45. await fs.writeFile(BRIVEN_FUNCTIONS_JS_OUTPUT_FILE, data)
  46. await fs.writeFile(BRIVEN_FUNCTIONS_JS_OUTPUT_VERSION_FILE, BRIVEN_FUNCTIONS_JS_VERSION)
  47. console.log('Briven Functions JS types downloaded successfully')
  48. } catch (error) {
  49. console.error('Error downloading Briven Functions JS types', error)
  50. process.exit(1)
  51. }
  52. }
  53. Promise.all([downloadTypes(), downloadBrivenFunctionsJsTypes()])