smartinject/ts/index.ts

31 lines
780 B
TypeScript
Raw Normal View History

2019-02-24 22:11:26 +00:00
import * as through2 from 'through2';
import { cache } from './injection';
import { Transform } from 'stream'; // needed for types
2017-02-28 22:40:13 +00:00
2019-02-24 22:11:26 +00:00
export let gulpPipe = function() {
return through2.obj(function(file, enc, cb) {
cache[file.path] = file;
return cb(null, file);
});
};
2017-02-28 22:40:13 +00:00
export interface fileObject {
2019-02-24 22:11:26 +00:00
path: string;
contents: Buffer;
2017-02-28 22:40:13 +00:00
}
export let injectFileArray = async (fileArray: fileObject[]) => {
for (let 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
export let getFileString = (filePathArg: string) => {
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:11:26 +00:00
};