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

scaffold-generator2

v1.0.0

Published

Scaffolds project files and directories

Downloads

9

Readme

scaffold-generator

Scaffold-generator is a scaffolding utility used to automate project creation from the specified template and data.

Scaffold-generator could be the core utility to create something like grunt-init and yeoman generators.

rename.json of grunt-init is silly and scaffold-generator use template engine for both file content and file name.

You are free to safely copy several sources to their destinations with one single scaffold-generator instance!

Installation

npm install scaffold-generator2 --save

Usage

Suppose the file structure is:

/path/from
         |-- {{main}}
         |-- package.json

And /path/from/package.json:

{
  "name": "{{name}}",
  "main": "{{main}}"
}
const Scaffold = require("scaffold-generator2");
const handlebars = require("handlebars");

new Scaffold({
  data: {
    name: "my-module",
    main: "lib/index.js",
  },
  render: (str, data) => handlebars.compile(str)(data),
})
  .copy("/path/from", "/path/to")
  .then(() => {
    console.log("done");
  });

Then:

File names will be substituted.

/path/to
       |-- lib
       |     |-- index.js
       |-- package.json

File contents will also be substitute. And the file /path/to/package.json will be

{
  "name": "my-module",
  "main": "lib/index.js"
}

new Scaffold(options)

  • options Object
    • data Object the data which will be substituted into the template file.
    • ignore (String|Array.<String>|Ignore)= the ignore rule or a array of rules.
    • render function(str, data): String the renderer to compile the template and apply data.
    • override Boolean=true whether should override existing files
    • backup Boolean=true if backup:true, a .bak file will be saved when overriding an existing file.

Creates an instance of scaffold-generator

.copy(from, to)

.copy(filesMap)

  • from path see 'cases' section
  • to path see 'cases' section
  • filesMap Object the {from: to} object

This method will still substitute the content and the pathname of template files with options.data.

scaffold-generator will fs.stat the types of from and to, and then determine what things are to be copied. See Cases section for details.

Returns Promise

.write(to, template)

Writes file to with rendered template if options.override is true.

Cases

.copy(fromDir, toDir)

Will try to copy all files inside fromDir(not fromDir itself) to toDir, with the filenames and file contents substituted.

.copy(fromFile, toFile)

Will try to write to fromFile with the substituted content of toFile

.copy(fromFile, toDir)

Will try to copy file fromFile into directory toDir