Skip to content
Open
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
10 changes: 10 additions & 0 deletions .c8rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"reporter": ["lcov", "text"],
"all": true,
"include": ["index.js"],
"check-coverage": true,
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100
}
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> ✏️ Briefly describe the issue you are experiencing (or the feature you want to see added to the plugin). Tell us what you were trying to do and what happened instead. Remember, this is _not_ a place to ask questions. For that, go to http://gitter.im/posthtml/posthtml
> ✏️ Briefly describe the issue you are experiencing (or the feature you want to see added to the plugin). Tell us what you were trying to do and what happened instead. Remember, this is _not_ a place to ask questions. For that, use https://github.com/posthtml/posthtml/discussions

### `Details`

Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test
on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:

jobs:
test:
name: Node ${{ matrix.node }}, posthtml ${{ matrix.posthtml }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: [20.19.0, 22.12.0, 22, 24, 26]
posthtml: ['0.16']
include:
- node: 24
posthtml: '0.16.0'
steps:
- name: Clone repository
uses: actions/[email protected]

- name: Set Node.js version
uses: actions/[email protected]
with:
node-version: ${{ matrix.node }}
cache: npm

- name: Install npm dependencies
run: npm ci

- name: Install posthtml ${{ matrix.posthtml }}
run: npm install --no-save posthtml@${{ matrix.posthtml }}

- name: Run checks
run: npm run check
14 changes: 1 addition & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
# OS

.DS_Store
._*

# NODEJS

npm-debug.log

dmd
jest
coverage
jsdoc-api
node_modules
.nyc_output
coverage
21 changes: 0 additions & 21 deletions .npmignore

This file was deleted.

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# Change Log

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
All notable changes to this project will be documented in this file.

## Unreleased (4.0.0)

### Breaking Changes

* `posthtml` is now a peer dependency (`^0.16.0 || ^0.17.0`): install it next to `gulp-posthtml`. The previous release bundled `posthtml@^0.11`.
* Require Node.js `^20.19.0 || >=22.12.0`.
* `posthtml-load-config` 2: `posthtml.config.js` support follows its current format.

### Bug Fixes

* Emit errors from config loading and from the config function as `PluginError` instead of leaving the stream hanging ([#18](https://github.com/posthtml/gulp-posthtml/issues/18)).

### Development

* Replace `through2` with Node.js `stream.Transform`; update `plugin-error` to 2.
* Replace ava, nyc and standard with `node:test`, c8 and ESLint; drop the `posthtml-sugarml` test fixtures.
* Replace Travis CI with GitHub Actions.

<a name="3.0.4"></a>
## [3.0.4](https://github.com/posthtml/gulp-posthtml/compare/v3.0.3...v3.0.4) (2018-01-22)
Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Pull requests are the greatest contributions, so be sure they are focused in sco
1. To begin, [fork this project], clone your fork, and add our upstream.
```bash
# Clone your fork of the repo into the current directory
git clone https://github.com/<your-username>/PLUGIN_NAME
git clone https://github.com/<your-username>/gulp-posthtml
# Navigate to the newly cloned directory
cd PLUGIN_NAME
cd gulp-posthtml
# Assign the original repo to a remote called "upstream"
git remote add upstream https://github.com/GITHUB_NAME/PLUGIN_NAME
git remote add upstream https://github.com/posthtml/gulp-posthtml
# Install the tools necessary for development
npm install
```
Expand All @@ -37,8 +37,8 @@ Pull requests are the greatest contributions, so be sure they are focused in sco

3. Be sure your code follows our practices.
```bash
# Test current code
npm run test
# Lint and test
npm run check
```

4. Push your branch up to your fork:
Expand Down
17 changes: 0 additions & 17 deletions PLUGIN.md

This file was deleted.

153 changes: 55 additions & 98 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,141 +1,110 @@
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]
[![coverage][cover]][cover-url]
[![code style][style]][style-url]
[![chat][chat]][chat-url]

<div align="center">
<img width="100" height="200" src="https://worldvectorlogo.com/logos/gulp.svg">
<a href="https://github.com/posthtml/posthtml">
<img width="220" height="200" title="PosHTML" src="http://posthtml.github.io/posthtml/logo.svg">
<img width="220" height="200" title="PostHTML" src="http://posthtml.github.io/posthtml/logo.svg">
</a>
<h1>Gulp PostHTML</h1>
</div>

<h2 align="center">Install</h2>

```bash
npm i -D gulp-posthtml
npm i -D gulp-posthtml posthtml
```

<h2 align="center">Usage</h2>

```js
import { task, src, dest } from 'gulp'
`posthtml` is a peer dependency: install the version you want to use (`^0.16.0 || ^0.17.0`). Requires Node.js `^20.19.0 || >=22.12.0`.

import posthtml from 'gulp-posthtml'

task('html', () => {
return src('src/*.html')
.pipe(posthtml())
.pipe(dest('dest'))
})
```

<h2 align="center">Options</h2>

### `Plugins`

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|`plugins`|`{Array}`|`[]`|PostHTML Plugins|
<h2 align="center">Usage</h2>

### `Options`
`gulp-posthtml` accepts plugins and options in three forms.

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|`options`|`{Object}`|`{}`|PostHTML Options|
### Plugins and options

**gulpfile.js**
```js
import { task, src, dest } from 'gulp'

import tap from 'gulp-tap'
import rename from 'gulp-rename'
import gulp from 'gulp'
import posthtml from 'gulp-posthtml'
import include from 'posthtml-include'

task('html', () => {
let path
const { src, dest } = gulp

const plugins = [ require('posthtml-include')({ root: path }) ]
const options = { parser: require('posthtml-sugarml')() }
export function html () {
const plugins = [include({ root: 'src/components' })]
const options = { closingSingleTag: 'slash' }

return src('src/*.html')
.pipe(tap((file) => path = file.path))
.pipe(posthtml(plugins, options))
.pipe(rename({ ext: '.html' }))
.pipe(dest('dest'))
})
}
```

### `Config`
`options` are [PostHTML options](https://github.com/posthtml/posthtml/blob/master/docs/core.md), including parser and render options. `from` and `to` default to the file path.

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|`plugins`|`{Array}`|`[]`|PostHTML Plugins|
|`options`|`{Object}`|`{}`|PostHTML Options|
### A function of the file

**gulpfile.js**
```js
import { task, src, dest } from 'gulp'
Return `{ plugins, options }` (or a Promise of it) for each [Vinyl](https://github.com/gulpjs/vinyl) file:

import rename from 'gulp-rename'
import posthtml from 'gulp-posthtml'


task('ssml', () => {
const config = (file) => ({
plugins: [ require('posthtml-include')({ root: file.dirname }) ],
options: { parser: require('posthtml-sugarml')() }
})

return src('src/*.sml')
.pipe(posthtml(config))
.pipe(rename({ ext: '.html' }))
```js
export function html () {
return src('src/**/*.html')
.pipe(posthtml((file) => ({
plugins: [include({ root: file.dirname })],
options: {}
})))
.pipe(dest('dest'))
})
}
```

### [`posthtml.config.js`](https://github.com/posthtml/posthtml-load-config)

#### `Context`

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|`env`|`{String}`|`'development'`|process.env.NODE_ENV|
|`file`|`{Object}`|`dirname, basename, extname`|File|
|`options`|`{Object}`|`{}`|Options (Parser, Render, Plugin Options)|
Pass an object (or nothing) to load `posthtml.config.js`, searched from the file's directory upwards, or from the `config` directory if set. The object is available in the config as `ctx.options`:

**posthtml.config.js**

```js
module.exports = ({ file, options, env }) => ({
parser: 'posthtml-sugarml'
plugins: {
'posthtml-include': { root: file.dirname },
'posthtm-expressions': { locals: options.locals }
'htmlnano': env === 'production' ? {} : false
'posthtml-expressions': { locals: options.locals },
htmlnano: env === 'production' ? {} : false
}
})
```

**gulpfile.js**

```js
import { task, src, dest } from 'gulp'
export function html () {
return src('src/*.html')
.pipe(posthtml({ locals: { title: 'Hello World!' } }))
.pipe(dest('dest'))
}
```

import rename from 'gulp-rename'
import posthtml from 'gulp-posthtml'
|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|`config`|`{String}`|file directory|Directory to search for `posthtml.config.js`|
|`...`|`{*}`||Any values, available as `ctx.options`|

### Errors

task('ssml', () => {
const ctx = { locals: { a: 'Hello World!'} }
Errors from plugins and config loading are emitted on the stream as [`PluginError`](https://github.com/gulpjs/plugin-error). Streaming files are not supported.

return src('src/*.sml')
.pipe(posthtml(ctx))
.pipe(rename({ ext: '.html' }))
.pipe(dest('dest'))
})
`.pipe()` does not forward errors, so with `.pipe()` a failing file leaves the task unfinished. Use `pipeline` to fail the task with the error:

```js
import { pipeline } from 'node:stream/promises'

export function html () {
return pipeline(
src('src/*.html'),
posthtml([include({ root: 'src/components' })]),
dest('dest')
)
}
```

<h2 align="center">Maintainer</h2>
Expand Down Expand Up @@ -174,17 +143,5 @@ task('ssml', () => {
[node]: https://img.shields.io/node/v/gulp-posthtml.svg
[node-url]: https://nodejs.org/

[deps]: https://david-dm.org/posthtml/gulp-posthtml.svg
[deps-url]: https://david-dm.org/posthtml/gulp-posthtml

[tests]: http://img.shields.io/travis/posthtml/gulp-posthtml.svg
[tests-url]: https://travis-ci.org/posthtml/gulp-posthtml

[cover]: https://coveralls.io/repos/github/posthtml/gulp-posthtml/badge.svg
[cover-url]: https://coveralls.io/github/posthtml/gulp-posthtml

[style]: https://img.shields.io/badge/code%20style-standard-yellow.svg
[style-url]: http://standardjs.com/

[chat]: https://badges.gitter.im/posthtml/posthtml.svg
[chat-url]: https://gitter.im/posthtml/posthtml
[tests]: https://github.com/posthtml/gulp-posthtml/actions/workflows/test.yml/badge.svg
[tests-url]: https://github.com/posthtml/gulp-posthtml/actions/workflows/test.yml
Loading