# amd2cmd

> transform AMD(require.js) to CommonJS

Latest version **0.2.1** (published 2016-07-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install amd2cmd
pnpm add amd2cmd
yarn add amd2cmd
bun add amd2cmd
```

Provides the command `amd2cmd`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2016-07-28 |
| First published | 2016-07-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | sinolz |
| Maintainers | jackingliu |

## Links

- npm: https://www.npmjs.com/package/amd2cmd
- Repository: https://github.com/sinolz/amd2cmd
- Homepage: https://github.com/sinolz/amd2cmd#readme
- Issues: https://github.com/sinolz/amd2cmd/issues
- npm.io page: https://npm.io/package/amd2cmd

## Dependencies (5)

- [acorn](https://npm.io/package/acorn.md) ^3.2.0
- [lodash](https://npm.io/package/lodash.md) ^4.13.1
- [vinyl-fs](https://npm.io/package/vinyl-fs.md) ^2.4.3
- [commander](https://npm.io/package/commander.md) ^2.9.0
- [map-stream](https://npm.io/package/map-stream.md) ^0.0.6

## Recent versions

- 0.2.1 (latest) — 2016-07-28
- 0.2.0 — 2016-07-19
- 0.1.1 — 2016-07-18
- 0.1.0 — 2016-07-16
- 0.0.11 — 2016-07-16
- 0.0.10 — 2016-07-16
- 0.0.8 — 2016-07-16
- 0.0.7 — 2016-07-15
- 0.0.6 — 2016-07-15
- 0.0.5 — 2016-07-15
- 0.0.4 — 2016-07-15
- 0.0.3 — 2016-07-15
- 0.0.2 — 2016-07-15

## README

# AMD2CMD

transform [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) or CommonJS inspired by [require.js](http://requirejs.org/) to [CommonJS](http://www.commonjs.org/).

[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![Dependency Status][depstat-image]][depstat-url]
[![devDependency Status][devdepstat-image]][devdepstat-url]

## Transform What

before(AMD):

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

transform after(CommonJS):

```js
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:

```bash
 npm install -g amd2cmd
```

Second, cd your project, and exec cmd:

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

### use with node.js

First, install amd2cmd:

```bash
 npm install --save amd2cmd
```

Then, you can use amd2cmd like this:

```js
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:

```js
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

```js
import { transform } from 'amd2cmd';

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

## scripts

Build the project shell:

```bash
 $ npm run build
```

Test the project shell:

```bash
 $ npm run test
```

Test the project with coverage result:

```bash
 $ npm run coverage
```

Generate JavaScript API doc:

```bash
 $ npm run doc
```

[npm-image]: https://badge.fury.io/js/amd2cmd.svg
[npm-url]: https://npmjs.org/package/amd2cmd
[travis-image]: https://travis-ci.org/sinolz/amd2cmd.svg?branch=master
[travis-url]: https://travis-ci.org/sinolz/amd2cmd
[coveralls-image]: https://coveralls.io/repos/github/sinolz/amd2cmd/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/sinolz/amd2cmd?branch=master

[depstat-url]: https://david-dm.org/sinolz/amd2cmd
[depstat-image]: https://img.shields.io/david/sinolz/amd2cmd/master.svg?style=flat-square
[devdepstat-image]: https://david-dm.org/sinolz/amd2cmd/dev-status.svg
[devdepstat-url]: https://david-dm.org/sinolz/amd2cmd#info=devDependencies

---
_Source: https://npm.io/package/amd2cmd · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
