Compare commits

...

5 Commits

Author SHA1 Message Date
4362e94a88 4.0.5 2016-06-24 03:36:55 +02:00
fea9675b2a improve memory.toFs(Sync) 2016-06-24 03:36:51 +02:00
4522907af3 update README 2016-06-23 19:40:37 +02:00
163eb5a70c 4.0.4 2016-06-23 19:02:39 +02:00
fa5371a6bd update metadata 2016-06-23 19:02:34 +02:00
10 changed files with 157 additions and 163 deletions

View File

@ -2,13 +2,12 @@
make files easily accessible for processing in javascript. make files easily accessible for processing in javascript.
## Status ## Status
[![Build Status](https://travis-ci.org/pushrocks/smartfile.svg?branch=master)](https://travis-ci.org/pushrocks/smartfile) [![build status](https://gitlab.com/pushrocks/smartfile/badges/master/build.svg)](https://gitlab.com/pushrocks/smartfile/commits/master)
[![Build status](https://ci.appveyor.com/api/projects/status/xefmtetv7bxupfby/branch/master?svg=true)](https://ci.appveyor.com/project/philkunz/smartfile/branch/master)
[![Dependency Status](https://david-dm.org/pushrocks/smartfile.svg)](https://david-dm.org/pushrocks/smartfile) [![Dependency Status](https://david-dm.org/pushrocks/smartfile.svg)](https://david-dm.org/pushrocks/smartfile)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartfile/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartfile/master/dependencies/npm) [![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartfile/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartfile/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartfile/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartfile) [![bitHound Code](https://www.bithound.io/github/pushrocks/smartfile/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartfile)
[![codecov.io](https://codecov.io/github/pushrocks/smartfile/coverage.svg?branch=master)](https://codecov.io/github/pushrocks/smartfile?branch=master) [![codecov.io](https://codecov.io/github/pushrocks/smartfile/coverage.svg?branch=master)](https://codecov.io/github/pushrocks/smartfile?branch=master)
## Supported file types: ## Usage
* .yml .yaml smartfile is an approach of being one tool to handle files in diverse environments.
* .json It can fetch files from remote locations, work with local disks and do pure memory operations.

View File

@ -1,4 +1,24 @@
import "typings-global"; import "typings-global";
/**
*
* @param filePath
* @returns {boolean}
*/
export declare let fileExistsSync: (filePath: any) => boolean;
/**
*
* @param filePath
* @returns {any}
*/
export declare let fileExists: (filePath: any) => any;
/**
* Checks if given path points to an existing directory
*/
export declare let isDirectory: (pathArg: any) => boolean;
/**
* Checks if a given path points to an existing file
*/
export declare let isFile: (pathArg: any) => boolean;
/** /**
* copies a file from A to B on the local disk * copies a file from A to B on the local disk
*/ */
@ -15,10 +35,6 @@ export declare let remove: (pathArg: string) => any;
* removes a file SYNCHRONOUSLY from local disk * removes a file SYNCHRONOUSLY from local disk
*/ */
export declare let removeSync: (pathArg: string) => boolean; export declare let removeSync: (pathArg: string) => boolean;
export declare let toFS: (options: {
from: string;
toPath: string;
}, cb?: any) => void;
/** /**
* *
* @param filePathArg * @param filePathArg
@ -60,17 +76,3 @@ export declare let listFolders: (pathArg: string) => any;
* lists Folders SYNCHRONOUSLY in a directory on local disk * lists Folders SYNCHRONOUSLY in a directory on local disk
*/ */
export declare let listFoldersSync: (pathArg: any) => any; export declare let listFoldersSync: (pathArg: any) => any;
/**
*
* @param filePath
* @returns {boolean}
*/
export declare let fileExistsSync: (filePath: any) => boolean;
/**
*
* @param filePath
* @returns {any}
*/
export declare let fileExists: (filePath: any) => any;
export declare let isDirectory: (pathArg: any) => boolean;
export declare let isFile: (pathArg: any) => boolean;

82
dist/smartfile.fs.js vendored

File diff suppressed because one or more lines are too long

View File

@ -45,11 +45,5 @@ export declare let toStringSync: (fileArg: plugins.vinyl) => string;
* @param fileNameArg * @param fileNameArg
* @param fileBaseArg * @param fileBaseArg
*/ */
export declare let toFs: (fileArg: any, optionsArg: { export declare let toFs: (fileContentArg: string | plugins.vinyl, filePathArg: any) => any;
fileName: string; export declare let toFsSync: (fileArg: any, filePathArg: string) => void;
filePath: string;
}) => any;
export declare let toFsSync: (fileArg: any, optionsArg: {
fileName: string;
filePath: string;
}) => void;

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "smartfile", "name": "smartfile",
"version": "4.0.3", "version": "4.0.5",
"description": "offers smart ways to work with files in nodejs", "description": "offers smart ways to work with files in nodejs",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
@ -13,7 +13,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/pushrocks/smartfile.git" "url": "https://gitlab.com/pushrocks/smartfile.git"
}, },
"keywords": [ "keywords": [
"filesystem", "filesystem",
@ -22,9 +22,9 @@
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)", "author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/pushrocks/smartfile/issues" "url": "https://gitlab.com/pushrocks/smartfile/issues"
}, },
"homepage": "https://github.com/pushrocks/smartfile", "homepage": "https://gitlab.com/pushrocks/smartfile",
"dependencies": { "dependencies": {
"beautylog": "^5.0.12", "beautylog": "^5.0.12",
"fs-extra": "^0.30.0", "fs-extra": "^0.30.0",

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,7 @@ import * as smartfile from "../dist/index";
let beautylog = require("beautylog"); let beautylog = require("beautylog");
let gulp = require("gulp"); let gulp = require("gulp");
let gFunction = require("gulp-function"); let gFunction = require("gulp-function");
import path = require("path");
import should = require("should"); import should = require("should");
let vinyl = require("vinyl"); let vinyl = require("vinyl");
@ -153,10 +154,7 @@ describe("smartfile".yellow,function(){
let localString = "myString"; let localString = "myString";
smartfile.memory.toFs( smartfile.memory.toFs(
localString, localString,
{ path.join(process.cwd(),"./test/temp/testMemToFs.txt")
fileName:"./test/temp/testMemToFs.txt",
filePath:process.cwd()
}
).then(done); ).then(done);
}); });
}); });
@ -164,10 +162,8 @@ describe("smartfile".yellow,function(){
it("should write a file to disk and return true if successfull",function(){ it("should write a file to disk and return true if successfull",function(){
let localString = "myString"; let localString = "myString";
smartfile.memory.toFsSync( smartfile.memory.toFsSync(
localString,{ localString,
fileName:"./test/temp/testMemToFsSync.txt", path.join(process.cwd(),"./test/temp/testMemToFsSync.txt")
filePath:process.cwd()
}
); );
}); });
}); });

