Skip to content

Commit

Permalink
feat(vendor-sync): use specified directory instead of curl and zip files
Browse files Browse the repository at this point in the history
  • Loading branch information
claimableperch committed Oct 29, 2024
1 parent 9b32b48 commit 35b5246
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
16 changes: 14 additions & 2 deletions lib/modules/createConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable global-require, import/no-dynamic-require */
const fs = require('fs-extra');
const { copyDirSync } = require('../utils/copy');
const { rmDirSync } = require('../utils/rm');
const path = require('path');
const glob = require('glob');
const { get, defaults } = require('lodash');
Expand Down Expand Up @@ -154,9 +156,19 @@ const createConfig = async (packageDir, hasVolumeSupport = true) => {
htaccessFile = `${htaccessFile}-subfolder`;
}

const composerWordpress = path.resolve( CWD, version[0] );
const vendorSync = `${packageDir}/wordpress`;
if ( fs.existsSync( vendorSync ) ) {
rmDirSync( vendorSync );
}
if ( fs.existsSync( composerWordpress ) ) {
copyDirSync( composerWordpress, vendorSync );
}
const usableVersions = fs.existsSync( vendorSync ) ? [ 'wordpress' ] : validVersions;

await renderTemplate(`${packageDir}/lib/templates/dockerfile.ejs`, `${packageDir}/Dockerfile`, {
isWpContent: config.wpContent,
versions: validVersions,
versions: usableVersions,
vip: config.muPlugins ? config.muPlugins.vip : false,
phpVersion: config.phpVersion || 7.4,
phpMemoryLimit: config.phpMemoryLimit || '128M',
Expand All @@ -166,7 +178,7 @@ const createConfig = async (packageDir, hasVolumeSupport = true) => {
const wpCypressConfig = {
...config,
version,
validVersions,
validVersions: usableVersions,
volumes,
activePlugins,
activeTheme,
Expand Down
10 changes: 7 additions & 3 deletions lib/templates/dockerfile.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ RUN curl -sS https://getcomposer.org/installer --output composer-setup.php \
&& php composer-setup.php --version=1.10.16 \
&& mv composer.phar /bin/composer

<% versions.forEach((version) => { %>
<% versions.forEach((version) => {
if ( version.match(/(\d+.?)+/) ) {
%>
RUN curl https://wordpress.org/wordpress-<%= version %>.tar.gz > wordpress-<%= version %>.tar.gz && \
mkdir -p /var/www/<%= version %> && \
tar -xzf wordpress-<%= version %>.tar.gz -C /var/www/<%= version %> && \
mv /var/www/<%= version %>/wordpress/* /var/www/<%= version %> && \
rm -rf /var/www/<%= version %>/wordpress && \
chown -R www-data:www-data /var/www/<%= version %><% if (isWpContent) { %> && \<% } else { %>;<% } %>
<% if (isWpContent) { %>rm -rf /var/www/<%= version %>/wp-content;<% } %>
<% }); %>
<% if (isWpContent) { %>rm -rf /var/www/<%= version %>/wp-content;<% } %>
<% } else { %>
ADD <%= version %> /var/www/wordpress
<% } }); %>
<% if (vip) { %>
RUN curl https://github.com/Automattic/vip-go-mu-plugins-built/archive/master.zip -L -o /usr/src/vip-mu-plugins.zip && \
Expand Down
22 changes: 22 additions & 0 deletions lib/utils/rm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const fs = require('fs-extra');
const path = require('path');
const rmDirSync = (src) => {
if (!fs.lstatSync(src).isDirectory()) {
return;
}

fs.readdirSync(src)
.forEach((item) => {
const srcItem = path.join(src, item);

if (fs.lstatSync(srcItem).isDirectory()) {
rmDirSync(srcItem);
} else {
fs.unlinkSync(srcItem);
}
});
fs.rmdirSync(src);
};
module.exports = {
rmDirSync,
};

0 comments on commit 35b5246

Please sign in to comment.