Skip to content

load plugins from local environment or from NPM #24

@starsinmypockets

Description

@starsinmypockets

Description

  • As a Developer I want to add a new page with functionality to the site so that I can continue development without needing to fork frontend => subapp
  • As a Developer I want a new blog index page that shows most popular posts from a currently non-supported source so that clients can continue to use existing blog => theming + controller + new backend call from within route controller
  • As a developer I want to add logging / analytics as middleware to process all requests so that I can integrate with existing systems => middleware

Acceptance Criteria

  • frontend application loads custom middleware from plugin in plugins directory
  • frontend application can load existing express middleware directly from npm
  • frontend application can load custom route with custom controller from theme
  • frontend application can load custom middleware with custom controller from theme
  • app loads successfully without any configured plugins or extensions

Implementation

PSUEDOCODE

// Find in node env:
CKAN_FE_PLUGINS="@ckan/logly mapPage"
CKAN_PLUGIN_DIRECTORY="/plugins"
CKAN_THEME_ROUTES="montreal"
CKAN_THEME_MIDDLEWARE=""
  
// coordinate various extension types here
function enableExtensions  {
  // check ENV for configured plugins
  // if custom plugins -> enableCustomPlugin()
  // if npm   // each -> enableNodePlugin()
  // check ENV for enabled theme extensions
  // if theme routes -> enableThemeRoutes
  // if theme middleware -> enableThemeMiddleware
}

function enableCustomPlugin(pluginPath, pluginName):
  console.log(pluginPath)
    app.use('/static', express.static(`./${pluginPath}/public`))
    require(`./${pluginPath}/${pluginName}/index.js`)(app)
  }

// require from node_modules and instantiate
function enableNodePlugin {name}
// allows developer to create new routes that leverage theme resources
def enableThemeRoutes(themePath, theme) {
  require('@ckan')(app)
}

// allows developer to enable theme-specific middleware
def enableThemeMiddleware(themePath, theme) {
  require(`./${themePath}/${theme}/middleware.js`)  
}

@todo add validation and error handling to all extension loading (try /catch & warn)
Also see the closed pull request #12 for a working example that:

  • dynamically loads routes from theme
  • dynamically loads static resources

Tasks

  • Implement support for required environment variables / config: [1hr]
    • CKAN_PLUGIN_DIRECTORY: Location of custom plugins, can be array (stretch), can default to /plugins
    • CKAN_FE_PLUGINS: space separated string of plugins to load
    • CKAN_THEME_ROUTES: space separated list of theme names with routes.js
    • CKAN_THEME_MIDDLEWARE: space separated list of theme names with middleware.js
    • [OTHERS?]
  • Implement plugin loading algorithms [above](Feature request: ability to add arbitrary route with template / controller / variables from path (and document) #11 implementation) [4hr]
  • Test [3hr]

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions