-
Notifications
You must be signed in to change notification settings - Fork 2
[feat] pluggable extension system #135
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
Open
stooit
wants to merge
3
commits into
uselagoon:main
Choose a base branch
from
stooit:feat/extensions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,519
−1,299
Open
Changes from 1 commit
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
|
|
||
| const EXTENSIONS_DIR = 'extensions'; | ||
| const OUTPUT_MANIFEST = 'extensions.json'; | ||
| const APP_DIR = 'src/app/(routegroups)'; | ||
| const COMPONENTS_DIR = 'src/components/extensions'; | ||
| const LIB_DIR = 'src/lib/extensions'; | ||
|
|
||
| type ExtensionManifest = { | ||
| meta: { name: string; version: string; description?: string }; | ||
| navigation?: { items?: unknown[]; sections?: unknown[] }; | ||
| pages?: { route: string; requiredRoles?: string[] }[]; | ||
| slots?: unknown[]; | ||
| features?: Record<string, boolean>; | ||
| }; | ||
|
|
||
| function findExtensions(): string[] { | ||
| if (!fs.existsSync(EXTENSIONS_DIR)) { | ||
| console.log(`No ${EXTENSIONS_DIR}/ directory found`); | ||
| return []; | ||
| } | ||
| return fs.readdirSync(EXTENSIONS_DIR).filter(name => { | ||
| const extPath = path.join(EXTENSIONS_DIR, name); | ||
| const manifestPath = path.join(extPath, 'extension.json'); | ||
| return fs.statSync(extPath).isDirectory() && fs.existsSync(manifestPath); | ||
| }); | ||
| } | ||
|
|
||
| function loadManifest(extName: string): ExtensionManifest | null { | ||
| try { | ||
| const content = fs.readFileSync(path.join(EXTENSIONS_DIR, extName, 'extension.json'), 'utf-8'); | ||
| return JSON.parse(content); | ||
| } catch (err) { | ||
| console.error(`Failed to load manifest for ${extName}:`, err); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| function copyRecursive(src: string, dest: string): void { | ||
| const stat = fs.statSync(src); | ||
| if (stat.isDirectory()) { | ||
| if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true }); | ||
| for (const child of fs.readdirSync(src)) { | ||
| copyRecursive(path.join(src, child), path.join(dest, child)); | ||
| } | ||
| } else { | ||
| fs.copyFileSync(src, dest); | ||
| console.log(` ${dest}`); | ||
| } | ||
| } | ||
|
|
||
| function copyPages(extName: string): void { | ||
| const pagesDir = path.join(EXTENSIONS_DIR, extName, 'pages'); | ||
| if (!fs.existsSync(pagesDir)) return; | ||
| console.log(` Copying pages...`); | ||
| copyRecursive(pagesDir, APP_DIR); | ||
| } | ||
|
|
||
| function copyComponents(extName: string): void { | ||
| const componentsDir = path.join(EXTENSIONS_DIR, extName, 'components'); | ||
| if (!fs.existsSync(componentsDir)) return; | ||
| const destDir = path.join(COMPONENTS_DIR, extName); | ||
| console.log(` Copying components...`); | ||
| copyRecursive(componentsDir, destDir); | ||
| } | ||
|
|
||
| function copyLib(extName: string): void { | ||
| const libDir = path.join(EXTENSIONS_DIR, extName, 'lib'); | ||
| if (!fs.existsSync(libDir)) return; | ||
| const destDir = path.join(LIB_DIR, extName); | ||
| console.log(` Copying lib...`); | ||
| copyRecursive(libDir, destDir); | ||
| } | ||
|
|
||
| function main(): void { | ||
| console.log('Building extensions...\n'); | ||
| const extensions = findExtensions(); | ||
| console.log(`Found ${extensions.length} extension(s): ${extensions.join(', ') || '(none)'}\n`); | ||
|
|
||
| const manifests: ExtensionManifest[] = []; | ||
| for (const extName of extensions) { | ||
| console.log(`Processing: ${extName}`); | ||
| const manifest = loadManifest(extName); | ||
| if (!manifest) continue; | ||
| copyPages(extName); | ||
| copyComponents(extName); | ||
| copyLib(extName); | ||
| manifests.push(manifest); | ||
| console.log(` ✓ ${manifest.meta.name} v${manifest.meta.version}\n`); | ||
| } | ||
|
|
||
| fs.writeFileSync(OUTPUT_MANIFEST, JSON.stringify({ extensions: manifests }, null, 2)); | ||
| console.log(`\nWrote ${OUTPUT_MANIFEST} with ${manifests.length} extension(s)`); | ||
| } | ||
|
|
||
| main(); |
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
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,22 @@ | ||
| 'use client'; | ||
|
|
||
| import { ReactNode } from 'react'; | ||
| import { redirect } from 'next/navigation'; | ||
| import { useExtensions } from '@/contexts/ExtensionContext'; | ||
|
|
||
| type Props = { | ||
| route: string; | ||
| children: ReactNode; | ||
| fallbackUrl?: string; | ||
| }; | ||
|
|
||
| export function ExtensionRouteGuard({ route, children, fallbackUrl = '/projects' }: Props) { | ||
| const { canAccessRoute, getPageConfig } = useExtensions(); | ||
|
|
||
| if (!canAccessRoute(route)) { | ||
| const pageConfig = getPageConfig(route); | ||
| redirect(pageConfig?.accessDeniedRedirect || fallbackUrl); | ||
| } | ||
|
|
||
| return <>{children}</>; | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
We're aware that there are some issues with the current sidebar implementation, and are working on a different way the sidebar is managed that will probably change how what I've made in this suggestion work. Probably ignore this suggestion for now until that other work goes through properly.
In saying that, the sidebar doesn't render properly when using
project-tabsin the provided example, but also doesn't render properly when usingsidebar-projectswithout changes belowNote: also pretty sure
project-tabs,environment-tabs,organization-tabs, andsettings-tabsare deprecated, so probably don't need to exist.This would need further work to properly support if needing to extend adding to the environments or others too.
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.
Ok cool, have cleaned up the deprecated
*-tabsthings and fixed up the slug replacement given they seem like the safe changes here