-
Notifications
You must be signed in to change notification settings - Fork 12
feat(edge-apps): migrate to Vite dev server with dist-based deployment #690
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7cd8a4b
feat(clock): migrate to Vite dev server with dist-based deployment
nicomiguelino 8873844
Merge branch 'master' into migrate-to-vite-dev-server
nicomiguelino 1aefe01
fix(vite): configure filesystem allow list for dev server
nicomiguelino a4e050e
feat(edge-apps): migrate remaining apps to Vite dev server
nicomiguelino ce953af
refactor(cli): extract common helper functions to reduce duplication
nicomiguelino b594bc0
fix(menu-board): import assets for Vite bundling compatibility
nicomiguelino 3e99cc4
chore(edge-apps-library): include `vite-plugins` in list of directori…
nicomiguelino 286608d
refactor(dev-server): improve error handling and file watching
nicomiguelino 4d801b5
feat(dev-server): trigger browser reload on config file changes
nicomiguelino a8a86bb
refactor(cap-alerting): use edge-apps-library CORS proxy server
nicomiguelino 0672ff7
refactor(vite): improve error message for file copy failures
nicomiguelino 72b0da6
refactor(menu-board): simplify asset functions using Vite inlining
nicomiguelino 18601d1
docs: update README files for Vite dev server migration
nicomiguelino 9978b70
chore: apply temporary changes to test if CI workflows break
nicomiguelino 70ff22e
chore: revert temporary changes
nicomiguelino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| import type { ViteDevServer, Plugin } from 'vite' | ||
| import YAML from 'yaml' | ||
| import fs from 'fs' | ||
| import path from 'path' | ||
|
|
||
| type ScreenlyManifestField = { | ||
| type: string | ||
| default_value?: string | ||
| title: string | ||
| optional: boolean | ||
| is_global?: boolean | ||
| help_text: string | Record<string, unknown> | ||
| } | ||
|
|
||
| type BaseScreenlyMockData = { | ||
| metadata: { | ||
| coordinates: [number, number] | ||
| hostname: string | ||
| screen_name: string | ||
| hardware: string | ||
| location: string | ||
| screenly_version: string | ||
| tags: string[] | ||
| } | ||
| settings: Record<string, string> | ||
| cors_proxy_url: string | ||
| } | ||
|
|
||
| const defaultScreenlyConfig: BaseScreenlyMockData = { | ||
| metadata: { | ||
| coordinates: [37.3861, -122.0839] as [number, number], | ||
| hostname: 'dev-hostname', | ||
| screen_name: 'Development Server', | ||
| hardware: 'x86', | ||
| location: 'Development Environment', | ||
| screenly_version: 'development-server', | ||
| tags: ['Development'], | ||
| }, | ||
| settings: { | ||
| enable_analytics: 'true', | ||
| tag_manager_id: '', | ||
| theme: 'light', | ||
| screenly_color_accent: '#972EFF', | ||
| screenly_color_light: '#ADAFBE', | ||
| screenly_color_dark: '#454BD2', | ||
| }, | ||
| cors_proxy_url: 'http://127.0.0.1:8080', | ||
| } | ||
|
|
||
| function generateScreenlyObject(config: BaseScreenlyMockData) { | ||
| return ` | ||
| // Generated screenly.js for development mode | ||
| window.screenly = { | ||
| signalReadyForRendering: () => {}, | ||
| metadata: ${JSON.stringify(config.metadata, null, 2)}, | ||
| settings: ${JSON.stringify(config.settings, null, 2)}, | ||
| cors_proxy_url: ${JSON.stringify(config.cors_proxy_url)} | ||
| } | ||
| ` | ||
| } | ||
|
|
||
| function generateMockData(rootDir: string): BaseScreenlyMockData { | ||
| const manifestPath = path.resolve(rootDir, 'screenly.yml') | ||
| const mockDataPath = path.resolve(rootDir, 'mock-data.yml') | ||
|
|
||
| const manifest = YAML.parse(fs.readFileSync(manifestPath, 'utf8')) | ||
| const screenlyConfig: BaseScreenlyMockData = structuredClone( | ||
| defaultScreenlyConfig, | ||
| ) | ||
|
|
||
| // Merge settings from manifest | ||
| for (const [key, value] of Object.entries(manifest.settings) as [ | ||
| string, | ||
| ScreenlyManifestField, | ||
| ][]) { | ||
| if (value.type === 'string' || value.type === 'secret') { | ||
| const manifestField: ScreenlyManifestField = value | ||
| const defaultValue = manifestField?.default_value ?? '' | ||
| screenlyConfig.settings[key] = defaultValue | ||
| } | ||
| } | ||
|
|
||
| // Override with mock-data.yml if it exists | ||
| if (fs.existsSync(mockDataPath)) { | ||
| const mockData = YAML.parse(fs.readFileSync(mockDataPath, 'utf8')) | ||
|
|
||
| // Override metadata if present | ||
| if (mockData.metadata) { | ||
| Object.assign(screenlyConfig.metadata, mockData.metadata) | ||
| } | ||
|
|
||
| // Override settings if present | ||
| if (mockData.settings) { | ||
| Object.assign(screenlyConfig.settings, mockData.settings) | ||
| } | ||
|
|
||
| // Override cors_proxy_url if present | ||
| if (mockData.cors_proxy_url) { | ||
| screenlyConfig.cors_proxy_url = mockData.cors_proxy_url | ||
| } | ||
| } | ||
|
|
||
| return screenlyConfig | ||
| } | ||
|
|
||
| export function screenlyDevServer(): Plugin { | ||
| let config: BaseScreenlyMockData | ||
| let rootDir: string | ||
|
|
||
| return { | ||
| name: 'screenly-dev-server', | ||
| configureServer(server: ViteDevServer) { | ||
| rootDir = server.config.root | ||
|
|
||
| // Generate initial mock data | ||
| config = generateMockData(rootDir) | ||
|
|
||
| // Watch for changes to screenly.yml | ||
| const manifestPath = path.resolve(rootDir, 'screenly.yml') | ||
| fs.watch(manifestPath, () => { | ||
| console.log('screenly.yml changed, regenerating mock data...') | ||
| config = generateMockData(rootDir) | ||
| }) | ||
|
|
||
| // Watch for changes to mock-data.yml if it exists | ||
| const mockDataPath = path.resolve(rootDir, 'mock-data.yml') | ||
| if (fs.existsSync(mockDataPath)) { | ||
| fs.watch(mockDataPath, () => { | ||
| console.log('mock-data.yml changed, regenerating mock data...') | ||
| config = generateMockData(rootDir) | ||
| }) | ||
| } | ||
|
|
||
| server.middlewares.use((req, res, next) => { | ||
| if (req.url === '/screenly.js?version=1') { | ||
| const screenlyJsContent = generateScreenlyObject(config) | ||
|
|
||
| res.setHeader('Content-Type', 'application/javascript') | ||
| res.end(screenlyJsContent) | ||
| return | ||
| } | ||
| next() | ||
| }) | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.