Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype blueprint package format via Playground CLI #2029

Draft
wants to merge 13 commits into
base: trunk
Choose a base branch
from

Conversation

brandonpayton
Copy link
Member

Motivation for the change, related issues

Let's explore a simple format for packaging assets with a Blueprint that may use them.

Related to WordPress/blueprints-library#118

Implementation details

This PR mounts the contents of the package at /internal/shared/blueprint-assets. It also creates dedicated Blueprint resources and references to use them, which will give us flexibility with how the assets are stored and accessed under the covers.

As part of this PR, I'd also like to explore making directory-related resources async per file. Right now, it appears that resolving a directory resource is asynchronous once, but it requires returning the data of all children at once via a FileTree that looks like

export interface FileTree
	extends Record<string, Uint8Array | string | FileTree> {}

Instead, it seems like we should only read file data when it is specifically looked up and used.

Testing Instructions (or ideally a Blueprint)

TBD

@brandonpayton brandonpayton added [Type] Enhancement New feature or request [Package][@wp-playground] Blueprints [Type] Exploration An exploration that may or may not result in mergable code labels Nov 25, 2024
@brandonpayton brandonpayton requested a review from a team November 25, 2024 20:56
@brandonpayton brandonpayton self-assigned this Nov 25, 2024
@brandonpayton brandonpayton force-pushed the prototype-blueprint-package-format branch from 24d8dde to f076cf2 Compare November 26, 2024 23:28
@brandonpayton
Copy link
Member Author

I had some trouble getting the Blueprint schema generated, and it turned out that making FileTree have maybe-async values was breaking type extraction by ts-json-schema-generator. This makes sense because Promises are not directly serializable.

It was possible to work around that conflict by making DirectoryLiteralReference just use a version of FileTree with normal, non-promise values. Then we can declare a FileTreeAsync type that can be used at runtime for resources like BlueprintAssetsDirectoryResource.

Now I am troubleshooting an issue with using blueprint asset resources at runtime.

// @TODO: Consider validating whether this is a zip file?
const zipFileName = pluginData.name.split('/').pop() || 'plugin.zip';
assetNiceName = zipNameToHumanName(zipFileName);
if (pluginData.name.endsWith('.php')) {
Copy link
Member Author

@brandonpayton brandonpayton Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes now have their own PR: #2033

I'll leave this here for now because I'm using it to test, but it should be removed before merging this PR.

adamziel pushed a commit that referenced this pull request Nov 28, 2024
## Motivation for the change, related issues

When testing #2029, I wanted to be able to install a plugin from a
single PHP file and have it activated as part of the same step. This
seemed reasonable, so I added support.

## Implementation details

Prior to this PR, if the `installPlugin` step received a file resource
it assumed it was a Zip file. This PR generally continues that practice
but makes an exception for file names ending with a `.php` extension.
File with names ending with `.php` are simply written to
`wp-content/plugins/<filename>`.

## Testing Instructions (or ideally a Blueprint)

CI - this PR adds a relevant unit test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package][@wp-playground] Blueprints [Type] Enhancement New feature or request [Type] Exploration An exploration that may or may not result in mergable code
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

1 participant