handle gulp in seperate module
This commit is contained in:
parent
7eed9dd6d3
commit
ed01ebeee8
8
dist/smartfile.memory.d.ts
vendored
8
dist/smartfile.memory.d.ts
vendored
@ -5,14 +5,6 @@ export interface IVinylFile {
|
||||
base: string;
|
||||
path: string;
|
||||
}
|
||||
/**
|
||||
* allows you to create a gulp stream
|
||||
* from String, from an Array of Strings, from Vinyl File, from an Array of VinylFiles
|
||||
* @param fileArg
|
||||
* @returns stream.Readable
|
||||
* @TODO: make it async;
|
||||
*/
|
||||
export declare let toGulpStream: (fileArg: string | string[] | IVinylFile | IVinylFile[], baseArg?: string) => any;
|
||||
/**
|
||||
* converts file to Object
|
||||
* @param fileStringArg
|
||||
|
38
dist/smartfile.memory.js
vendored
38
dist/smartfile.memory.js
vendored
File diff suppressed because one or more lines are too long
11
test/test.ts
11
test/test.ts
@ -5,6 +5,10 @@ import { expect, tap } from 'tapbundle'
|
||||
|
||||
import * as vinyl from 'vinyl'
|
||||
|
||||
// ---------------------------
|
||||
// smartfile.fs
|
||||
// ---------------------------
|
||||
|
||||
tap.test('.fs.fileExistsSync -> should return an accurate boolean', async () => {
|
||||
expect(smartfile.fs.fileExistsSync('./test/mytest.json')).to.be.true
|
||||
expect(smartfile.fs.fileExistsSync('./test/notthere.json')).be.false
|
||||
@ -91,7 +95,7 @@ tap.test('smartfile.fs.removeManySync -> should remove and array of single files
|
||||
})
|
||||
|
||||
// ---------------------------
|
||||
// .interpreter
|
||||
// smartfile.interpreter
|
||||
// ---------------------------
|
||||
|
||||
tap.test('.interpreter.filetype() -> should get the file type from a string', async () => {
|
||||
@ -125,11 +129,6 @@ tap.test('.fs.toVinylSync -> should read an ' + '.json OR .yaml' + ' file to an
|
||||
expect(vinyl.isVinyl(testData)).to.be.true
|
||||
})
|
||||
|
||||
tap.test('.memory.toGulpStream() -> should produce a valid gulp stream', async () => {
|
||||
let localArray = [ 'test1', 'test2', 'test3' ]
|
||||
smartfile.memory.toGulpStream(localArray)
|
||||
})
|
||||
|
||||
tap.test('.memory.toVinylFileSync() -> should produce a vinylFile', async () => {
|
||||
let localString = 'myString'
|
||||
let localOptions = { filename: 'vinylfile2', base: '/someDir' }
|
||||
|
@ -10,44 +10,6 @@ export interface IVinylFile {
|
||||
path: string,
|
||||
}
|
||||
|
||||
let Readable = require('stream').Readable
|
||||
|
||||
/**
|
||||
* allows you to create a gulp stream
|
||||
* from String, from an Array of Strings, from Vinyl File, from an Array of VinylFiles
|
||||
* @param fileArg
|
||||
* @returns stream.Readable
|
||||
* @TODO: make it async;
|
||||
*/
|
||||
export let toGulpStream = function(fileArg: string|string[]|IVinylFile|IVinylFile[],baseArg: string = '/'){
|
||||
let fileArray = []
|
||||
|
||||
if (typeof fileArg === 'string' || vinyl.isVinyl(fileArg)) { // make sure we work with an array later on
|
||||
fileArray.push(fileArg)
|
||||
} else if (Array.isArray(fileArg)) {
|
||||
fileArray = fileArg
|
||||
} else {
|
||||
throw new Error('fileArg has unknown format')
|
||||
}
|
||||
|
||||
let vinylFileArray: IVinylFile[] = [] // we want to have an array of vinylFiles
|
||||
|
||||
for (let fileIndexArg in fileArray) { // convert fileArray in vinylArray
|
||||
let file = fileArray[fileIndexArg]
|
||||
file instanceof vinyl ?
|
||||
vinylFileArray.push(file) :
|
||||
vinylFileArray.push(toVinylFileSync(file,{filename: fileIndexArg,base: baseArg}))
|
||||
};
|
||||
|
||||
let stream = new Readable({ objectMode: true })
|
||||
for (let vinylFileIndexArg in vinylFileArray) {
|
||||
let vinylFile = vinylFileArray[vinylFileIndexArg]
|
||||
stream.push(vinylFile)
|
||||
};
|
||||
stream.push(null) // signal end of stream;
|
||||
return stream
|
||||
}
|
||||
|
||||
/**
|
||||
* converts file to Object
|
||||
* @param fileStringArg
|
||||
|
Loading…
Reference in New Issue
Block a user