Created
August 9, 2016 10:06
-
-
Save qrg/d1e51cab2a74a15cac6e25b0b90ce2d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| import fs from 'fs'; | |
| import replaceExt from 'replace-ext'; | |
| import pug from 'pug'; | |
| import BrowserSync from 'browser-sync'; | |
| import gulp from 'gulp'; | |
| import size from 'gulp-size'; | |
| import plumber from 'gulp-plumber'; | |
| import notify from 'gulp-notify'; | |
| import tap from 'gulp-tap'; | |
| import gulpif from 'gulp-if'; | |
| import yaml from 'gulp-yaml'; | |
| import {templates, contents, server, notice} from '../config'; | |
| import mode from '../lib/mode'; | |
| export default function () { | |
| const watching = mode.watching; | |
| const bs = BrowserSync.get(server.name); | |
| return gulp.src(contents.src.path) | |
| .pipe(gulpif(watching, plumber({ | |
| errorHandler: notify.onError(notice.errorFormat) | |
| }))) | |
| .pipe(yaml()) | |
| .pipe(tap(applyTemplate)) | |
| .pipe(size({title: 'html:', showFiles: true})) | |
| .pipe(gulp.dest(templates.dest.dir)) | |
| .pipe(gulpif(watching, bs.stream({once: true}))); | |
| } | |
| function applyTemplate(dataFile) { | |
| const parsedData = JSON.parse(dataFile.contents.toString()); | |
| const template = fs.readFileSync(parsedData.template, 'utf8'); | |
| dataFile.path = replaceExt(dataFile.path, '.html'); | |
| const compiled = pug.compile(template, { | |
| pretty: true | |
| })(parsedData.contents); | |
| dataFile.contents = new Buffer(compiled, 'utf8'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment