How to use vinyl - 10 common examples

To help you get started, we’ve selected a few vinyl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jgable / gulp-cache / test / index.js View on Github external
const outputFile1 = file.clone({ contents: false }),
					outputFile2 = file.clone({ contents: false });

				outputFile1.contents = new Buffer(`${String(file.contents)}-1`);
				outputFile2.contents = new Buffer(`${String(file.contents)}-2`);

				this.push(outputFile1);
				this.push(outputFile2);

				cb(null);
			});

			const pushedFilesCount = 2;

			const targetFile = new File({
				contents: new Buffer('abufferwiththiscontent')
			});

			fakeTask = through.obj(updatedFileHandler);

			const opts = {
				value:   sandbox.spy(cache.defaultOptions.value),
				restore: sandbox.spy(cache.defaultOptions.restore)
			};

			// Create a proxied plugin stream
			let proxied = cache(fakeTask, opts),
				count = 0;

			cacheStep();
github amtrack / force-dev-tool / lib / metadata-file.js View on Github external
var config = new(require("./config"))();
var folderToMetadataType = config.get("folderBasedMetadataMap");
var metadataTypeToFolder = _.invert(folderToMetadataType);

/**
 * MetadataFile represents a file on the filesystem.
 * It inherits from vinyl.
 * Note that the path should be relative to `src`.
 */

var MetadataFile = module.exports = function(opts) {
	File.call(this, opts);
};

MetadataFile.prototype = Object.create(File.prototype);
MetadataFile.prototype.constructor = MetadataFile;

MetadataFile.prototype.basenameDirname = function() {
	var self = this;
	return path.basename(path.dirname(self.path));
};

MetadataFile.prototype.waveTemplateDirname = function() {
	// Metadata like WaveTemplateBundles are deeply nested and contain ambiguous subfolders like 'dashboard'.
	var self = this;
	var pathComponents = self.path.split(path.sep);
	return pathComponents[1];
};

