https://github.com/pvdlg/ncat
Concatenate multiple files, with their sourcemaps and optionally stdin, a banner and a footer
https://github.com/pvdlg/ncat
banner cat cli concat concatenate concatenation file files footer header sourcemap
Last synced: about 1 year ago
JSON representation
Concatenate multiple files, with their sourcemaps and optionally stdin, a banner and a footer
- Host: GitHub
- URL: https://github.com/pvdlg/ncat
- Owner: pvdlg
- License: mit
- Created: 2017-06-10T18:50:56.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-03-27T05:17:37.000Z (about 6 years ago)
- Last Synced: 2025-04-09T17:01:39.436Z (about 1 year ago)
- Topics: banner, cat, cli, concat, concatenate, concatenation, file, files, footer, header, sourcemap
- Language: JavaScript
- Homepage:
- Size: 203 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# **ncat**
Node CLI to concatenate multiple files, with their sourcemaps and optionally stdin, a banner and a footer.
[](https://travis-ci.org/pvdlg/ncat)
[](https://ci.appveyor.com/project/pvdlg/ncat)
[](https://codecov.io/gh/pvdlg/ncat)
[](https://greenkeeper.io/)
[](https://github.com/pvdlg/ncat/blob/master/LICENSE)
## Installation
```bash
$ npm i -g|-D ncat
```
## Usage
```bash
$ ncat [] [OPTIONS] [-o|--output ]
```
The arguments may be a list of files:
```bash
$ ncat file_1.js file_2.js -o dist/bundle.js
```
or a list of globs:
```bash
$ ncat 'src/**/*.js !**/rainbow.js' src/**/{cake,unicorn}.css -o dist/bundle.js
```
If file is a single dash (`-`) ncat reads from the standard input:
```bash
$ echo 'Insert between file_1.js and file_2.js' | ncat file_1.js - file_2.js -o dist/bundle.js
```
If `-o|--output` is omitted ncat writes to the standard input:
```bash
$ ncat file_1.js file_2.js | uglifyjs > dist/bundle.min.js
```
## Options
| Name | Type | Default | Description |
|:------------------|:-----------------:|:-----------:|:--------------------------------------------------------------------------------------------------------------------------------------------------|
| `-o, --output` | `{String}` | `undefined` | Output File |
| `-m, --map` | `{Boolean}` | `false` | Create an external sourcemap (including the sourcemaps of existing files) |
| `-e, --map-embed` | `{Boolean}` | `false` | Embed the code in the sourcemap (only apply to code without an existing sourcemap) |
|`-b, --banner` |`{Boolean\|String}`| `false` | Add a banner built with the package.json file. Optionally pass the path to a .js file containing custom banner that can be called with `require()`|
| `-f, --footer` | `{String}` | `undefined` | The path to .js file containing custom footer that can be called with `require()` |
| `-h, --help` | `{Boolean}` | `false` | CLI Help |
| `-v, --version` | `{Boolean}` | `false` | CLI Version |
## Examples
### Concatenate files and standard input
#### Files
```javascript
---------- file_1.min.js ----------
< First part of JS code (minified) ... >
---------- file_2.js ----------
```
#### Command
```bash
$ uglifyjs file_2.js | ncat file_1.min.js - --output dist/bundle.js
```
#### Result
```javascript
---------- dist/bundle.js ----------
< First part of JS code (minified) ... >
< Second part of JS code (minified) ... >
```
### Concatenate with sourcemaps
#### Files
```javascript
---------- file_1.js ----------
< First part of JS code ... >
/*# sourceMappingURL=file_1.js.map */
---------- file_1.js.map ----------
{"version": 3,"file": "file_1.js", ... }
---------- file_2.js ----------
< Second part of JS code ... >
/*# sourceMappingURL=file_2.js.map */
---------- file_2.js.map ----------
{"version": 3,"file": "file_2.js", ... }
```
#### Command
```bash
$ ncat file_1.js file_2.js --map --output dist/bundle.js
```
#### Result
```javascript
---------- dist/bundle.js ----------
< First part of JS code ... >
< Second part of JS code ... >
/*# sourceMappingURL=bundle.map */
---------- bundle.js.map ----------
{"version": 3,"file": "bundle.js", ... }
```
### Add a banner to a file
#### Files
```javascript
---------- bootstrap.js ----------
< JS code ... >
```
#### Command
```bash
$ ncat bootstrap.js --banner --output dist/bundle.js
```
#### Result
```javascript
---------- dist/bundle.js ----------
/*!
* Bootstrap v4.0.0
* https://getbootstrap.com
*
* Copyright 2017 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT license
*/
< JS code ... >
```
### Add a custom banner and footer to a file
#### Files
```javascript
---------- bootstrap.js ----------
< JS code ... >
---------- build/banner.js ----------
const pkg = require('read-pkg-up').sync().pkg;
module.exports =
`/*!
* ${pkg.name} v${pkg.version} (${pkg.homepage})
*
* Copyright (c) 2011-${new Date().getFullYear()} ${pkg.author.name}
* Licensed under the ${pkg.license} license */
(function () {`;
---------- build/footer.js ----------
module.exports = `
})()`
```
#### Command
```bash
$ ncat bootstrap.js --banner build/banner.js --footer build/footer.js --output dist/bundle.js
```
#### Result
```javascript
---------- dist/bundle.js ----------
/*!
* Bootstrap v4.0.0 (https://getbootstrap.com)
*
* Copyright (c) 2011-2017 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under the MIT license */
(function () {
< JS code ... >
})()
```