Skip to content

PHP: Add prependPath option to listFiles method #462

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

Conversation

eliot-akira
Copy link
Collaborator

@eliot-akira eliot-akira commented May 28, 2023

What?

Add prependPath option to PHP.listFiles method, which will prepend given folder path to every file found in it.

Why?

It's a common need to iterate over a list of files with each file path being an accessible path instead of only the file name. Idea mentioned in:

For example, this is a common pattern:

const files = await playground.listFiles( folderPath )

for (const file of files) {
	const filePath = `${folderPath}/${file}`;
	...
}

Also expressed as:

const filePaths = (await playground.listFiles( folderPath )).map(
  (name: string) => `${folderPath}/${name}`)
)

With the new option, the above can be simplified as:

const filePaths = await playground.listFiles(folderPath, { prependPath: true })

How?

  • Add prependPath option to BasePHP.listFiles method
  • Document the option and what it does
  • Add test

Testing Instructions

  1. Check out the branch.
  2. Run nx test playground-blueprints

Sorry, something went wrong.

@eliot-akira eliot-akira changed the title BasePHP: Add includePath option to listFiles method PHP: Add includePath option to listFiles method May 28, 2023
@eliot-akira eliot-akira changed the title PHP: Add includePath option to listFiles method PHP: Add prependPath option to listFiles method May 30, 2023
@eliot-akira eliot-akira marked this pull request as ready for review May 30, 2023 17:20
@eliot-akira
Copy link
Collaborator Author

OK, renamed option to prependPath and added a test for it.

@adamziel adamziel merged commit 45519d8 into WordPress:trunk Jun 1, 2023
@adamziel
Copy link
Collaborator

adamziel commented Jun 1, 2023

This is amazing @eliot-akira, it will save everyone writing the boilerplate - thank you for your willingness to help!

adamziel added a commit that referenced this pull request Jun 1, 2023
The options argument for listFiles was added to BasePHP in #462. This
commit adds it to an interface and a Web PHP Endpoint so that it can be
used across the board in web and node.js applications
adamziel added a commit that referenced this pull request Jun 1, 2023
…490)

The options argument for listFiles was added to BasePHP in #462. This
commit adds it to an interface and a Web PHP Endpoint so that it can be
used across the board in web and node.js applications
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants