How to use the File function from gulp-util

Find comprehensive JavaScript gulp-util.File code examples handpicked from public code repositorys.

6
7
8
9
10
11
12
13
14
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var through = require('through');
var os = require('os');
var File = gutil.File;

//We need this one for the in-built webserver
var connect = require('gulp-connect');
fork icon3
star icon9
watch icon8

+ 3 other calls in file

1
2
3
4
5
6
7
8
9
10
    path = require('path'),
    readFileSync = require('fs').readFileSync,
    through = require('through');

var PluginError = gutil.PluginError,
    File = gutil.File;

var COMMENT_MAP = {
  css: { start: '/*', end: '*/' },
  js:  { start: '/*', end: '*/' }
fork icon1
star icon8
watch icon2

93
94
95
96
97
98
99
100
101
102
  path = prefixes[dtype] + "_" + index + ".html";
} else {
  path = dtype + ".html";
}

newFile = new gutil.File({path: path});

newFile.contents = new Buffer(contents);

stream.push(newFile);
fork icon0
star icon5
watch icon23

+ 3 other calls in file

4
5
6
7
8
9
10
11
12
const concat = require('gulp-concat');
const uglifyjs = require('uglify-es');
const composer = require('gulp-uglify/composer');
const gutil = require('gulp-util');
const through = require('through');
const File = gutil.File;
const connect = require('gulp-connect');
const watch = require('glob-watcher');
const uglify = composer(uglifyjs, console);
fork icon989
star icon0
watch icon10

85
86
87
88
89
90
91
92
93
94
## new File(obj)

This is just [vinyl](https://github.com/wearefractal/vinyl)

```javascript
var file = new gutil.File({
  base: path.join(__dirname, './fixtures/'),
  cwd: __dirname,
  path: path.join(__dirname, './fixtures/test.coffee')
});
fork icon104
star icon0
watch icon2

82
83
84
85
86
87
88
89
90
91
        }
    }
}, this);

if (buffer.length) {
    joinedFile = new gutil.File({
        cwd: file.cwd,
        base: file.base,
        path: path.join(file.base, name),
        contents: new Buffer(buffer.join(gutil.linefeed))
fork icon93
star icon0
watch icon2

60
61
62
63
64
65
66
67
68
69
var cwd = process.cwd();
process.chdir(path.resolve(path.dirname(file.path)));
raml2html.render(file.contents, options.config).then(
  function (output) {
    process.chdir(cwd);
    stream.push(new gutil.File({
      base: file.base,
      cwd: file.cwd,
      path: gutil.replaceExtension(file.path, options.extension),
      contents: new Buffer(output)
fork icon4
star icon5
watch icon9

64
65
66
67
68
69
70
71
72
73
  .value()
  .join('\n');

console.log(csv);

var outFile = new gutil.File();
outFile.path = 'kanjiTestForm.csv';
outFile.contents = new Buffer(csv);

this.push(outFile);
fork icon0
star icon0
watch icon0

65
66
67
68
69
70
71
72
73
74
}

options.logLevel = 2;

options.out = function( text ) {
  var outFile = new gutil.File({
    path: file.relative,
    contents: new Buffer( text )
  });
  cb( null, outFile );
fork icon0
star icon0
watch icon0