JSPM

  • Created
  • Published
  • Downloads 12
  • Score
    100M100P100Q46955F
  • License ISC

Package Exports

  • re-define

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (re-define) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

re-define

Let's re-define something ... without any configuration ... just do the magic.

re-define is able to resolve whole dependencies tree as well as single module.

from: CommonJS, Plain JS, AMD, AMD CJS to: * ... yep custom templates are allowed.

Build Status

Getting Started

Install the module: npm install -g re-define

###Usage

Usage: re-define [options]

Options:
  '-c, --config [name]'         , 'Re-define config'
  '-w, --wrapper [type]'        , 'Wrapper type report, iife, empty , umd'
  '-b, --base [dir]'            , 'Base folder for project'
  '-n, --name [module]'         , 'AMD module name'
  '-r, --return [module]'       , 'Export module'
  '--debug'                     , 'Debug mode, creating re-define.log file'
  '--include-files [file#as]'   , 'Include external files'
  '--exclude-folders [folders]' , 'Ignore folders - a,b,c,d'
  '--exclude-deps [deps]'       , 'Ignore deps - ".css"'
  '--externals [module#as]'     , 'Map externals to global - jquery#this.jquery'

Example usage

//0 configuration
re-define 
  • in case of mess
find . -type f -name '*js' | re-define --return main -externals 'jquery#this.jquery,deps_template#this.deps.template'

###Config

  { base    : '.'
  , name    : 'module_name'
  , wrapper : 'umd/amd-web'
  , debug   : false
  , return  : ''
  , separator      : '|'
  , excludeFolders : ['.git', 'node_modules', 'bower_components']
  , excludeFiles   : []
  , excludeDeps    : ['\.css$/']
  , includeTypes   : ['\.html$', '\.js$']
  , includeFiles   : [] //filepath#alias, alias = module.name
  , externals      : [] //external module#global_ref

                      ///////////////
                     // Equipment //
                    ///////////////

  , converter: [ common_js, amd_define, amd_require, amd_cjs ]
  , wrappers:  [ iife, amd-define, umd/amd-web, umd/4all ] 
}

Example wrapper:

(function (parent, factory){
  if (typeof define === 'function' && define.amd) {
    define('{{{name}}}', [{{{seq join append '\'|\'' external css}}}], factory)
  } else if (typeof exports === 'object') {
    module.exports = factory({{{seq join '#require(|)' append '\'|\'' append external}}})
  } else {
    {{#each external}}var {{seq ../escape this}} = {{{seq ../ref this}}}
    {{/each}}
    {{#if exports}}parent['{{{seq ref exports}}}'] = {{/if}}factory({{{seq escape external}}})
  }
}(this, function ({{{seq escape external}}}) {
  {{{code}}}

  return {{{exports}}}
}));

Release notes

0.0.16-beta (breaking changes)

  • switched to streams
  • more flexible integration with command line
find . -type f | re-define --return main | esformatter
//(builtin dir traversing)
re-define --return deps/four --include '../external/jquery.js#jquery'
  • traversing directories instead of checking what is inside module
  • when piping - input should be empty or file paths

0.0.16

  • more flexible file traversing (no more main file, shims or other odd things)
  • using streams instead of async
  • easier to follow code
  • switched to acorn
  • changed API

0.0.15

  • minor cli improvements re-define build.config

0.0.14

  • colors not included in package.json
  • --stream flag is no longer needed

0.0.13

  • resolver - include#path - pull in external js files
  • deps reports - re-define --report

0.0.12

  • converter - amd commonjs - define(function(req, mod, exp) {})

TODO

  • report with d3 charts
  • increase test coverage
  • removing debugger/console.log statements
  • grunt task
  • gulp support

Advanced usage

####Instance

var redefine = require('re-define')
  , myConfig = {}
  , config = redefine.config(myConfig)

  readStream (file paths or you can just write to redefine)
    .pipe(redefine.convert(config))
    .pipe(writeStream)

Custom converter (todo)

converter: {
  common_js   : require('./lib/converter/cjs')
, amd_cjs     : require('./lib/converter/amd-cjs')
, amd_define  : require('./lib/converter/amd-define')
, amd_require : require('./lib/converter/amd-require')
}

Custom wrapper (todo)

wrappers: {
  'iife'        : file('./lib/templates/iife.hbs')
, 'amd-define'  : file('./lib/templates/amd-define.hbs')
, 'umd/amd-web' : file('./lib/templates/amd-web.hbs')
, 'umd/all'     : file('./lib/templates/return-exports-global.hbs')
}

Custom handlebars helper (todo)

helpers: { 
  join   : function() { return _.toArray(arguments).join(',') }
, escape : function() { return _.map(arguments, function(d) { return config.escape(d) })}
}

Interceptors