Code Monkey home page Code Monkey logo

cptmpl's Introduction

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!

cptmpl's People

Contributors

github-actions[bot] avatar wesleytodd avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

cptmpl's Issues

Multi-line diff formatting broken

? Conflict in configured.js, overwrite? Diff

   'use strict'

module.exports = function (opts) {
  return function (req, res) {
 -
       res.json({
      opts: opts
    })
 -
     }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.