From 2fc25c6e3fab0f11914561e801a92240e3b751ff Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Mon, 31 Dec 2018 19:22:23 -0700 Subject: [PATCH] format source code --- gulpfile.js/tasks/build.js | 16 +++++--- gulpfile.js/tasks/preview-pages.js | 75 +++++++++++++++++++++----------------- 2 files changed, 52 insertions(+), 39 deletions(-) diff --git a/gulpfile.js/tasks/build.js b/gulpfile.js/tasks/build.js index 76e48d7..fa75b08 100644 --- a/gulpfile.js/tasks/build.js +++ b/gulpfile.js/tasks/build.js @@ -60,12 +60,16 @@ module.exports = (src, dest, preview) => () => { .pipe(uglify()), vfs.src('css/site.css', opts).pipe(postcss(postcssPlugins)), vfs.src('font/*.woff*(2)', opts), - vfs.src('img/**/*.{jpg,ico,png,svg}', opts).pipe(imagemin([ - imagemin.gifsicle(), - imagemin.jpegtran(), - imagemin.optipng(), - imagemin.svgo({ plugins: [{ removeViewBox: false }] }), - ])), + vfs + .src('img/**/*.{jpg,ico,png,svg}', opts) + .pipe( + imagemin([ + imagemin.gifsicle(), + imagemin.jpegtran(), + imagemin.optipng(), + imagemin.svgo({ plugins: [{ removeViewBox: false }] }), + ]) + ), vfs.src('helpers/*.js', opts), vfs.src('layouts/*.hbs', opts), vfs.src('partials/*.hbs', opts) diff --git a/gulpfile.js/tasks/preview-pages.js b/gulpfile.js/tasks/preview-pages.js index c31a5c1..12f3219 100644 --- a/gulpfile.js/tasks/preview-pages.js +++ b/gulpfile.js/tasks/preview-pages.js @@ -21,40 +21,49 @@ const ASCIIDOC_ATTRIBUTES = { module.exports = (src, previewSrc, previewDest, sink = () => map(), layouts = {}) => () => Promise.all([ loadSampleUiModel(previewSrc), - toPromise(merge(compileLayouts(src, layouts), registerPartials(src), registerHelpers(src), copyImages(previewSrc, previewDest))), - ]).then(([baseUiModel]) => Object.assign(baseUiModel, { env: process.env })).then((baseUiModel) => - vfs - .src('**/*.adoc', { base: previewSrc, cwd: previewSrc }) - .pipe( - map((file, enc, next) => { - const siteRootPath = path.relative(ospath.dirname(file.path), ospath.resolve(previewSrc)) - const uiModel = Object.assign({}, baseUiModel) - uiModel.page = Object.assign({}, uiModel.page) - uiModel.siteRootPath = siteRootPath - uiModel.siteRootUrl = path.join(siteRootPath, 'index.html') - uiModel.uiRootPath = path.join(siteRootPath, '_') - if (file.stem === '404') { - uiModel.page = { layout: '404', title: 'Page Not Found' } - } else { - const doc = asciidoctor.load(file.contents, { safe: 'safe', attributes: ASCIIDOC_ATTRIBUTES }) - uiModel.page.attributes = Object.entries(doc.getAttributes()) - .filter(([name, val]) => name.startsWith('page-')) - .reduce((accum, [name, val]) => { - accum[name.substr(5)] = val - return accum - }, {}) - uiModel.page.layout = doc.getAttribute('page-layout', 'default') - uiModel.page.title = doc.getDocumentTitle() - uiModel.page.contents = Buffer.from(doc.convert()) - } - file.extname = '.html' - file.contents = Buffer.from(layouts[uiModel.page.layout](uiModel)) - next(null, file) - }) + toPromise( + merge( + compileLayouts(src, layouts), + registerPartials(src), + registerHelpers(src), + copyImages(previewSrc, previewDest) ) - .pipe(vfs.dest(previewDest)) - .pipe(sink()) - ) + ), + ]) + .then(([baseUiModel]) => Object.assign(baseUiModel, { env: process.env })) + .then((baseUiModel) => + vfs + .src('**/*.adoc', { base: previewSrc, cwd: previewSrc }) + .pipe( + map((file, enc, next) => { + const siteRootPath = path.relative(ospath.dirname(file.path), ospath.resolve(previewSrc)) + const uiModel = Object.assign({}, baseUiModel) + uiModel.page = Object.assign({}, uiModel.page) + uiModel.siteRootPath = siteRootPath + uiModel.siteRootUrl = path.join(siteRootPath, 'index.html') + uiModel.uiRootPath = path.join(siteRootPath, '_') + if (file.stem === '404') { + uiModel.page = { layout: '404', title: 'Page Not Found' } + } else { + const doc = asciidoctor.load(file.contents, { safe: 'safe', attributes: ASCIIDOC_ATTRIBUTES }) + uiModel.page.attributes = Object.entries(doc.getAttributes()) + .filter(([name, val]) => name.startsWith('page-')) + .reduce((accum, [name, val]) => { + accum[name.substr(5)] = val + return accum + }, {}) + uiModel.page.layout = doc.getAttribute('page-layout', 'default') + uiModel.page.title = doc.getDocumentTitle() + uiModel.page.contents = Buffer.from(doc.convert()) + } + file.extname = '.html' + file.contents = Buffer.from(layouts[uiModel.page.layout](uiModel)) + next(null, file) + }) + ) + .pipe(vfs.dest(previewDest)) + .pipe(sink()) + ) function loadSampleUiModel (src) { return fs.readFile(ospath.join(src, 'ui-model.yml'), 'utf8').then((contents) => yaml.safeLoad(contents)) -- 2.11.0