Giter Club home page Giter Club logo

nodefy's Introduction

nodefy

convert AMD modules into a node.js compatible format.

How?

This tool uses Esprima to parse the code and replace define() calls, doing the less amount of changes as possible to the code.

Input

define(['foo', '../bar/baz'], function(foo, baz){

    var lorem = 'ipsum';

    return {
        log : function(){
            console.log(lorem);
        }
    };

});

Output

    var foo = require('foo');
    var baz = require('../bar/baz');

    var lorem = 'ipsum';

    module.exports = {
        log : function(){
            console.log(lorem);
        }
    };

CLI

You can use it as a CLI tool:

[sudo] npm install -g nodefy
nodefy -o cjs "src/**.js"

This will convert all ".js" files inside the src folder and put the results on the cjs folder.

It also works with stdin and stdout:

cat "src/foo.js" | nodefy

For a list of available options run:

nodefy -h

Standalone Lib

It is also available as a regular node.js library.

var nodefy = require('nodefy');

// nodefy.parse(string)
// returns node.js style module
var cjsModule = nodefy.parse(jsString);

// nodefy.convert(inputPath [, outputPath], callback)
// if outputPath is omitted it won't write the result
nodefy.convert('foo.js', function(err, result){
    console.log(result);
});

// nodefy.batchConvert(glob [, outputFolder], callback)
// if outputFolder is omitted it won't write the result
nodefy.batchConvert('src/**.js', 'cjs', function(err, results){
    // results is an array of {sourcePath, outputPath, result}
});

Inspiration / Why?

I couldn't find any tool that did what I wanted - convert AMD modules into plain node.js - so I decided to code my own. There are alternatives but they all add more complexity than I wanted.

This project was created mainly because of amd-utils, since many methods are useful on both environments.

The name was inpired by browserify.

Features, Goals & Limitations

The Asynchronous Module Definition is very flexible, it supports plugins, many configuration settings to define how modules should be loaded and asynchronous module loading.

This tool aims to convert basic modules, plugins and advanced settings probably are NOT going to be supported in the near future (I have plans to support basic configs, see issue 6). Check the uRequire project in case you need something more complex or create a new feature request on the issues tracker.

Alternatives

License

Released under the MIT license

nodefy's People

Contributors

millermedeiros avatar

Watchers

Harold Rodriguez avatar James Cloos 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.