-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script to upload app files #15290
Script to upload app files #15290
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
|
WalkthroughThis pull request introduces minor modifications across several files, primarily adding newlines at the end of various Changes
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (3)
scripts/upload-app-files-to-supabase.mjs (3)
7-9
: Consider improving the error message specificity.Good environment validation! Consider making the error message more specific by checking and reporting each missing variable separately.
-if (!process.env.SUPABASE_URL || !process.env.SUPABASE_KEY) { - throw new Error('Missing required environment variables SUPABASE_URL and/or SUPABASE_KEY') +if (!process.env.SUPABASE_URL) { + throw new Error('Missing required environment variable SUPABASE_URL') +} +if (!process.env.SUPABASE_KEY) { + throw new Error('Missing required environment variable SUPABASE_KEY') }
43-46
: Enhance error reporting and tracking.Consider collecting errors in an array to provide a summary at the end of processing. This would help track all failures in one place.
+const errors = []; + async function findAndUploadFiles() { try { // ... existing code ... if (error) { - console.error(`Error uploading ${filename}:`, error) + const errorMsg = `Error uploading ${filename}: ${error.message}`; + console.error(errorMsg) + errors.push(errorMsg) continue } // ... existing code ... } catch (err) { - console.error('Error finding files:', err) + const errorMsg = `Error finding files: ${err.message}`; + console.error(errorMsg) + errors.push(errorMsg) } + return errors; }Also applies to: 49-51, 53-55
58-61
: Improve script completion handling.Add proper exit codes and operation summary for better integration with CI/CD pipelines.
// Run the script findAndUploadFiles() - .then(() => console.log('Upload complete')) - .catch(err => console.error('Script failed:', err)) + .then((errors) => { + console.log('Upload complete') + if (errors.length > 0) { + console.log(`Failed to process ${errors.length} files:`) + errors.forEach(err => console.log(`- ${err}`)) + process.exit(1) + } + process.exit(0) + }) + .catch(err => { + console.error('Script failed:', err) + process.exit(1) + })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
components/clear_books/clear_books.app.mjs
(1 hunks)components/dixa/dixa.app.mjs
(1 hunks)components/linkup/linkup.app.mjs
(1 hunks)components/mailboxlayer/mailboxlayer.app.mjs
(1 hunks)components/nextdoor/nextdoor.app.mjs
(1 hunks)pnpm-workspace.yaml
(1 hunks)scripts/.gitignore
(1 hunks)scripts/package.json
(1 hunks)scripts/upload-app-files-to-supabase.mjs
(1 hunks)
✅ Files skipped from review due to trivial changes (7)
- components/clear_books/clear_books.app.mjs
- components/nextdoor/nextdoor.app.mjs
- components/linkup/linkup.app.mjs
- components/mailboxlayer/mailboxlayer.app.mjs
- components/dixa/dixa.app.mjs
- scripts/.gitignore
- scripts/package.json
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Verify TypeScript components
- GitHub Check: pnpm publish
- GitHub Check: Publish TypeScript components
🔇 Additional comments (2)
scripts/upload-app-files-to-supabase.mjs (1)
11-15
: LGTM! Supabase client configuration is correct.pnpm-workspace.yaml (1)
8-8
: LGTM! Workspace configuration updated correctly.The addition of 'scripts/**' follows the existing pattern and will properly manage the script's dependencies.
const files = await glob('../components/**/*.app.mjs', { | ||
// No need to recurse into the standard subdirs, since app files are always at | ||
// the root of the components/${app} directory | ||
ignore: ['node_modules/**', 'actions/**', 'common/**', 'sources/**'], | ||
absolute: true | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Make path resolution more robust.
The relative path '../components' could break if the script is run from a different directory. Consider using path.resolve
to create an absolute path relative to the script's location.
- const files = await glob('../components/**/*.app.mjs', {
+ const files = await glob(path.resolve(__dirname, '../components/**/*.app.mjs'), {
Committable suggestion skipped: line range outside the PR's diff.
for (const filePath of files) { | ||
try { | ||
const content = await readFile(filePath, 'utf8') | ||
|
||
const filename = path.basename(filePath) | ||
const app = filename.replace('.app.mjs', '') | ||
|
||
const { data, error } = await supabase | ||
.from('registry_app_files') | ||
.insert({ | ||
app: app, | ||
app_file: content | ||
}) | ||
|
||
if (error) { | ||
console.error(`Error uploading ${filename}:`, error) | ||
continue | ||
} | ||
|
||
console.log(`Successfully uploaded ${filename}`) | ||
} catch (err) { | ||
console.error(`Error processing ${filePath}:`, err) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add content validation and duplicate handling.
Consider these improvements:
- Validate file content before upload
- Handle potential duplicates in the database
const content = await readFile(filePath, 'utf8')
+ // Validate content
+ if (!content.trim()) {
+ throw new Error('Empty file')
+ }
const filename = path.basename(filePath)
const app = filename.replace('.app.mjs', '')
const { data, error } = await supabase
.from('registry_app_files')
- .insert({
+ .upsert({
app: app,
app_file: content
- })
+ }, {
+ onConflict: 'app',
+ ignoreDuplicates: false
+ })
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
for (const filePath of files) { | |
try { | |
const content = await readFile(filePath, 'utf8') | |
const filename = path.basename(filePath) | |
const app = filename.replace('.app.mjs', '') | |
const { data, error } = await supabase | |
.from('registry_app_files') | |
.insert({ | |
app: app, | |
app_file: content | |
}) | |
if (error) { | |
console.error(`Error uploading ${filename}:`, error) | |
continue | |
} | |
console.log(`Successfully uploaded ${filename}`) | |
} catch (err) { | |
console.error(`Error processing ${filePath}:`, err) | |
} | |
} | |
for (const filePath of files) { | |
try { | |
const content = await readFile(filePath, 'utf8') | |
// Validate content | |
if (!content.trim()) { | |
throw new Error('Empty file') | |
} | |
const filename = path.basename(filePath) | |
const app = filename.replace('.app.mjs', '') | |
const { data, error } = await supabase | |
.from('registry_app_files') | |
.upsert({ | |
app: app, | |
app_file: content | |
}, { | |
onConflict: 'app', | |
ignoreDuplicates: false | |
}) | |
if (error) { | |
console.error(`Error uploading ${filename}:`, error) | |
continue | |
} | |
console.log(`Successfully uploaded ${filename}`) | |
} catch (err) { | |
console.error(`Error processing ${filePath}:`, err) | |
} | |
} |
Summary by CodeRabbit
New Features
Chores
.gitignore
to exclude.env*
filespackage.json
for scripts with necessary dependenciesDocumentation