Socket
Socket
Sign inDemoInstall

cptmpl

Package Overview
Dependencies
68
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cptmpl

Copy and process a template file


Version published
Weekly downloads
38
decreased by-17.39%
Maintainers
1
Install size
8.87 MB
Created
Weekly downloads
 

Changelog

Source

0.1.0 (2024-01-03)

Features

  • promptModule and displayDiff options to override ui (0e18011)

Bug Fixes

  • ci: updated ci and github stuff (c3ff9a5)
  • deps: updated deps as much as we can without breakage (9daff70)
  • devdeps: updated standard and mocha (8819abf)

Readme

Source

Copy and process a template file or files

[NPM Version NPM Downloads test js-standard-style

This small utility helps manage copying EJS template files. It has a programmatic and cli interface for simple usage whatever your context.

Usage

$ npm i --save cptmpl
$ cptmpl --help

    Usage:
			cptmpl --src="<Source Template>" --dest="<Destination File>" --data="<Data As JSON>" [options]
			cptmpl <Source Template> <Destination File> <Data As JSON> [options]

    Options:

      -s, --src                   the source template
      -d, --dest                  the destination file
      -D, --data                  a JSON string of data for the template
      -r, --recursive             copy a directory of templates recursivly
      -f, --force                 force overwite file
      --mode                      the file permissions mode
      -V, --version               output the version number
      --help                      display this help

    Template Format:

      See (EJS Documentation)[https://www.npmjs.com/package/ejs].

      <% if (user) { %>
        <h2><%= user.name %></h2>
      <% } %>
const cptmpl = require('cptmpl')

(async function () {
  await cptmpl('foo.md', 'bar.md', {
    name: 'world'
  }, {
    // Defaults shown
    force: false,
    mode: undefined,
    handleConflicts: <Default Handle Conflicts Function>
    processTemplateFilenames: (dest, data) => {
      // Process the filename however you need and
      // return the modified path
      return dest
    }
  })

  // Recursivly copy src directory to dest
  await cptmpl.recursive('src', 'dest', {
    name: 'world'
  })
})()

Example Diff

$ cptmpl --src foo.md --dest bar.md --data='{"name": "world"}'
$ cptmpl --src foo.md --dest bar.md --data='{"name": "wes"}'
? Conflict in bar.md, overwrite? (yndH) d
>> Diff

   # This is my Template

 - Hello world!
 + Hello wes!

? Conflict in bar.md, overwrite? Yes
$ cat bar.md
# This is my Template

Hello wes!

Keywords

FAQs

Last updated on 03 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc