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

@existdb/gulp-replace-tmpl

v1.0.4

Published

Replace placeholders in files

Downloads

65

Readme

gulp-replace-tmpl

Replace placeholders in files similar to replacements found in ant projects.

This project was started to have only one place where the version information is stored for existdb projects built with @existdb/gulp-exist. Though it is recommended to have the version information stored, modified and read from the package.json file in your repository root, you can choose to read the version information from elsewhere, too.

Installation

npm i --save-dev @existdb/gulp-replace-tmpl

Usage

Replace placeholders in files and warn when a replacement is missing.

The placeholders must start and end with an @. If you want to replace @something@ in a file, your replacements must have a key something.

If one or more placeholders are not found in your replacements, a warning will be logged to the console, specifying in which file on which line the placeholder was found.

The Input and output files are up to you.

Options

The exported function has a second parameter that allows you to configure its behaviour.

  • prefix (String): default: "package" Defines a prefix each key must begin with. Only ASCII characters are allowed ([A-Za-z0-9]+).
  • unprefixed (Boolean): default: false If this is set to true, keys will not be prefixed. This setting overrides any value of prefix.
  • debug (Boolean): default: false Print debug output of the resulting map of replacements before replacments take place.

example

Start a new project with

mkdir boaty
cd boaty
npm init -y
npm i --save-dev gulp @existdb/gulp-replace-tmpl

Create file .existdb.json

{
    "servers": {
        "localhost": {
            "server": "http://localhost:8080/exist",
            "user": "admin",
            "password": "",
            "root": "/db/apps/boaty"
        }
    },
    "package": {
        "author": "I M Devloper",
        "target": "myapp",
        "description": "My App does X",
        "namespace": "http://my.app/",
        "website": "http://my.app/",
        "status": "beta",
        "title": "The Title of My App"
    }
}

A repo.xml.tmpl

<?xml version="1.0" encoding="UTF-8"?>
<meta xmlns="http://exist-db.org/xquery/repo">
  <description>@package.description@</description>
  <author>@package.author@</author>
  <website>@package.website@</website>
  <status>@package.status@</status>
  <target>@package.target@</target>
  <license>@package.license@</license>
  <copyright>true</copyright>
  <type>application</type>
</meta>

and a expath-pkg.xml.tmpl

<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://expath.org/ns/pkg" 
  name="@package.namespace@"
  abbrev="@package.target@" version="@package.version@" spec="1.0">
  <title>@package.title@</title>
  <!-- <dependency processor="http://exist-db.org" semver-min="4.7.0"/> -->
</package>

Finally, we need a gulpfile.js to define a task "templates" that we can call from the command line.

const { src, dest } = require('gulp')
const replace = require('@existdb/gulp-replace-tmpl')

// read only version and license metadata from package.json
const { version, license } = require('package.json')
// read additional metadata from .existdb.json
const packageMetadata = require('.existdb.json').package

// .tmpl replacements to include 
// an array of objects the first definition of a key wins
const replacements = [packageMetadata, {version, license}]

/**
 * replace placeholders in *.ext.tmpl and 
 * output replaced file contents to build/*.ext
 */
function templates() {
    return src('*.tmpl') // search for .tmpl files in project root
        .pipe(replace(replacements)) // replace placeholders
        .pipe(rename(path => { path.extname = "" })) // remove .tmpl extension
        .pipe(dest('build/'))
}

exports.templates = templates

With this setup you can now run

npx gulp templates

repo.xml and expath-pkg.xml should now be in the build directory with the placeholders replaced by the values provided.

Tests

TODO