smartinject/ts/index.ts
2019-02-24 23:14:47 +01:00

32 lines
780 B
TypeScript

import * as through2 from 'through2';
import { cache } from './injection';
import { Transform } from 'stream'; // needed for types
export const gulpPipe = () => {
return through2.obj((file, enc, cb) => {
cache[file.path] = file;
return cb(null, file);
});
};
export interface IFileObject {
path: string;
contents: Buffer;
}
export const injectFileArray = async (fileArray: IFileObject[]) => {
for (const fileObject of fileArray) {
/* if (/[yourTestFilenameHere.js]/.test(request)) {
// console.log('injected:' + fileObject.path)
} */
cache[fileObject.path] = fileObject;
}
return fileArray;
};
export const getFileString = (filePathArg: string) => {
if (cache[filePathArg]) {
return cache[filePathArg].contents.toString();
}
};