Skip to content

Conversation

@nicomiguelino
Copy link
Contributor

@nicomiguelino nicomiguelino commented Dec 23, 2025

User description

  • Remove local .prettierrc.json files for apps using edge-apps-library
  • Add prettier field in package.json to reference shared config from apps using the edge-apps-library

PR Type

Enhancement, Tests


Description

  • Centralize Prettier config across edge apps

  • Add format:check script to all apps

  • Update CI to use format:check

  • Cleanup local Prettier configs


Diagram Walkthrough

flowchart LR
  A["Local .prettierrc in each app"] -- "remove" --> B["Shared config in edge-apps-library"]
  B -- "referenced via package.json 'prettier'" --> C["Each edge app"]
  C -- "add 'format:check' script" --> D["Consistent formatting checks"]
  D -- "used by" --> E["CI workflow (edge-app-checks)"]
  F["Power BI main.js"] -- "minor formatting cleanup" --> G["Consistent style"]
Loading

File Walkthrough

Relevant files
Formatting
1 files
main.js
Normalize JS formatting and semicolons removal                     
+59/-47 
Configuration changes
2 files
edge-app-checks.yml
Use unified format:check in CI                                                     
+1/-1     
package.json
Reference local Prettier config explicitly                             
+1/-0     
Dependencies
11 files
.prettierrc.json
Remove local Prettier config file                                               
+0/-6     
.prettierrc.json
Remove local Prettier config file                                               
+0/-6     
.prettierrc.json
Remove local Prettier config file                                               
+0/-6     
.prettierrc.json
Remove local Prettier config file                                               
+0/-6     
.prettierrc.json
Remove local Prettier config file                                               
+0/-6     
.prettierrc.json
Remove local Prettier config file                                               
+0/-6     
.prettierrc.json
Remove local Prettier config file                                               
+0/-6     
.prettierrc.json
Remove local Prettier config file                                               
+0/-6     
.prettierrc.json
Remove local Prettier config file                                               
+0/-6     
.prettierrc.json
Remove local Prettier config file                                               
+0/-6     
.prettierrc.json
Remove local Prettier config file                                               
+0/-6     
Enhancement
13 files
package.json
Add shared Prettier config and format:check                           
+2/-0     
package.json
Add shared Prettier config and format:check                           
+2/-0     
package.json
Add shared Prettier config and format:check                           
+2/-0     
package.json
Add shared Prettier config and format:check                           
+2/-0     
package.json
Add format:check and pin Prettier config path                       
+3/-1     
package.json
Add shared Prettier config and format:check                           
+2/-0     
package.json
Add shared Prettier config and format:check                           
+2/-0     
package.json
Add shared Prettier config and format:check                           
+2/-0     
package.json
Switch to shared Prettier config and scripts                         
+4/-2     
package.json
Add shared Prettier config and format:check                           
+2/-0     
package.json
Add shared Prettier config and format:check                           
+2/-0     
package.json
Add shared Prettier config and format:check                           
+2/-0     
package.json
Add shared Prettier config and format:check                           
+2/-0     

- remove local .prettierrc.json files
- add prettier field in package.json to reference shared config
@github-actions
Copy link

github-actions bot commented Dec 23, 2025

PR Reviewer Guide 🔍

(Review updated until commit 7997c38)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Issue

The IIFE now starts with a leading semicolon (';') for safety, but the file header comment and whitespace may already ensure safe concatenation. Confirm this change doesn't conflict with any bundling/minification step and that the script still loads correctly in all target environments.

