npm.devtool.tech
πŸ‘ You can access gulp-flatten package with using gulpFlatten variable in browser devtools!
remove or replace relative path for files

code/package/bundle size

0B
publish
0B
install
0B
bundle minified
0B
bundle gzipped

gulp-flatten NPM version Build Status

Remove or replace relative path for files (gulp v3).

Install

npm install gulp-flatten

Usage

Example source directory with bower compoments:

β”œβ”€β”€ angular
β”‚Β Β  β”œβ”€β”€ README.md
β”‚Β Β  β”œβ”€β”€ angular-csp.css
β”‚Β Β  β”œβ”€β”€ angular.js
β”‚Β Β  β”œβ”€β”€ angular.min.js
β”‚Β Β  └── bower.json
β”œβ”€β”€ angular-route
β”‚Β Β  β”œβ”€β”€ README.md
β”‚Β Β  β”œβ”€β”€ angular-route.js
β”‚Β Β  β”œβ”€β”€ angular-route.min.js
β”‚Β Β  β”œβ”€β”€ angular-route.min.js.map
β”‚Β Β  └── bower.json
β”œβ”€β”€ angular-sanitize
β”‚Β Β  β”œβ”€β”€ README.md
β”‚Β Β  β”œβ”€β”€ angular-sanitize.js
β”‚Β Β  β”œβ”€β”€ angular-sanitize.min.js
β”‚Β Β  β”œβ”€β”€ angular-sanitize.min.js.map
β”‚Β Β  └── bower.json
└── bootstrap
 Β Β  β”œβ”€β”€ DOCS-LICENSE
 Β Β  β”œβ”€β”€ LICENSE
 Β Β  β”œβ”€β”€ LICENSE-MIT
 Β Β  β”œβ”€β”€ README.md
 Β Β  β”œβ”€β”€ bower.json
 Β Β  └── dist
        β”œβ”€β”€ css
        β”‚Β Β  β”œβ”€β”€ bootstrap-theme.css
        β”‚Β Β  β”œβ”€β”€ bootstrap-theme.min.css
        β”‚Β Β  β”œβ”€β”€ bootstrap.css
        β”‚Β Β  └── bootstrap.min.css
        β”œβ”€β”€ fonts
        β”‚Β Β  β”œβ”€β”€ glyphicons-halflings-regular.eot
        β”‚Β Β  β”œβ”€β”€ glyphicons-halflings-regular.svg
        β”‚Β Β  β”œβ”€β”€ glyphicons-halflings-regular.ttf
        β”‚Β Β  └── glyphicons-halflings-regular.woff
        └── js
            β”œβ”€β”€ bootstrap.js
            └── bootstrap.min.js

By default gulp stores files with it's relative paths. To copy all minified javascript files from bower_components to build folder without relative paths:

var flatten = require('gulp-flatten');

gulp.src('bower_components/**/*.min.js')
  .pipe(flatten())
  .pipe(gulp.dest('build/js'));

Result will be list of all .min.js files inside build/js dir:

build
└── js
    β”œβ”€β”€ angular-route.min.js
    β”œβ”€β”€ angular-sanitize.min.js
    β”œβ”€β”€ angular.min.js
    └── bootstrap.min.js

Options

flatten(options)

options.newPath

Type: String
Default: ''

Relative path for file.

options.includeParents

Type: Number or Array of two numbers

If passed in as positive number, it will include the number of top-level parents in the output. Using this code:

gulp.src(['bower_components/**/*.css'])
  .pipe(flatten({ includeParents: 1} ))
  .pipe(gulp.dest('build/'));

will create this structure (from sample directory tree above):

└── bootstrap
    β”œβ”€β”€ bootstrap-theme.css
    β”œβ”€β”€ bootstrap-theme.min.css
    β”œβ”€β”€ bootstrap.css
    └── bootstrap.min.css

If passed in as negative number, it will include the number of bottom-level parents in the output. Using this code:

gulp.src(['bower_components/**/*.css'])
  .pipe(flatten({ includeParents: -1} )) //or indludeParents: [0, 1]
  .pipe(gulp.dest('build/'));

will create this structure:

└── css
    β”œβ”€β”€ bootstrap-theme.css
    β”œβ”€β”€ bootstrap-theme.min.css
    β”œβ”€β”€ bootstrap.css
    └── bootstrap.min.css

If passes as array of two numbers, both parents from top and bottom will be kept in resulting path of a file.

gulp.src(['bower_components/**/*.css'])
  .pipe(flatten({ includeParents: [1, 1]} ))
  .pipe(gulp.dest('build/'));

will create this structure:

└── bootstrap
    └── css
        β”œβ”€β”€ bootstrap-theme.css
        β”œβ”€β”€ bootstrap-theme.min.css
        β”œβ”€β”€ bootstrap.css
        └── bootstrap.min.css

options.subPath

Type: Number or Array of two Numbers [begin, end]

This options applies Array.slice to the array of path elements and allows you to receive a subsequences of the path.

gulp.src(['bower_components/**/*.css'])
  .pipe(flatten({ subPath: [1, 1]} ))
  .pipe(gulp.dest('build/'));

This as an example would flatten top1/top2/bottom2/bottom1/file.txt to top2/file.txt.

[1, -1] would flatten top1/top2/bottom2/bottom1/file.txt to top2/bottom2/file.txt.

Please refer to the Array.slice documentation for a detailed description.

! If you're using both options.includeParents combined with options.subPath please note that options.includeParents is applied first.

License

MIT

πŸ”ŽExplore PackageπŸ”ŽCDN Script

Score

Popularity22/100
Quality75/100
Maintenance32/100