Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

fly-flatten

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fly-flatten - npm Package Compare versions

Comparing version
0.0.1
to
1.0.0
+39
index.js
const path = require('path');
const normalize = path.normalize;
const sep = path.sep;
module.exports = function (fly) {
fly.plugin('flatten', {every: false}, function * (files, opts) {
if (!files.length) {
return this.emit('plugin_warning', {
plugin: 'fly-flatten',
warning: 'No source files to flatten!'
});
}
const levels = opts.levels || 0;
// find shortest `dir` path; glob originated here
const globBaseDir = files.map(o => o.dir).sort()[0];
for (let file of files) {
file.dir = trimmer(globBaseDir, file.dir, levels);
}
});
};
function trimmer(baseDir, fileDir, levels) {
if (levels === 0) {
return baseDir;
}
let dirs = fileDir.replace(baseDir, '');
const arr = dirs.split(sep);
const len = arr.length;
if (levels < len) {
dirs = arr.splice(len - levels).join(sep);
}
return normalize(baseDir + sep + dirs);
}
+1
-1
This software is released under the MIT license:
Copyright (c) 2015 luke <luke.edwards05@gmail.com> https://lukeed.com
Copyright (c) 2015 Luke Edwards <luke.edwards05@gmail.com> (https://lukeed.com)

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

{
"name": "fly-flatten",
"version": "0.0.1",
"description": "DEPRECATED -- Flattens all files within a glob selection into a single level.",
"version": "1.0.0",
"description": "Flatten all sources files to specified maximum of sub-directories.",
"repository": "https://github.com/lukeed/fly-flatten",
"license": "MIT",
"repository": "https://github.com/lukeed/fly-flatten",
"files": [

@@ -13,2 +13,3 @@ "index.js"

"fly-plugin",
"directories",
"flatten",

@@ -18,17 +19,18 @@ "glob"

"scripts": {
"test": "echo DEPRECATED. Integrated in Fly ^0.8.8! -- https://github.com/bucaran/fly/pull/135"
"test": "tape test/*.js | tap-spec"
},
"author": {
"name": "luke",
"name": "Luke Edwards",
"email": "luke.edwards05@gmail.com",
"url": "https://lukeed.com"
},
"dependencies": {
},
"devDependencies": {
"fly": "^2.0.5",
"fly-clear": "^1.0.1",
"tap-spec": "^4.1.1",
"tape": "^4.6.3"
},
"engines": {
"iojs": ">= 1.0.0",
"node": ">= 0.11.0"
"node": ">= 4.6"
}
}
+96
-24

@@ -1,34 +0,106 @@

<div align="center">
<a href="http://github.com/flyjs/fly">
<img width=200px src="https://cloud.githubusercontent.com/assets/8317250/8733685/0be81080-2c40-11e5-98d2-c634f076ccd7.png">
</a>
</div>
# fly-flatten [![][travis-badge]][travis-link]
> DEPRECATED - [Flatten](https://github.com/lukeed/fly-flatten) all files within a glob selection into a single level.
> Flatten all sources files to specified maximum of sub-directories.
[![][fly-badge]][fly]
[![npm package][npm-ver-link]][releases]
[![][dl-badge]][npm-pkg-link]
[![][travis-badge]][travis-link]
[![][mit-badge]][mit]
A source's directory structure isn't always desirable in the output. With `fly-flatten`, you may dictate how many _parent directories_ of a file to keep.
## Install
```a
npm install --save-dev fly-flatten
```
## Usage
DEPRECATED! Integrated into core of Fly@^0.8.8. Check out [this PR](https://github.com/bucaran/fly/pull/135).
```sh
src
├── images
│ ├── img.jpg
│ ├── foo
│ ├── foo.jpg
│ ├── bar
│ ├── bar.jpg
```
```js
exports.images = function * (fly) {
yield fly.source('src/images/**/*.jpg').flatten({ levels: 1 }).target('dist/img');
}
```
```sh
# output
dist
├── img
│ ├── img.jpg
│ ├── foo
│ ├── foo.jpg
│ ├── bar
│ ├── bar.jpg
```
## API
### .flatten(options)
#### options.levels
Type: `Number`<br>
Default: `0`
The number of sub-directories allowed **in relation to** your glob root.
## Examples
All examples use the [demo file tree](#usage) listed above.
### Level: 0
No parent directories are kept.
> **Note:** The `img` directory is kept because we've used `.target('dist/img')`.
```
dist
├── img
│ ├── img.jpg
│ ├── foo.jpg
│ ├── bar.jpg
```
### Level: 1
Each file is allowed to keep 1 parent directory.
```
dist
├── img
│ ├── img.jpg
│ ├── foo
│ ├── foo.jpg
│ ├── bar
│ ├── bar.jpg
```
### Level: 5
Our file tree is **only** 2 levels deep (`images [0]/foo [1]/bar [2]/bar.jpg`). Because our "allowed levels" exceeds our tree depth, `fly-flatten` won't do anthing and so the entire structure will be copied.
```sh
dist
├── img
│ ├── img.jpg
│ ├── foo
│ ├── foo.jpg
│ ├── bar
│ ├── bar.jpg
```
## License
[MIT][mit] © [Luke Edwards][author] et [al][contributors]
MIT © [Luke Edwards](https://lukeed.com)
[mit]: http://opensource.org/licenses/MIT
[author]: https://lukeed.com
[contributors]: https://github.com/lukeed/fly-flatten/graphs/contributors
[releases]: https://github.com/lukeed/fly-flatten/releases
[fly]: https://www.github.com/flyjs/fly
[fly-badge]: https://img.shields.io/badge/fly-JS-05B3E1.svg?style=flat-square
[mit-badge]: https://img.shields.io/badge/license-MIT-444444.svg?style=flat-square
[npm-pkg-link]: https://www.npmjs.org/package/fly-flatten
[npm-ver-link]: https://img.shields.io/npm/v/fly-flatten.svg?style=flat-square
[dl-badge]: http://img.shields.io/npm/dm/fly-flatten.svg?style=flat-square
[travis-link]: https://travis-ci.org/lukeed/fly-flatten
[travis-badge]: http://img.shields.io/travis/lukeed/fly-flatten.svg?style=flat-square