UNPKG

@codedoc/core

Version:

Create beautiful modern documentation websites.

56 lines 3.46 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import chalk from 'chalk'; import { join } from 'path'; import { sequentially, handleError } from 'rxline'; import { readFile, mapExt, mapRoot } from 'rxline/fs'; import { post, save } from '@connectv/sdh'; import { content } from './content'; import { namespace } from './namespace'; import { pageSpecificMeta } from '../components/page/meta-override/post'; export function rebuild(files, config, builder, assets, webpackConfig) { const _ogstyles = assets.styles.theme.registry.toString(); return new Promise((resolve, reject) => { files .peek(file => console.log(`${chalk.gray('# rebuilding ........ ' + join(file.root, file.path))}`)) .pipe(readFile(), content(builder, assets.toc, config, assets.styles), post(assets.bundle.collect()), post(namespace(config)), post(pageSpecificMeta), (file) => { (config.page.post || []).forEach(p => file.content.post(html => p(html, file, config))); return file; }, mapExt(() => '.html'), mapRoot(() => config.dest.html), save()) .pipe(handleError((err, file, rethrow) => { rethrow(new Error(chalk `{redBright # ERROR} in {underline ${file.path}}\n${(err === null || err === void 0 ? void 0 : err.message) || err}`)); })) .peek(file => console.log(`${chalk.green('#')}${chalk.gray(' rebuilt:: .........')} ${join(file.root, file.path)}`)) .process() .collect(sequentially, (built) => __awaiter(this, void 0, void 0, function* () { if (assets.styles.theme.registry.toString() !== _ogstyles) { console.log(`${chalk.gray('# rebuilding ........ ' + assets.styles.path)}`); yield assets.styles.save(); console.log(`${chalk.green('#')} ${chalk.gray('rebuilt:: .........')} ${assets.styles.path}`); } if (assets.bundle.repack) { console.log(`${chalk.gray('# rebuilding ........ ' + assets.bundle.path)}`); yield save(assets.bundle, webpackConfig); assets.bundle.repack = false; console.log(`${chalk.green('#')} ${chalk.gray('rebuilt:: .........')} ${assets.bundle.path}`); } if (config.afterBuild) { console.log(chalk.gray('# running after build hooks ...')); for (let hook of config.afterBuild) { console.log(chalk.gray('# running ......... ' + hook.name + '()')); yield hook({ config, built, source: files, partial: true }); console.log(`${chalk.green('#')} ${chalk.gray('finished:: ......')} ${hook.name}()`); } } resolve(assets); }), reject); }); } //# sourceMappingURL=rebuild.js.map