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
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
2 changes: 1 addition & 1 deletion packages/php-wasm/universal/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export type {
} from './php-request-handler';
export { rotatePHPRuntime } from './rotate-php-runtime';
export { writeFiles } from './write-files';
export type { FileTree } from './write-files';
export type { FileTree, FileTreeAsync } from './write-files';

export {
DEFAULT_BASE_URL,
Expand Down
16 changes: 12 additions & 4 deletions packages/php-wasm/universal/src/lib/write-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ export interface WriteFilesOptions {
rmRoot?: boolean;
}

export interface FileTree
extends Record<string, Uint8Array | string | FileTree> {}
type FileContent = Uint8Array | string | FileTree;
type MaybePromise<T> = T | Promise<T>;

export interface FileTree extends Record<string, FileContent> {}

export interface FileTreeAsync
extends Record<string, MaybePromise<FileContent>> {}

/**
* Writes multiple files to a specified directory in the Playground
Expand All @@ -32,15 +37,18 @@ export interface FileTree
export async function writeFiles(
php: UniversalPHP,
root: string,
newFiles: FileTree,
newFiles: MaybePromise<FileTreeAsync>,
{ rmRoot = false }: WriteFilesOptions = {}
) {
if (rmRoot) {
if (await php.isDir(root)) {
await php.rmdir(root, { recursive: true });
}
}
for (const [relativePath, content] of Object.entries(newFiles)) {
newFiles = await newFiles;
for (const relativePath of Object.keys(newFiles)) {
const content = await newFiles[relativePath];

const filePath = joinPaths(root, relativePath);
if (!(await php.fileExists(dirname(filePath)))) {
await php.mkdir(dirname(filePath));
Expand Down
Loading