mirror of
https://github.com/morten-olsen/morten-olsen.github.io.git
synced 2026-02-08 01:46:28 +01:00
init
This commit is contained in:
34
bin/bundler/index.ts
Normal file
34
bin/bundler/index.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
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 };
|
||||
Reference in New Issue
Block a user