New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kopy

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kopy

Gracefully copy a directory and render templates.

  • 5.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3K
decreased by-12.81%
Maintainers
1
Weekly downloads
 
Created
Source

kopy

NPM version NPM downloads Build Status

Gracefully copy a directory and render templates.

Why is this useful?

This could be used to build a scaffolding tool like yeoman or vue-cli.

Install

$ npm install --save kopy

Usage

const copy = require('kopy')

copy('./template', './dest', {
  data: {
    foo: 'bar'
  }
}).then(({files}) => {
  console.log(files) // array of filenames in './dest'
}).catch(err => {
  console.log(err.stack)
})

Template Syntax

Templates could use lodash.template syntax or any template engine supported by jstransformer

API

copy(src, dest, options)

Returns a Promise which resolve {files, data, answers, merged}, merged is the result of answers of answers merged with data.

src

Type: string
Required: true

Source directory. Could be a relative or absolute path.

dest

Type: string
Required: true

Destination directory.

options
template

Type: object
Default: require('jstransformer-ejs')

You can use a custom template engine, like [handlebars]:

copy(src, dest, {
  template: require('jstransformer-handlebars')
})
templateOptions

Type: object

The template engine options.

clean

Type: boolean
Default: false

Whether to clean destination directory before writing to it.

cwd

Type: string
Default: process.cwd()

Current working directory.

data

Type: object
Default: undefined

The data to render templates in source directory.

prompts

Type: Array<InquirerPrompt>
Default: undefined

inquirer prompts, the answers of prompts will be assigned to data

skipInterpolation

Type: string | Array<string> | function
Default: undefined (we skip all binary files by default)

Patterns(minimatch) used to skip interpolation, eg: ./foo*/bar-*.js

It could also be a function, whose first arg is file path and second arg is file content, eg. we want to exclude all .js files:

copy(src, dest, {
  skipInterpolation(file, content) {
    return /\.js$/.test(file)
  }
})
disableInterpolation

Type: boolean
Default: false

Similar to skipInterpolation, but disableInterpolation disables all template interpolation, template markup will remain the way it is.

filters

Type: object
Default: undefined

An object containing file filter rules, the key of each entry is a minimatch pattern, and its value is a JavaScript expression evaluated in the context of (prompt answers) data:

copy(src, dest, {
  filters: {
    '**/*.js': 'useJavaScript',
    '**/*.ts': '!useJavaScript'
  }
})
skipExisting

Type: function boolean
Default: undefined

Whether to skip existing file, it could be function that takes the path to existing file as argument.

copy(src, dest, {
  skipExisting(file) {
    console.log(`${file} exists, skipped!`)
  }
})

kopy © EGOIST, Released under the MIT License.
Authored and maintained by EGOIST with help from contributors (list).

egoistian.com · GitHub @egoist · Twitter @rem_rin_rin

Keywords

FAQs

Package last updated on 01 Mar 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc