Coder Social home page Coder Social logo

cjroth / gulp-filelist Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 20.0 489 KB

Output list of files in current stream to JSON file or custom format.

License: MIT License

JavaScript 100.00%
gulp javascript stream gulp-filelist angular angularjs npm npm-package npm-module nodejs node node-js

gulp-filelist's Introduction

gulp-filelist

NPM Version NPM Downloads Node.js Version Build Status

Output list of files in current stream to JSON file or custom format.

Add to your Node.js dev dependencies:

npm install --savedev gulp-filelist

Add it to your gulp file:

gulp
  .src(['awesome.file', 'lame.file'])
  .pipe(require('gulp-filelist')('filelist.json'))
  .pipe(gulp.dest('out'))

Outputs out/filelist.json:

[
  "awesome.file",
  "lame.file"
]

Installation

$ npm install gulp-filelist

Options

Absolute Paths: { absolute: true }

gulp
  .src(['awesome.file', 'lame.file'])
  .pipe(require('gulp-filelist')('filelist.json', { absolute: true }))
  .pipe(gulp.dest('out'))

Outputs:

[
  "/Users/chris/my-project/out/awesome.file",
  "/Users/chris/my-project/out/lame.file"
]

Relative Paths: { relative: true }

gulp
  .src(['awesome.file', 'lame.file'])
  .pipe(require('gulp-rename')(function(path) { path.dirname = 'foo' }))
  .pipe(require('gulp-filelist')('filelist.json', { relative: true }))
  .pipe(gulp.dest('out'))

Outputs:

[
  "foo/awesome.file",
  "foo/lame.file"
]

Flattened Paths: { flatten: true }

gulp
  .src(['awesome.file', 'lame.file'])
  .pipe(require('gulp-filelist')('filelist.json', { flatten: true }))
  .pipe(gulp.dest('out'))

Outputs:

[
  "awesome.file",
  "lame.file"
]

Paths without Extensions: { removeExtensions: true }

gulp
  .src(['directory/awesome.file', 'directory/lame.file'])
  .pipe(require('gulp-filelist')('filelist.json', { removeExtensions: true }))
  .pipe(gulp.dest('out'))

Outputs:

[
  "directory/awesome",
  "directory/lame"
]

Output file with custom template: { destRowTemplate: <rowStringTemplate | function> }

usage with string template

gulp
  .src(['directory/awesome.file', 'directory/lame.file'])
  .pipe(require('gulp-filelist')('filelist.json', { destRowTemplate: "/// <amd dependency='@filePath@'/>" }))
  .pipe(gulp.dest('out'))

Outputs:

[
  "/// <amd dependency='directory/awesome'/>",
  "/// <amd dependency='directory/lame'/>"
]

usage with formatter function

function formatter(filePath) {
  return filePath.substring(filePath.lastIndexOf('/') + 1) + ': ' + filePath + '\r\n';
}

gulp
  .src(['directory/awesome.file', 'directory/lame.file'])
  .pipe(require('gulp-filelist')('filelist.json', { destRowTemplate: formatter }))
  .pipe(gulp.dest('out'))

Outputs:

[
  "awesome: directory/awesome",
  "lame: directory/lame"
]

gulp-filelist's People

Contributors

alexdej avatar andreapaciolla avatar barvian avatar chewiebug avatar cjroth avatar colmmcbarron avatar dependabot[bot] avatar devel-pa avatar kaivosukeltaja avatar mrmowgli avatar omichelsen avatar renyard avatar spacedawwwg avatar treago avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gulp-filelist's Issues

File path in globals

Hi! The plugin is very good, but there is a proposal to add functionality - the ability to make a withdrawal of paths, not only in the json file, but for example, to be able to transfer path in task as a global variable

Update npm

Hi, any chance to get npm updated with recent bug fixes?

Access file properties in template

Is it possible to access say the file timestamp form within the formatting function? We need to include the file timestamp in the json output.

Output as dependency

I'm trying to configure another task to consume the file output but cannot seem to get the dependency behavior I'm looking for. So far I haven't been able to determine if this is an issue with my configuration or understanding of gulp itself or the plugin usage.

I have a task creating the list

