0.2.1 • Published 10 years ago

amd2cmd v0.2.1

Weekly downloads
3
License
ISC
Repository
github
Last release
10 years ago

AMD2CMD

transform AMD or CommonJS inspired by require.js to CommonJS.

NPM version Build Status Coverage Status Dependency Status devDependency Status

Transform What

before(AMD):

define(['dep1', 'dep2'], function(dep1, dep2OtherName) {
  return dep1 + dep2OtherName;
});

transform after(CommonJS):

var dep1 = require('dep1');
var dep2OtherName = require('dep2');
module.exports = dep1 + dep2OtherName;
  • transform define(['dep1', 'dep2'], function() {}); to require('dep1');require('dep2');
  • transform define(function(){return statements;}) to module.exports = statements;
  • transform require('obj/xxx') to require('../obj/xxx')

So, Notice this tool can not transform all require.js features.

Usage

cli

First, install amd2cmd:

 npm install -g amd2cmd

Second, cd your project, and exec cmd:

 amd2cmd --in=src/scripts/**/*.js --out=build/scripts --basedir=src/scripts

use with node.js

First, install amd2cmd:

 npm install --save amd2cmd

Then, you can use amd2cmd like this:

import { amd2cmd } from 'amd2cmd';

amd2cmd(['src/scripts/**/*.js'], 'build/scripts', 'src/scripts')
.on('finish', function() {
  console.log('finish to transform amd code to cmd code');
});

or like this:

import { transformCode } from 'amd2cmd';

const cmdCode = transformCode(`define(['dep1', 'dep2'], function(dep1, dep2OtherName) {
  return dep1 + dep2OtherName;
});`, 'file path', 'base path');

console.log(cmdCode);
/* print:
var dep1 = require('dep1');
var dep2OtherName = require('dep2');
module.exports = dep1 + dep2OtherName;
*/

use with gulp

import { transform } from 'amd2cmd';

gulp.src('app/**/*.js')
.pipe(transform({
  basedir: 'app'
}))
.pipe(gulp.dest('build/scripts'));

scripts

Build the project shell:

 $ npm run build

Test the project shell:

 $ npm run test

Test the project with coverage result:

 $ npm run coverage

Generate JavaScript API doc:

 $ npm run doc
0.2.1

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago