+++ /dev/null
-'use strict'
-
-const { parallel, series, tree } = require('gulp')
-const camelcase = (name) => name.replace(/[-]./g, (m) => m.substr(1).toUpperCase())
-const exportTasks = require('./tasks/lib/export-tasks')
-const task = require('./tasks/lib/task')
-const taskFns = require('require-directory')(module, './tasks', { recurse: false, rename: camelcase })
-const path = require('path')
-
-const bundleName = 'ui'
-const buildDir = 'build'
-const previewSiteSrcDir = 'preview-site-src'
-const previewSiteDestDir = 'public'
-const srcDir = 'src'
-const destDir = path.join(previewSiteDestDir, '_')
-const { reload: livereload } = process.env.LIVERELOAD === 'true' ? require('gulp-connect') : {}
-
-const cssFileGlobs = path.join(srcDir, 'css/**/*.css')
-const jsFileGlobs = ['gulpfile.js', 'tasks/**/*.js', path.join(srcDir, '{helpers,js}/**/*.js')]
-
-const { remove, lintCss, lintJs, format, build, pack, previewPages, previewServe } = taskFns
-
-const cleanTask = task({
- name: 'clean',
- desc: 'Clean files and folders generated by build',
- then: remove(['build', 'public']),
-})
-
-const lintCssTask = task({
- name: 'lint:css',
- desc: 'Lint the CSS source files using stylelint (standard config)',
- then: lintCss(cssFileGlobs),
-})
-
-const lintJsTask = task({
- name: 'lint:js',
- desc: 'Lint the JavaScript source files using eslint (JavaScript Standard Style)',
- then: lintJs(jsFileGlobs),
-})
-
-const lintTask = task({
- name: 'lint',
- desc: 'Lint the CSS and JavaScript source files',
- then: parallel(lintCssTask, lintJsTask),
-})
-
-const formatTask = task({
- name: 'format',
- desc: 'Format the JavaScript source files using prettify (JavaScript Standard Style)',
- then: format(jsFileGlobs),
-})
-
-const buildTask = task({
- name: 'build',
- desc: 'Build and stage the UI assets for bundling',
- then: build(srcDir, destDir, tree().nodes.some((name) => ~name.indexOf('preview'))),
-})
-
-const bundleBuildTask = task({
- name: 'bundle:build',
- desc: 'Lint the source files and build and stage the UI assets for bundling',
- then: series(cleanTask, lintTask, buildTask),
-})
-
-const bundlePackTask = task({
- name: 'bundle:pack',
- desc: 'Create a bundle of the staged UI assets for publishing',
- then: pack(destDir, buildDir, bundleName),
-})
-
-const bundleTask = task({
- name: 'bundle',
- desc: 'Clean, lint, build, and bundle the UI for publishing',
- then: series(bundleBuildTask, bundlePackTask),
-})
-
-const previewPagesTask = task({
- name: 'preview:pages',
- desc: 'Generate pages for the preview by applying the specified layout template',
- then: previewPages(srcDir, destDir, previewSiteSrcDir, previewSiteDestDir, livereload),
-})
-
-const previewBuildTask = task({
- name: 'preview:build',
- desc: 'Process and stage the UI assets and generate pages for the preview',
- then: parallel(buildTask, previewPagesTask),
-})
-
-const previewServeTask = task({
- name: 'preview:serve',
- desc: 'Launch server to preview UI',
- then: previewServe(previewSiteDestDir, {
- port: 5252,
- livereload,
- watch: { src: [srcDir, previewSiteSrcDir], onChange: previewBuildTask },
- }),
-})
-
-const previewTask = task({
- name: 'preview',
- desc: 'Generate a preview site and launch a server to view it',
- then: series(previewBuildTask, previewServeTask),
-})
-
-module.exports = exportTasks(
- task({ name: 'default', desc: `(${bundleTask.displayName})`, then: series(bundleTask) }),
- cleanTask,
- lintTask,
- formatTask,
- buildTask,
- bundleTask,
- previewTask,
- previewBuildTask
-)
--- /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 merge = require('merge-stream')
+const { obj: map } = require('through2')
+const path = require('path')
+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 = path.resolve('node_modules', relpath)
+ const basename = path.basename(abspath)
+ const destpath = path.join(dest, 'font', basename)
+ if (!fs.pathExists(destpath)) fs.copy(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()),
+ 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 { parallel, series, tree } = require('gulp')
+const camelcase = (name) => name.replace(/[-]./g, (m) => m.substr(1).toUpperCase())
+const exportTasks = require('./lib/export-tasks')
+const task = require('./lib/task')
+const taskFns = require('require-directory')(module, '.', { recurse: false, rename: camelcase })
+const path = require('path')
+
+const bundleName = 'ui'
+const buildDir = 'build'
+const previewSiteSrcDir = 'preview-site-src'
+const previewSiteDestDir = 'public'
+const srcDir = 'src'
+const destDir = path.join(previewSiteDestDir, '_')
+const { reload: livereload } = process.env.LIVERELOAD === 'true' ? require('gulp-connect') : {}
+
+const cssFileGlobs = path.join(srcDir, 'css/**/*.css')
+const jsFileGlobs = ['gulpfile.js/**/*.js', path.join(srcDir, '{helpers,js}/**/*.js')]
+
+const { remove, lintCss, lintJs, format, build, pack, previewPages, previewServe } = taskFns
+
+const cleanTask = task({
+ name: 'clean',
+ desc: 'Clean files and folders generated by build',
+ then: remove(['build', 'public']),
+})
+
+const lintCssTask = task({
+ name: 'lint:css',
+ desc: 'Lint the CSS source files using stylelint (standard config)',
+ then: lintCss(cssFileGlobs),
+})
+
+const lintJsTask = task({
+ name: 'lint:js',
+ desc: 'Lint the JavaScript source files using eslint (JavaScript Standard Style)',
+ then: lintJs(jsFileGlobs),
+})
+
+const lintTask = task({
+ name: 'lint',
+ desc: 'Lint the CSS and JavaScript source files',
+ then: parallel(lintCssTask, lintJsTask),
+})
+
+const formatTask = task({
+ name: 'format',
+ desc: 'Format the JavaScript source files using prettify (JavaScript Standard Style)',
+ then: format(jsFileGlobs),
+})
+
+const buildTask = task({
+ name: 'build',
+ desc: 'Build and stage the UI assets for bundling',
+ then: build(srcDir, destDir, tree().nodes.some((name) => ~name.indexOf('preview'))),
+})
+
+const bundleBuildTask = task({
+ name: 'bundle:build',
+ desc: 'Lint the source files and build and stage the UI assets for bundling',
+ then: series(cleanTask, lintTask, buildTask),
+})
+
+const bundlePackTask = task({
+ name: 'bundle:pack',
+ desc: 'Create a bundle of the staged UI assets for publishing',
+ then: pack(destDir, buildDir, bundleName),
+})
+
+const bundleTask = task({
+ name: 'bundle',
+ desc: 'Clean, lint, build, and bundle the UI for publishing',
+ then: series(bundleBuildTask, bundlePackTask),
+})
+
+const previewPagesTask = task({
+ name: 'preview:pages',
+ desc: 'Generate pages for the preview by applying the specified layout template',
+ then: previewPages(srcDir, destDir, previewSiteSrcDir, previewSiteDestDir, livereload),
+})
+
+const previewBuildTask = task({
+ name: 'preview:build',
+ desc: 'Process and stage the UI assets and generate pages for the preview',
+ then: parallel(buildTask, previewPagesTask),
+})
+
+const previewServeTask = task({
+ name: 'preview:serve',
+ desc: 'Launch server to preview UI',
+ then: previewServe(previewSiteDestDir, {
+ port: 5252,
+ livereload,
+ watch: { src: [srcDir, previewSiteSrcDir], onChange: previewBuildTask },
+ }),
+})
+
+const previewTask = task({
+ name: 'preview',
+ desc: 'Generate a preview site and launch a server to view it',
+ then: series(previewBuildTask, previewServeTask),
+})
+
+module.exports = exportTasks(
+ task({ name: 'default', desc: `(${bundleTask.displayName})`, then: series(bundleTask) }),
+ cleanTask,
+ lintTask,
+ formatTask,
+ buildTask,
+ bundleTask,
+ previewTask,
+ previewBuildTask
+)
--- /dev/null
+'use strict'
+
+module.exports = (...tasks) =>
+ tasks.reduce((acc, task) => (acc[task.displayName || task.name] = task) && acc, { default: tasks.shift() })
--- /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')
+
+module.exports = ({ name, desc, anon, then: fn }) => {
+ if (name) {
+ const displayName = fn.displayName
+ if (displayName === '<series>' || displayName === '<parallel>') {
+ metadata.get(fn).tree.label = `${displayName} ${name}`
+ }
+ fn.displayName = name
+ }
+ if (desc) fn.description = desc
+ return fn
+}
--- /dev/null
+'use strict'
+
+const stylelint = require('gulp-stylelint')
+const vfs = require('vinyl-fs')
+
+module.exports = (files) => () =>
+ vfs.src(files).pipe(stylelint({ reporters: [{ formatter: 'string', console: true }] }))
--- /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 handlebars = require('handlebars')
+const { obj: map } = require('through2')
+const path = require('path')
+const requireFromString = require('require-from-string')
+const vfs = require('vinyl-fs')
+const yaml = require('js-yaml')
+
+module.exports = (src, dest, siteSrc, siteDest, onComplete) => () =>
+ Promise.all([loadSampleUiModel(siteSrc), compileLayouts(src), registerPartials(src), registerHelpers(src)]).then(
+ ([uiModel, layouts]) =>
+ vfs
+ .src('**/*.html', { base: siteSrc, cwd: siteSrc })
+ .pipe(
+ map((file, enc, next) => {
+ const compiledLayout = layouts[file.stem === '404' ? '404.hbs' : 'default.hbs']
+ const siteRootPath = path.relative(path.dirname(file.path), path.resolve(siteSrc))
+ uiModel.env = process.env
+ uiModel.siteRootPath = siteRootPath
+ uiModel.siteRootUrl = path.join(siteRootPath, 'index.html')
+ uiModel.uiRootPath = path.join(siteRootPath, '_')
+ uiModel.page.contents = file.contents.toString().trim()
+ file.contents = Buffer.from(compiledLayout(uiModel))
+ next(null, file)
+ })
+ )
+ .pipe(vfs.dest(siteDest))
+ .pipe(onComplete ? onComplete() : map((file, enc, next) => next()))
+ )
+
+function loadSampleUiModel (siteSrc) {
+ return fs.readFile(path.join(siteSrc, 'ui-model.yml'), 'utf8').then((contents) => yaml.safeLoad(contents))
+}
+
+function registerPartials (src) {
+ return new Promise((resolve, reject) =>
+ vfs
+ .src('partials/*.hbs', { base: src, cwd: src })
+ .pipe(
+ map((file, enc, next) => {
+ handlebars.registerPartial(file.stem, file.contents.toString())
+ next()
+ })
+ )
+ .on('error', reject)
+ .on('finish', resolve)
+ )
+}
+
+function registerHelpers (src) {
+ return new Promise((resolve, reject) =>
+ vfs
+ .src('helpers/*.js', { base: src, cwd: src })
+ .pipe(
+ map((file, enc, next) => {
+ handlebars.registerHelper(file.stem, requireFromString(file.contents.toString()))
+ next()
+ })
+ )
+ .on('error', reject)
+ .on('finish', resolve)
+ )
+}
+
+function compileLayouts (src) {
+ const layouts = {}
+ return new Promise((resolve, reject) =>
+ vfs
+ .src('layouts/*.hbs', { base: src, cwd: src })
+ .pipe(
+ map((file, enc, next) => {
+ layouts[file.basename] = handlebars.compile(file.contents.toString(), { preventIndent: true })
+ next()
+ })
+ )
+ .on('error', reject)
+ .on('finish', () => resolve(layouts))
+ )
+}
--- /dev/null
+'use strict'
+
+const chokidar = require('chokidar')
+const connect = require('gulp-connect')
+
+module.exports = (serveDir, opts = {}) => (done) => {
+ const watch = opts.watch
+ delete opts.watch
+ opts = Object.assign({ root: serveDir }, opts)
+ let onStart
+ if (watch && watch.src && watch.onChange) {
+ onStart = () =>
+ chokidar
+ .watch(watch.src, { ignoreInitial: true })
+ .on('add', watch.onChange)
+ .on('change', watch.onChange)
+ .on('unlink', watch.onChange)
+ }
+ connect.server(opts, function () {
+ this.server.on('close', done)
+ if (onStart) onStart()
+ })
+}
--- /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 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 merge = require('merge-stream')
-const { obj: map } = require('through2')
-const path = require('path')
-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 = path.resolve('node_modules', relpath)
- const basename = path.basename(abspath)
- const destpath = path.join(dest, 'font', basename)
- if (!fs.pathExists(destpath)) fs.copy(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()),
- 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'
-
-module.exports = (...tasks) =>
- tasks.reduce((acc, task) => (acc[task.displayName || task.name] = task) && acc, { default: tasks.shift() })
+++ /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')
-
-module.exports = ({ name, desc, anon, then: fn }) => {
- if (name) {
- const displayName = fn.displayName
- if (displayName === '<series>' || displayName === '<parallel>') {
- metadata.get(fn).tree.label = `${displayName} ${name}`
- }
- fn.displayName = name
- }
- if (desc) fn.description = desc
- return fn
-}
+++ /dev/null
-'use strict'
-
-const stylelint = require('gulp-stylelint')
-const vfs = require('vinyl-fs')
-
-module.exports = (files) => () =>
- vfs.src(files).pipe(stylelint({ reporters: [{ formatter: 'string', console: true }] }))
+++ /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 handlebars = require('handlebars')
-const { obj: map } = require('through2')
-const path = require('path')
-const requireFromString = require('require-from-string')
-const vfs = require('vinyl-fs')
-const yaml = require('js-yaml')
-
-module.exports = (src, dest, siteSrc, siteDest, onComplete) => () =>
- Promise.all([
- loadSampleUiModel(siteSrc),
- compileLayouts(src),
- registerPartials(src),
- registerHelpers(src),
- ]).then(([uiModel, layouts]) =>
- vfs
- .src('**/*.html', { base: siteSrc, cwd: siteSrc })
- .pipe(
- map((file, enc, next) => {
- const compiledLayout = layouts[file.stem === '404' ? '404.hbs' : 'default.hbs']
- const siteRootPath = path.relative(path.dirname(file.path), path.resolve(siteSrc))
- uiModel.env = process.env
- uiModel.siteRootPath = siteRootPath
- uiModel.siteRootUrl = path.join(siteRootPath, 'index.html')
- uiModel.uiRootPath = path.join(siteRootPath, '_')
- uiModel.page.contents = file.contents.toString().trim()
- file.contents = Buffer.from(compiledLayout(uiModel))
- next(null, file)
- })
- )
- .pipe(vfs.dest(siteDest))
- .pipe(onComplete ? onComplete() : map((file, enc, next) => next()))
- )
-
-function loadSampleUiModel (siteSrc) {
- return fs.readFile(path.join(siteSrc, 'ui-model.yml'), 'utf8').then((contents) => yaml.safeLoad(contents))
-}
-
-function registerPartials (src) {
- return new Promise((resolve, reject) =>
- vfs
- .src('partials/*.hbs', { base: src, cwd: src })
- .pipe(
- map((file, enc, next) => {
- handlebars.registerPartial(file.stem, file.contents.toString())
- next()
- })
- )
- .on('error', reject)
- .on('finish', resolve)
- )
-}
-
-function registerHelpers (src) {
- return new Promise((resolve, reject) =>
- vfs
- .src('helpers/*.js', { base: src, cwd: src })
- .pipe(
- map((file, enc, next) => {
- handlebars.registerHelper(file.stem, requireFromString(file.contents.toString()))
- next()
- })
- )
- .on('error', reject)
- .on('finish', resolve)
- )
-}
-
-function compileLayouts (src) {
- const layouts = {}
- return new Promise((resolve, reject) =>
- vfs
- .src('layouts/*.hbs', { base: src, cwd: src })
- .pipe(
- map((file, enc, next) => {
- layouts[file.basename] = handlebars.compile(file.contents.toString(), { preventIndent: true })
- next()
- })
- )
- .on('error', reject)
- .on('finish', () => resolve(layouts))
- )
-}
+++ /dev/null
-'use strict'
-
-const chokidar = require('chokidar')
-const connect = require('gulp-connect')
-
-module.exports = (serveDir, opts = {}) => (done) => {
- const watch = opts.watch
- delete opts.watch
- opts = Object.assign({ root: serveDir }, opts)
- let onStart
- if (watch && watch.src && watch.onChange) {
- onStart = () =>
- chokidar
- .watch(watch.src, { ignoreInitial: true })
- .on('add', watch.onChange)
- .on('change', watch.onChange)
- .on('unlink', watch.onChange)
- }
- connect.server(opts, function () {
- this.server.on('close', done)
- if (onStart) onStart()
- })
-}