2019-02-24 22:14:47 +00:00
|
|
|
import * as through2 from 'through2';
|
2019-02-24 22:11:26 +00:00
|
|
|
import { cache } from './injection';
|
|
|
|
import { Transform } from 'stream'; // needed for types
|
2017-02-28 22:40:13 +00:00
|
|
|
|
2019-02-24 22:14:47 +00:00
|
|
|
export const gulpPipe = () => {
|
|
|
|
return through2.obj((file, enc, cb) => {
|
2019-02-24 22:11:26 +00:00
|
|
|
cache[file.path] = file;
|
|
|
|
return cb(null, file);
|
|
|
|
});
|
|
|
|
};
|
2017-02-28 22:40:13 +00:00
|
|
|
|
2019-02-24 22:14:47 +00:00
|
|
|
export interface IFileObject {
|
2019-02-24 22:11:26 +00:00
|
|
|
path: string;
|
|
|
|
contents: Buffer;
|
2017-02-28 22:40:13 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 22:14:47 +00:00
|
|
|
export const injectFileArray = async (fileArray: IFileObject[]) => {
|
|
|
|
for (const fileObject of fileArray) {
|
2017-07-30 15:44:27 +00:00
|
|
|
/* if (/[yourTestFilenameHere.js]/.test(request)) {
|
|
|
|
// console.log('injected:' + fileObject.path)
|
|
|
|
} */
|
2019-02-24 22:11:26 +00:00
|
|
|
cache[fileObject.path] = fileObject;
|
2017-02-28 22:40:13 +00:00
|
|
|
}
|
2019-02-24 22:11:26 +00:00
|
|
|
return fileArray;
|
|
|
|
};
|
2017-07-30 20:00:20 +00:00
|
|
|
|
2019-02-24 22:14:47 +00:00
|
|
|
export const getFileString = (filePathArg: string) => {
|
2017-07-30 20:00:20 +00:00
|
|
|
if (cache[filePathArg]) {
|
2019-02-24 22:11:26 +00:00
|
|
|
return cache[filePathArg].contents.toString();
|
2017-07-30 20:00:20 +00:00
|
|
|
}
|
2019-02-24 22:14:47 +00:00
|
|
|
};
|