Skip to content

Commit 68cfd15

Browse files
authored
Script to upload app files (#15290)
1 parent 29d795a commit 68cfd15

File tree

4 files changed

+146
-4
lines changed

4 files changed

+146
-4
lines changed

pnpm-lock.yaml

Lines changed: 67 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ packages:
55
- 'platform/**'
66
- 'packages/**'
77
- 'docs-v2/**'
8+
- 'scripts/**'

scripts/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "scripts",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"@supabase/supabase-js": "^2.45.6",
14+
"dotenv": "^16.4.7",
15+
"glob": "^11.0.0"
16+
}
17+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { createClient } from '@supabase/supabase-js'
2+
import { readFile } from 'fs/promises'
3+
import { glob } from 'glob'
4+
import path from 'path'
5+
import 'dotenv/config'
6+
7+
if (!process.env.SUPABASE_URL || !process.env.SUPABASE_KEY) {
8+
throw new Error('Missing required environment variables SUPABASE_URL and/or SUPABASE_KEY')
9+
}
10+
11+
// Configure Supabase client
12+
const supabase = createClient(
13+
process.env.SUPABASE_URL,
14+
process.env.SUPABASE_KEY
15+
)
16+
17+
async function findAndUploadFiles() {
18+
try {
19+
// Find all .app.mjs files recursively
20+
const files = await glob('../components/**/*.app.mjs', {
21+
// No need to recurse into the standard subdirs, since app files are always at
22+
// the root of the components/${app} directory
23+
ignore: ['node_modules/**', 'actions/**', 'common/**', 'sources/**'],
24+
absolute: true
25+
})
26+
27+
console.log(`Found ${files.length} .app.mjs files`)
28+
29+
for (const filePath of files) {
30+
try {
31+
const content = await readFile(filePath, 'utf8')
32+
33+
const filename = path.basename(filePath)
34+
const app = filename.replace('.app.mjs', '')
35+
36+
const { data, error } = await supabase
37+
.from('registry_app_files')
38+
.insert({
39+
app: app,
40+
app_file: content
41+
})
42+
43+
if (error) {
44+
console.error(`Error uploading ${filename}:`, error)
45+
continue
46+
}
47+
48+
console.log(`Successfully uploaded ${filename}`)
49+
} catch (err) {
50+
console.error(`Error processing ${filePath}:`, err)
51+
}
52+
}
53+
} catch (err) {
54+
console.error('Error finding files:', err)
55+
}
56+
}
57+
58+
// Run the script
59+
findAndUploadFiles()
60+
.then(() => console.log('Upload complete'))
61+
.catch(err => console.error('Script failed:', err))

0 commit comments

Comments
 (0)