mirror of
https://github.com/morten-olsen/morten-olsen.github.io.git
synced 2026-02-08 01:46:28 +01:00
35 lines
688 B
TypeScript
35 lines
688 B
TypeScript
import { resolve } from 'path';
|
|
import { Observable } from '../observable';
|
|
|
|
type Asset = {
|
|
content: string | Buffer;
|
|
};
|
|
|
|
class Bundler {
|
|
#assets: Map<string, Observable<Asset>>;
|
|
|
|
constructor() {
|
|
this.#assets = new Map();
|
|
}
|
|
|
|
public get paths() {
|
|
return [...this.#assets.keys()];
|
|
}
|
|
|
|
public register = (path: string, asset: Observable<Asset>) => {
|
|
const realPath = resolve('/', path);
|
|
if (!this.#assets.has(realPath)) {
|
|
this.#assets.set(realPath, asset);
|
|
}
|
|
return realPath;
|
|
};
|
|
|
|
public get = (path: string) => {
|
|
const realPath = resolve('/', path);
|
|
return this.#assets.get(realPath);
|
|
};
|
|
}
|
|
|
|
export type { Asset };
|
|
export { Bundler };
|