Skip to content

Commit

Permalink
Refactor plugin to use new builders directory and break out utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
reynoldsalec committed Oct 26, 2023
1 parent 16259ac commit c1899b3
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 68 deletions.
15 changes: 7 additions & 8 deletions services/php/builder.js → builders/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
const _ = require('lodash');
const path = require('path');
const semver = require('semver');
const utils = require('./../../lib/utils');

const addBuildStep = require('./../utils/add-build-step');
/*
* Helper to get nginx config
*/
Expand All @@ -18,7 +17,7 @@ const nginxConfig = options => ({
info: {managed: true},
home: options.home,
name: `${options.name}_nginx`,
overrides: utils.cloneOverrides(options.overrides),
overrides: require('../utils/clone-overrides')(options.overrides),
project: options.project,
root: options.root,
ssl: options.nginxSsl,
Expand Down Expand Up @@ -108,7 +107,7 @@ module.exports = {
'/var/www/.composer/vendor/bin',
'/helpers',
],
confSrc: __dirname,
confSrc: path.resolve(__dirname, '..', 'config'),
command: ['sh -c \'a2enmod rewrite && apache2-foreground\''],
composer_version: '2.2.18',
image: 'apache',
Expand Down Expand Up @@ -171,19 +170,19 @@ module.exports = {

// Add our composer things to run step
if (!_.isEmpty(options.composer)) {
const commands = utils.getInstallCommands(options.composer, pkger, ['composer', 'global', 'require', '-n']);
utils.addBuildStep(commands, options._app, options.name, 'build_internal');
const commands = require('../utils/get-install-commands')(['composer', 'global', 'require', '-n']);
addBuildStep(commands, options._app, options.name, 'build_internal');
}

// Add activate steps for xdebug
if (options.xdebug) {
utils.addBuildStep(['docker-php-ext-enable xdebug'], options._app, options.name, 'build_as_root_internal');
addBuildStep(['docker-php-ext-enable xdebug'], options._app, options.name, 'build_as_root_internal');
}

// Install the desired composer version
if (options.composer_version) {
const commands = [`/helpers/install-composer.sh ${options.composer_version}`];
utils.addBuildStep(commands, options._app, options.name, 'build_internal', true);
addBuildStep(commands, options._app, options.name, 'build_internal', true);
}

// Add in nginx if we need to
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
60 changes: 0 additions & 60 deletions lib/utils.js

This file was deleted.

14 changes: 14 additions & 0 deletions utils/add-build-step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

// Modules
const _ = require('lodash');

/*
* Helper to get global deps
* @TODO: this looks pretty testable? should services have libs?
*/
module.exports = (steps, app, name, step = 'build_internal', front = false) => {
const current = _.get(app, `config.services.${name}.${step}`, []);
const add = (front) ? _.flatten([steps, current]) : _.flatten([current, steps]);
_.set(app, `config.services.${name}.${step}`, _.uniq(add));
};
15 changes: 15 additions & 0 deletions utils/clone-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

// Modules
const _ = require('lodash');

/*
* Helper to get global deps
* @TODO: this looks pretty testable? should services have libs?
*/
module.exports = (overrides = {}) => {
const newOverrides = _.cloneDeep(overrides);
if (_.has(newOverrides, 'image')) delete newOverrides.image;
if (_.has(newOverrides, 'build')) delete newOverrides.build;
return newOverrides;
};
13 changes: 13 additions & 0 deletions utils/get-install-commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

// Modules
const _ = require('lodash');

/*
* Helper to get global deps
* @TODO: this looks pretty testable? should services have libs?
*/
module.exports = (deps, pkger, prefix = []) => _(deps)
.map((version, pkg) => _.flatten([prefix, pkger(pkg, version)]))
.map(command => command.join(' '))
.value();

0 comments on commit c1899b3

Please sign in to comment.