diff --git a/.travis.yml b/.travis.yml
index 1e4f3b2..94324d5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,9 @@
language: node_js
node_js:
-- '4.1'
-before_install:
-- npm install -g tsd
+- '4.2.4'
deploy:
provider: npm
- email: npm@smart-coordination.com
+ email: npm@lossless.digital
api_key:
secure: 3RdzAcS9d6sLJs3tHM2uCVU2wV2NsKiLiYWue98DevgijIqTFDHtYuoP29p7fbB4SV87JRbTK1y41QM2u/CCjnbB+mrAUg/Pn08dTibmzi9liom67sLczIPD4eZeMznXPRaddESQdzqrtQfc/6P+1JQO7XWexLNebgYtMrUzYcOrHPWf/Uktk2cKiYfrO8piSR+HOFh2rzC5HjVZ/7fKDIa9bqTlBETkNc7s2NgB++jKRF9LNMVGI/9EmxjBzSSE1juOz26Ahp4+/+P3Lc5LngnTFOYsPoW5iWNY+AQltZxhu9K+rrtfn90rmQDnO7RCGO5yZgMS2+0UjJedwV+4ancU3nzoNmiuoIL7DjQ7NQlt0QKMmIqZuBFBc3tdxqotxNoJDk8/Ui0yfHWzJz0Fd22OI+VdTWNH1y5Vyywsql6wwkl2+Da1WhZf/Mn2gPgLPI0lssPTIl/u3Bey+167tZ3HvX0yqlvPO/JbqK02+5VrRBaV67vT00DG+dh4nnwqcX14Umx2a3JHt3tSGkDnDKpsLbvqjhPhkMRsCIloju+wMnyKjtScMZW+2FeO2n4PgbjNhF+5SG8pDmTS8p0Vy7iohUOiGIJty7K/1r6sQ1FNluhO5Ol3mBDs6wjg6S5QCSNL9eylpV52FV0UX4cRCijmzso+n48I2BbSwjghTB8=
on:
diff --git a/index.d.ts b/index.d.ts
index b2bd66e..68f542c 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -4,12 +4,16 @@ declare module SmartfilePlugins {
beautylog: any;
fs: any;
path: any;
+ q: any;
vinyl: any;
vinylFile: any;
yaml: any;
requireReload: any;
};
}
+declare module SmartfileCheck {
+ var init: (objectArg: any) => void;
+}
declare module SmartfileSimple {
var init: (objectArg: any) => void;
}
@@ -23,6 +27,7 @@ declare var plugins: {
beautylog: any;
fs: any;
path: any;
+ q: any;
vinyl: any;
vinylFile: any;
yaml: any;
diff --git a/index.js b/index.js
index c99aa3e..b7ffd98 100644
--- a/index.js
+++ b/index.js
@@ -8,6 +8,7 @@ var 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"),
@@ -17,6 +18,33 @@ var SmartfilePlugins;
};
})(SmartfilePlugins || (SmartfilePlugins = {}));
///
+var SmartfileCheck;
+(function (SmartfileCheck) {
+ var checks = {
+ fileExistsSync: function (filePath) {
+ var fileExistsBool = 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;
+ }
+ };
+ SmartfileCheck.init = function (objectArg) {
+ objectArg.checks = checks;
+ };
+})(SmartfileCheck || (SmartfileCheck = {}));
+///
var SmartfileSimple;
(function (SmartfileSimple) {
/**
@@ -82,11 +110,13 @@ var SmartfileRequire;
})(SmartfileRequire || (SmartfileRequire = {}));
///
///
+///
///
///
///
var plugins = SmartfilePlugins.init();
var smartfile = {};
+SmartfileCheck.init(smartfile);
SmartfileSimple.init(smartfile);
SmartfileVinyl.init(smartfile);
SmartfileRequire.init(smartfile);
diff --git a/package.json b/package.json
index 9191b2e..453ee6a 100644
--- a/package.json
+++ b/package.json
@@ -28,6 +28,7 @@
"beautylog": "2.0.6",
"fs-extra": "0.26.5",
"js-yaml": "3.5.2",
+ "q": "^1.4.1",
"require-reload": "0.2.2",
"vinyl": "1.1.1",
"vinyl-file": "2.0.0"
diff --git a/test/test.js b/test/test.js
index 0b9da88..4ca1669 100644
--- a/test/test.js
+++ b/test/test.js
@@ -27,4 +27,19 @@ describe("smartfile", function () {
(vinyl.isVinyl(testData)).should.be.true();
});
});
+ 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();
+ });
+ });
+ });
});
diff --git a/ts/index.ts b/ts/index.ts
index e58e2c2..7cc04ea 100644
--- a/ts/index.ts
+++ b/ts/index.ts
@@ -1,5 +1,6 @@
///
///
+///
///
///
///
@@ -7,6 +8,7 @@ var plugins = SmartfilePlugins.init();
var smartfile:any = {};
+SmartfileCheck.init(smartfile);
SmartfileSimple.init(smartfile);
SmartfileVinyl.init(smartfile);
SmartfileRequire.init(smartfile);
diff --git a/ts/smartfile.check.ts b/ts/smartfile.check.ts
new file mode 100644
index 0000000..342a6f6
--- /dev/null
+++ b/ts/smartfile.check.ts
@@ -0,0 +1,26 @@
+///
+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;
+ }
+}
\ No newline at end of file
diff --git a/ts/smartfile.plugins.ts b/ts/smartfile.plugins.ts
index 846575e..5c3cbd9 100644
--- a/ts/smartfile.plugins.ts
+++ b/ts/smartfile.plugins.ts
@@ -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"),
diff --git a/ts/test.ts b/ts/test.ts
index d7b6eb0..7b6d091 100644
--- a/ts/test.ts
+++ b/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();
+ });
+ })
+ });
});
diff --git a/ts/typings.json b/ts/typings.json
index ce4c01d..0e9ea42 100644
--- a/ts/typings.json
+++ b/ts/typings.json
@@ -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"
}