gulp.task('audit', function(){
    const pagefiles = [
        path.join(config.paths.src, '/hbs/pages/**/*.hbs'),
        path.join(config.paths.src, '/js/**/*.js'),
        "!" + path.join(config.paths.src, '/js/_modules/*.js'),
        path.join(config.paths.src, '/scss/**/*.scss'),
        "!" + path.join(config.paths.src, '/scss/_partials/*.scss')
    ];

    return gulp.src(pagefiles)
    .pipe(filelist('filelist.json', { relative: true }))
    .pipe(gulp.dest(config.paths.tmp));
});

The sequential task:

gulp.task('pages', ['audit'], function(){
    console.log('###########################################');
    console.log('Audited ' + files.length + ' files in source folders');
    console.log('###########################################');

    ....
});

...errs as the target JSON doesn't exist. Shouldn't 'pages' be waiting for filelist.json? Any insight would be greatly appreciated.

Thanks-

Paths are wrong after rename with default settings

Hi! Thanks for this plugin, it is exactly what I need! I ran into one issue with it which is that the paths in the filelist are not correct when I have gulp-rename upstream.

For example with this config

const filelist = require('gulp-filelist');
const gulp = require('gulp');
const rename = require('gulp-rename');

gulp.task('default', function() {
  return gulp.src('files/*.txt')
    .pipe(rename(path => {
      path.dirname = 'myfiles';
    }))
    .pipe(filelist('myfiles.json'))
    .pipe(gulp.dest('out/'));
});

and files a.txt b.txt c.txt in files/

I get

[
  "files/myfiles/a.txt",
  "files/myfiles/b.txt",
  "files/myfiles/c.txt"
]

But I would expect it to be my renamed path (and it would be more helpful if it were).

First example in readme is wrong?

I'm not getting the same result for the first example in the README

  gulp.src(['awesome.file', 'lame.file'])
    .pipe(require('gulp-filelist')('filelist.json'))
    .pipe(gulp.dest('out'))

produces out/filelist.json:

[
  "awesome.file",
  "lame.file"
]

README says it should be

[
  "out/awesome.file",
  "out/lame.file"
]

Creating custom json output?

Is it possible to achieve the following with gulp-filelist?

If I have a folder structure like:

pages/
├── lesson01/
│   ├── 01_001
│   ├── 01_002
├── lesson02/
│   ├── 02_001
│   ├── 02_002

How can I output a json file like this:

{
  "lesson01": [
    "01_001",
    "01_002"
  ],
  "lesson02": [
    "02_001",
    "02_002"
  ]
}

Any help is appreciated.

Conversion to Gulp 4 fails

I'm converting an older gulp file to Gulp 4, and I'm down to just a few failing tasks. When I run the task without gulp-filelist everything works correctly. From what I have seen it may just be an issue of updating the version of Vinyl being used under the hood, perhaps updating the versions of dependencies in package.json?

gulp.task('data:sites-json', gulp.series(() => 
  gulp.src('/site/**/*.*', { base: '/app'})
    .pipe(gulpFileList('tmp/sites.json'))
    .pipe(logger(logOptions))
    .pipe(gulp.dest('tmp/data'))
));

Running the task appears to work, however the result doesn't get written and fails:

[07:17:23] Before Dest Files...
[07:17:23] tmp//sites.json  ->  tmp/sites.less
[07:17:23] After DestFiles
[07:17:23] '<anonymous>' errored after 24 ms
[07:17:23] Error: Received a non-Vinyl object in `dest()`
    at DestroyableTransform.normalize [as _transform] (/app/node_modules/vinyl-fs/lib/dest/prepare.js:16:17)
    at DestroyableTransform.Transform._read (/app/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/app/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:83)
    at doWrite (/app/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/app/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at DestroyableTransform.Writable.write (/app/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at Pumpify.Duplexify._write (/app/node_modules/duplexify/index.js:208:22)
    at doWrite (/app/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/app/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at Pumpify.Writable.write (/app/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:334:11)

Update npmjs package for version 0.5

Hi,

I've installed gulp-filelist using npm, where npm uses version 0.4 of your library.
Unfortunately, this version does not contain the latest fix (where you removed the this.push(file);, which is something I need.

For now, I helped myself by downloading and installing this package directly from github, using

npm install git://github.com/cjroth/gulp-filelist.git

Though for future purpose it would be nice if the package on npmjs is updated.
Thanks!

Support removing extension

I'd like to use this to make a list of valid keys in a path which is like this: presets/#nameIActuallyWant#.json. flatten takes care of the presets/ part, but it would be awesome if this module could also take care of removing the extension.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.