From ce962886377bf2baa8e5dd8e24d1df3126295a79 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Mon, 31 Dec 2018 19:21:12 -0700 Subject: [PATCH] copy images for preview site --- gulpfile.js/index.js | 2 +- gulpfile.js/tasks/preview-pages.js | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gulpfile.js/index.js b/gulpfile.js/index.js index 11f64ac..55a29a8 100644 --- a/gulpfile.js/index.js +++ b/gulpfile.js/index.js @@ -73,7 +73,7 @@ const bundleTask = task({ const previewPagesTask = task({ name: 'preview:pages', - call: previewPages(srcDir, destDir, previewSrcDir, previewDestDir, livereload), + call: previewPages(srcDir, previewSrcDir, previewDestDir, livereload), }) const previewBuildTask = task({ diff --git a/gulpfile.js/tasks/preview-pages.js b/gulpfile.js/tasks/preview-pages.js index cbf6fbb..c31a5c1 100644 --- a/gulpfile.js/tasks/preview-pages.js +++ b/gulpfile.js/tasks/preview-pages.js @@ -18,16 +18,16 @@ const ASCIIDOC_ATTRIBUTES = { 'source-highlighter': 'highlight.js', } -module.exports = (src, dest, siteSrc, siteDest, sink = () => map(), layouts = {}) => () => +module.exports = (src, previewSrc, previewDest, sink = () => map(), layouts = {}) => () => Promise.all([ - loadSampleUiModel(siteSrc), - toPromise(merge(compileLayouts(src, layouts), registerPartials(src), registerHelpers(src))), + 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: siteSrc, cwd: siteSrc }) + .src('**/*.adoc', { base: previewSrc, cwd: previewSrc }) .pipe( map((file, enc, next) => { - const siteRootPath = path.relative(ospath.dirname(file.path), ospath.resolve(siteSrc)) + 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 @@ -52,12 +52,12 @@ module.exports = (src, dest, siteSrc, siteDest, sink = () => map(), layouts = {} next(null, file) }) ) - .pipe(vfs.dest(siteDest)) + .pipe(vfs.dest(previewDest)) .pipe(sink()) ) -function loadSampleUiModel (siteSrc) { - return fs.readFile(ospath.join(siteSrc, 'ui-model.yml'), 'utf8').then((contents) => yaml.safeLoad(contents)) +function loadSampleUiModel (src) { + return fs.readFile(ospath.join(src, 'ui-model.yml'), 'utf8').then((contents) => yaml.safeLoad(contents)) } function registerPartials (src) { @@ -87,6 +87,10 @@ function compileLayouts (src, layouts) { ) } +function copyImages (src, dest) { + return vfs.src('**/*.{png,svg}', { base: src, cwd: src }).pipe(vfs.dest(dest)) +} + function toPromise (stream) { return new Promise((resolve, reject) => stream.on('error', reject).on('finish', resolve)) } -- 2.11.0