stackpress
Version:
Incept is a content management framework.
50 lines (49 loc) • 1.75 kB
JavaScript
import * as reactus from 'reactus';
export default async function build(server, cli) {
const cwd = server.config.path('server.cwd', process.cwd());
const plugins = server.config.path('view.engine.plugins', []);
const cssFiles = server.config.path('view.engine.cssFiles', []);
const assetPath = server.config.path('view.engine.assetPath');
const clientPath = server.config.path('view.engine.clientPath');
const pagePath = server.config.path('view.engine.pagePath');
const engine = reactus.build({
cwd,
plugins,
assetPath,
clientPath,
pagePath,
cssFiles
});
for (const views of server.views.values()) {
for (const view of views) {
await engine.set(view.entry);
}
}
if (engine.size === 0) {
return [];
}
const responses = [];
if (clientPath) {
cli?.verbose && cli.control.system('Building clients...');
responses.push(await engine.buildAllClients());
cli?.verbose && cli.control.success('Clients built.');
}
if (assetPath) {
cli?.verbose && cli.control.system('Building assets...');
responses.push(await engine.buildAllAssets());
cli?.verbose && cli.control.success('Assets built.');
}
if (pagePath) {
cli?.verbose && cli.control.system('Building pages...');
responses.push(await engine.buildAllPages());
cli?.verbose && cli.control.success('Pages built.');
}
return responses.map(response => {
const results = response.results;
if (typeof results?.contents === 'string') {
results.contents = results.contents.substring(0, 100) + ' ...';
}
return results;
});
}
;