-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const fs = require( 'fs' ) | ||
const path = require( 'path' ) | ||
const winston = require( 'winston' ) | ||
|
||
const isDirectory = source => fs.lstatSync( source ).isDirectory( ) | ||
const getDirectories = source => fs.readdirSync( source ).map( name => path.join( source, name ) ).filter( isDirectory ) | ||
|
||
module.exports = ( ) => { | ||
winston.debug( 'Scanning for speckle plugins...' ) | ||
|
||
// gather potential plugin subdirectories | ||
const rootDirs = process.env.PLUGIN_DIRS.split( `,` ) | ||
let pluginDirs = [ ] | ||
rootDirs.forEach( dir => { | ||
if ( fs.existsSync( dir ) ) { | ||
let dirs = getDirectories( dir ) | ||
pluginDirs = [ ...dirs, pluginDirs ] | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
didimitrie
Author
Member
|
||
} else | ||
winston.warn( `specified plugin directory does not exist: ${dir}` ) | ||
} ) | ||
|
||
// read in manifest files | ||
let plugins = [] | ||
pluginDirs.forEach( dir => { | ||
let file = path.normalize( `${dir}//speckle-plugin-manifest.json` ) | ||
if ( fs.existsSync( file ) ) { | ||
let obj = JSON.parse( fs.readFileSync( file, 'utf8' ) ) | ||
obj.sourceDir = dir | ||
plugins.push( obj ) | ||
} else | ||
winston.warn( `No plugin manifest file found in ${dir}.` ) | ||
} ) | ||
|
||
// check for conflicts | ||
let serveLocations = [] | ||
plugins.forEach( pl => { | ||
if ( serveLocations.indexOf( pl.serveFrom ) < 0 ) | ||
serveLocations.push( pl.serveFrom ) | ||
else { | ||
winston.warn( `Conflicting plugin endpoint found at: ${pl.serveFrom} in folder ${pl.sourceDir}. | ||
It will load from ${pl.serveFrom + '-dupe'} instead.` ) | ||
pl.serveFrom += '-dupe' | ||
} | ||
} ) | ||
winston.debug( `Found ${plugins.length} plugin(s):${plugins.map( p => ' ' + p.name )}` ) | ||
|
||
return plugins | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<h1>Sample Speckle Frontend Plugin</h1> | ||
<p>This is just an example of how you can register a speckle frontend plugin. Its manifest file looks something like this:</p> | ||
<pre> | ||
{ | ||
"name": "Sample Plugin", | ||
"version":"", | ||
"desc": "This plugin tests plugins", | ||
"serveFrom": "/sample-plugin", | ||
"author": "DAS", | ||
"contact":"[email protected]", | ||
"homepage":"https://dimitrie.org" | ||
} | ||
</pre> | ||
<p> | ||
This file (`speckle-plugin-manifest.json`) is picked up by the server which then serves the plugin statically from the location specified. | ||
</p> | ||
<p> | ||
Thanks for watching 👋 <a href="https://speckle.works">Speckle!</a> | ||
</p> | ||
<style type="text/css"> | ||
a,p,h1 { | ||
font-family: sans-serif; | ||
} | ||
h1 { | ||
color: royalblue; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "Sample Plugin", | ||
"version":"0.1.0", | ||
"desc": "This plugin tests plugins", | ||
"serveFrom": "/sample-plugin", | ||
"author": "DAS", | ||
"contact":"[email protected]", | ||
"homepage":"https://dimitrie.org" | ||
} |
Does this do what it's supposed to?
[ ...[ 1, 2 ], [ 3, 4 ] ]
evaluates to[ 1, 2, [ 3, 4 ] ]
. Should it bepluginDirs.push(...dirs)
?