added checks
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
/// <reference path="./smartfile.plugins.ts" />
|
||||
/// <reference path="./smartfile.check.ts" />
|
||||
/// <reference path="./smartfile.simple.ts" />
|
||||
/// <reference path="./smartfile.vinyl.ts" />
|
||||
/// <reference path="./smartfile.require.ts" />
|
||||
@ -7,6 +8,7 @@ var plugins = SmartfilePlugins.init();
|
||||
|
||||
|
||||
var smartfile:any = {};
|
||||
SmartfileCheck.init(smartfile);
|
||||
SmartfileSimple.init(smartfile);
|
||||
SmartfileVinyl.init(smartfile);
|
||||
SmartfileRequire.init(smartfile);
|
||||
|
26
ts/smartfile.check.ts
Normal file
26
ts/smartfile.check.ts
Normal file
@ -0,0 +1,26 @@
|
||||
/// <reference path="./index.ts" />
|
||||
module SmartfileCheck {
|
||||
var checks = {
|
||||
fileExistsSync: function(filePath):boolean {
|
||||
var fileExistsBool:boolean = false;
|
||||
try {
|
||||
plugins.fs.readFileSync(filePath)
|
||||
fileExistsBool = true
|
||||
}
|
||||
catch(err){
|
||||
fileExistsBool = false;
|
||||
}
|
||||
return fileExistsBool;
|
||||
},
|
||||
fileExists: function(filePath){
|
||||
var done = plugins.q.defer();
|
||||
plugins.fs.access(filePath, plugins.fs.R_OK, function (err) {
|
||||
err ? done.reject() : done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
};
|
||||
export var init = function(objectArg){
|
||||
objectArg.checks = checks;
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ module SmartfilePlugins {
|
||||
beautylog: require("beautylog"),
|
||||
fs: require("fs-extra"),
|
||||
path: require("path"),
|
||||
q: require("q"),
|
||||
vinyl: require("vinyl"),
|
||||
vinylFile: require("vinyl-file"),
|
||||
yaml: require("js-yaml"),
|
||||
|
15
ts/test.ts
15
ts/test.ts
@ -33,4 +33,19 @@ describe("smartfile",function(){
|
||||
|
||||
});
|
||||
});
|
||||
describe(".checks".yellow,function(){
|
||||
describe(".fileExistsSync".yellow,function(){
|
||||
it("should return an accurate boolean",function(){
|
||||
(smartfile.checks.fileExistsSync("./test/mytest.json")).should.be.true();
|
||||
(smartfile.checks.fileExistsSync("./test/notthere.json")).should.be.false();
|
||||
});
|
||||
});
|
||||
describe(".fileExists".yellow,function(){
|
||||
it("should return a working promise",function(){
|
||||
(smartfile.checks.fileExists("./test/mytest.json")).should.be.Promise();
|
||||
(smartfile.checks.fileExists("./test/mytest.json")).should.be.fulfilled();
|
||||
(smartfile.checks.fileExists("./test/notthere.json")).should.not.be.fulfilled();
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"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": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts"
|
||||
}
|
||||
|
Reference in New Issue
Block a user