;(function () {
Error Handling

The catch block in the token refresh loop lacks an error parameter and logging. Consider capturing and optionally logging the error (when display_errors is true) to aid debugging token refresh failures without exposing sensitive info in production.

} catch {
  nextTimeout = Math.min(
    initErrorDelaySec * Math.pow(2, currentErrorStep),
    nextTimeout,
  )
  if (currentErrorStep >= maxErrorStep) {
    return
  }
  currentErrorStep += 1
}
CI Consistency

CI now relies on 'format:check' across apps. Ensure all apps define this script and that paths (e.g., vendor directories excluded in Power BI) are consistently handled to avoid false positives or missed files.

- name: Run formatting check
  working-directory: edge-apps/${{ matrix.app }}
  run: bun run format:check

@github-actions
Copy link

github-actions bot commented Dec 23, 2025

PR Code Suggestions ✨

Latest suggestions up to 7997c38
Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Validate token fetch responses

Check response.ok before parsing JSON to avoid throwing on non-2xx responses and
return a clear error. Also validate that token exists to prevent passing undefined
to report.setAccessToken, which will break token refresh.

edge-apps/powerbi/static/js/main.js [15-33]

 async function getEmbedToken() {
   if (screenly.settings.embed_token) {
     return screenly.settings.embed_token
   }
 
-  var response = await fetch(
+  const response = await fetch(
     screenly.settings.screenly_oauth_tokens_url + 'embed_token/',
     {
       method: 'GET',
       headers: {
         Accept: 'application/json',
         Authorization: `Bearer ${screenly.settings.screenly_app_auth_token}`,
       },
     },
   )
 
-  const { token } = await response.json()
-  return token
+  if (!response.ok) {
+    throw new Error(`Failed to fetch embed token: ${response.status} ${response.statusText}`)
+  }
+
+  const data = await response.json()
+  if (!data || !data.token) {
+    throw new Error('Embed token missing in response')
+  }
+  return data.token
 }
Suggestion importance[1-10]: 8

__

Why: Checking response.ok and verifying token existence prevents runtime errors and failed refreshes; the diff’s existing_code matches the new hunk and the improved code accurately applies the changes.

Medium
General
Harden token refresh loop

Capture the error in the catch block and log via panic to aid diagnostics. Also
ensure newToken is a non-empty string before calling setAccessToken to avoid silent
failures.

edge-apps/powerbi/static/js/main.js [35-60]

 function initTokenRefreshLoop(report) {
   var currentErrorStep = 0
   var initErrorDelaySec = 15
   var maxErrorStep = 7
 
   async function run() {
     var nextTimeout = DEFAULT_TOKEN_REFRESH_SEC
     try {
       var newToken = await getEmbedToken()
+      if (!newToken || typeof newToken !== 'string') {
+        throw new Error('Received invalid embed token')
+      }
       await report.setAccessToken(newToken)
       currentErrorStep = 0
-    } catch {
+    } catch (err) {
+      if (typeof panic?.log === 'function') {
+        panic.log('Token refresh error', err)
+      }
       nextTimeout = Math.min(
         initErrorDelaySec * Math.pow(2, currentErrorStep),
         nextTimeout,
       )
       if (currentErrorStep >= maxErrorStep) {
         return
       }
       currentErrorStep += 1
     }
     setTimeout(run, nextTimeout * 1000)
   }
 
   setTimeout(run, DEFAULT_TOKEN_REFRESH_SEC * 1000)
 }
Suggestion importance[1-10]: 7

__

Why: Adding error logging and token validation improves resiliency and debuggability; mapping matches the new hunk and the proposed code reflects the described changes, though impact is moderate.

Medium
Add workflow fallback for formatting

Ensure every app defines a format:check script, otherwise the workflow will fail for
apps that haven't adopted the new script yet. Add a fallback to run Prettier
directly if the script is missing.

.github/workflows/edge-app-checks.yml [156-158]

 - name: Run formatting check
   working-directory: edge-apps/${{ matrix.app }}
-  run: bun run format:check
+  run: |
+    if bun run | grep -q "format:check"; then
+      bun run format:check
+    else
+      prettier --check .
+    fi
Suggestion importance[1-10]: 6

__

Why: The fallback helps prevent CI failures if some apps lack format:check; it’s a reasonable enhancement though not critical, and the existing snippet correctly maps to the new hunk lines.

Low

Previous suggestions

Suggestions up to commit 1ec11e3
CategorySuggestion                                                                                                                                    Impact
General
Make Prettier config path robust

Using a relative path for prettier can break when tools run from a different working
directory (e.g., workspace root or CI). Point to the shareable config package or use
a path relative to this file with file: to ensure resolution. Alternatively, add a
prettier script that invokes Prettier with a resolved config path.

edge-apps/menu-board/package.json [20]

-"prettier": "../edge-apps-library/.prettierrc.json",
+"prettier": "file:../edge-apps-library/.prettierrc.json",
Suggestion importance[1-10]: 5

__

Why: The suggestion is reasonable—using a file: URL can improve resolution reliability—but it's not strictly necessary and depends on tooling behavior. It correctly targets the new "prettier" field at line 20.

Low
Use file URL for config path

The plain relative path may not be resolved by all tooling contexts. Use a file: URL
so Node-based resolution is unambiguous, reducing CI/editor inconsistencies when
locating the Prettier config.

edge-apps/qr-code/package.json [23]

-"prettier": "../edge-apps-library/.prettierrc.json",
+"prettier": "file:../edge-apps-library/.prettierrc.json",
Suggestion importance[1-10]: 5

__

Why: Similar to the first, this can reduce ambiguity in some contexts but may be redundant in others; it's a moderate improvement and correctly references the added "prettier" entry at line 23.

Low

@nicomiguelino nicomiguelino changed the title refactor: centralize prettier config for menu-board and qr-code refactor: streamline formatting pipeline for all Edge Apps using a build system Dec 23, 2025
- standardize formatting checks across apps
- remove local .prettierrc.json files
- add prettier field to package.json for each app
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR centralizes Prettier configuration across Edge Apps by removing local .prettierrc.json files and pointing each app's package.json to a shared configuration file in edge-apps-library. This streamlines the formatting pipeline and ensures consistent code formatting across all apps.

Key changes:

  • Removed duplicate .prettierrc.json files from 11 edge apps
  • Added prettier field in package.json for each app to reference shared config
  • Added format:check script to all apps for CI validation
  • Updated GitHub workflow to use the new format:check script

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
edge-apps/asset-metadata/.prettierrc.json Deleted local Prettier config in favor of shared config
edge-apps/asset-metadata/package.json Added prettier config reference and format:check script
edge-apps/bamboo-hr-app/.prettierrc.json Deleted local Prettier config in favor of shared config
edge-apps/bamboo-hr-app/package.json Added prettier config reference and format:check script
edge-apps/blueprint/package.json Added prettier config reference to self for local use
edge-apps/calendar/.prettierrc.json Deleted local Prettier config in favor of shared config
edge-apps/calendar/package.json Added prettier config reference and format:check script
edge-apps/clock/.prettierrc.json Deleted local Prettier config in favor of shared config
edge-apps/clock/package.json Added prettier config reference and format:check script
edge-apps/edge-apps-library/package.json Added format:check script and self-referencing prettier config
edge-apps/google-calendar/.prettierrc.json Deleted local Prettier config in favor of shared config
edge-apps/google-calendar/package.json Added prettier config reference and format:check script
edge-apps/menu-board/.prettierrc.json Deleted local Prettier config in favor of shared config
edge-apps/menu-board/package.json Added prettier config reference and format:check script
edge-apps/outlook-calendar/.prettierrc.json Deleted local Prettier config in favor of shared config
edge-apps/outlook-calendar/package.json Added prettier config reference and format:check script
edge-apps/powerbi/package.json Added prettier config reference and format/format:check scripts (with naming collision)
edge-apps/qr-code/.prettierrc.json Deleted local Prettier config in favor of shared config
edge-apps/qr-code/package.json Added prettier config reference and format:check script
edge-apps/simple-message-app/.prettierrc.json Deleted local Prettier config in favor of shared config
edge-apps/simple-message-app/package.json Added prettier config reference and format:check script
edge-apps/simple-table-app/.prettierrc.json Deleted local Prettier config in favor of shared config
edge-apps/simple-table-app/package.json Added prettier config reference and format:check script
edge-apps/welcome-app/.prettierrc.json Deleted local Prettier config in favor of shared config
edge-apps/welcome-app/package.json Added prettier config reference and format:check script
.github/workflows/edge-app-checks.yml Updated workflow to use new format:check script instead of hardcoded prettier command

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

Persistent review updated to latest commit 7997c38

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant