npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-splice

v1.0.0

Published

Splice one file into another in a gulp stream

Downloads

11

Readme

gulp-splice

Splices one file into another in a gulp pipeline.

Install

> npm install gulp-splice

Usage

The inner file is spliced into the outer file by replacing the first occurancy of the key in the outer file with the contents of the inner file:

outer.txt

This is outer file content.
<#key#>
This is outer file content.
inner.txt

This is inner file content.
var splice = require('gulp-splice');

gulp.src(['inner.txt','outer.txt']).pipe(splice('<#key#>'))
outer.txt

This is outer file content.
This is inner file content.
This is outer file content.

In the above, both files entered through the pipe. But you can also specify inner or outer files that do not enter through the pipe:

gulp.src('outer.txt').pipe(splice({key:'<#key#>', inner:'inner.txt'}))

gulp.src('inner.txt').pipe(splice({key:'<#key#>', outer:'outer.txt'}))

gulp.src().pipe(splice({key:'<#key#>', inner:'inner.txt', outer:'outer.txt' }))

And all three produce the same result as the original:

outer.txt

This is outer file content.
This is inner file content.
This is outer file content.

You can also send more than two files in through the pipe:

gulp.src('*.txt').pipe(splice('<#key#>'))

In the absence of inner and outer options all non-outer files are concatinated to form a single inner file and spliced into the outer file, which is the first file that contains the key:

outer.txt

This is outer file content.
This is non-outer file 1 content.
This is non-outer file 2 content.
This is non-outer file 3 content.
...
This is outer file content.

Adding an inner option disables the concatination of non-outer files, and all other files not involved in the splice are passed through:

gulp.src('*.txt').pipe(splice({key: '<#key#>', inner:'file1.txt'))
outer.txt

This is outer file content.
This is file 1 content.
This is outer file content.
file2.txt

...
file3.txt

...
...

API

splice('key') 
splice(options)

options.key : string

The key is a string that identifies the insertion point in the outer file. Only the first occurance in the outer file is replaced with the contents of the inner file.

options.outer : string

If the outer option is present, the outer file is the file specified by the option. If the file arrives down the pipe it is plucked from the file stream, otherwise it is opened from the file system. If the outer option is absent, the outer file is the first file arriving down the pipe that contains the key.

options.inner : string

If the inner option is present, the inner file is the file specified by the option. If the file arrives down the pipe it is plucked from the file stream, otherwise it is opened from the file system. If the inner option is absent, all non-outer files ariving down the pipe are concatinated to form the inner file.

Example

Here's an example that inlines HTML view templates into the bottom of the index.html:

index.html

<html>
<body>
<h1>Main</h1>
##views##
</body>
</html>
partial-A.html

<h1>View A</h1>
partial-B.html

<h1>View B</h1>
partial-C.html

<h1>View C</h1>
gulp.src('*.html')
	.pipe(htmlmin())
	.pipe(splice('##views##'))
	.dest('dist/')
dist/index.html

<html><body><h1>Main</h1><h1>View A</h1><h1>View B</h1><h1>View C</h1></body></html>

Test

> npm test