now has working memory module
This commit is contained in:
parent
581b9e21d3
commit
c60eac7787
53
dist/smartfile.memory.js
vendored
53
dist/smartfile.memory.js
vendored
File diff suppressed because one or more lines are too long
@ -1,4 +1,5 @@
|
||||
{
|
||||
"mode":"default",
|
||||
"codecov":true
|
||||
"codecov":true,
|
||||
"coverageTreshold":80
|
||||
}
|
62
test/test.js
62
test/test.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
74
test/test.ts
74
test/test.ts
@ -1,9 +1,10 @@
|
||||
/// <reference path="../ts/typings/main.d.ts" />
|
||||
let smartfile = require("../dist/index.js");
|
||||
let beautylog = require("beautylog");
|
||||
let should = require("should");
|
||||
let vinyl = require("vinyl");
|
||||
let gulp = require("gulp");
|
||||
let gFunction = require("gulp-function");
|
||||
import should = require("should");
|
||||
let vinyl = require("vinyl");
|
||||
|
||||
describe("smartfile".yellow,function(){
|
||||
describe(".checks".yellow,function(){
|
||||
@ -21,6 +22,8 @@ describe("smartfile".yellow,function(){
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
describe(".fsaction".yellow,function(){
|
||||
describe(".copy()".yellow,function(){
|
||||
it("should copy a directory",function(){
|
||||
@ -38,10 +41,12 @@ describe("smartfile".yellow,function(){
|
||||
|
||||
});
|
||||
it("should remove single files",function(){
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe(".local".yellow,function(){
|
||||
describe("toGulpStreamSync() and toGulpDestSync",function(){
|
||||
it("should produce a gulp stream",function(done){
|
||||
@ -83,6 +88,69 @@ describe("smartfile".yellow,function(){
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe(".memory",function(){
|
||||
describe(".toGulpStream()",function(){
|
||||
it("should produce a valid gulp stream",function(){
|
||||
let localArray = ["test1","test2","test3"];
|
||||
smartfile.memory.toGulpStream(localArray)
|
||||
.pipe(gulp.dest("./test/temp/"));
|
||||
});
|
||||
});
|
||||
describe("toVinylFileSync()",function(){
|
||||
it("should produce a vinylFile",function(){
|
||||
let localString = "myString";
|
||||
let localOptions = {filename:"vinylfile2",base:"/someDir"};
|
||||
(smartfile.memory.toVinylFileSync(localString,localOptions) instanceof vinyl).should.be.true();
|
||||
});
|
||||
});
|
||||
describe("toVinylArraySync()",function(){
|
||||
it("should produce a an array of vinylfiles",function(){
|
||||
let localStringArray = ["string1","string2","string3"];
|
||||
let localOptions = {filename:"vinylfile2",base:"/someDir"};
|
||||
let testResult = smartfile.memory.toVinylArraySync(localStringArray,localOptions);
|
||||
testResult.should.be.Array();
|
||||
(testResult.length === 3).should.be.true();
|
||||
for (let myKey in testResult){
|
||||
(testResult[myKey] instanceof vinyl).should.be.true();
|
||||
}
|
||||
});
|
||||
});
|
||||
describe("toStringSync()",function(){
|
||||
it("should produce a String from vinyl file",function(){
|
||||
let localString = smartfile.memory.toStringSync(new vinyl({
|
||||
base:"/",
|
||||
path:"/test.txt",
|
||||
contents: new Buffer("myString")
|
||||
}));
|
||||
localString.should.equal("myString");
|
||||
});
|
||||
});
|
||||
describe("toFs()",function(){
|
||||
it("should write a file to disk and return a promise",function(done){
|
||||
let localString = "myString";
|
||||
smartfile.memory.toFs(
|
||||
localString,
|
||||
{
|
||||
fileName:"./test/temp/testMemToFs.txt",
|
||||
filePath:process.cwd()
|
||||
}
|
||||
).then(done);
|
||||
});
|
||||
});
|
||||
describe("toFsSync()",function(){
|
||||
it("should write a file to disk and return true if successfull",function(){
|
||||
let localString = "myString";
|
||||
smartfile.memory.toFsSync(
|
||||
localString,{
|
||||
fileName:"./test/temp/testMemToFsSync.txt",
|
||||
filePath:process.cwd()
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe(".remote",function(){
|
||||
describe("toGulpStreamSync()",function(){
|
||||
it("should produce a gulp stream",function(done){
|
||||
|
@ -8,7 +8,7 @@ let Readable = require("stream").Readable;
|
||||
* @returns stream.Readable
|
||||
* @TODO: make it async;
|
||||
*/
|
||||
export let toGulpStream = function(fileArg:string|string[]|plugins.vinyl|plugins.vinyl[],baseArg?:string){
|
||||
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
|
||||
@ -25,7 +25,7 @@ export let toGulpStream = function(fileArg:string|string[]|plugins.vinyl|plugins
|
||||
let file = fileArray[fileIndexArg];
|
||||
file instanceof plugins.vinyl ?
|
||||
vinylFileArray.push(file) :
|
||||
vinylFileArray.push(toVinylFileSync(file,{filename:fileIndexArg,base:"/"}));
|
||||
vinylFileArray.push(toVinylFileSync(file,{filename:fileIndexArg,base:baseArg}));
|
||||
};
|
||||
|
||||
let stream = new Readable({ objectMode: true });
|
||||
@ -42,7 +42,7 @@ export let toGulpStream = function(fileArg:string|string[]|plugins.vinyl|plugins
|
||||
* @param fileArg
|
||||
* @param optionsArg
|
||||
*/
|
||||
export let toVinylFileSync = function(fileArg:string,optionsArg?:{filename:string,base:string,relPath?:string}){
|
||||
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 = "/";
|
||||
@ -60,7 +60,7 @@ export let toVinylFileSync = function(fileArg:string,optionsArg?:{filename:strin
|
||||
* @param arrayArg
|
||||
* @param optionsArg
|
||||
*/
|
||||
export let toVinylArraySync = function(arrayArg:string[],optionsArg?:{filename:string,base:string,relPath?:string}){
|
||||
export let toVinylArraySync = function(arrayArg:string[],optionsArg?:{filename?:string,base?:string,relPath?:string}){
|
||||
let vinylArray = [];
|
||||
for(let stringIndexArg in arrayArg){
|
||||
let myString = arrayArg[stringIndexArg];
|
||||
@ -69,14 +69,53 @@ export let toVinylArraySync = function(arrayArg:string[],optionsArg?:{filename:s
|
||||
return vinylArray;
|
||||
};
|
||||
|
||||
/**
|
||||
* takes a vinylFile object and converts it to String
|
||||
*/
|
||||
export let toStringSync = function(fileArg:plugins.vinyl){
|
||||
return fileArg.contents.toString("utf8");
|
||||
};
|
||||
|
||||
export let toFs = function(fileArg:string|plugins.vinyl,fileNameArg?:string,fileBaseArg?:string){
|
||||
|
||||
/**
|
||||
* writes string or vinyl file to disk.
|
||||
* @param fileArg
|
||||
* @param fileNameArg
|
||||
* @param fileBaseArg
|
||||
*/
|
||||
export let toFs = function(fileArg,optionsArg:{fileName:string,filePath:string}){
|
||||
let done = plugins.q.defer();
|
||||
|
||||
//function checks to abort if needed
|
||||
if (!fileArg || !optionsArg || !(typeof optionsArg.fileName === "string"))
|
||||
throw new Error("expected a valid arguments");
|
||||
if (!(typeof optionsArg.filePath === "string")) optionsArg.filePath = "/";
|
||||
|
||||
let filePath:string = plugins.path.join(optionsArg.filePath,optionsArg.fileName);
|
||||
let fileString:string;
|
||||
if (fileArg instanceof plugins.vinyl){
|
||||
|
||||
fileString = toStringSync(fileArg);
|
||||
} else if (typeof fileArg === "string") {
|
||||
fileString = fileArg;
|
||||
}
|
||||
plugins.fs.writeFile(filePath,fileString,"utf8",done.resolve);
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
export let toFsSync = function(){
|
||||
|
||||
export let toFsSync = function(fileArg,optionsArg:{fileName:string,filePath:string}){
|
||||
//function checks to abort if needed
|
||||
if (!fileArg || !optionsArg || !(typeof optionsArg.fileName === "string"))
|
||||
throw new Error("expected a valid arguments");
|
||||
if (!(typeof optionsArg.filePath === "string")) optionsArg.filePath = "/";
|
||||
|
||||
let filePath = plugins.path.join(optionsArg.filePath,optionsArg.fileName);
|
||||
let fileString:string;
|
||||
|
||||
if (fileArg instanceof plugins.vinyl){
|
||||
fileString = toStringSync(fileArg);
|
||||
} else if (typeof fileArg === "string") {
|
||||
fileString = fileArg;
|
||||
}
|
||||
plugins.fs.writeFileSync(filePath,fileString,"utf8");
|
||||
};
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts",
|
||||
"mocha": "github:Bartvds/tsd-deftools/typings/DefinitelyTyped/mocha/mocha.d.ts",
|
||||
"node": "registry:dt/node",
|
||||
"should": "registry:dt/should",
|
||||
"vinyl": "registry:dt/vinyl"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user