Git Product home page Git Product logo

epr's Introduction

EPR travis status

epr lets you use nicer require paths in your node programs. It lets you change code like this:

var module1 = require('../../../modules/module1'),
    module2 = require('./another/path/module2')

to

var module1 = require('module1'),
    module2 = require('module2')

How do you install it?

npm install -g epr

How do you use it?

Add an epr key to your package.json:

{
  "epr": {
    "module1": "lib/modules/module1"
  }
}

and run epr:

epr

epr will create symlinks in node_modules/ for each attribute in your epr object. Normal node rules follow, so you can add a package.json file for each of your directories to point to a main, or you can just use it as a shortcut:

var module1 = require('module1'),
// or
    module2 = require('module1/module2')

to set this up for deployments, call epr in your postinstall script

Any advice?

There are several ways you can use epr, you can link to individual modules, or you can link to directories that contain several modules. In either case I'd recommend linking to directories rather than specific files in either case. That makes them easier to later split out to external packages if you want to.

So if you are linking to an individual module, at say lib/modules/mymodule, just add "mymodule":"lib/modules/mymodule". This is best if you've got some sort of code that could be an external module, but you want to keep it internal for whatever reason.

If you've got a directory that contains modules of a particular type, say a "modals" directory, you can link to that by adding "modals": "lib/modals", and can be required with something like require('modals/user')

Lastly you could just link to lib/ or wherever else you store most your code.

Does it do anything else?

Sure,

  • epr clean: delete all symlinks that are not in package.json
  • epr empty: delete all symlinks in node_modules

can I use it from javascript?

Sure,

var epr = require('epr')
epr.entangle(process.cwd(), {module1: 'lib/module1'}) // create symlinks
epr.clean(process.cwd(), {module1: 'lib/module1'}) // same as epr clean
epr.empty(process.cwd()) // same as epr empty

All epr api functions can either take a standard node callback or return a promise

epr.entangle(process.cwd(), {module1: 'lib/module1'}, function(err){
  if(err) {
    console.error(err)
  } else {
    console.log('success!')
  }
})

epr.entangle(process.cwd(), {module1: 'lib/module1'}.then(function(){
  console.log('success!')
}, function(err){
  console.error(err)
})

I'd like to make a change

See contributing

What's with the name?

EPR is a reference to the Einstein-Podolsky-Rosen thought experiment which was the origin of the concept of entanglement in quantum mechanics, and the term "spooky action at a distance".

OS support

epr will definitely run under any unix, but it has not been tested under windows. Any testing or PRs for windows support would be greatly appreciated. It has specifically been tested to run in heroku.

epr's People

Contributors

mpolun-mdsol avatar

Watchers

James Cloos avatar Max Polun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.