0.4.0 • Published 7 years ago

gulp-flatten v0.4.0

Weekly downloads
53,485
License
MIT
Repository
github
Last release
7 years ago

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

ldu-gulpfunctions@corinty/proxmamy-gulpak-gulp@phparkle/semantic-ui@siiron/sds-icons@siiron/sds-starter-kit@mygooder/semantic@vchangal/devkit@somoscuatro/gulp-wordpress-themethunderbirdgulp-bsm-helpersdkfds-docsfomantic-ui-semeia@infinitebrahmanuniverse/nolb-gulp-fdagger-tasks@everything-registry/sub-chunk-1807cells-shortlifeweb-dev-toolswetype-utilws-voice-infinity-global-modulews-react-base-dictionaryws-react-global-modulews-react-modal-dialogws-intranet-global-modulews-react-tablesponge-rodsushimanveevaveezardvanilla-semantic-uiismart-gulpfileitbjs-transpilerjoes-gulp-tasksjaune-tasksjsonresume-theme-timeline-fixedlaravel-elixir-componentscells-app-gulp-tasksstreamsoftco-developmentsurvivejsspa-routerterraformatheme-core-plugin--sasstoolbelt-standard-ad-buildertmt-helios-ui-bootstrappertonic-sass@arwa.lokhandwala/ui-component-library@angular-template/ng1-build@ajhyndman/relay@building-blox/blox@bspeare/uds1000-packages@bolt/build-styles@bolt/build-patternkityworkofflinewebfletch_js_utilities@fourkitchens/emulsify-gulp@egis/build-tools@geit/styles@goat-cli/styles@luca.pipolo/gulp-static-starterkit@mantle/wp-theme-gulp@microsoft/gulp-core-build@networkteam/gulpfile@ongov/ontario-design-system-complete-styles@ontario-digital-service/ontario-design-system-complete-styles@ontario-lrc/ontario-design-system-complete-styles@pitcher/fomantic-ui@nwetzel/modern-web-dev-build@otixo/semantic-ui@peergrade/relay@spicypixel/build-kit-js@romger/react-geo@romger/react-global-module@romger/react-modal-dialog@romger/react-tablemvw-creatormodern-web-dev-buildmingjiemystikpaccop2-theme-coreozone-components-demonweb.jsoneweighnwt-gulpfilepeach_html_productionpeach-html-generatepatternityscaffold-pipeline-bbruibai-reactsemantic-ui-happysemantic-uisemantic-ui-xyzsemui-onyxnode-build-web-appng-boltng1-template-gulpplantingjs
0.4.0

7 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago