Compare commits

..

7 Commits

Author SHA1 Message Date
38f10e0d04 4.0.8 2016-06-28 10:00:03 +02:00
2e2b8351f8 fix regex filter 2016-06-28 09:59:59 +02:00
8c386ee91c remove tyings.json 2016-06-28 08:48:47 +02:00
9828689f31 4.0.7 2016-06-28 08:40:25 +02:00
8205da5284 add folder lists array and make them filterable through regex 2016-06-28 08:40:22 +02:00
2fc132ab20 4.0.6 2016-06-28 06:57:54 +02:00
e948d08f2e add smartfile.fs.ensureDir 2016-06-28 06:57:51 +02:00
8 changed files with 270 additions and 20 deletions

View File

@ -19,6 +19,14 @@ export declare let isDirectory: (pathArg: any) => boolean;
* Checks if a given path points to an existing file * Checks if a given path points to an existing file
*/ */
export declare let isFile: (pathArg: any) => boolean; export declare let isFile: (pathArg: any) => boolean;
/**
* ensures that a directory is in place
*/
export declare let ensureDir: (dirPathArg: string) => any;
/**
* ensures that a directory is in place
*/
export declare let ensureDirSync: (dirPathArg: string) => void;
/** /**
* copies a file from A to B on the local disk * copies a file from A to B on the local disk
*/ */
@ -70,9 +78,31 @@ export declare let toVinylSync: (filePathArg: any, options?: {}) => any;
export declare let requireReload: (path: string) => any; export declare let requireReload: (path: string) => any;
/** /**
* lists Folders in a directory on local disk * lists Folders in a directory on local disk
* @returns Promise
*/ */
export declare let listFolders: (pathArg: string) => any; export declare let listFolders: (pathArg: string, regexFilter?: RegExp) => any;
/** /**
* lists Folders SYNCHRONOUSLY in a directory on local disk * lists Folders SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/ */
export declare let listFoldersSync: (pathArg: any) => any; export declare let listFoldersSync: (pathArg: string, regexFilter?: RegExp) => string[];
/**
* lists Files in a directory on local disk
* @returns Promise
*/
export declare let listFiles: (pathArg: string, regexFilter?: RegExp) => any;
/**
* lists Files SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export declare let listFilesSync: (pathArg: string, regexFilter?: RegExp) => string[];
/**
* lists all items (folders AND files) in a directory on local disk
* @returns Promise
*/
export declare let listAllItems: (pathArg: string, regexFilter?: RegExp) => any;
/**
* lists all items (folders AND files) SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export declare let listAllItemsSync: (pathArg: string, regexFilter?: RegExp) => string[];

102
dist/smartfile.fs.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
{ {
"mode":"default", "mode":"default",
"codecov":true, "codecov":true,
"coverageTreshold":80 "coverageTreshold":70
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "smartfile", "name": "smartfile",
"version": "4.0.5", "version": "4.0.8",
"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",

File diff suppressed because one or more lines are too long

View File

@ -40,6 +40,24 @@ describe("smartfile".yellow,function(){
}); });
}); });
}); });
describe(".listFilesSync()",function(){
it("should get the file type from a string",function(){
smartfile.fs.listFilesSync("./test/").should.containDeep([ "mytest.json"]);
smartfile.fs.listFilesSync("./test/").should.not.containDeep([ "notExistentFile"]);
smartfile.fs.listFilesSync("./test/",/mytest\.json/).should.containDeep([ "mytest.json"]);
smartfile.fs.listFilesSync("./test/",/mytests.json/).should.not.containDeep([ "mytest.json"]);
});
});
describe(".listFiles()",function(){
it("should get the file type from a string",function(done){
smartfile.fs.listFiles("./test/")
.then(function(folderArrayArg){
folderArrayArg.should.containDeep([ "mytest.json"]);
folderArrayArg.should.not.containDeep([ "notExistentFile"]);
done();
});
});
});
describe(".copy()".yellow,function(){ describe(".copy()".yellow,function(){
it("should copy a directory",function(){ it("should copy a directory",function(){
smartfile.fs.copy("./test/testfolder/","./test/temp/") smartfile.fs.copy("./test/testfolder/","./test/temp/")

View File

@ -55,6 +55,22 @@ export let isFile = function(pathArg):boolean{
============================ FS ACTIONS ========================= ============================ FS ACTIONS =========================
===============================================================*/ ===============================================================*/
/**
* ensures that a directory is in place
*/
export let ensureDir = (dirPathArg:string) => {
let done = plugins.q.defer();
plugins.fs.ensureDir(dirPathArg,done.resolve);
return done.promise;
}
/**
* ensures that a directory is in place
*/
export let ensureDirSync = (dirPathArg:string) => {
plugins.fs.ensureDirSync(dirPathArg);
}
/** /**
* copies a file from A to B on the local disk * copies a file from A to B on the local disk
*/ */
@ -157,21 +173,103 @@ export let requireReload = function(path:string){
/** /**
* lists Folders in a directory on local disk * lists Folders in a directory on local disk
* @returns Promise
*/ */
export let listFolders = function(pathArg:string){ export let listFolders = function(pathArg:string,regexFilter?:RegExp){
let done = plugins.q.defer(); let done = plugins.q.defer();
let folderArray = plugins.fs.readdirSync(pathArg).filter(function(file) { let folderArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory(); return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
}); });
if(regexFilter){
folderArray = folderArray.filter((fileItem) => {
return regexFilter.test(fileItem);
});
}
done.resolve(folderArray); done.resolve(folderArray);
return done.promise; return done.promise;
}; };
/** /**
* lists Folders SYNCHRONOUSLY in a directory on local disk * lists Folders SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/ */
export let listFoldersSync = function(pathArg){ export let listFoldersSync = function(pathArg:string,regexFilter?:RegExp):string[]{
return plugins.fs.readdirSync(pathArg).filter(function(file) { let folderArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory(); return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
}); });
if(regexFilter){
folderArray = folderArray.filter((fileItem) => {
return regexFilter.test(fileItem);
});
};
return folderArray;
}; };
/**
* lists Files in a directory on local disk
* @returns Promise
*/
export let listFiles = function(pathArg:string, regexFilter?:RegExp){
let done = plugins.q.defer();
let fileArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isFile();
});
if(regexFilter){
fileArray = fileArray.filter((fileItem) => {
return regexFilter.test(fileItem);
});
};
done.resolve(fileArray);
return done.promise;
};
/**
* lists Files SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export let listFilesSync = function(pathArg:string, regexFilter?:RegExp):string[]{
let fileArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isFile();
});
if(regexFilter){
fileArray = fileArray.filter((fileItem) => {
return regexFilter.test(fileItem);
});
};
return fileArray;
};
/**
* lists all items (folders AND files) in a directory on local disk
* @returns Promise
*/
export let listAllItems = function(pathArg:string, regexFilter?:RegExp){
let done = plugins.q.defer();
let allItmesArray = plugins.fs.readdirSync(pathArg);
if(regexFilter){
allItmesArray = allItmesArray.filter((fileItem) => {
return regexFilter.test(fileItem);
});
};
done.resolve(allItmesArray);
return done.promise;
};
/**
* lists all items (folders AND files) SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export let listAllItemsSync = function(pathArg:string, regexFilter?:RegExp):string[]{
let allItmesArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isFile();
});
if(regexFilter){
allItmesArray = allItmesArray.filter((fileItem) => {
return regexFilter.test(fileItem);
});
};
return allItmesArray;
};

View File

@ -1,8 +0,0 @@
{
"globalDependencies": {
"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"
}
}