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

temporify

v0.1.2

Published

Generate temporary files and directories

Downloads

8

Readme

Temporify - generate temporary directories & files

Temporify is a temporary directory & files generator which is used to build a temporary project in automation test.

Installation

Via npm:

$ npm install --save-dev temporify

Usage

Constructor

new Temporify(args)

args can be:

  • args.subdir - a relative path for a sub directory that contains generated files.
  • args.variables - a map of key/values that provides a default model for template compilations.
  • args.skipCompareDir - skip comparing directory trees between real temporary and descriptors, only compare files if this option is true (default: false).
  • args.throwIfError - throw an error if parameters of assign() are invalid (default: true).

Example:

var Temporify = require('temporify');

var temporify = new Temporify({
  subdir: 'example-project',
  variables: {
    version: '1.0.3'
  }
});

Methods

temporify.assign(args)

Method assign is used to declare a directory or a file that will be generated.

args can be a descriptor which is an object describing a directory/file or an array of descriptors. A descriptor composes of following fields:

  • dir - a path of the directory/file.
  • filename - a string that provides the name of file.
  • mode - a number that provides the mode of file.
  • template - an ejs template that is used to compile into a file contents.
  • variables - a collection of variable templates.

This method returns the temporify object itself.

temporify.generate()

Method generate() is used to generate directories/files which have been declared before. It has no arguments and returns the temporify object itself.

temporify.exec(command, opts)

Method exec() creates a new child_process and executes the provided command. The arguments can be:

  • command - a command string (for example: npm install).
  • opts.cwd - the current working directory (default is value of temporify.homedir).
  • opts.env - the environment variables in key/value format.
  • opts.shell - a path to the shell (default is /bin/sh).

This method returns the child_process result object in format (code, stdout, stderr).

temporify.stats()

Method stats() collects temporary directory information and compares with declared descriptors. It returns the a JSON array that contains statistics.

temporify.cleanup()

Method cleanup() deletes all contents (sub directories and files) of the main temporary directory. It takes no arguments and returns the temporify object itself.

temporify.destroy()

Method destroy() deletes the temporary directory completely. It has no arguments and returns nothing.

Examples

var Temporify = require('temporify');

var builder = new Temporify({
  subdir: 'example-project'
});

console.log('Root directory: %s', builder.basedir);
// Root directory: /tmp/tmp-29557R96Xic2Typ4t
console.log('Home directory: %s', builder.homedir);
// Root directory: /tmp/tmp-29557R96Xic2Typ4t/example-project

builder.assign({
  filename: 'server.js',
  template: `
    var devebot = require('devebot');
    module.exports = devebot.launchApplication({
      appRootPath: __dirname
    });
  `
});

builder.assign([{
  dir: 'lib/',
  filename: 'example.js',
  template: `
    function Example(params = {}) {
      var L = params.loggingFactory.getLogger();
      var T = params.loggingFactory.getTracer();
    }
    module.exports = Example;
  `
}, {
  dir: 'config/',
  filename: 'sandbox.js',
  template: `
    module.exports = {
      application: {
        host: "0.0.0.0"
      }
    };
  `
}]);

builder.assign({
  filename: 'README.md',
  template: `
  # example-project
  `
});

// generate temporary directory structure
builder.generate();

// ... do something with the [example-project] ...
// ... display directory structure, for example ...
console.log(JSON.stringify(builder.ls(), null, 2));
// [
//   "config",
//   "config/sandbox.js",
//   "lib",
//   "lib/example.js",
//   "README.md",
//   "server.js"
// ]

// clean-up
builder.destroy();

License

MIT