--- /dev/null
+'use strict'
+
+const metadata = require('undertaker/lib/helpers/metadata')
+const { watch } = require('gulp')
+
+module.exports = ({ name, desc, opts, call: fn, loop }) => {
+ if (name) {
+ const displayName = fn.displayName
+ if (displayName === '<series>' || displayName === '<parallel>') {
+ metadata.get(fn).tree.label = `${displayName} ${name}`
+ }
+ fn.displayName = name
+ }
+ if (loop) {
+ const delegate = fn
+ name = delegate.displayName
+ delegate.displayName = `${name}:loop`
+ fn = () => watch(loop, { ignoreInitial: false }, delegate)
+ fn.displayName = name
+ }
+ if (desc) fn.description = desc
+ if (opts) fn.flags = opts
+ return fn
+}
--- /dev/null
+'use strict'
+
+module.exports = (...tasks) => {
+ const seed = {}
+ if (tasks.length) {
+ if (tasks.lastIndexOf(tasks[0]) > 0) {
+ const task1 = tasks.shift()
+ seed.default = Object.assign(task1.bind(null), { description: `=> ${task1.displayName}`, displayName: 'default' })
+ }
+ return tasks.reduce((acc, it) => (acc[it.displayName || it.name] = it) && acc, seed)
+ } else {
+ return seed
+ }
+}
--- /dev/null
+'use strict'
+
+const { obj: map } = require('through2')
+const PluginError = require('plugin-error')
+const prettierEslint = require('prettier-eslint')
+
+module.exports = () => {
+ const report = { changed: 0, unchanged: 0 }
+ return map(format).on('finish', () => {
+ if (report.changed > 0) {
+ const changed = 'formatted '
+ .concat(report.changed)
+ .concat(' file')
+ .concat(report.changed === 1 ? '' : 's')
+ const unchanged = 'left '
+ .concat(report.unchanged)
+ .concat(' file')
+ .concat(report.unchanged === 1 ? '' : 's')
+ .concat(' unchanged')
+ console.log(`prettier-eslint: ${changed}; ${unchanged}`)
+ } else {
+ console.log(`prettier-eslint: left ${report.unchanged} file${report.unchanged === 1 ? '' : 's'} unchanged`)
+ }
+ })
+
+ function format (file, enc, next) {
+ if (file.isNull()) return next()
+ if (file.isStream()) return next(new PluginError('gulp-prettier-eslint', 'Streaming not supported'))
+
+ const input = file.contents.toString()
+ const output = prettierEslint({ text: input, filePath: file.path })
+
+ if (input === output) {
+ report.unchanged += 1
+ } else {
+ report.changed += 1
+ file.contents = Buffer.from(output)
+ }
+
+ next(null, file)
+ }
+}
--- /dev/null
+'use strict'
+
+const asciidoctor = require('asciidoctor.js')()
+const fs = require('fs-extra')
+const handlebars = require('handlebars')
+const { obj: map } = require('through2')
+const merge = require('merge-stream')
+const ospath = require('path')
+const path = ospath.posix
+const requireFromString = require('require-from-string')
+const vfs = require('vinyl-fs')
+const yaml = require('js-yaml')
+
+const ASCIIDOC_ATTRIBUTES = {
+ experimental: '',
+ icons: 'font',
+ sectanchors: '',
+ 'source-highlighter': 'highlight.js',
+}
+
+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)
+ })
+ )
+ .pipe(vfs.dest(previewDest))
+ .pipe(sink())
+ )
+
+function loadSampleUiModel (src) {
+ return fs.readFile(ospath.join(src, 'ui-model.yml'), 'utf8').then((contents) => yaml.safeLoad(contents))
+}
+
+function registerPartials (src) {
+ return vfs.src('partials/*.hbs', { base: src, cwd: src }).pipe(
+ map((file, enc, next) => {
+ handlebars.registerPartial(file.stem, file.contents.toString())
+ next()
+ })
+ )
+}
+
+function registerHelpers (src) {
+ return vfs.src('helpers/*.js', { base: src, cwd: src }).pipe(
+ map((file, enc, next) => {
+ handlebars.registerHelper(file.stem, requireFromString(file.contents.toString()))
+ next()
+ })
+ )
+}
+
+function compileLayouts (src, layouts) {
+ return vfs.src('layouts/*.hbs', { base: src, cwd: src }).pipe(
+ map((file, enc, next) => {
+ layouts[file.stem] = handlebars.compile(file.contents.toString(), { preventIndent: true })
+ next()
+ })
+ )
+}
+
+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))
+}
--- /dev/null
+'use strict'
+
+const autoprefixer = require('autoprefixer')
+const browserify = require('browserify')
+const buffer = require('vinyl-buffer')
+const concat = require('gulp-concat')
+const cssnano = require('cssnano')
+const fs = require('fs-extra')
+const imagemin = require('gulp-imagemin')
+const { obj: map } = require('through2')
+const merge = require('merge-stream')
+const ospath = require('path')
+const path = ospath.posix
+const postcss = require('gulp-postcss')
+const postcssCalc = require('postcss-calc')
+const postcssImport = require('postcss-import')
+const postcssUrl = require('postcss-url')
+const postcssVar = require('postcss-custom-properties')
+const uglify = require('gulp-uglify')
+const vfs = require('vinyl-fs')
+
+module.exports = (src, dest, preview) => () => {
+ const opts = { base: src, cwd: src }
+ const postcssPlugins = [
+ postcssImport(),
+ postcssUrl([
+ {
+ filter: '**/~typeface-*/files/*',
+ url: (asset) => {
+ const relpath = asset.pathname.substr(1)
+ const abspath = ospath.resolve('node_modules', relpath)
+ const basename = ospath.basename(abspath)
+ const destpath = ospath.join(dest, 'font', basename)
+ if (!fs.pathExistsSync(destpath)) fs.copySync(abspath, destpath)
+ return path.join('..', 'font', basename)
+ },
+ },
+ ]),
+ postcssVar({ preserve: preview ? 'preserve-computed' : false }),
+ postcssCalc(),
+ autoprefixer({ browsers: ['last 2 versions'] }),
+ preview ? () => {} : cssnano({ preset: 'default' }),
+ ]
+
+ return merge(
+ vfs
+ .src('js/+([0-9])-*.js', opts)
+ .pipe(uglify())
+ .pipe(concat('js/site.js')),
+ vfs
+ .src('js/vendor/*.js', Object.assign({ read: false }, opts))
+ .pipe(
+ // see https://gulpjs.org/recipes/browserify-multiple-destination.html
+ map((file, enc, next) => {
+ file.contents = browserify(file.relative, { basedir: src, detectGlobals: false }).bundle()
+ next(null, file)
+ })
+ )
+ .pipe(buffer())
+ .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('helpers/*.js', opts),
+ vfs.src('layouts/*.hbs', opts),
+ vfs.src('partials/*.hbs', opts)
+ ).pipe(vfs.dest(dest))
+}
--- /dev/null
+'use strict'
+
+const prettier = require('../lib/gulp-prettier-eslint')
+const vfs = require('vinyl-fs')
+
+module.exports = (files) => () =>
+ vfs
+ .src(files)
+ .pipe(prettier())
+ .pipe(vfs.dest((file) => file.base))
--- /dev/null
+'use strict'
+
+const camelCase = (name) => name.replace(/[-]./g, (m) => m.substr(1).toUpperCase())
+
+module.exports = require('require-directory')(module, __dirname, { recurse: false, rename: camelCase })
--- /dev/null
+'use strict'
+
+const stylelint = require('gulp-stylelint')
+const vfs = require('vinyl-fs')
+
+module.exports = (files) => (done) =>
+ vfs
+ .src(files)
+ .pipe(stylelint({ reporters: [{ formatter: 'string', console: true }], failAfterError: true }))
+ .on('error', done)
--- /dev/null
+'use strict'
+
+const eslint = require('gulp-eslint')
+const vfs = require('vinyl-fs')
+
+module.exports = (files) => (done) =>
+ vfs
+ .src(files)
+ .pipe(eslint())
+ .pipe(eslint.format())
+ .pipe(eslint.failAfterError())
+ .on('error', done)
--- /dev/null
+'use strict'
+
+const vfs = require('vinyl-fs')
+const zip = require('gulp-vinyl-zip')
+
+module.exports = (src, dest, bundleName) => () =>
+ vfs
+ .src('**/*', { base: src, cwd: src })
+ .pipe(zip.zip(`${bundleName}-bundle.zip`))
+ .pipe(vfs.dest(dest))
--- /dev/null
+'use strict'
+
+const fs = require('fs-extra')
+const { obj: map } = require('through2')
+const vfs = require('vinyl-fs')
+
+module.exports = (files) => () =>
+ vfs.src(files, { allowEmpty: true }).pipe(map((file, enc, next) => fs.remove(file.path, next)))
--- /dev/null
+'use strict'
+
+const connect = require('gulp-connect')
+
+module.exports = (root, opts = {}, watch = undefined) => (done) => {
+ connect.server({ ...opts, root }, function () {
+ this.server.on('close', done)
+ if (watch) watch()
+ })
+}
--- /dev/null
+'use strict'
+
+const { parallel, series, tree, watch } = require('gulp')
+const createTask = require('./gulp.d/lib/create-task')
+const exportTasks = require('./gulp.d/lib/export-tasks')
+
+const bundleName = 'ui'
+const buildDir = 'build'
+const previewSrcDir = 'preview-src'
+const previewDestDir = 'public'
+const srcDir = 'src'
+const destDir = `${previewDestDir}/_`
+const { reload: livereload } = process.env.LIVERELOAD === 'true' ? require('gulp-connect') : {}
+
+const task = require('./gulp.d/tasks')
+const glob = {
+ all: [srcDir, previewSrcDir],
+ css: `${srcDir}/css/**/*.css`,
+ js: ['gulpfile.js', 'gulp.d/**/*.js', `${srcDir}/{helpers,js}/**/*.js`],
+}
+
+const cleanTask = createTask({
+ name: 'clean',
+ desc: 'Clean files and folders generated by build',
+ call: task.remove(['build', 'public']),
+})
+
+const lintCssTask = createTask({
+ name: 'lint:css',
+ desc: 'Lint the CSS source files using stylelint (standard config)',
+ call: task.lintCss(glob.css),
+})
+
+const lintJsTask = createTask({
+ name: 'lint:js',
+ desc: 'Lint the JavaScript source files using eslint (JavaScript Standard Style)',
+ call: task.lintJs(glob.js),
+})
+
+const lintTask = createTask({
+ name: 'lint',
+ desc: 'Lint the CSS and JavaScript source files',
+ call: parallel(lintCssTask, lintJsTask),
+})
+
+const formatTask = createTask({
+ name: 'format',
+ desc: 'Format the JavaScript source files using prettify (JavaScript Standard Style)',
+ call: task.format(glob.js),
+})
+
+const buildTask = createTask({
+ name: 'build',
+ desc: 'Build and stage the UI assets for bundling',
+ call: task.build(srcDir, destDir, tree().nodes.some((name) => ~name.indexOf('preview'))),
+})
+
+const bundleBuildTask = createTask({
+ name: 'bundle:build',
+ call: series(cleanTask, lintTask, buildTask),
+})
+
+const bundlePackTask = createTask({
+ name: 'bundle:pack',
+ desc: 'Create a bundle of the staged UI assets for publishing',
+ call: task.pack(destDir, buildDir, bundleName),
+})
+
+const bundleTask = createTask({
+ name: 'bundle',
+ desc: 'Clean, lint, build, and bundle the UI for publishing',
+ call: series(bundleBuildTask, bundlePackTask),
+})
+
+const buildPreviewPagesTask = createTask({
+ name: 'preview:build-pages',
+ call: task.buildPreviewPages(srcDir, previewSrcDir, previewDestDir, livereload),
+})
+
+const previewBuildTask = createTask({
+ name: 'preview:build',
+ desc: 'Process and stage the UI assets and generate pages for the preview',
+ call: parallel(buildTask, buildPreviewPagesTask),
+})
+
+const previewServeTask = createTask({
+ name: 'preview:serve',
+ call: task.serve(previewDestDir, { port: 5252, livereload }, () => watch(glob.all, previewBuildTask)),
+})
+
+const previewTask = createTask({
+ name: 'preview',
+ desc: 'Generate a preview site and launch a server to view it',
+ call: series(previewBuildTask, previewServeTask),
+})
+
+module.exports = exportTasks(
+ bundleTask,
+ cleanTask,
+ lintTask,
+ formatTask,
+ buildTask,
+ bundleTask,
+ bundlePackTask,
+ previewTask,
+ previewBuildTask
+)
+++ /dev/null
-'use strict'
-
-const { parallel, series, tree, watch } = require('gulp')
-const task = require('./lib/task')
-
-const bundleName = 'ui'
-const buildDir = 'build'
-const previewSrcDir = 'preview-src'
-const previewDestDir = 'public'
-const srcDir = 'src'
-const destDir = `${previewDestDir}/_`
-const { reload: livereload } = process.env.LIVERELOAD === 'true' ? require('gulp-connect') : {}
-
-const { remove, lintCss, lintJs, format, build, pack, previewPages, serve } = require('./tasks')
-const glob = {
- all: [srcDir, previewSrcDir],
- css: `${srcDir}/css/**/*.css`,
- js: ['gulpfile.js/**/*.js', `${srcDir}/{helpers,js}/**/*.js`],
-}
-
-const cleanTask = task({
- name: 'clean',
- desc: 'Clean files and folders generated by build',
- call: remove(['build', 'public']),
-})
-
-const lintCssTask = task({
- name: 'lint:css',
- desc: 'Lint the CSS source files using stylelint (standard config)',
- call: lintCss(glob.css),
-})
-
-const lintJsTask = task({
- name: 'lint:js',
- desc: 'Lint the JavaScript source files using eslint (JavaScript Standard Style)',
- call: lintJs(glob.js),
-})
-
-const lintTask = task({
- name: 'lint',
- desc: 'Lint the CSS and JavaScript source files',
- call: parallel(lintCssTask, lintJsTask),
-})
-
-const formatTask = task({
- name: 'format',
- desc: 'Format the JavaScript source files using prettify (JavaScript Standard Style)',
- call: format(glob.js),
-})
-
-const buildTask = task({
- name: 'build',
- desc: 'Build and stage the UI assets for bundling',
- call: build(srcDir, destDir, tree().nodes.some((name) => ~name.indexOf('preview'))),
-})
-
-const bundleBuildTask = task({
- name: 'bundle:build',
- call: series(cleanTask, lintTask, buildTask),
-})
-
-const bundlePackTask = task({
- name: 'bundle:pack',
- desc: 'Create a bundle of the staged UI assets for publishing',
- call: pack(destDir, buildDir, bundleName),
-})
-
-const bundleTask = task({
- name: 'bundle',
- desc: 'Clean, lint, build, and bundle the UI for publishing',
- call: series(bundleBuildTask, bundlePackTask),
-})
-
-const previewPagesTask = task({
- name: 'preview:pages',
- call: previewPages(srcDir, previewSrcDir, previewDestDir, livereload),
-})
-
-const previewBuildTask = task({
- name: 'preview:build',
- desc: 'Process and stage the UI assets and generate pages for the preview',
- call: parallel(buildTask, previewPagesTask),
-})
-
-const previewServeTask = task({
- name: 'preview:serve',
- call: serve(previewDestDir, { port: 5252, livereload }, () => watch(glob.all, previewBuildTask)),
-})
-
-const previewTask = task({
- name: 'preview',
- desc: 'Generate a preview site and launch a server to view it',
- call: series(previewBuildTask, previewServeTask),
-})
-
-module.exports = require('./lib/export-tasks')(
- bundleTask,
- cleanTask,
- lintTask,
- formatTask,
- buildTask,
- bundleTask,
- bundlePackTask,
- previewTask,
- previewBuildTask
-)
+++ /dev/null
-'use strict'
-
-module.exports = (...tasks) => {
- const seed = {}
- if (tasks.length) {
- if (tasks.lastIndexOf(tasks[0]) > 0) {
- const task1 = tasks.shift()
- seed.default = Object.assign(task1.bind(null), { description: `=> ${task1.displayName}`, displayName: 'default' })
- }
- return tasks.reduce((acc, it) => (acc[it.displayName || it.name] = it) && acc, seed)
- } else {
- return seed
- }
-}
+++ /dev/null
-'use strict'
-
-const { obj: map } = require('through2')
-const PluginError = require('plugin-error')
-const prettierEslint = require('prettier-eslint')
-
-module.exports = () => {
- const report = { changed: 0, unchanged: 0 }
- return map(format).on('finish', () => {
- if (report.changed > 0) {
- const changed = 'formatted '
- .concat(report.changed)
- .concat(' file')
- .concat(report.changed === 1 ? '' : 's')
- const unchanged = 'left '
- .concat(report.unchanged)
- .concat(' file')
- .concat(report.unchanged === 1 ? '' : 's')
- .concat(' unchanged')
- console.log(`prettier-eslint: ${changed}; ${unchanged}`)
- } else {
- console.log(`prettier-eslint: left ${report.unchanged} file${report.unchanged === 1 ? '' : 's'} unchanged`)
- }
- })
-
- function format (file, enc, next) {
- if (file.isNull()) return next()
- if (file.isStream()) return next(new PluginError('gulp-prettier-eslint', 'Streaming not supported'))
-
- const input = file.contents.toString()
- const output = prettierEslint({ text: input, filePath: file.path })
-
- if (input === output) {
- report.unchanged += 1
- } else {
- report.changed += 1
- file.contents = Buffer.from(output)
- }
-
- next(null, file)
- }
-}
+++ /dev/null
-'use strict'
-
-const metadata = require('undertaker/lib/helpers/metadata')
-const { watch } = require('gulp')
-
-module.exports = ({ name, desc, opts, call: fn, loop }) => {
- if (name) {
- const displayName = fn.displayName
- if (displayName === '<series>' || displayName === '<parallel>') {
- metadata.get(fn).tree.label = `${displayName} ${name}`
- }
- fn.displayName = name
- }
- if (loop) {
- const delegate = fn
- name = delegate.displayName
- delegate.displayName = `${name}:loop`
- fn = () => watch(loop, { ignoreInitial: false }, delegate)
- fn.displayName = name
- }
- if (desc) fn.description = desc
- if (opts) fn.flags = opts
- return fn
-}
+++ /dev/null
-'use strict'
-
-const autoprefixer = require('autoprefixer')
-const browserify = require('browserify')
-const buffer = require('vinyl-buffer')
-const concat = require('gulp-concat')
-const cssnano = require('cssnano')
-const fs = require('fs-extra')
-const imagemin = require('gulp-imagemin')
-const { obj: map } = require('through2')
-const merge = require('merge-stream')
-const ospath = require('path')
-const path = ospath.posix
-const postcss = require('gulp-postcss')
-const postcssCalc = require('postcss-calc')
-const postcssImport = require('postcss-import')
-const postcssUrl = require('postcss-url')
-const postcssVar = require('postcss-custom-properties')
-const uglify = require('gulp-uglify')
-const vfs = require('vinyl-fs')
-
-module.exports = (src, dest, preview) => () => {
- const opts = { base: src, cwd: src }
- const postcssPlugins = [
- postcssImport(),
- postcssUrl([
- {
- filter: '**/~typeface-*/files/*',
- url: (asset) => {
- const relpath = asset.pathname.substr(1)
- const abspath = ospath.resolve('node_modules', relpath)
- const basename = ospath.basename(abspath)
- const destpath = ospath.join(dest, 'font', basename)
- if (!fs.pathExistsSync(destpath)) fs.copySync(abspath, destpath)
- return path.join('..', 'font', basename)
- },
- },
- ]),
- postcssVar({ preserve: preview ? 'preserve-computed' : false }),
- postcssCalc(),
- autoprefixer({ browsers: ['last 2 versions'] }),
- preview ? () => {} : cssnano({ preset: 'default' }),
- ]
-
- return merge(
- vfs
- .src('js/+([0-9])-*.js', opts)
- .pipe(uglify())
- .pipe(concat('js/site.js')),
- vfs
- .src('js/vendor/*.js', Object.assign({ read: false }, opts))
- .pipe(
- // see https://gulpjs.org/recipes/browserify-multiple-destination.html
- map((file, enc, next) => {
- file.contents = browserify(file.relative, { basedir: src, detectGlobals: false }).bundle()
- next(null, file)
- })
- )
- .pipe(buffer())
- .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('helpers/*.js', opts),
- vfs.src('layouts/*.hbs', opts),
- vfs.src('partials/*.hbs', opts)
- ).pipe(vfs.dest(dest))
-}
+++ /dev/null
-'use strict'
-
-const prettier = require('../lib/gulp-prettier-eslint')
-const vfs = require('vinyl-fs')
-
-module.exports = (files) => () =>
- vfs
- .src(files)
- .pipe(prettier())
- .pipe(vfs.dest((file) => file.base))
+++ /dev/null
-'use strict'
-
-const camelCase = (name) => name.replace(/[-]./g, (m) => m.substr(1).toUpperCase())
-
-module.exports = require('require-directory')(module, __dirname, { recurse: false, rename: camelCase })
+++ /dev/null
-'use strict'
-
-const stylelint = require('gulp-stylelint')
-const vfs = require('vinyl-fs')
-
-module.exports = (files) => (done) =>
- vfs
- .src(files)
- .pipe(stylelint({ reporters: [{ formatter: 'string', console: true }], failAfterError: true }))
- .on('error', done)
+++ /dev/null
-'use strict'
-
-const eslint = require('gulp-eslint')
-const vfs = require('vinyl-fs')
-
-module.exports = (files) => (done) =>
- vfs
- .src(files)
- .pipe(eslint())
- .pipe(eslint.format())
- .pipe(eslint.failAfterError())
- .on('error', done)
+++ /dev/null
-'use strict'
-
-const vfs = require('vinyl-fs')
-const zip = require('gulp-vinyl-zip')
-
-module.exports = (src, dest, bundleName) => () =>
- vfs
- .src('**/*', { base: src, cwd: src })
- .pipe(zip.zip(`${bundleName}-bundle.zip`))
- .pipe(vfs.dest(dest))
+++ /dev/null
-'use strict'
-
-const asciidoctor = require('asciidoctor.js')()
-const fs = require('fs-extra')
-const handlebars = require('handlebars')
-const { obj: map } = require('through2')
-const merge = require('merge-stream')
-const ospath = require('path')
-const path = ospath.posix
-const requireFromString = require('require-from-string')
-const vfs = require('vinyl-fs')
-const yaml = require('js-yaml')
-
-const ASCIIDOC_ATTRIBUTES = {
- experimental: '',
- icons: 'font',
- sectanchors: '',
- 'source-highlighter': 'highlight.js',
-}
-
-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)
- })
- )
- .pipe(vfs.dest(previewDest))
- .pipe(sink())
- )
-
-function loadSampleUiModel (src) {
- return fs.readFile(ospath.join(src, 'ui-model.yml'), 'utf8').then((contents) => yaml.safeLoad(contents))
-}
-
-function registerPartials (src) {
- return vfs.src('partials/*.hbs', { base: src, cwd: src }).pipe(
- map((file, enc, next) => {
- handlebars.registerPartial(file.stem, file.contents.toString())
- next()
- })
- )
-}
-
-function registerHelpers (src) {
- return vfs.src('helpers/*.js', { base: src, cwd: src }).pipe(
- map((file, enc, next) => {
- handlebars.registerHelper(file.stem, requireFromString(file.contents.toString()))
- next()
- })
- )
-}
-
-function compileLayouts (src, layouts) {
- return vfs.src('layouts/*.hbs', { base: src, cwd: src }).pipe(
- map((file, enc, next) => {
- layouts[file.stem] = handlebars.compile(file.contents.toString(), { preventIndent: true })
- next()
- })
- )
-}
-
-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))
-}
+++ /dev/null
-'use strict'
-
-const fs = require('fs-extra')
-const { obj: map } = require('through2')
-const vfs = require('vinyl-fs')
-
-module.exports = (files) => () =>
- vfs.src(files, { allowEmpty: true }).pipe(map((file, enc, next) => fs.remove(file.path, next)))
+++ /dev/null
-'use strict'
-
-const connect = require('gulp-connect')
-
-module.exports = (root, opts = {}, watch = undefined) => (done) => {
- connect.server({ ...opts, root }, function () {
- this.server.on('close', done)
- if (watch) watch()
- })
-}