Skip to content

Commit

Permalink
feat(webpack): setup relative path plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
harryandriyan committed May 10, 2022
1 parent 2ea647b commit c22b691
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 101 deletions.
2 changes: 1 addition & 1 deletion admin-ui/app/redux/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import initSaga from './InitSaga'
import licenseSaga from './LicenseSaga'
import licenseDetailsSaga from './LicenseDetailsSaga'
import oidcDiscoverySaga from './OidcDiscoverySaga'
import process from '../../../plugins/PluginSagasResolver'
import process from 'Plugins/PluginSagasResolver'

export default function* rootSaga() {
const pluginSagaArr = process()
Expand Down
2 changes: 1 addition & 1 deletion admin-ui/app/redux/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
import hardSet from 'redux-persist/lib/stateReconciler/hardSet'
import reducerRegistry from '../reducers/ReducerRegistry'
import process from '../../../plugins/PluginReducersResolver'
import process from 'Plugins/PluginReducersResolver'
// create the saga middleware
const sagaMiddleware = createSagaMiddleware()
const middlewares = [sagaMiddleware]
Expand Down
2 changes: 1 addition & 1 deletion admin-ui/app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import ByeBye from './Pages/ByeBye'

import Gluu404Error from './Apps/Gluu/Gluu404Error'
import GluuNavBar from './Apps/Gluu/GluuNavBar'
import { processRoutes } from '../../plugins/PluginMenuResolver'
import { processRoutes } from 'Plugins/PluginMenuResolver'
import { hasPermission } from '../utils/PermChecker'

//------ Route Definitions --------
Expand Down
194 changes: 96 additions & 98 deletions admin-ui/build/plugin-cli.js
Original file line number Diff line number Diff line change
@@ -1,127 +1,125 @@
const program = require('commander');
const mkdirp = require('mkdirp');
const fse = require('fs-extra');
const config = require('./../config');
const pluginsObj = require('../plugins.config');
const path = require('path');
const unzipper = require('unzipper');
const rimraf = require('rimraf');
const program = require('commander')
const mkdirp = require('mkdirp')
const fse = require('fs-extra')
const config = require('./../config')
const pluginsObj = require('../plugins.config')
const path = require('path')
const unzipper = require('unzipper')
const rimraf = require('rimraf')

function dirParamToPath(dirParam) {
switch(dirParam) {
case 'plugins_repo':
return config.pluginsRepoDir;
case 'plugins':
return config.pluginsDir;
case 'rootDir':
return config.rootDir;
}
return null;
switch(dirParam) {
case 'plugins_repo':
return config.pluginsRepoDir
case 'plugins':
return config.pluginsDir
case 'rootDir':
return config.rootDir
}
return null
}

const commands = {

cleanExceptDefault: function(args) {
const plugins = [];
try {
plugins = args.split(',');
} catch(e) {
console.error('The args passed is invalid or undefined. All plugins will be removed.');
}
cleanExceptDefault: function(args) {
let plugins = []
try {
plugins = args.split(',')
} catch(e) {
console.error('The args passed is invalid or undefined. All plugins will be removed.')
}

const pluginsDir = dirParamToPath('plugins');
const pluginsDir = dirParamToPath('plugins')

fse.readdirSync(pluginsDir)
fse.readdirSync(pluginsDir)
.map(file => path.join(pluginsDir, file))
.filter(path => fse.statSync(path).isDirectory())
.filter(path => !plugins.includes(this.getLastFolderName(path)))
//.filter(path => fse.readdirSync(path).length === 0)
.map(path => rimraf.sync(path));
},
resetPluginConfig: function() {
const pluginsDir = dirParamToPath('plugins');
let configJson = []
.map(path => rimraf.sync(path))
},
resetPluginConfig: function() {
const pluginsDir = dirParamToPath('plugins')
const configJson = []

fse.readdirSync(pluginsDir)
fse.readdirSync(pluginsDir)
.map(file => path.join(pluginsDir, file))
.filter(path => fse.statSync(path).isDirectory())
.filter(path => fse.readdirSync(path).length > 0)
.map(path => configJson.push(this.createPluginEntry(this.getLastFolderName(path))));
fse.writeFileSync(path.join(dirParamToPath('rootDir'), 'plugins.config.json'),JSON.stringify(configJson, null, 2));
.filter(path => fse.readdirSync(path).length > 0)
.map(path => configJson.push(this.createPluginEntry(this.getLastFolderName(path))))
fse.writeFileSync(path.join(dirParamToPath('rootDir'), 'plugins.config.json'), JSON.stringify(configJson, null, 2))
},
addPlugin: function(sourcePath) {
const pluginsPath = dirParamToPath('plugins')

},
addPlugin: function(sourcePath) {
const pluginsPath = dirParamToPath('plugins');

if (!fse.existsSync(sourcePath)) {
console.error('Plugin zip not found at %s', sourcePath);
return;
}
var lastFolderName = this.getLastFolderName(sourcePath).split('.').slice(0, -1).join('.');
if (!fse.existsSync(sourcePath)) {
console.error('Plugin zip not found at %s', sourcePath)
return
}
const lastFolderName = this.getLastFolderName(sourcePath).split('.').slice(0, -1).join('.')

const pluginPathInRepo = path.join(pluginsPath, lastFolderName);
if (fse.existsSync(pluginPathInRepo)) {
console.error('Plugin with %s name already present in plugin repo.', lastFolderName);
return;
}
const pluginPathInRepo = path.join(pluginsPath, lastFolderName)
if (fse.existsSync(pluginPathInRepo)) {
console.error('Plugin with %s name already present in plugin repo.', lastFolderName)
return
}

mkdirp.sync(pluginPathInRepo);
fse.createReadStream(sourcePath).pipe(unzipper.Extract({ path: pluginPathInRepo }));
mkdirp.sync(pluginPathInRepo)
fse.createReadStream(sourcePath).pipe(unzipper.Extract({ path: pluginPathInRepo }))

pluginsObj.push(this.createPluginEntry(lastFolderName));
fse.writeFileSync(path.join(dirParamToPath('rootDir'), 'plugins.config.json'),JSON.stringify(pluginsObj, null, 2))
pluginsObj.push(this.createPluginEntry(lastFolderName))
fse.writeFileSync(path.join(dirParamToPath('rootDir'), 'plugins.config.json'), JSON.stringify(pluginsObj, null, 2))

},
removePlugin: function(pluginName) {
try {
const pluginsPath = dirParamToPath('plugins');
const pluginPathInRepo = path.join(pluginsPath, pluginName);
},
removePlugin: function(pluginName) {
try {
const pluginsPath = dirParamToPath('plugins')
const pluginPathInRepo = path.join(pluginsPath, pluginName)

if (fse.existsSync(pluginPathInRepo)) {
rimraf.sync(pluginPathInRepo);
if (fse.existsSync(pluginPathInRepo)) {
rimraf.sync(pluginPathInRepo)
fse.writeFileSync(
path.join(dirParamToPath('rootDir'), 'plugins.config.json'),
JSON.stringify(pluginsObj
.filter(ele => ele.key !== pluginName)), null, 2);

}
} catch (e) {
console.error('Error in enabling plugin. Check the plugin keys entered in args.')
JSON.stringify(pluginsObj.filter(ele => ele.key !== pluginName)), null, 2
)
}
},
createPluginEntry: function(pluginKey) {
const pluginObj = {};
pluginObj.key = pluginKey;
pluginObj.metadataFile = './' + pluginKey+ '/plugin-metadata';
return pluginObj;
},
showAllPlugins: function() {
if(pluginsObj.length == 0) {
console.log('- No Plugin in repo.')
return;
}
console.log('Following plugins are present.')
pluginsObj.forEach(ele => {
console.log('- '+ele.key)
});
},
getLastFolderName: function(path) {
return path.replace(/\\/g, '/').split('/').filter(function(el) {
return el.trim().length > 0;
}).pop();
} catch (e) {
console.error('Error in enabling plugin. Check the plugin keys entered in args.')
}
};
},
createPluginEntry: function(pluginKey) {
const pluginObj = {}
pluginObj.key = pluginKey
pluginObj.metadataFile = './' + pluginKey+ '/plugin-metadata'
return pluginObj
},
showAllPlugins: function() {
if(pluginsObj.length == 0) {
console.log('- No Plugin in repo.')
return
}
console.log('Following plugins are present.')
pluginsObj.forEach(ele => {
console.log('- '+ele.key)
})
},
getLastFolderName: function(path) {
return path.replace(/\\/g, '/').split('/').filter(function(el) {
return el.trim().length > 0
}).pop()
}
}

program
.option('-cpd, --cleanExceptDefault []')
.option('-rpc, --resetPluginConfig')
.option('-sap, --showAllPlugins')
.option('-ap, --addPlugin []')
.option('-rp, --removePlugin []')
.parse(process.argv);
.option('-cpd, --cleanExceptDefault []')
.option('-rpc, --resetPluginConfig')
.option('-sap, --showAllPlugins')
.option('-ap, --addPlugin []')
.option('-rp, --removePlugin []')
.parse(process.argv)

for (const commandName in commands) {
if (commands.hasOwnProperty(commandName) && program[commandName]) {
commands[commandName](program[commandName]);
}
// eslint-disable-next-line no-prototype-builtins
if (commands.hasOwnProperty(commandName) && program[commandName]) {
commands[commandName](program[commandName])
}
}

0 comments on commit c22b691

Please sign in to comment.