@isdenmois/amd-to-es6
convert amd to es6
Last updated 2 years ago by isdenmois .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @isdenmois/amd-to-es6 
SYNC missed versions from official npm registry.

AMD to ES6 converter

Codeship

Installation

npm install @isdenmois/amd-to-es6

If you'd like to use it in the cli consider installing globally or use npx

npm install -g @isdenmois/amd-to-es6

Usage

cli

Convert a single file with:

amdtoes6 app.js > app-es6.js

Convert multiple files in given dir with:

amdtoes6 --src=src --dest=build

Convert multiple files in given dir recursively with:

amdtoes6 --src=src --dest=build --glob=**/*.js

Convert multiple files and replace them with:

amdtoes6 --src=src --replace

node

Convert a single file with:

const amdtoes6 = require('@isdenmois/amd-to-es6');
const source = 'define({ hello: 'world' });';
const result = amdtoes6(source); // export default { hello: 'world' };

Examples:

AMD

define([
    'core/view',
    'subapp/hello/template/layout'
], function (View, template) {
    'use strict';

    return View.extend({
        template: template
    });

});

ES6

import View from 'core/view';
import template from 'subapp/hello/template/layout';

export default View.extend({
    template: template
});

AMD

define(function (require) {
    'use strict';

    var Marionette = require('marionette');

    return Marionette.Object.extend({
        initialize: function () {
            console.log('hello world');
        }
    });
});

ES6

import Marionette from 'marionette';

export default Marionette.Object.extend({
    initialize: function () {
        console.log('hello world');
    }
});

There are more examples in the test/fixture directory

Options


  Usage: amdtoes6 [options]

  Options:

    -s, --src <dirname>     Directory of the source files
    -d, --dest <dirname>    Directory of the destination files
    -g, --glob [glob]       Glob pattern for the src to match for input files
    -r, --recursive         Set glob pattern to **/*.js with no hassle
    -b, --beautify          Beautify the output
    --replace           Replace the input files with results
    --suffix <string>   Replace suffix of the files
    --side              Import side effects with camel cased named
    --assigned          Automatically assign custom name to side effects
    --quotes            Single, double or auto quotes in the output
    --comments          Basic comments, copy them to the top of the output file

Inspired by:

https://github.com/jonbretman/amd-to-as6

Current Tags

  • 0.11.2                                ...           latest (2 years ago)

1 Versions

  • 0.11.2                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 2
Dependencies (6)
Dev Dependencies (10)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |