Roots Discourse

Deployment on Shared Hosting

Hi
I have been developing a theme for a godaddy managed wordpress hosting , and since they don’t allow composer to run on their production server i usually go through doing yarn build:production , composer install --no-dev and then uploading everything except node_modules through cyberduck . The client asks for a change and i have to go on through all these process again and again … is there an easy way to do this at least with the uploading part ?

What I do is up until now.

  • Edit it locally,
  • clone the folder and clean it up. (removing node_modules and such)
  • Then zip the theme.
  • upload it in the remote Wp dash->themes->new theme -> upload theme
  • it then asks to replace existing theme
  • done

This is a bit hacky, but it works for me. I wish to create a github autoupdate script via the build in wp update hook. But I’m not there yet. Works for public repos but not for private yes.

Is this hacky workaround a solution?

IMHO it could be quite helpful to add an “eject” task to Sage that automatically creates a minimal theme ZIP as build artifact.

Note: node_modules/ is only required for building the theme - it is not needed and should not be needed by the theme during runtime. If there are any files that should be available for the theme, either add them using webpack (e.g. imported SASS, url(...)) or copy them from node_modules/ into dist/ or - for some cases - resources/.

For Sage 10 themes:

#!/bin/sh
echo 'Building theme.zip from Sage 10 theme.' && \
echo "Note: This script doesn't clean up the existing temporary folder (./theme-zip-contents). You have to do this your yourself." && \
echo '(1/4) Ensuring all theme composer dependencies are installed (theme runtime)...' && \
composer install -q && \
echo '(2/4) Ensuring folder for theme zip contents...' && \
mkdir -p ./theme-zip-contents && \
echo '(3/4) Copying relevant theme files into folder...' && \
cp -a  ./style.css          ./theme-zip-contents/ && \
cp -a  ./functions.php      ./theme-zip-contents/ && \
cp -a  ./index.php          ./theme-zip-contents/ && \
cp -a  ./screenshot.png     ./theme-zip-contents/ && \
cp -aR ./app                ./theme-zip-contents/ && \
cp -aR ./config             ./theme-zip-contents/ && \
cp -aR ./public             ./theme-zip-contents/ && \
cp -aR ./vendor             ./theme-zip-contents/ && \
cp -a  ./bootstrap/app.php  ./theme-zip-contents/ && \
echo '(4/4) Creating theme zip file...' && \
zip -r -q ./theme.zip ./theme-zip-contents/* && \
echo 'Done. You find the theme zip as `theme.zip` inside this directory.'

This script above creates (should create) a ZIP with the minimal set of files needed to use the plugin.

For Sage 9 themes:

#!/bin/sh
echo 'Building theme.zip from Sage 9 theme.' && \
echo "Note: This script doesn't clean up the existing temporary folder (./theme-zip-contents). You have to do this your yourself." && \
echo '(1/4) Ensuring all theme composer dependencies are installed (theme runtime)...' && \
composer install -q && \
echo '(2/4) Ensuring folder for theme zip contents...' && \
mkdir -p ./theme-zip-contents && \
echo '(3/4) Copying relevant theme files into folder...' && \
cp -aR ./app           ./theme-zip-contents/ && \
cp -a  ./composer.lock ./theme-zip-contents/ && \
cp -a  ./composer.lock ./theme-zip-contents/ && \
cp -aR ./config        ./theme-zip-contents/ && \
cp -aR ./dist          ./theme-zip-contents/ && \
cp -aR ./resources     ./theme-zip-contents/ && \
cp -aR ./vendor        ./theme-zip-contents/ && \
echo '(4/4) Creating theme zip file...' && \
zip -r -q ./theme.zip ./theme-zip-contents/* && \
echo 'Done. You find the theme zip as `theme.zip` inside this directory.'
3 Likes

Thank you for the reply. Is it possible to use git hooks if we have a repository where we are committing only those finished theme ( aka after composer install --no-dev) ?

Thank you for your kind help . Will try it . I was thinking about using git hooks where we would be able to update the changed files only ( say if it is a small sass change , you have to upload an entire theme again ) .

You could take a look at this. afragen/github-updater I haven’t worked with it myself. But he also has an old repo with the bare theme update code. afragen/github-theme-updater. This might point you in the right direction. I’ve tried working with the last repo. But I ran into a wall with private repos. I can’t set a access token header for the updated file download.

If you have SSH access into the server, you can simply use rsync to upload new and delete changed files. Create a script on your local computer to generate the build and upload it.

For Sage 9:

#!/bin/bash

yarn build:production
rsync -aP --delete-after ./dist ./vendor ./app ./resources ./config username@XX.XX.XXX.XX:/home/...
1 Like

I would recommend setting up a CI / CD pipeline! It’s a lot of work the first time but once you get the hang of continuous deployment… it’s one of the most important tools in my workflow.

This topic was automatically closed after 42 days. New replies are no longer allowed.