Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 || {};
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,
gitS.on('data', function(data) {
if (!isVinyl(data)) {
console.log(data);
gotData = true;
}
});
return fs.readFileSync(file.path);
};
var Views = App.Views;
var views = new Views({View: Vinyl});
views.addView('a.hbs', {path: 'a.hbs', content: 'a'});
views.addView('b.hbs', {path: 'b.hbs', content: 'b'});
views.addView('c.hbs', {path: 'c.hbs', content: 'c'});
app = new App();
app.create('pages', views);
var a = app.pages.getView('a.hbs');
assert(a instanceof Vinyl);
assert(Vinyl.isVinyl(a));
assert(typeof a.read === 'function');
views.addView('d.hbs', {path: 'd.hbs', content: 'd'});
var d = app.pages.getView('d.hbs');
assert(d instanceof Vinyl);
assert(Vinyl.isVinyl(d));
});
});
prepare('index.html', {use: badMiddleware}).on('data', function (file) {
t.notEqual(vinyl, null);
t.notEqual(file, vinyl);
t.ok(isVinylFile(file));
});
return fs.readFileSync(file.path);
};
var Views = App.Views;
var views = new Views({View: Vinyl});
views.addView('a.hbs', {path: 'a.hbs', content: 'a'});
views.addView('b.hbs', {path: 'b.hbs', content: 'b'});
views.addView('c.hbs', {path: 'c.hbs', content: 'c'});
app = new App();
app.create('pages', views);
var a = app.pages.getView('a.hbs');
assert(a instanceof Vinyl);
assert(Vinyl.isVinyl(a));
assert.equal(typeof a.read, 'function');
views.addView('d.hbs', {path: 'd.hbs', content: 'd'});
var d = app.pages.getView('d.hbs');
assert(d instanceof Vinyl);
assert(Vinyl.isVinyl(d));
});
});
function isVinyl(file) {
return (
Vinyl.isVinyl(file) ||
file instanceof Vinyl ||
(file && /function File\(/.test(file.constructor.toString()) && file.contents && file.path)
);
}
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);
function isVinylFile(file) {
if (Vinyl.isVinyl(file)) {
return true;
}
if (!file || (typeof file !== 'object')) {
return false;
}
const properties = new Set(Object.getOwnPropertyNames(file));
if ((!properties.has('cwd') && !properties.has('_cwd'))
|| fileProperties.filter(p => !properties.has(p)).length
) {
return false;
}
const content = Object.getOwnPropertyDescriptor(file, '_contents');
return (typeof content === 'object') && content.writable && content.enumerable && content.configurable;
}