Open alexnitta opened 1 year ago
Good idea @alexnitta, I had not thought about monorepo-style projects. Is your plenti.json
at the project root or packages/web/src/plenti.json
?
I think we could probably just add a file_prefix
option to the cms
settings defined in plenti.json
. We're planning on modifying that API a bit anyways now that we're adding other providers like Gitea.
My plenti.json file is at packages/web/src/plenti.json
- so it's in the usual location relative to the content
folder.
I think the extra config option sounds great. Do you have any idea of when that feature might make it into a release? I'm on the verge of finishing a project for a client, and this is the last piece of the CMS that is not working.
Thanks for building such a great framework for nonprofits, by the way. I'm really excited to deliver this project to the client - which happens to be my son's preschool, a nonprofit organization - and Plenti is a perfect match for their needs.
I was able to work around this by adding a shell script to my .gitlab-ci.yml
. The shell script uses sed
to append the packages/web/src/
subdirectory before the file path in pubic/spa/core/cms/publish.js
. Now I am able to use the CMS editor to save changes - so @jimafisk there's no need to rush the official fix into a release, but whenever you have time for that I'd be happy to remove this patch from my codebase.
To restate the problem, my issue is that my JSON content is not located in ./content
relative to the root of the repo; since I'm using a monorepo, it's located in ./packages/web/src/content
instead. This breaks the current version of the CMS editor when trying to save changes, because the generated JS file in public/spa/core/cms/publish.js
assumes the file paths are relative to the root of the repository.
For anyone else facing this same problem, here's my .gitlab-ci.yml
with some comments added where I changed things.
image: docker:stable
pages:
before_script:
- apk add --update curl wget && rm -rf /var/cache/apk/*
script:
# Move to the subdirectory of the monorepo where the plenti.json file is.
# This is also where the `content` folder is located which contains all of the JSON content.
- cd packages/web/src
# These next three steps are the same as in the example at https://plenti.co/docs/gitlab-piplines/
- wget -c $(curl -s https://api.github.com/repos/plentico/plenti/releases/latest | grep -o 'http.*linux_64-bit.tar.gz')
- tar -zxvf *_linux_64-bit.tar.gz
- ./plenti build
# Move back up one folder to where the patch script is located
- cd ..
# Run the patch script
- ./patch_cms_publish.sh
artifacts:
paths:
- packages/web/public
publish: packages/web/public
only:
- main
And here is the packages/web/patch_cms_publish.sh
script:
#!/bin/sh
# This script is used to patch the public/spa/core/cms/publish.js script to use the correct file path
# when committing changes with the GitLab API. This is necessary because the script expects the
# JSON `content` folder path to start from the root of the repo, but our JSON `content` folder is in
# a subdirectory of the monorepo.
sed -i.bak 's/file_path:/&"packages\/web\/src\/" + /' public/spa/core/cms/publish.js
The script needs to be committed with git add --chmod=+x packages/web/patch_cms_publish.sh
so that it can be executed.
I'm really excited to deliver this project to the client - which happens to be my son's preschool, a nonprofit organization
That's wonderful, so glad it's fitting your needs! Providing a low-overhead solution for nonprofits is one of our primary goals.
I was able to work around this by adding a shell script
That's very clever, thanks for sharing your workaround!
there's no need to rush the official fix into a release
Sounds great, thanks for letting me know. I'm a little overbooked this month and next, but this is something I'm interested in adding to the project. Thanks for the suggestion!
My pleasure, glad that I could be helpful in some way! As I mentioned, this is a really great fit for my client's needs, and I totally appreciate your contributions to the ecosystem. Plenti fills a niche that I haven't seen addressed by any other framework.
My project is set up as a monorepo, which means that my JSON content lives in a non-standard folder. For example, my
_index.json
file is inpackages/web/src/content/_index.json
, rather thancontent/_index.json
. This seems to break the publishing capability of the CMS editor.When I make some changes in the CMS editor and click "Save", I see an "Error Saving" message in the button. I opened the network tab in the dev tools and found the request body that gets sent to
https://gitlab.com/api/v4/projects/...
, which looks like this:and the 400 response body is:
This makes sense, because my repo doesn't have a file at
content/_index.json
; it's actually atpackages/web/src/content/_index.json
. It seems that thefile_path
for each element of theactions
array should be modified if thecontent
folder is in a non-standard location. This should be possible by locating theplenti.json
file and using its location as the starting directory for thefile_path
in each action, or possibly by adding some kind of config option inplenti.json
to help with non-standard (i.e. nested) locations for thecontent
folder that contains the JSON files.