npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sscaff

v2.0.388

Published

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

Downloads

578,991

Readme

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