implemented memory module
This commit is contained in:
@ -5,6 +5,7 @@ import SmartfileChecks = require("./smartfile.checks");
|
||||
import SmartfileFsaction = require("./smartfile.fsaction");
|
||||
import SmartfileGet = require("./smartfile.get");
|
||||
import SmartfileLocal = require("./smartfile.local");
|
||||
import SmartfileMemory = require("./smartfile.memory");
|
||||
import SmartfileRemote = require("./smartfile.remote");
|
||||
|
||||
|
||||
@ -14,6 +15,7 @@ var smartfile:any = {
|
||||
checks: SmartfileChecks,
|
||||
get: SmartfileGet,
|
||||
local: SmartfileLocal,
|
||||
memory: SmartfileMemory,
|
||||
remote: SmartfileRemote,
|
||||
requireReload: SmartfileLocal.requireReload
|
||||
};
|
||||
|
82
ts/smartfile.memory.ts
Normal file
82
ts/smartfile.memory.ts
Normal file
@ -0,0 +1,82 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
|
||||
import plugins = require("./smartfile.plugins");
|
||||
let Readable = require("stream").Readable;
|
||||
/**
|
||||
* allows you to create a gulp stream from filestring
|
||||
* @param fileArg
|
||||
* @returns stream.Readable
|
||||
* @TODO: make it async;
|
||||
*/
|
||||
export let toGulpStream = function(fileArg:string|string[]|plugins.vinyl|plugins.vinyl[],baseArg?:string){
|
||||
let fileArray = [];
|
||||
|
||||
if(typeof fileArg === "string" || fileArg instanceof plugins.vinyl){ // 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:plugins.vinyl[] = []; //we want to have an array of vinylFiles
|
||||
|
||||
for (let fileIndexArg in fileArray){ //convert fileArray in vinylArray
|
||||
let file = fileArray[fileIndexArg];
|
||||
file instanceof plugins.vinyl ?
|
||||
vinylFileArray.push(file) :
|
||||
vinylFileArray.push(toVinylFileSync(file,{filename:fileIndexArg,base:"/"}));
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
/**
|
||||
* takes a string and converts it to vinyl file
|
||||
* @param fileArg
|
||||
* @param optionsArg
|
||||
*/
|
||||
export let toVinylFileSync = function(fileArg:string,optionsArg?:{filename:string,base:string,relPath?:string}){
|
||||
optionsArg? void(0) : optionsArg = {filename: "vinylfile", base: "/"};
|
||||
optionsArg.filename ? void(0) : optionsArg.filename = "vinylfile";
|
||||
optionsArg.base ? void(0) : optionsArg.base = "/";
|
||||
optionsArg.relPath ? void("0") : optionsArg.relPath = "";
|
||||
let vinylFile = new plugins.vinyl({
|
||||
base: optionsArg.base,
|
||||
path: plugins.path.join(optionsArg.base,optionsArg.relPath,optionsArg.filename),
|
||||
contents: new Buffer(fileArg)
|
||||
});
|
||||
return vinylFile;
|
||||
};
|
||||
|
||||
/**
|
||||
* takes a string array and some options and returns a vinylfile array
|
||||
* @param arrayArg
|
||||
* @param optionsArg
|
||||
*/
|
||||
export let toVinylArraySync = function(arrayArg:string[],optionsArg?:{filename:string,base:string,relPath?:string}){
|
||||
let vinylArray = [];
|
||||
for(let stringIndexArg in arrayArg){
|
||||
let myString = arrayArg[stringIndexArg];
|
||||
vinylArray.push(toVinylFileSync(myString,optionsArg));
|
||||
}
|
||||
return vinylArray;
|
||||
};
|
||||
|
||||
|
||||
export let toFs = function(fileArg:string|plugins.vinyl,fileNameArg?:string,fileBaseArg?:string){
|
||||
if (fileArg instanceof plugins.vinyl){
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
export let toFsSync = function(){
|
||||
|
||||
};
|
||||
|
@ -5,9 +5,9 @@ export let gulp = require("gulp");
|
||||
export let g = {
|
||||
remoteSrc: require("gulp-remote-src")
|
||||
};
|
||||
export let path = require("path");
|
||||
export import path = require("path");
|
||||
export let q = require("q");
|
||||
export let vinyl = require("vinyl");
|
||||
export import vinyl = require("vinyl");
|
||||
export let vinylFile = require("vinyl-file");
|
||||
export let yaml = require("js-yaml");
|
||||
export let request = require("request");
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"ambientDependencies": {
|
||||
"browserify": "github:DefinitelyTyped/DefinitelyTyped/browserify/browserify.d.ts",
|
||||
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts",
|
||||
"mocha": "github:Bartvds/tsd-deftools/typings/DefinitelyTyped/mocha/mocha.d.ts",
|
||||
"node": "registry:dt/node#4.0.0+20160311162451"
|
||||
"node": "registry:dt/node",
|
||||
"vinyl": "registry:dt/vinyl"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user