Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ The default `root.layout.js` is featured below, and is implemented with [`uhtml`
import { html, render } from 'uhtml-isomorphic'

/**
* @template T extends object
* @template {Record<string, any>} T
* @typedef {import('top-bun').LayoutFunction<T>} LayoutFunction
*/

Expand Down Expand Up @@ -460,7 +460,7 @@ import defaultRootLayout from './root.layout.js'
import { html } from 'uhtml-isomorphic'

/**
* @template T extends object
* @template {Record<string, any>} T
* @typedef {import('top-bun').LayoutFunction<T>} LayoutFunction
*/

Expand Down
2 changes: 1 addition & 1 deletion examples/css-modules/src/layouts/root.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { html } from 'htm/preact'
import { render } from 'preact-render-to-string'

/**
* @template T extends object
* @template {Record<string, any>} T
* @typedef {import('../build-pages/resolve-layout.js').LayoutFunction<T>} LayoutFunction
*/

Expand Down
2 changes: 1 addition & 1 deletion examples/preact/src/layouts/root.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { html } from 'htm/preact'
import { render } from 'preact-render-to-string'

/**
* @template T extends object
* @template {Record<string, any>} T
* @typedef {import('../build-pages/resolve-layout.js').LayoutFunction<T>} LayoutFunction
*/

Expand Down
2 changes: 1 addition & 1 deletion examples/tailwind/src/layouts/root.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { html } from 'htm/preact'
import { render } from 'preact-render-to-string'

/**
* @template T extends object
* @template {Record<string, any>} T
* @typedef {import('../build-pages/resolve-layout.js').LayoutFunction<T>} LayoutFunction
*/

Expand Down
47 changes: 32 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,51 @@ import { TopBunAggregateError } from './lib/helpers/top-bun-aggregate-error.js'
*/

/**
* @template T extends Object.<string, any>
* @template {Record<string, any>} T
* @typedef {import('./lib/build-pages/resolve-layout.js').LayoutFunction<T>} LayoutFunction
*/

/**
* @template T extends Object.<string, any>
* @template {Record<string, any>} T
* @typedef {import('./lib/build-pages/resolve-vars.js').PostVarsFunction<T>} PostVarsFunction
*/

/**
* @template T extends Object.<string, any>
* @template {Record<string, any>} T
* @typedef {import('./lib/build-pages/page-builders/page-writer.js').PageFunction<T>} PageFunction
*/

/**
* @template T extends Object.<string, any>
* @template {Record<string, any>} T
* @typedef {import('./lib/build-pages/page-builders/template-builder.js').TemplateFunction<T>} TemplateFunction
*/

/**
* @template T extends Object.<string, any>
* @template {Record<string, any>} T
* @typedef {import('./lib/build-pages/page-builders/template-builder.js').TemplateAsyncIterator<T>} TemplateAsyncIterator
*/

/**
* @typedef {import('./lib/build-pages/page-builders/template-builder.js').TemplateOutputOverride} TemplateOutputOverride
*/

const DEFAULT_IGNORES = /** @type {const} */ ([
'.*',
'coverage',
'node_modules',
'package.json',
'package-lock.json',
'pnpm-lock.yaml',
'yarn.lock',
])

/**
* @template {TopBunOpts} [CurrentOpts=TopBunOpts]
*/
export class TopBun {
/** @type {string} */ #src = ''
/** @type {string} */ #dest = ''
/** @type {TopBunOpts} */ opts = {}
/** @type {Readonly<CurrentOpts & { ignore: string[] }>} */ opts
/** @type {FSWatcher?} */ #watcher = null
/** @type {any?} */ #cpxWatcher = null
/** @type {browserSync.BrowserSyncInstance?} */ #browserSyncServer = null
Expand All @@ -60,20 +73,24 @@ export class TopBun {
*
* @param {string} src - The src path of the page build
* @param {string} dest - The dest path of the page build
* @param {TopBunOpts} [opts] - The options for the site build
* @param {CurrentOpts} [opts] - The options for the site build
*/
constructor (src, dest, opts = {}) {
assert(src, 'src is a required argument')
assert(dest, 'dest is a required argument')

const defaultIgnore = ['.*', 'node_modules', basename(dest), 'package.json', 'pacakge-lock.json']

opts.ignore = defaultIgnore.concat(makeArray(opts.ignore))
constructor (src, dest, opts = /** @type {CurrentOpts} */ ({})) {
if (!src || typeof src !== 'string') throw new TypeError('src should be a (non-empty) string')
if (!dest || typeof dest !== 'string') throw new TypeError('dest should be a (non-empty) string')
if (!opts || typeof opts !== 'object') throw new TypeError('opts should be an object')

this.#src = src
this.#dest = dest

this.opts = opts
this.opts = {
...opts,
ignore: [
...DEFAULT_IGNORES,
basename(dest),
...makeArray(opts.ignore),
],
}
}

get watching () {
Expand Down
9 changes: 2 additions & 7 deletions lib/build-pages/page-builders/html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ import assert from 'node:assert'
import { readFile } from 'fs/promises'
import Handlebars from 'handlebars'

/**
* @template T
* @typedef {import('../page-writer.js').PageBuilderType<T>} PageBuilderType
*/

/**
* Build all of the bundles using esbuild.
* @template T
* @type {PageBuilderType<T>}
* @template {Record<string, any>} T
* @type {import('../page-writer.js').PageBuilderType<T>}
*/
export async function htmlBuilder ({ pageInfo }) {
assert(pageInfo.type === 'html', 'html builder requires a "html" page type')
Expand Down
9 changes: 2 additions & 7 deletions lib/build-pages/page-builders/js/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import assert from 'node:assert'

/**
* @template T
* @typedef {import('../page-writer.js').PageBuilderType<T>} PageBuilderType
*/

/**
* Build all of the bundles using esbuild.
* @template T
* @type {PageBuilderType<T>}
* @template {Record<string, any>} T
* @type {import('../page-writer.js').PageBuilderType<T>}
*/
export async function jsBuilder ({ pageInfo }) {
assert(pageInfo.type === 'js', 'js page builder requries "js" page type')
Expand Down
9 changes: 2 additions & 7 deletions lib/build-pages/page-builders/md/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ import { getMd, renderMd } from './get-md.js'

const md = getMd()

/**
* @template T
* @typedef {import('../page-writer.js').PageBuilderType<T>} PageBuilderType
*/

/**
* Build all of the bundles using esbuild.
* @template T
* @type {PageBuilderType<T>}
* @template {Record<string, any>} T
* @type {import('../page-writer.js').PageBuilderType<T>}
*/
export async function mdBuilder ({ pageInfo }) {
assert(pageInfo.type === 'md', 'md builder requires an "md" page type')
Expand Down
10 changes: 5 additions & 5 deletions lib/build-pages/page-builders/page-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { writeFile, mkdir } from 'fs/promises'
*/

/**
* @template T extends Object.<string, any>
* @template {Record<string, any>} T
* @typedef {import('../page-data.js').PageData<T>} PageData
*/

/**
* pageLayout functions Can be used to type a name.layout.js file
*
* @async
* @template T extends Object.<string, any>
* @template {Record<string, any>} T
* @callback PageFunction
* @param {object} params - The parameters for the pageLayout.
* @param {T} params.vars - All default, global, layout, page, and builder vars shallow merged.
Expand All @@ -26,14 +26,14 @@ import { writeFile, mkdir } from 'fs/promises'
*/

/**
* @template T extends Object.<string, any>
* @template {Record<string, any>} T
* @typedef PageBuilderResult
* @property {object} vars - Any variables resolved by the builder
* @property {PageFunction<T>} pageLayout - The function that returns the rendered page
*/

/**
* @template T extends Object.<string, any>
* @template {Record<string, any>} T
* @callback PageBuilderType
*
* @param {object} params
Expand All @@ -43,7 +43,7 @@ import { writeFile, mkdir } from 'fs/promises'

/**
* Handles rendering and writing a page to disk
* @template T extends object
* @template {Record<string, any>} T
* @param {object} params
* @param {string} params.src - The src folder.
* @param {string} params.dest - The dest folder.
Expand Down
8 changes: 4 additions & 4 deletions lib/build-pages/page-builders/template-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { writeFile, mkdir } from 'fs/promises'
*/

/**
* @template T extends object
* @template {Record<string, any>} T
* @typedef {import('../page-data.js').PageData<T>} PageData
*/

Expand All @@ -18,7 +18,7 @@ import { writeFile, mkdir } from 'fs/promises'
/**
* Callback for rendering a template.
*
* @template T extends Object.<string, any>,
* @template {Record<string, any>} T
* @callback TemplateFunction
* @param {object} params - The parameters for the template.
* @param {T} params.vars - All of the site globalVars.
Expand All @@ -29,7 +29,7 @@ import { writeFile, mkdir } from 'fs/promises'
*/

/**
* @template T
* @template {Record<string, any>} T
* @typedef {Parameters<TemplateFunction<T>>} TemplateFunctionParams
*/

Expand All @@ -51,7 +51,7 @@ import { writeFile, mkdir } from 'fs/promises'

/**
* The template builder renders templates agains the globalVars variables
* @template T extends Object.<string, any>
* @template {Record<string, any>} T
* @param {object} params
* @param {string} params.src - The src path of the site build.
* @param {string} params.dest - The dest path of the site build.
Expand Down
9 changes: 2 additions & 7 deletions lib/build-pages/page-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ import pretty from 'pretty'
* @typedef {import('./index.js').ResolvedLayout<T>} ResolvedLayout
*/

/**
* @template T
* @typedef {import('./resolve-vars.js').PostVarsFunction<T>} PostVarsFunction
*/

/**
* Represents the data for a page.
* @template T extends object
* @template {Record<string, any>} T
*/
export class PageData {
/** @type {PageInfo} */ pageInfo
Expand Down Expand Up @@ -84,7 +79,7 @@ export class PageData {
}

/**
* @type {PostVarsFunction<T>}
* @type {import('./resolve-vars.js').PostVarsFunction<T>}
*/
async #renderPostVars ({ vars, styles, scripts, pages, page }) {
if (!this.#initalized) throw new Error('Initialize PageData before accessing renderPostVars')
Expand Down
2 changes: 1 addition & 1 deletion lib/build-pages/resolve-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

/**
* @template T extends object
* @template {Record<string, any>} T
* @typedef {import('./page-data.js').PageData<T>} PageData
*/

Expand Down
15 changes: 3 additions & 12 deletions lib/build-pages/resolve-vars.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/**
* @typedef {import('../identify-pages.js').PageInfo} PageInfo
*/

/**
* @template T
* @typedef {import('./page-data.js').PageData<T>} PageData
*/

/**
* Resolve variables by importing them from a specified path.
*
Expand Down Expand Up @@ -44,14 +35,14 @@ export async function resolveVars ({
* postVars functions Can be used to generate page vars but access all page data
*
* @async
* @template T extends Object.<string, any>
* @template {Record<string, any>} T
* @callback PostVarsFunction
* @param {object} params - The parameters for the pageLayout.
* @param {T} params.vars - All default, global, layout, page, and builder vars shallow merged.
* @param {string[]} [params.scripts] - Array of script URLs to include.
* @param {string[]} [params.styles] - Array of stylesheet URLs to include.
* @param {PageInfo} params.page - Info about the current page
* @param {PageData<T>[]} params.pages - An array of info about every page
* @param {import('../identify-pages.js').PageInfo} params.page - Info about the current page
* @param {import('./page-data.js').PageData<T>[]} params.pages - An array of info about every page
* @returns {Promise<T>} The rendered postVars
*/

Expand Down
12 changes: 6 additions & 6 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ import { ensureDest } from './helpers/ensure-dest.js'

/**
* @typedef TopBunOpts
* @property {string[]?} [ignore] - Array of file/folder patterns to ignore.
* @property {boolean?} [static=true] - Enable/disable static file processing
* @property {boolean?} [metafile=true] - Enable/disable the writing of the esbuild metadata file.
* @property {string[]?} [ignore=[]] - Array of ignore strings
* @property {string[]?} [target=[]] - Array of target strings to pass to esbuild
* @property {boolean?} [buildDrafts=false] - Build draft files with the published:false variable
* @property {string[]|undefined} [ignore] - Array of file/folder patterns to ignore.
* @property {boolean|undefined} [static=true] - Enable/disable static file processing
* @property {boolean|undefined} [metafile=true] - Enable/disable the writing of the esbuild metadata file.
* @property {string[]|undefined} [ignore=[]] - Array of ignore strings
* @property {string[]|undefined} [target=[]] - Array of target strings to pass to esbuild
* @property {boolean|undefined} [buildDrafts=false] - Build draft files with the published:false variable
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/defaults/default.root.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { html, render } from 'uhtml-isomorphic'

/**
* @template T extends object
* @template {Record<string, any>} T
* @typedef {import('../build-pages/resolve-layout.js').LayoutFunction<T>} LayoutFunction
*/

Expand Down
7 changes: 1 addition & 6 deletions test-cases/general-features/src/blog/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { html } from 'uhtml-isomorphic'
import { dirname, basename } from 'node:path'

/**
* @template T
* @typedef {import('../../../../index.js').LayoutFunction<T>} LayoutFunction
*/

/**
* @type {LayoutFunction<{}>}
* @type {import('../../../../index.js').LayoutFunction<{}>}
*/
export default async function blogIndex ({
/** vars */
Expand Down
Loading