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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Implement lazily-read VFSDirectoryResource
brandonpayton committed Nov 26, 2024
commit 2f25639607bf8a485305beec75323610201d9f09
49 changes: 36 additions & 13 deletions packages/playground/blueprints/src/lib/resources.ts
Original file line number Diff line number Diff line change
@@ -281,7 +281,12 @@ export class VFSDirectoryResource extends Resource<Directory> {
}

async resolve() {
return Promise.reject('Not implemented');
const name = this.name;
const files = await createLazyVFSFileTree(
this.reference.path,
this.playground!
);
return { name, files };
}

/** @inheritDoc */
@@ -334,19 +339,37 @@ export class BlueprintAssetDirectoryResource extends VFSDirectoryResource {
}
}

// export class LazyVFSFileTree extends Proxy implements FileTree {
// #root: string;

// constructor(root: string) {
// this.#root = root;
// super({}, {
// ownKeys() {
export async function createLazyVFSFileTree(
path: string,
playground: UniversalPHP
): Promise<FileTree> {
const keys = await playground.listFiles(path);
const keySet = new Set(keys);

// }
// })
// }

// }
return new Proxy<FileTree>(
{},
{
ownKeys() {
return keys;
},
async get(target, prop: string) {
if (!keySet.has(prop)) {
return undefined;
}
const fullPath = joinPaths(path, prop);
if (!(await playground.fileExists(fullPath))) {
return undefined;
}

if (await playground.isDir(fullPath)) {
return createLazyVFSFileTree(fullPath, playground);
} else {
return playground.readFileAsBuffer(joinPaths(path, prop));
}
},
}
);
}

/**
* A `Resource` that represents a literal file.