/
index.js
55 lines (43 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
const path = require('path');
const fs = require('fs');
const array = require('stream-array');
const Vinyl = require('vinyl');
const nn = require('normalize-newline');
function getFile(file) {
const testBase = path.join(__dirname, '..');
if (fs.existsSync(path.join(testBase, file))) {
return path.join(testBase, file);
}
return file;
}
function readAndRemove(file) {
const fp = getFile(file);
const content = read(fp);
fs.unlinkSync(fp);
return content;
}
function read(file) {
const content = fs.readFileSync(getFile(file), 'utf8');
return nn(content);
}
function getVinyl(...args) {
function create(filepath) {
if (filepath) {
const file = path.join(__dirname, '../fixtures', filepath);
return new Vinyl({
cwd: __dirname,
base: path.dirname(file),
path: file,
contents: Buffer.from(read(file)),
});
}
return new Vinyl();
}
return array(args.map(create));
}
module.exports = {
getVinyl,
read,
readAndRemove,
};