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

[Blueprints] Ensure plugins and themes are installed in subfolders when using url references in the installPlugin/Theme step #2128

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export const activatePlugin: StepHandler<ActivatePluginStep> = async (
die( $response->get_error_message() );
} else if ( false === $response ) {
die( "The activatePlugin step wasn't able to find the plugin $plugin_path." );
} else if ( $response === null ) {
// When the response is null, the plugin was successfully activated
die( 'true' );
}
`,
env: {
Expand All @@ -75,6 +78,12 @@ export const activatePlugin: StepHandler<ActivatePluginStep> = async (
},
});
if (activatePluginResult.text) {
/**
* If the plugin was successfully activated, we can return early.
*/
if (activatePluginResult.text === 'true') {
return;
}
Comment on lines +81 to +86
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This isn't directly related to this PR, but while I was debugging it, I realized that this will make the activatePlugin step more robust and will avoid the extra check when it's not needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On it's own this fix would allow the PR test to pass because the plugin would successfully activate inside the plugins folder.

logger.warn(
`Plugin ${pluginPath} activation printed the following bytes: ${activatePluginResult.text}`
);
Expand Down
14 changes: 11 additions & 3 deletions packages/playground/blueprints/src/lib/steps/install-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,23 @@ export async function installAsset(
targetPath,
zipFile,
ifAlreadyInstalled = 'overwrite',
targetFolderName = ''
targetFolderName = '',
}: InstallAssetOptions
): Promise<{
assetFolderPath: string;
assetFolderName: string;
}> {
// Extract to temporary folder so we can find asset folder name
const zipFileName = zipFile.name;
const assetNameGuess = zipFileName.replace(/\.zip$/, '');
let assetNameGuess = zipFileName.replace(/\.zip$/, '');
/**
* Some resource types like GitDirectoryReference and UrlReference
* don't have a name, so we need to generate a random name to ensure
* the asset folder name exists.
*/
if (!zipFileName) {
assetNameGuess = `${randomString(32, '')}`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Technically this could break if the path already exists, but I wasn't sure if checking the path would overcomplicate the implementation.

}

const wpContent = joinPaths(await playground.documentRoot, 'wp-content');
const tmpDir = joinPaths(wpContent, randomString());
Expand Down Expand Up @@ -88,7 +96,7 @@ export async function installAsset(
}

// If a specific slug was requested be used, use that.
if ( targetFolderName && targetFolderName.length ) {
if (targetFolderName && targetFolderName.length) {
assetFolderName = targetFolderName;
}

Expand Down
Loading