deno-types.ts66 lines · main
| 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 | |
| 8 | import fs from 'fs/promises' |
| 9 | import path from 'path' |
| 10 | |
| 11 | const DENO_VERSION = 'v1.45.0' |
| 12 | const BRIVEN_FUNCTIONS_JS_VERSION = '2.4.4' |
| 13 | |
| 14 | const DENO_TYPES_URL = `https://github.com/denoland/deno/releases/download/${DENO_VERSION}/lib.deno.d.ts` |
| 15 | const BRIVEN_FUNCTIONS_JS_TYPES_URL = `https://jsr.io/@supabase/functions-js/${BRIVEN_FUNCTIONS_JS_VERSION}/src/edge-runtime.d.ts` |
| 16 | |
| 17 | const OUTPUT_FILE = path.join(path.dirname(__dirname), 'public', 'deno', 'lib.deno.d.ts') |
| 18 | const BRIVEN_FUNCTIONS_JS_OUTPUT_FILE = path.join( |
| 19 | path.dirname(__dirname), |
| 20 | 'public', |
| 21 | 'deno', |
| 22 | 'edge-runtime.d.ts' |
| 23 | ) |
| 24 | const OUTPUT_VERSION_FILE = path.join(path.dirname(__dirname), 'public', 'deno', 'deno-version.txt') |
| 25 | const BRIVEN_FUNCTIONS_JS_OUTPUT_VERSION_FILE = path.join( |
| 26 | path.dirname(__dirname), |
| 27 | 'public', |
| 28 | 'deno', |
| 29 | 'briven-functions-js-version.txt' |
| 30 | ) |
| 31 | |
| 32 | async function downloadTypes() { |
| 33 | console.log('Downloading Deno types') |
| 34 | |
| 35 | try { |
| 36 | const response = await fetch(DENO_TYPES_URL) |
| 37 | const data = await response.text() |
| 38 | |
| 39 | await fs.writeFile(OUTPUT_FILE, data) |
| 40 | await fs.writeFile(OUTPUT_VERSION_FILE, DENO_VERSION) |
| 41 | |
| 42 | console.log('Deno types downloaded successfully') |
| 43 | } catch (error) { |
| 44 | console.error('Error downloading Deno types', error) |
| 45 | process.exit(1) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | async function downloadBrivenFunctionsJsTypes() { |
| 50 | console.log('Downloading Briven Functions JS types') |
| 51 | |
| 52 | try { |
| 53 | const response = await fetch(BRIVEN_FUNCTIONS_JS_TYPES_URL) |
| 54 | const data = await response.text() |
| 55 | |
| 56 | await fs.writeFile(BRIVEN_FUNCTIONS_JS_OUTPUT_FILE, data) |
| 57 | await fs.writeFile(BRIVEN_FUNCTIONS_JS_OUTPUT_VERSION_FILE, BRIVEN_FUNCTIONS_JS_VERSION) |
| 58 | |
| 59 | console.log('Briven Functions JS types downloaded successfully') |
| 60 | } catch (error) { |
| 61 | console.error('Error downloading Briven Functions JS types', error) |
| 62 | process.exit(1) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | Promise.all([downloadTypes(), downloadBrivenFunctionsJsTypes()]) |