|
1 | 1 | const createDebugger = require('./../../utils/debug');
|
2 | 2 | const path = require('path');
|
3 | 3 |
|
4 |
| -// @TODO: only load this if we need it |
5 |
| -const LandoOclifPlugin = require('./../../utils/plugin'); |
6 |
| - |
7 | 4 | module.exports = async({id, argv, config}) => {
|
8 | 5 | let debug = createDebugger(config.dirname, 'hooks', 'init');
|
9 | 6 | // Below is mostly just to DEBUG confirm we can get this far
|
@@ -53,42 +50,39 @@ module.exports = async({id, argv, config}) => {
|
53 | 50 |
|
54 | 51 | // @TODO: move findPlugin to utils/utils.js? and eventually into @lando/oclifer?
|
55 | 52 | // @TODO: eventually we should make criteria able to match by more than just name/id
|
56 |
| - const findPlugin = (plugins = [], criteria) => plugins.find(({name}) => name === criteria); |
57 |
| - // @TODO: remove command should eventually be a method on LandoOclifPlugin |
58 |
| - const removeCommand = (plugin = {}, cmdId) => { |
59 |
| - const commandIndex = plugin.commands.findIndex(({id}) => id === cmdId); |
60 |
| - if (commandIndex === -1) { |
61 |
| - debug('could not find a command called %s in plugin %s, doing nothing', cmdId, plugin.name); |
62 |
| - return plugin.commands; |
63 |
| - } |
64 |
| - plugin.commands.splice(commandIndex, 1); |
65 |
| - debug('removed command %s: plugin now has commands %o', cmdId, plugin.commands.map(command => command.id).join(', ')); |
66 |
| - return plugin.commands; |
67 |
| - }; |
| 53 | + // const findPlugin = (plugins = [], criteria) => plugins.find(({name}) => name === criteria); |
| 54 | + const findPluginIndex = (plugins = [], criteria) => plugins.findIndex(({name}) => name === criteria); |
68 | 55 |
|
69 |
| - // @TODO: restantiate corePlugin as a ocliflandoplugin? |
| 56 | + // @TODO: We should only load our plugin class and replace the core plugin if |
| 57 | + // we have an id/argv combination that will require command removal and/or |
| 58 | + // dynamically loading commands eg hyperdrive install docker-desktop |
| 59 | + const LandoOclifPlugin = require('./../../utils/plugin'); |
| 60 | + // Create a drop in replacement of the corePlugin using our extended plugin class and load it |
| 61 | + // @NOTE: root probably will not be universally config.root |
| 62 | + const newCorePlugin = new LandoOclifPlugin({type: 'hyperdrive', root: config.root}); |
| 63 | + await newCorePlugin.load(); |
70 | 64 |
|
71 | 65 | // if id-argv matches a signature then remove id and load up queuer
|
72 | 66 | // @NOTE: should this be both add and install?
|
73 | 67 | if (id === 'install' && argv[0] === 'docker-desktop') {
|
74 |
| - // Lets remove the add command |
75 |
| - const corePlugin = findPlugin(config.plugins, '@lando/hyperdrive'); |
76 |
| - // delete corePlugin.manifest.commands.add; |
77 |
| - corePlugin.commands = removeCommand(corePlugin, 'install'); |
| 68 | + // Remove the install command |
| 69 | + newCorePlugin.commands = newCorePlugin.removeCommand('install'); |
78 | 70 | // find the correct install plugin?
|
79 |
| - const installerPlugin = findPlugin(config.installers, 'docker-desktop'); |
80 |
| - config.plugins.push(new LandoOclifPlugin(config, {id: 'install', path: installerPlugin.path})); |
| 71 | + // const installerPlugin = findPlugin(config.installers, 'docker-desktop'); |
| 72 | + // config.plugins.push(new LandoOclifPlugin(config, {id: 'install', path: installerPlugin.path})); |
81 | 73 | }
|
82 | 74 |
|
83 | 75 | // if id-argv matches a signature then remove id and load up queuer
|
84 | 76 | // @NOTE: should this be both add and install?
|
85 | 77 | if (id === 'uninstall' && argv[0] === 'docker-desktop') {
|
86 |
| - // Lets remove the add command |
87 |
| - const corePlugin = findPlugin(config.plugins, '@lando/hyperdrive'); |
88 |
| - // delete corePlugin.manifest.commands.add; |
89 |
| - corePlugin.commands = removeCommand(corePlugin, 'uninstall'); |
| 78 | + // Lets remove the uninstall command |
| 79 | + newCorePlugin.commands = newCorePlugin.removeCommand('uninstall'); |
90 | 80 | // find the correct install plugin?
|
91 |
| - const uninstallerPlugin = findPlugin(config.uninstallers, 'docker-desktop'); |
92 |
| - config.plugins.push(new LandoOclifPlugin(config, {id: 'uninstall', path: uninstallerPlugin.path})); |
| 81 | + // const uninstallerPlugin = findPlugin(config.uninstallers, 'docker-desktop'); |
| 82 | + // config.plugins.push(new LandoOclifPlugin(config, {id: 'uninstall', path: uninstallerPlugin.path})); |
93 | 83 | }
|
| 84 | + |
| 85 | + // Let's replace it with our extended plugin class |
| 86 | + const corePluginIndex = findPluginIndex(config.plugins, '@lando/hyperdrive'); |
| 87 | + config.plugins.splice(corePluginIndex, 1, newCorePlugin); |
94 | 88 | };
|
0 commit comments