View File

@ -3,6 +3,54 @@ import "typings-global";
import plugins = require("./smartfile.plugins"); import plugins = require("./smartfile.plugins");
import SmartfileInterpreter = require("./smartfile.interpreter"); import SmartfileInterpreter = require("./smartfile.interpreter");
/*===============================================================
============================ Checks =============================
===============================================================*/
/**
*
* @param filePath
* @returns {boolean}
*/
export let fileExistsSync = function(filePath):boolean {
let fileExistsBool:boolean = false;
try {
plugins.fs.readFileSync(filePath);
fileExistsBool = true
}
catch(err){
fileExistsBool = false;
}
return fileExistsBool;
};
/**
*
* @param filePath
* @returns {any}
*/
export let fileExists = function(filePath){
let done = plugins.q.defer();
plugins.fs.access(filePath, plugins.fs.R_OK, function (err) {
err ? done.reject() : done.resolve();
});
return done.promise;
};
/**
* Checks if given path points to an existing directory
*/
export let isDirectory = function(pathArg):boolean{
return plugins.fs.statSync(pathArg).isDirectory();
};
/**
* Checks if a given path points to an existing file
*/
export let isFile = function(pathArg):boolean{
return plugins.fs.statSync(pathArg).isFile();
};
/*=============================================================== /*===============================================================
============================ FS ACTIONS ========================= ============================ FS ACTIONS =========================
===============================================================*/ ===============================================================*/
@ -50,11 +98,6 @@ export let removeSync = function(pathArg:string):boolean{
============================ Write/Read ========================= ============================ Write/Read =========================
===============================================================*/ ===============================================================*/
export let toFS = function(options:{from:string,toPath:string}, cb=undefined){
};
/** /**
* *
* @param filePathArg * @param filePathArg
@ -132,41 +175,3 @@ export let listFoldersSync = function(pathArg){
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory(); return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
}); });
}; };
/**
*
* @param filePath
* @returns {boolean}
*/
export let fileExistsSync = function(filePath):boolean {
let fileExistsBool:boolean = false;
try {
plugins.fs.readFileSync(filePath);
fileExistsBool = true
}
catch(err){
fileExistsBool = false;
}
return fileExistsBool;
};
/**
*
* @param filePath
* @returns {any}
*/
export let fileExists = function(filePath){
let done = plugins.q.defer();
plugins.fs.access(filePath, plugins.fs.R_OK, function (err) {
err ? done.reject() : done.resolve();
});
return done.promise;
};
export let isDirectory = function(pathArg):boolean{
return plugins.fs.statSync(pathArg).isDirectory();
};
export let isFile = function(pathArg):boolean{
return plugins.fs.statSync(pathArg).isFile();
};

View File

@ -2,6 +2,7 @@ import "typings-global";
import plugins = require("./smartfile.plugins"); import plugins = require("./smartfile.plugins");
import SmartfileInterpreter = require("./smartfile.interpreter"); import SmartfileInterpreter = require("./smartfile.interpreter");
import vinyl = require("vinyl");
let Readable = require("stream").Readable; let Readable = require("stream").Readable;
/** /**
* allows you to create a gulp stream * allows you to create a gulp stream
@ -96,33 +97,31 @@ export let toStringSync = function(fileArg:plugins.vinyl){
* @param fileNameArg * @param fileNameArg
* @param fileBaseArg * @param fileBaseArg
*/ */
export let toFs = function(fileArg,optionsArg:{fileName:string,filePath:string}){ export let toFs = function(fileContentArg:string|vinyl,filePathArg){
let done = plugins.q.defer(); let done = plugins.q.defer();
//function checks to abort if needed //function checks to abort if needed
if (!fileArg || !optionsArg || !(typeof optionsArg.fileName === "string")) if (!fileContentArg || !filePathArg) throw new Error("expected valid arguments");
throw new Error("expected a valid arguments");
if (!(typeof optionsArg.filePath === "string")) optionsArg.filePath = "/";
let filePath:string = plugins.path.join(optionsArg.filePath,optionsArg.fileName); // prepare actual write action
let fileString:string; let fileString:string;
if (fileArg instanceof plugins.vinyl){ let filePath:string = filePathArg;
fileString = toStringSync(fileArg); if (fileContentArg instanceof plugins.vinyl){
} else if (typeof fileArg === "string") { fileString = toStringSync(fileContentArg);
fileString = fileArg; } else if (typeof fileContentArg === "string") {
fileString = fileContentArg;
} }
plugins.fs.writeFile(filePath,fileString,"utf8",done.resolve); plugins.fs.writeFile(filePath,fileString,"utf8",done.resolve);
return done.promise; return done.promise;
}; };
export let toFsSync = function(fileArg,optionsArg:{fileName:string,filePath:string}){ export let toFsSync = function(fileArg,filePathArg:string){
//function checks to abort if needed //function checks to abort if needed
if (!fileArg || !optionsArg || !(typeof optionsArg.fileName === "string")) if (!fileArg || !filePathArg) throw new Error("expected a valid arguments");
throw new Error("expected a valid arguments");
if (!(typeof optionsArg.filePath === "string")) optionsArg.filePath = "/";
let filePath = plugins.path.join(optionsArg.filePath,optionsArg.fileName); // prepare actual write action
let fileString:string; let fileString:string;
let filePath:string = filePathArg;
if (fileArg instanceof plugins.vinyl){ if (fileArg instanceof plugins.vinyl){
fileString = toStringSync(fileArg); fileString = toStringSync(fileArg);