-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
44 lines (40 loc) · 1.6 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Plugin, KeyedStoreTrigger, Step } from "@shanzhai/interfaces";
import { parsedPugStore } from "@shanzhai/parsed-pug-store";
import { htmlSourceStore } from "@shanzhai/html-source-store";
import { RenderPugStep } from "@shanzhai/render-pug-step";
import { pugLocalStore } from "@shanzhai/pug-local-store";
import { MergeObjectInput } from "@shanzhai/merge-object-input";
import { DeleteFromKeyedStoreStep } from "@shanzhai/delete-from-keyed-store-step";
import { KeyedStoreGetInput } from "@shanzhai/keyed-store-get-input";
import { KeyedStoreSetOutput } from "@shanzhai/keyed-store-set-output";
import { KeyedStoreGetAllInput } from "@shanzhai/keyed-store-get-all-input";
const replaceExtension = (from: string): string =>
from.replace(/\.pug$/, `.html`);
const renderPugPlugin: Plugin<{
readonly renderPug: KeyedStoreTrigger;
}> = {
triggers: {
renderPug: {
type: `keyedStore`,
keyedStore: parsedPugStore,
refreshAllWhenStoresChange: [pugLocalStore],
down(key: string): Step {
return new DeleteFromKeyedStoreStep(
htmlSourceStore,
replaceExtension(key)
);
},
up(key: string): Step {
const withReplacedExtension = replaceExtension(key);
return new RenderPugStep(
`Render Pug "${key}" as "${withReplacedExtension}"`,
new KeyedStoreGetInput(parsedPugStore, key),
new MergeObjectInput(new KeyedStoreGetAllInput(pugLocalStore)),
new KeyedStoreSetOutput(htmlSourceStore, withReplacedExtension)
);
},
writesToStores: [htmlSourceStore],
},
},
};
export = renderPugPlugin;