partpipe - embedding version/date/any data to template text/source.

A command line tool,like C-preprocessor/sed/awk/perl.for embedding version/date/any data to template text/source.

Like #ifdef, you can enable/disable parts of template text/source by command line.

Additionally, applying unix filter to parts of input stream. you can write markdown / pug inside your source code.

Examples

Embedding verion

$ cat example.js 
console.log("version is @PARTPIPE@VERSION@PARTPIPE@");

$ partpipe VERSION=1.2.0 -O destDir/ -- example.js
$ cat destDir/example.js
console.log('version is 1.2.0');

Embedding current date

$ cat LICENSE
Copyright 2017-@PARTPIPE@!date +Y@PARTPIPE@ Your Name

$ partpipe -O destDir/ -- LICENSE
$ cat destDir/LICENSE
Copyright 2017-2019 Your Name

ifdef / endif like

$ cat expample.js
@PARTPIPE@RELEASE
console.log('relase build')
@PARTPIPE@
@PARTPIPE@DEBUG
console.log('debug build')
@PARTPIPE@

$ partpipe RELEASE= DEBUG  -O destDir/ -- example.js
$ cat expmple.js
console.log('debug build)'

Applying unix filter to parts of a template

$ cat example.js
var html=`
@PARTPIPE@|md2html
# Hello World
This is a greeting application.
@PARTPIPE@
`;

$ partpipe -O destDir/ -- example.js
$ cat destDir/example.js
var html=`
<H1>Hello World</H1>
<p>This is a greeting application.</p>
`;

Install

sudo npm install -g partpipe

Usage

partpipe [<options>] [<TAG>[=<replacetext>]]... -O <outputdir> [-- files1 files2 ...]
version -
Copyright(c) 2017-2019,@kssfilo(https://kanasys.com/gtech/)
A command line tool,like C-preprocessor/sed/awk/perl.for embedding version/date/any data to template text/source.

Like #ifdef, you can enable/disable parts of template text/source by command line.

Additionally, applying unix filter to parts of input stream. you can write markdown / pug inside your source code.

Options

- h            show this usage
- d            debug mode
- o <filename> destination file name(default:stdout). use -O in multi-file mode
- O <dirname>  destination dir.file name will be same as input filename or partipe.out. 
- i <filename> input file name(default:stdin). 
- c            clear contents of unknown tag(default:passthrough)
- s            show contents of unknown tag(default:passthrough)
- w            error on unknown tag(default:paththrough)
- f <string>   use <string> as block separator(default:@PARTPIPE@)
- I            don't process indents
- C            old mode(ver 0.x.x compatible)

you can specify multi-file like this '-i file1 -i file2 ..' or '-- file1 file2 *.txt ..'

Tags

<TAG>=<replacetext>  replaces @PARTPIPE@<TAG>@PARTPIPE@ with <replacetext>. e.g. 'VERSION=1.2.0' replaces '@PARTPIPE@VERSION@PARTPIPE@'

<TAG>  shows   <block> of @PARTPIPE@<TAG>;<block>@PARTPIPE@ e.g. 'DEBUG' replaces '@PARTPIPE@DEBUG;console.log("debug mode")@PARTPIPE@' to 'console.log("debug mode")'
<TAG>= removes <block> of @PARTPIPE@<TAG>;<block>@PARTPIPE@ e.g. 'DEBUG=' replaces '@PARTPIPE@DEBUG;console.log("debug mode")@PARTPIPE@' to ''

<TAG>@<command> apply <command> to <block> of @PARTPIPE@TAG;<block>@PARTPIPE@ e.g. "MD@md2html" applys '@PARTPIPE@MD;# title@PARTPIPE@' to '<h1>titile</h1>'
# you can omit <block>. like '@PARTPIPE@DATE@PARTPIPE' in template text and 'DATE@date +%m%d%Y'. in command like. result will be '17/07/2019'

Examples

Replace by tag

$ cat example.js
console.log("version is @PARTPIPE@VERSION@PARTPIPE@");

$ partpipe VERSION=1.2.0 -O destDir/ -- example.js
$ cat destDir/example.js
console.log('version is 1.2.0');

Show/Remove by tag like #ifdef

$ cat example.js
@PARTPIPE@RELEASE;console.log('release build');@PARTPIPE@
@PARTPIPE@DEBUG;console.log('debug build');@PARTPIPE@

$ partpipe RELEASE DEBUG=  -O destDir/ -- example.js
$ cat destDir/example.js
console.log('release build');

$ partpipe RELEASE= DEBUG  -O destDir/ -- example.js
$ cat destDir/example.js
console.log('debug build');

multi-line

$ cat expample.js
@PARTPIPE@RELEASE
console.log('release build')
@PARTPIPE@
@PARTPIPE@DEBUG
console.log('debug build')
@PARTPIPE@

$ partpipe RELEASE= DEBUG  -O destDir/ -- example.js
console.log('debug build');

Embedding date or any command result

$ cat LICENSE
Copyright 2017-@PARTPIPE@!date +Y@PARTPIPE@ Your Name

$ partpipe -O destDir/ -- LICENSE
$ cat destDir/LICENSE
Copyright 2017-2019 Your Name

if tag is start by '!', partpipe treats it as command line. you can embed date or web data(by curl/norl) or everything

Applying unix filter to parts of template

$ cat example.js
var html=`
@PARTPIPE@|md2html
# Hello World
This is a greeting application.
@PARTPIPE@
`;

$ partpipe -O destDir/ -- example.js
$ cat destDir/example.js
var html=`
<H1>Hello World</H1>
<p>This is a greeting application.</p>
`;

if tag is start by '|', partpipe also treats it as command line. then inject the block to this stdin.

you can write markdown or pug in your program code. off course, any unix filter can be used such as sort / uniq.

Specify unix filter or any command in command line

$ cat example.js
var html=`
@PARTPIPE@MARKDOWN
# Hello World
This is a greeting application.
@PARTPIPE@
`;

$ partpipe 'MARKDOWN@md2html' -O destDir -- example.js
$ cat example.js
var html=`
<H1>Hello World</H1>
<p>This is a greeting application.</p>
`;

you can specify filter by command line. embed like normal tag. then add '@' in partpipe command line.

Use as module

var partpipe=require("partpipe");

var input=`Colors:
@PARTPIPE@|sort|uniq
Red
Blue
Green
Blue
Red
@PARTPIPE@`;

partpipe(input).then((result)=>console.log(result));

Change Log

Popular Articles from This Page

Top Page

Economizing Technology > partpipe - embedding version/date/any data to template text/source.