MetadataFile.prototype.parentDirname = function() {
	var self = this;
github jgable / gulp-cache / src / task-proxy.js View on Github external
cachedValuesWithNormalPaths.forEach((cachedFile) => {
				// Extend the cached value onto the file, but don't overwrite original path info
				const file = new File({
					// custom properties
					...cachedFile,
					// file info
					...pick(inputFile, ['cwd', 'base', 'stat', 'history', 'path']),
					// file contents
					contents: cachedFile.contents
				});

				// Restore the file path if it was set
				if (cachedFile.path && cachedFile.gulpCache$filePathChangedInsideTask) {
					file.path = cachedFile.path;
				}

				// Restore the file base if it was set
				if (cachedFile.base && cachedFile.gulpCache$fileBaseChangedInsideTask) {
					file.base = cachedFile.base;
github jonschlinkert / load-templates / index.js View on Github external
createView(view, options) {
    options = options || {};
    let opts = Object.assign({ cwd: process.cwd() }, this.options);
    let key;

    if (typeOf(view) === 'object') {
      view = File.isVinyl(view) ? view : new File(view);
      opts = Object.assign({}, opts, options);

    } else if (typeof view === 'string') {
      key = view;
      if (File.isVinyl(options)) {
        view = options;
      } else {
        view = new File(Object.assign({ path: key }, options));
        opts = Object.assign({}, opts, options);
      }
      view.cwd = opts.cwd;
    } else {
      throw new TypeError('expected view to be a string or object');
    }

    view.cwd = path.resolve(view.cwd);
    view.base = path.resolve(options.base || view.cwd);

    // prime the view's metadata objects
    view.options = view.options || {};
    view.locals = view.locals || {};
github gulpjs / vinyl-sourcemap / index.js View on Github external
function add(file, callback) {

  // Bail early an error if the file argument is not a Vinyl file
  if (!File.isVinyl(file)) {
    return callback(new Error(PLUGIN_NAME + '-add: Not a vinyl file'));
  }

  // Bail early with an error if file has streaming contents
  if (file.isStream()) {
    return callback(new Error(PLUGIN_NAME + '-add: Streaming not supported'));
  }

  // Bail early successfully if file is null or already has a sourcemap
  if (file.isNull() || file.sourceMap) {
    return callback(null, file);
  }

  var state = {
    path: '', // Root path for the sources in the map
    map: null,
github max-team / Mars / packages / mars-build / src / gulp-mars-h5.js View on Github external
const compilers = {
    templateCompiler,
    styleCompiler,
    scriptPostCompiler,
    scriptCompiler,
    configCompiler
};

// const delToVueTag = require('./h5/transform/tag');
// // const generate = require('./compiler/template/generate');

let componentSet = {}; // 小程序使用的组件集合
// let mainOptions = {}; // 配置集合
let pagesInfo = {}; // 页面title集合

Vinyl.prototype.writeFileSync = function () {
    if (!this.contents || !this.path) {
        throw new Error('Vinyl.prototype.writeFileSync() requires path and contents to write');
    }

    fs.writeFileSync(this.path, this.contents.toString());
};


// /**
//  * @file gulp plugin
//  * @author zhangwentao 
//  */
// /* eslint-disable fecs-min-vars-per-destructure */
// const renderFunctionName = '__renderFunction';
// const {getFileCompilers} = require('../file/base');
github max-team / Mars / packages / mars-build / src / compiler / sfc / File.js View on Github external
/* eslint-disable no-native-reassign */

/* eslint-disable fecs-min-vars-per-destructure */

const Vinyl = require('vinyl');
const fs = require('fs-extra');

Vinyl.prototype.writeFileSync = function () {
    if (!this.contents || !this.path) {
        throw new Error('Vinyl.prototype.writeFileSync() requires path and contents to write');
    }

    fs.outputFileSync(this.path, this.contents.toString());
};

Vinyl.prototype.appendContent = function (str) {
    const content = this.contents ? this.contents.toString() : '';
    this.contents = Buffer.from(content + str);
};

module.exports = Vinyl;
github max-team / Mars / packages / mars-build / src / compiler / sfc / File.js View on Github external
/**
 * @file gulp plugin
 * @author zhangwentao 
 */

/* eslint-disable fecs-no-require */

/* eslint-disable no-native-reassign */

/* eslint-disable fecs-min-vars-per-destructure */

const Vinyl = require('vinyl');
const fs = require('fs-extra');

Vinyl.prototype.writeFileSync = function () {
    if (!this.contents || !this.path) {
        throw new Error('Vinyl.prototype.writeFileSync() requires path and contents to write');
    }

    fs.outputFileSync(this.path, this.contents.toString());
};

Vinyl.prototype.appendContent = function (str) {
    const content = this.contents ? this.contents.toString() : '';
    this.contents = Buffer.from(content + str);
};

module.exports = Vinyl;
github gameclosure / devkit-core / src / build / resources / index.js View on Github external
function ResourceFile(directory, filename, outputDirectory, statCache) {

  if (!filename) { throw new Error("Expected a filename"); }

  this.sourcePath = path.resolve(directory.src, filename);
  this.sourceDirectory = directory.src;

  // a vinyl file records changes to the file's path -- the first path in the
  // history is the location on disk, then we set the path to the target
  // location
  File.call(this, {
    base: directory.src,
    path: this.sourcePath,
    stat: statCache && statCache[this.sourcePath]
  });

  this.sourceRelativePath = path.relative(this.sourceDirectory, this.sourcePath);
  this.targetRelativePath = slash(path.join(directory.target, this.sourceRelativePath));

  this.base = outputDirectory;
  this.path = path.join(outputDirectory, this.targetRelativePath);

  this._isStream = true;
}
github stevelacy / gulp-git / test / commit.js View on Github external
gitS.on('data', function(data) {
          if (!isVinyl(data)) {
            console.log(data);
            gotData = true;
          }
        });

vinyl

Virtual file format.

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis