|
| 1 | +import chroma from 'chroma-js'; |
| 2 | +import def from '../default'; |
| 3 | +import denodeify from 'promise-denodeify'; |
| 4 | +import extend from 'extend'; |
| 5 | +import fs from 'fs'; |
| 6 | +import fse from 'fs-extra'; |
| 7 | +import { minify } from 'html-minifier'; |
| 8 | +import path from 'path'; |
| 9 | +import sassdocExtras from 'sassdoc-extras'; |
| 10 | +import swig from './swig'; |
| 11 | + |
| 12 | +const copy = denodeify(fse.copy, Promise); |
| 13 | +const renderFile = denodeify(swig.renderFile, Promise); |
| 14 | +const writeFile = denodeify(fs.writeFile, Promise); |
| 15 | + |
| 16 | +const applyDefaults = ctx => |
| 17 | + extend({}, def, ctx, { |
| 18 | + groups: extend(def.groups, ctx.groups), |
| 19 | + display: extend(def.display, ctx.display), |
| 20 | + }); |
| 21 | + |
| 22 | +const shortcutIcon = (dest, ctx) => { |
| 23 | + if (!ctx.shortcutIcon) { |
| 24 | + ctx.shortcutIcon = { type: 'internal', url: 'assets/images/favicon.png' }; |
| 25 | + } else if (ctx.shortcutIcon.type === 'internal') { |
| 26 | + ctx.shortcutIcon.url = 'assets/images/' + ctx.shortcutIcon.url; |
| 27 | + |
| 28 | + return () => |
| 29 | + copy(ctx.shortcutIcon.path, path.resolve(dest, ctx.shortcutIcon.url)); |
| 30 | + } |
| 31 | +}; |
| 32 | + |
| 33 | +export default (dest, ctx) => { |
| 34 | + ctx = applyDefaults(ctx); |
| 35 | + |
| 36 | + sassdocExtras.markdown(ctx); |
| 37 | + sassdocExtras.display(ctx); |
| 38 | + sassdocExtras.groupName(ctx); |
| 39 | + sassdocExtras.shortcutIcon(ctx); |
| 40 | + |
| 41 | + ctx.data.byGroupAndType = sassdocExtras.byGroupAndType(ctx.data); |
| 42 | + |
| 43 | + const index = path.resolve(__dirname, '../views/documentation/index.html.swig'); |
| 44 | + |
| 45 | + return Promise.all([ |
| 46 | + copy(path.resolve(__dirname, '../assets'), path.resolve(dest, 'assets')) |
| 47 | + .then(shortcutIcon(dest, ctx)), |
| 48 | + |
| 49 | + renderFile(index, ctx) |
| 50 | + .then(html => minify(html, { collapseWhitespace: true })) |
| 51 | + .then(html => writeFile(path.resolve(dest, 'index.html'), html)), |
| 52 | + ]); |
| 53 | +}; |
0 commit comments