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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pinc

v0.2.0

Published

pretty include engine

Readme

pinc

pinc (pretty include) は設定ファイル( pinc.yaml )にもとづいてファイルインクルードを実現するインクルードエンジンです。

インストール

npm install pinc

(※ pinc コマンドを利用する為には npm install -g でインストールするか node_modules/.bin/ にPATHを通す必要があります)

用途

例えば、以下のディレクトリ構成の場合を考えます。

./
    pinc.yaml
    template/
        default.html
    partial/
        header.html
        footer.html
        main.html

それぞれのファイル内容は以下のとおりです。

pinc.yaml:

P001:
  url: index.html
  template: default.html
  partial:
    header: header.html
    footer: footer.html
    main: main.html

template/default.html:

<!doctype html>
<html lang="ja">
<head>
{{ header }}
</head>
<body>
<div clas="main">
{{ main }}
</div>
{{ footer }}
</body>
</html>

template ファイルに 埋め込み指示コード {{ IDENTIFIER }} を記載します。 この時の IDENTIFIER は partial の属性名に対応します。

partial/header.html:

  <meta charset="utf-8">

partial/footer.html:

<div>
</div>

partial/main.html:

hello world.

この状態で pinc コマンドを実行すると、カレントディレクトリにある pinc.yaml に基づいてインクルードが実行されます。つまり、partial.headerであるheader.htmlの中身を {{ header }} に展開します。

$ pinc
P001 -> index.html

インクルードされた結果は dest ディレクトリに出力されます。
その際のファイル名およびパスは url で指定したものになります。

./
    pinc.yaml
    dest/
        index.html
    template/
        default.html
    partial/
        header.html
        footer.html
        main.html

出力された dest/index.html の中身は以下のとおりです。
partialの各ファイルの内容が展開されています。

<!doctype html>
<html lang="ja">
<head>
  <meta charset="utf-8">
</head>
<body>
<div clas="main">
hello world.
</div>
<div>
</div>
</body>
</html>

pinc はこれを実現するためだけのアプリケーションです。

pinc.yamlについて

設定ファイル pinc.yaml には以下のような記述をします。

(id):
  url: path
  template: path
  partial:
    (key): path

※ (id), (key) はそれぞれ任意の文字列

  • yamlハッシュのキーとして数値のみを指定することは推奨しません。その場合、意図しない動作をする可能性があります。
  • pinc.yaml に記載する id は処理には利用されませんが、yamlハッシュである性質上、ユニークでなければなりません。
  • pinc.yaml には yamlに準拠したコメント(#)を含めることができます。
  • template に指定した値 path が指すファイルが存在しない場合、エラー(Error)が発生し該当のファイルは作成されません。
  • partial に指定した値 path が指すファイルが存在しない場合、警告(Warn)が発生し空ファイルとみなして処理します。
  • partial に指定した値 path が@から始まる文字列の場合、それはファイルパスではなく文字列として扱われ、その文字列がそのままインクルード対象なります。(0.1.0 > )
  • template および partial に指定するファイルパスにはディレクトリを含めることができます。
  • url に指定するファイルパスにはディレクトリを含めることができます。生成時にそのディレクトリも自動的に作成します。

その他仕様

  • template ファイルに記載する埋め込み指示コード {{ IDENTIFIER }} は空白も含めて厳密でなければなりません。正規表現では {{ \w+ }} となります。
  • pinc が動作する上で template ディレクトリ、 partial ディレクトリ、および pinc.yaml は必須です。
    これらのディレクトリやファイルの名称を変更したい場合は pinc --help を参照ください
$ pinc --help

Usage: pinc [options] [target_yaml_file]

	--help, -h
		Displays help information about this script
		'pinc -h' or 'pinc --help'

	--version
		Displays version info
		pinc --version

	--dest, -d
		destination directory
		pinc -d dest

	--template, -t
		template directory
		pinc -t template'

	--partial, -p
		partial directory
		pinc -p partial