UNPKG

2.68 kBJavaScriptView Raw
1const Asset = require("./domain/asset");
2const AssetService = require("./app/asset-service");
3const AssetFacade = require("./asset-facade");
4const vinylServe = require("vinyl-serve");
5
6const liftoff = require("./util/liftoff");
7
8const service = new AssetService();
9
10// -- DSL vocabularies -- //
11// These are used in bulbofiles.
12
13/**
14 * Creates and registers an asset by the given paths and returns AssetFacade interface for further modification of asset building.
15 * See the document of AssetFacade about what can be modified about the assets.
16 * @param {Array<string|string[]>} paths The paths of the asset
17 * @return {Function}
18 */
19exports.asset = (...paths) => {
20 const asset = new Asset(...paths);
21
22 service.addAsset(asset);
23
24 return new AssetFacade(asset);
25};
26
27/**
28 * Sets the dest.
29 * @param {String} dest The destination
30 */
31exports.dest = (dest) => service.setDest(dest);
32
33/**
34 * Sets the default of the asset's base path.
35 * @param {string} base The default base path
36 */
37exports.base = (base) => service.setAssetBasePath(base);
38
39/**
40 * Sets the port number.
41 * @param {Number} port The port number
42 */
43exports.port = (port) => service.setPort(port);
44
45/**
46 * Sets the debug page title.
47 * @param {string} debugPageTitle
48 */
49exports.debugPageTitle = (debugPageTitle) =>
50 service.setDebugPageTitle(debugPageTitle);
51
52/**
53 * Sets the debug page path.
54 * @param {string} debugPagePath
55 */
56exports.debugPagePath = (debugPagePath) =>
57 service.setDebugPagePath(debugPagePath);
58
59// -- API for CLI -- //
60// These are used in CLIs.
61
62/**
63 * Serves the assets at localhost.
64 * @return {Promise}
65 */
66exports.serve = () => service.serve();
67
68/**
69 * Builds the assets to the destination.
70 * @return {Promise}
71 */
72exports.build = () => service.build();
73
74/**
75 * Watches and builds the assets.
76 */
77exports.watchAndBuild = () => service.watchAndBuild();
78
79/**
80 * Unwatches the assets.
81 */
82exports.unwatch = () => service.unwatch();
83
84/**
85 * Returns true iff the assets are empty.
86 * @return {Boolean}
87 */
88exports.isEmpty = () => service.isEmpty();
89
90/**
91 * Sets the logger title.
92 * @param {string} name The logger title
93 */
94exports.loggerTitle = (title) =>
95 service.setLogger(require("./util/logger")(title));
96
97// -- Private API -- //
98// These are used in tests.
99
100/**
101 * Sets the logger. Private API.
102 * @param {Logger} logger The logger
103 */
104exports.setLogger = (logger) => service.setLogger(logger);
105
106/**
107 * Clears all the assets. Private API.
108 * @private
109 */
110exports.clear = () => service.clear();
111
112/**
113 * Adds the connect middleware.
114 * @param {Function} middleware
115 */
116exports.addMiddleware = (middleware) => {
117 vinylServe.addMiddleware(middleware);
118};
119
120exports.cli = { liftoff };