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

src-gen

v0.0.2

Published

Base library used to create code generation packages.

Downloads

14

Readme

Build Status NPM version

Introduction

src-gen is a library used to create code generation packages. src-gen is heavily influenced by gulp, and takes advantage of node-streams.

Generally speaking, globs are submitted to src-gen functions that target a set of files in a template directory. Those files are then processed, or copied, and output into a target directory.

In practice most files in a template are pass-through copies of files in the source directory, but some files are also templated via embedded JS as provided by Lodash templating. By default a file with a .ftl extensions is processed as template and the resulting output is placed in the target directory in a file of the same name without the .ftl extension. So a file source/package.json.ftl in the source directory is process and output into target/package.json.

However, a source generation template isn't limited to embeded JS and copies. The full power of Node and NPM modules are also available. The idea though is to leverage processing streams based on globs, and process each file.

Here is some good reading material on Gulp streams: gulpy, gulp-vision.

Overview

The idea behind this src-gen is to help easily create new templates for code generation tasks. I've used the lib to create procs, new-npms, static nginx sites, even pom.xml based maven java projects.

Additionally, there is a command line that executes src-gen templates. Link forth-coming.

Installation

%> npm install src-gen --save

Usage

src-gen is geared around globs and pipes, just like gulp. So, given a directory structure like this:

new-npm
├── gitignore
├── index.js.ftl
├── license
├── package.json
├── readme.md
├── src
│   └── FirstClass.coffee.ftl
├── tests
│   ├── lib
│   │   └── globals.coffee
│   └── src
│       └── FirstTest.coffee.ftl
└── travis.yml

Produced via: (M-1 M-! tree --noreport files/source/test1/new-npm)

Then we can merge a number of processing commands. The code below shows how this might be done in coffee. First the rungen function is created which takes an options object with the source, target, name, etc. With opts src-gen is initialized. It will use the source directory as cwd while creating streams for processing files, and then target as the dest() of the output streams. These are concepts from gulp in general, but really they are the interface to vinyl-fs.

  rungen = (opts, done) ->
    # Alias of project name as derived from directory.
	# May need to sanitize name to make it a proper symbol.
	opts.symbol = opts.name.replace('-', '')
    { copy, gen, to, toJson, packageFile, run, file } = require('src-gen')(opts)
    gen(
      copy('**/*.coffee', 'license', 'readme.md', 'travis.yml')
	  file('package.json', toJson(packageFile(opts)))
	  to('gitignore', '.gitignore')
	  to('src/FirstClass.coffee.ftl', "#{opts.name}.coffee")
	  to('tests/src/FirstTest.coffee.ftl', "#{opts.name}-tests.coffee")
	  to('index.js.ftl', 'index.js')
	)
	.on('end', (err) ->
	  if !err? and !opts.$isTesting
	    run(
		  'npm install coffee-script lodash nject moment --save'
		  'npm install mocha chai gulp --save-dev'
		  'git init'
		  "chmod +x #{opts.entryPoint}"
		  'npm test'
        )(done)
	  else
	    done()
	)

License

See license file.

The use and distribution terms for this software are covered by the Eclipse Public License 1.0, which can be found in the file 'license' at the root of this distribution. By using this software in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software.