Skip to content

Commit

Permalink
Remove hardcoding into registry, correct extends logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
reynoldsalec committed Nov 24, 2023
1 parent 345ea93 commit 77c74eb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
6 changes: 3 additions & 3 deletions builders/varnish-nginx.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

const _ = require('lodash');
const landoNginx = require('./../../node_modules/@lando/nginx/builders/nginx.js');
const landoNginx = require('./../node_modules/@lando/nginx/builders/nginx.js');

// Builder
module.exports = {
name: 'varnish-nginx',
parent: 'nginx',
builder: (parent, config) => class VarnishNginx extends landoNginx(parent, config) {
parent: '_service',
builder: (parent, config) => class VarnishNginx extends landoNginx.builder(parent, landoNginx.config) {
constructor(id, options = {}) {
super(id, options, {services: _.set({}, options.name)});
};
Expand Down
31 changes: 0 additions & 31 deletions builders/varnish.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,6 @@ const varnishSsl = options => ({
],
});

// Add hardcoded varnishServices to lando.factory.registry.
const addDependencies = options => {
const lando = _.get(options, '_app._lando');
// Traverse registry and remove any services that we have locally
const varnishServices = ['nginx'];
_.remove(lando.factory.registry, service => {
return _.includes(varnishServices, service.name);
});

// Make an array of absolute paths to the plugins we need to add
const varnishServicesPath = varnishServices.map(service => {
return path.join(__dirname, `../node_modules/@lando/${service}`);
});

// Loop that array and add each plugin to the registry and move scripts if the folder exists.
varnishServicesPath.forEach(servicePath => {
// Add the plugin to the registry
lando.factory.add(path.join(servicePath, 'builders', `${servicePath.split('/').pop()}.js`));

// Move the script to the conDir and make executable.
if (fs.existsSync(path.join(servicePath, 'scripts'))) {
const confDir = path.join(lando.config.userConfRoot, 'scripts');
const dest = lando.utils.moveConfig(path.join(servicePath, 'scripts'), confDir);
lando.utils.makeExecutable(fs.readdirSync(dest), dest);
lando.log.debug('automoved scripts from %s to %s and set to mode 755',
path.join(servicePath, 'scripts'), confDir);
}
});
};

// Builder
module.exports = {
name: 'varnish',
Expand All @@ -76,7 +46,6 @@ module.exports = {
builder: (parent, config) => class LandoVarnish extends parent {
constructor(id, options = {}, factory) {
options = _.merge({}, config, options);
addDependencies(options);

// Arrayify the backend
if (!_.isArray(options.backends)) options.backends = [options.backends];
Expand Down

0 comments on commit 77c74eb

Please sign in to comment.