Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sscaff

Package Overview
Dependencies
Maintainers
2
Versions
668
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sscaff

Stupid scaffoling: create a copy of a directory with variable substitution

  • 2.0.388
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
136K
increased by10.06%
Maintainers
2
Weekly downloads
 
Created
Source

sscaff

Stupid scaffolding: copies an entire directory with variable substitution and pre/post node.js hooks.

Installation

yarn add sscaff

or:

npm install sscaff

Usage

Create a template directory with files and subdirectories. For example:

my-first-template
  {{name}}.txt
    Hello, my name is {{name}}!

Now, use sscaff to create a copy and substitute:

import { sscaff } from 'sscaff';

await sscaff('my-first-template', 'outdir', {
  name: 'oliver'
});

This will create the following:

outdir
  oliver.txt
    Hello, my name is oliver!

Built-in Substitutions

  • {{ $base }} will be substituted by the base name of the output directory (e.g. outdir in the example above).
  • {{ }} will be substituted by the empty string. You can use this substitution to "salt" a file name so it won't be recognized by the parent project. For example, if you want your template to include a gitignore file, you should call it {{}}.gitignore so it won't be recognized as a "real" gitignore in the parent project.

Hooks

If the template directory has a file named .hooks.sscaff.js, and exports pre and/or post functions, those will be called before and after the creation of the output, respectively.

These functions are both executed with the output directory as the working directory and accept the variables dictionary. Both functions can either be synchronous or asynchronous.

The pre function may also modify the variables dictionary (i.e. add variables, modify them, etc).

For example, let's add the following .hooks.sscaff.js file to my-first-template above.

const fs = require('fs').promises;

exports.pre = variables => {
  variables.orig = variables.name;
  variables.name = variables.name[0].toUpperCase() + variables.name.slice(1);
};

exports.post = async (variables) => {
  await fs.writeFile(variables.orig + '.bak', 'hello hello');
};

The resulting output will look like this now:

outdir
  Oliver.txt
    Hello, my name is Oliver!
  oliver.bak
    hello hello

Contributions

All contributions are welcome, just raise an issue or submit a PR. Add a test, update readme. Do the right thing.

License

Apache 2.0

FAQs

Package last updated on 21 Aug 2023

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