UNPKG

1.65 kBJavaScriptView Raw
1/**
2 * The interface which exposes as "asset" in bulbofile
3 */
4class AssetFacade {
5 /**
6 * @param {Asset} asset The asset to modify
7 */
8 constructor(asset) {
9 this.assetModel = asset;
10 }
11
12 /**
13 * Gets the asset model.
14 * @return {Asset}
15 */
16 getAssetModel() {
17 return this.assetModel;
18 }
19
20 /**
21 * Adds the asset paths.
22 * @param {Array<string|string[]>} paths The paths
23 */
24 asset(...paths) {
25 this.getAssetModel().addAssetPaths(...paths);
26
27 return this;
28 }
29
30 /**
31 * Sets the asset options.
32 * @param {object} opts The options to pass to the vinyl-fs
33 */
34 assetOptions(opts) {
35 this.getAssetModel().setAssetOpts(opts);
36
37 return this;
38 }
39
40 /**
41 * Sets the watch paths and opts.
42 * @param {Array<string|string[]>} watchPaths The paths to watch
43 */
44 watch(...watchPaths) {
45 this.getAssetModel().addWatchPaths(...watchPaths);
46
47 return this;
48 }
49
50 /**
51 * Sets the watch options.
52 * @param {object} options The watch options
53 */
54 watchOptions(options) {
55 this.getAssetModel().setWatchOpts(options);
56
57 return this;
58 }
59
60 /**
61 * Sets the base path.
62 * @param {string} base The base path
63 */
64 base(base) {
65 this.getAssetModel().setAssetOpts({ base });
66
67 return this;
68 }
69
70 /**
71 * Adds the trasform of transform stream.
72 * @param {Transform} transform The transform to pass to the vinyl stream
73 */
74 pipe(transform) {
75 if (!transform) {
76 throw new Error(
77 `null transform is given for asset: ${this.getAssetModel().toString()}`,
78 );
79 }
80
81 this.getAssetModel().addPipe(transform);
82
83 return this;
84 }
85}
86
87module.exports = AssetFacade;