{"id":13494132,"url":"https://github.com/armed/gulp-flatten","last_synced_at":"2025-04-05T12:05:45.567Z","repository":{"id":13140071,"uuid":"15822370","full_name":"armed/gulp-flatten","owner":"armed","description":"Gulp plugin: remove or replace relative paths for files","archived":false,"fork":false,"pushed_at":"2022-12-03T03:16:09.000Z","size":137,"stargazers_count":107,"open_issues_count":3,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T11:07:09.508Z","etag":null,"topics":["flatten","gulp","gulp-plugin","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/armed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-11T12:46:46.000Z","updated_at":"2025-02-05T00:23:02.000Z","dependencies_parsed_at":"2023-01-13T17:19:20.407Z","dependency_job_id":null,"html_url":"https://github.com/armed/gulp-flatten","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armed%2Fgulp-flatten","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armed%2Fgulp-flatten/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armed%2Fgulp-flatten/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armed%2Fgulp-flatten/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/armed","download_url":"https://codeload.github.com/armed/gulp-flatten/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332604,"owners_count":20921853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flatten","gulp","gulp-plugin","javascript"],"created_at":"2024-07-31T19:01:22.188Z","updated_at":"2025-04-05T12:05:45.527Z","avatar_url":"https://github.com/armed.png","language":"JavaScript","readme":"# [gulp](http://gulpjs.com)-flatten [![NPM version](https://img.shields.io/npm/v/gulp-flatten.svg)](http://badge.fury.io/js/gulp-flatten) [![Build Status](https://api.travis-ci.org/armed/gulp-flatten.svg?branch=master)](https://travis-ci.org/armed/gulp-flatten)\n\n\u003eRemove or replace relative path for files (gulp v3).\n\n## Install\n\n```\nnpm install gulp-flatten\n```\n\n## Usage\n\nExample source directory with bower compoments:\n```\n├── angular\n│   ├── README.md\n│   ├── angular-csp.css\n│   ├── angular.js\n│   ├── angular.min.js\n│   └── bower.json\n├── angular-route\n│   ├── README.md\n│   ├── angular-route.js\n│   ├── angular-route.min.js\n│   ├── angular-route.min.js.map\n│   └── bower.json\n├── angular-sanitize\n│   ├── README.md\n│   ├── angular-sanitize.js\n│   ├── angular-sanitize.min.js\n│   ├── angular-sanitize.min.js.map\n│   └── bower.json\n└── bootstrap\n    ├── DOCS-LICENSE\n    ├── LICENSE\n    ├── LICENSE-MIT\n    ├── README.md\n    ├── bower.json\n    └── dist\n        ├── css\n        │   ├── bootstrap-theme.css\n        │   ├── bootstrap-theme.min.css\n        │   ├── bootstrap.css\n        │   └── bootstrap.min.css\n        ├── fonts\n        │   ├── glyphicons-halflings-regular.eot\n        │   ├── glyphicons-halflings-regular.svg\n        │   ├── glyphicons-halflings-regular.ttf\n        │   └── glyphicons-halflings-regular.woff\n        └── js\n            ├── bootstrap.js\n            └── bootstrap.min.js\n```\n\nBy default `gulp` stores files with it's relative paths. To copy all minified javascript files from `bower_components` to `build` folder without relative paths:\n```js\nvar flatten = require('gulp-flatten');\n\ngulp.src('bower_components/**/*.min.js')\n  .pipe(flatten())\n  .pipe(gulp.dest('build/js'));\n```\n\nResult will be list of all `.min.js` files inside `build/js` dir:\n```\nbuild\n└── js\n    ├── angular-route.min.js\n    ├── angular-sanitize.min.js\n    ├── angular.min.js\n    └── bootstrap.min.js\n```\n\n## Options\n\n### flatten(options)\n\n#### options.newPath\n\nType: `String`  \nDefault: `''`\n\nRelative path for file.\n\n#### options.includeParents\n\nType: `Number` or `Array` of two numbers\n\nIf passed in as positive number, it will include the number of top-level parents in the output. Using this code:\n\n```js\ngulp.src(['bower_components/**/*.css'])\n  .pipe(flatten({ includeParents: 1} ))\n  .pipe(gulp.dest('build/'));\n```\n\nwill create this structure (from sample directory tree above):\n\n```\n└── bootstrap\n    ├── bootstrap-theme.css\n    ├── bootstrap-theme.min.css\n    ├── bootstrap.css\n    └── bootstrap.min.css\n```\n\nIf passed in as negative number, it will include the number of bottom-level parents in the output. Using this code:\n\n```js\ngulp.src(['bower_components/**/*.css'])\n  .pipe(flatten({ includeParents: -1} )) //or indludeParents: [0, 1]\n  .pipe(gulp.dest('build/'));\n```\n\nwill create this structure:\n\n```\n└── css\n    ├── bootstrap-theme.css\n    ├── bootstrap-theme.min.css\n    ├── bootstrap.css\n    └── bootstrap.min.css\n```\n\nIf passes as array of two numbers, both parents from top and bottom will be kept in resulting path of a file.\n\n```js\ngulp.src(['bower_components/**/*.css'])\n  .pipe(flatten({ includeParents: [1, 1]} ))\n  .pipe(gulp.dest('build/'));\n```\n\nwill create this structure:\n\n```\n└── bootstrap\n    └── css\n        ├── bootstrap-theme.css\n        ├── bootstrap-theme.min.css\n        ├── bootstrap.css\n        └── bootstrap.min.css\n```\n\n#### options.subPath\n\nType: Number or Array of two Numbers [begin, end]\n\nThis options applies `Array.slice` to the array of path elements and allows you\nto receive a subsequences of the path.\n\n```js\ngulp.src(['bower_components/**/*.css'])\n  .pipe(flatten({ subPath: [1, 1]} ))\n  .pipe(gulp.dest('build/'));\n```\nThis as an example would flatten `top1/top2/bottom2/bottom1/file.txt` to `top2/file.txt`.\n\n`[1, -1]` would flatten `top1/top2/bottom2/bottom1/file.txt` to `top2/bottom2/file.txt`.\n\nPlease refer to the [Array.slice documentation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) for a detailed description.\n\n**!** If you're using both `options.includeParents` combined with `options.subPath`\nplease note that `options.includeParents` is applied first.\n\n## License\n\nMIT\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farmed%2Fgulp-flatten","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farmed%2Fgulp-flatten","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farmed%2Fgulp-flatten/lists"}