Compare commits

...

19 Commits

Author SHA1 Message Date
ff2e34696a 4.0.9 2016-07-01 01:38:57 +02:00
23188dfe3f now has fileTree function 2016-07-01 01:37:48 +02:00
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
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
5ff7f8c3ac 4.0.3 2016-06-23 18:42:42 +02:00
0c49bbd4b2 4.0.2 2016-06-23 18:41:52 +02:00
f2e2a22a57 add gitlab-ci.yml 2016-06-23 18:41:45 +02:00
6ae30110f8 4.0.1 2016-06-23 18:39:06 +02:00
7b4626586c rename some actions 2016-06-23 18:39:02 +02:00
16 changed files with 569 additions and 184 deletions

36
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,36 @@
image: hosttoday/ht-docker-node:npmts
stages:
- test
- release
testLEGACY:
stage: test
script:
- npmci test legacy
tags:
- docker
allow_failure: true
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags:
- docker
release:
stage: release
script:
- npmci publish
only:
- tags
tags:
- docker

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,12 +1,48 @@
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;
/**
* 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
*/
export declare let copy: (fromArg: string, toArg: string) => any; export declare let copy: (fromArg: string, toArg: string) => any;
/**
* copies a file SYNCHRONOUSLY from A to B on the local disk
*/
export declare let copySync: (fromArg: string, toArg: string) => boolean; export declare let copySync: (fromArg: string, toArg: string) => boolean;
/**
* removes a file or folder from local disk
*/
export declare let remove: (pathArg: string) => any; export declare let remove: (pathArg: string) => any;
/**
* 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
@ -40,19 +76,34 @@ export declare let toVinylSync: (filePathArg: any, options?: {}) => any;
* @returns {any} * @returns {any}
*/ */
export declare let requireReload: (path: string) => any; export declare let requireReload: (path: string) => any;
export declare let foldersSync: (pathArg: any) => any;
export declare let folders: (pathArg: string) => any;
/** /**
* * lists Folders in a directory on local disk
* @param filePath * @returns Promise
* @returns {boolean}
*/ */
export declare let fileExistsSync: (filePath: any) => boolean; export declare let listFolders: (pathArg: string, regexFilter?: RegExp) => any;
/** /**
* * lists Folders SYNCHRONOUSLY in a directory on local disk
* @param filePath * @returns an array with the folder names as strings
* @returns {any}
*/ */
export declare let fileExists: (filePath: any) => any; export declare let listFoldersSync: (pathArg: string, regexFilter?: RegExp) => string[];
export declare let isDirectory: (pathArg: any) => boolean; /**
export declare let isFile: (pathArg: any) => boolean; * 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[];
export declare let listFileTree: (dirPath: string, miniMatchFilter: string) => any;

201
dist/smartfile.fs.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,4 @@
import "typings-global"; import "typings-global";
import plugins = require("./smartfile.plugins");
/** /**
* allows you to create a gulp stream * allows you to create a gulp stream
* from String, from an Array of Strings, from Vinyl File, from an Array of VinylFiles * from String, from an Array of Strings, from Vinyl File, from an Array of VinylFiles
@ -7,7 +6,7 @@ import plugins = require("./smartfile.plugins");
* @returns stream.Readable * @returns stream.Readable
* @TODO: make it async; * @TODO: make it async;
*/ */
export declare let toGulpStream: (fileArg: string | string[] | plugins.vinyl | plugins.vinyl[], baseArg?: string) => any; export declare let toGulpStream: (fileArg: any, baseArg?: string) => any;
/** /**
* converts file to Object * converts file to Object
* @param fileStringArg * @param fileStringArg
@ -24,7 +23,7 @@ export declare let toVinylFileSync: (fileArg: string, optionsArg?: {
filename?: string; filename?: string;
base?: string; base?: string;
relPath?: string; relPath?: string;
}) => plugins.vinyl; }) => any;
/** /**
* takes a string array and some options and returns a vinylfile array * takes a string array and some options and returns a vinylfile array
* @param arrayArg * @param arrayArg
@ -38,18 +37,12 @@ export declare let toVinylArraySync: (arrayArg: string[], optionsArg?: {
/** /**
* takes a vinylFile object and converts it to String * takes a vinylFile object and converts it to String
*/ */
export declare let toStringSync: (fileArg: plugins.vinyl) => string; export declare let toStringSync: (fileArg: any) => any;
/** /**
* writes string or vinyl file to disk. * writes string or vinyl file to disk.
* @param fileArg * @param fileArg
* @param fileNameArg * @param fileNameArg
* @param fileBaseArg * @param fileBaseArg
*/ */
export declare let toFs: (fileArg: any, optionsArg: { export declare let toFs: (fileContentArg: any, 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,13 +1,14 @@
import "typings-global"; import "typings-global";
export declare let beautylog: any; export import beautylog = require("beautylog");
export declare let fs: any; export declare let fs: any;
export declare let gulp: any; export declare let gulp: any;
export declare let glob: any;
export declare let g: { export declare let g: {
remoteSrc: any; remoteSrc: any;
}; };
export import path = require("path"); export declare let path: any;
export declare let q: any; export declare let q: any;
export import vinyl = require("vinyl"); export declare let vinyl: any;
export declare let vinylFile: any; export declare let vinylFile: any;
export declare let yaml: any; export declare let yaml: any;
export declare let request: any; export declare let request: any;

View File

@ -3,6 +3,7 @@ require("typings-global");
exports.beautylog = require("beautylog"); exports.beautylog = require("beautylog");
exports.fs = require("fs-extra"); exports.fs = require("fs-extra");
exports.gulp = require("gulp"); exports.gulp = require("gulp");
exports.glob = require("glob");
exports.g = { exports.g = {
remoteSrc: require("gulp-remote-src") remoteSrc: require("gulp-remote-src")
}; };
@ -14,4 +15,4 @@ exports.yaml = require("js-yaml");
exports.request = require("request"); exports.request = require("request");
exports.requireReload = require("require-reload"); exports.requireReload = require("require-reload");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDYixpQkFBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztBQUNqQyxVQUFFLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFDO0FBQ3pCLFlBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7QUFDdkIsU0FBQyxHQUFHO0lBQ1gsU0FBUyxFQUFFLE9BQU8sQ0FBQyxpQkFBaUIsQ0FBQztDQUN4QyxDQUFDO0FBQ1ksWUFBSSxXQUFXLE1BQU0sQ0FBQyxDQUFDO0FBQzFCLFNBQUMsR0FBRyxPQUFPLENBQUMs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nMtZXh0cmFcIik7XG5leHBvcnQgbGV0IGd1bHAgPSByZXF1aXJlKFwiZ3VscFwiKTtcbmV4cG9ydCBsZXQgZ2xvYiA9IHJlcXVpcmUoXCJnbG9iXCIpO1xuZXhwb3J0IGxldCBnID0ge1xuICAgIHJlbW90ZVNyYzogcmVxdWlyZShcImd1bHAtcmVtb3RlLXNyY1wiKVxufTtcbmV4cG9ydCBsZXQgcGF0aCA9IHJlcXVpcmUoXCJwYXRoXCIpO1xuZXhwb3J0IGxldCBxID0gcmVxdWlyZShcInFcIik7XG5leHBvcnQgbGV0IHZpbnlsID0gcmVxdWlyZShcInZpbnlsXCIpO1xuZXhwb3J0IGxldCB2aW55bEZpbGUgPSByZXF1aXJlKFwidmlueWwtZmlsZVwiKTtcbmV4cG9ydCBsZXQgeWFtbCA9IHJlcXVpcmUoXCJqcy15YW1sXCIpO1xuZXhwb3J0IGxldCByZXF1ZXN0ID0gcmVxdWlyZShcInJlcXVlc3RcIik7XG5leHBvcnQgbGV0IHJlcXVpcmVSZWxvYWQgPSByZXF1aXJlKFwicmVxdWlyZS1yZWxvYWRcIik7XG4iXX0=

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.0", "version": "4.0.9",
"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,19 +22,22 @@
"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": {
"@types/glob": "^5.0.22-alpha",
"@types/gulp": "^3.8.22-alpha",
"beautylog": "^5.0.12", "beautylog": "^5.0.12",
"fs-extra": "^0.30.0", "fs-extra": "^0.30.0",
"glob": "^7.0.5",
"gulp": "^3.9.1", "gulp": "^3.9.1",
"gulp-remote-src": "^0.4.1", "gulp-remote-src": "^0.4.1",
"js-yaml": "^3.6.1", "js-yaml": "^3.6.1",
"q": "^1.4.1", "q": "^1.4.1",
"request": "^2.72.0", "request": "^2.72.0",
"require-reload": "0.2.2", "require-reload": "0.2.2",
"typings-global": "^1.0.3", "typings-global": "^1.0.5",
"vinyl": "^1.1.1", "vinyl": "^1.1.1",
"vinyl-file": "^2.0.0" "vinyl-file": "^2.0.0"
}, },

File diff suppressed because one or more lines are too long

View File

@ -3,12 +3,11 @@ 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");
describe("smartfile".yellow,function(){ describe("smartfile".yellow,function(){
describe(".fs".yellow,function(){ describe(".fs".yellow,function(){
describe(".fileExistsSync".yellow,function(){ describe(".fileExistsSync".yellow,function(){
it("should return an accurate boolean",function(){ it("should return an accurate boolean",function(){
@ -23,15 +22,15 @@ describe("smartfile".yellow,function(){
(smartfile.fs.fileExists("./test/notthere.json")).should.not.be.fulfilled(); (smartfile.fs.fileExists("./test/notthere.json")).should.not.be.fulfilled();
}); });
}); });
describe(".foldersSync()",function(){ describe(".listFoldersSync()",function(){
it("should get the file type from a string",function(){ it("should get the file type from a string",function(){
smartfile.fs.foldersSync("./test/").should.containDeep([ "testfolder"]); smartfile.fs.listFoldersSync("./test/").should.containDeep([ "testfolder"]);
smartfile.fs.foldersSync("./test/").should.not.containDeep([ "notExistentFolder"]); smartfile.fs.listFoldersSync("./test/").should.not.containDeep([ "notExistentFolder"]);
}); });
}); });
describe(".folders()",function(){ describe(".listFolders()",function(){
it("should get the file type from a string",function(done){ it("should get the file type from a string",function(done){
smartfile.fs.folders("./test/") smartfile.fs.listFolders("./test/")
.then(function(folderArrayArg){ .then(function(folderArrayArg){
folderArrayArg.should.containDeep([ "testfolder"]); folderArrayArg.should.containDeep([ "testfolder"]);
folderArrayArg.should.not.containDeep([ "notExistentFolder"]); folderArrayArg.should.not.containDeep([ "notExistentFolder"]);
@ -39,6 +38,34 @@ 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(".listFileTree()",function(){
it("should get a file tree",function(done){
smartfile.fs.listFileTree(path.resolve("./test/"),"**/*.txt")
.then(function(folderArrayArg){
folderArrayArg.should.containDeep([ "testfolder/testfile1.txt"]);
folderArrayArg.should.not.containDeep([ "mytest.json"]);
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/")
@ -153,10 +180,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 +188,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,10 +3,77 @@ 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 =========================
===============================================================*/ ===============================================================*/
/**
* 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
*/
export let copy = function(fromArg:string, toArg:string){ export let copy = function(fromArg:string, toArg:string){
var done = plugins.q.defer(); var done = plugins.q.defer();
plugins.fs.copy(fromArg,toArg,{},function(){ plugins.fs.copy(fromArg,toArg,{},function(){
@ -15,11 +82,17 @@ export let copy = function(fromArg:string, toArg:string){
return done.promise; return done.promise;
}; };
/**
* copies a file SYNCHRONOUSLY from A to B on the local disk
*/
export let copySync = function(fromArg:string,toArg:string):boolean{ export let copySync = function(fromArg:string,toArg:string):boolean{
plugins.fs.copySync(fromArg,toArg); plugins.fs.copySync(fromArg,toArg);
return true; return true;
}; };
/**
* removes a file or folder from local disk
*/
export let remove = function(pathArg:string){ export let remove = function(pathArg:string){
var done = plugins.q.defer(); var done = plugins.q.defer();
plugins.fs.remove(pathArg,function(){ plugins.fs.remove(pathArg,function(){
@ -28,6 +101,9 @@ export let remove = function(pathArg:string){
return done.promise; return done.promise;
}; };
/**
* removes a file SYNCHRONOUSLY from local disk
*/
export let removeSync = function(pathArg:string):boolean{ export let removeSync = function(pathArg:string):boolean{
plugins.fs.removeSync(pathArg); plugins.fs.removeSync(pathArg);
return true; return true;
@ -38,11 +114,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
@ -100,56 +171,118 @@ export let requireReload = function(path:string){
return plugins.requireReload(path); return plugins.requireReload(path);
}; };
export let foldersSync = function(pathArg){ /**
return plugins.fs.readdirSync(pathArg).filter(function(file) { * lists Folders in a directory on local disk
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory(); * @returns Promise
}); */
}; export let listFolders = function(pathArg:string,regexFilter?:RegExp){
export let folders = function(pathArg:string){
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
* @param filePath * @returns an array with the folder names as strings
* @returns {boolean}
*/ */
export let fileExistsSync = function(filePath):boolean { export let listFoldersSync = function(pathArg:string,regexFilter?:RegExp):string[]{
let fileExistsBool:boolean = false; let folderArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
try { return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
plugins.fs.readFileSync(filePath); });
fileExistsBool = true if(regexFilter){
} folderArray = folderArray.filter((fileItem) => {
catch(err){ return regexFilter.test(fileItem);
fileExistsBool = false; });
} };
return fileExistsBool; return folderArray;
}; };
/** /**
* * lists Files in a directory on local disk
* @param filePath * @returns Promise
* @returns {any}
*/ */
export let fileExists = function(filePath){ export let listFiles = function(pathArg:string, regexFilter?:RegExp){
let done = plugins.q.defer(); let done = plugins.q.defer();
plugins.fs.access(filePath, plugins.fs.R_OK, function (err) { let fileArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
err ? done.reject() : done.resolve(); 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; return done.promise;
}; };
export let isDirectory = function(pathArg):boolean{ /**
return plugins.fs.statSync(pathArg).isDirectory(); * 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;
}; };
export let isFile = function(pathArg):boolean{ /**
return plugins.fs.statSync(pathArg).isFile(); * 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;
};
export let listFileTree = (dirPath:string, miniMatchFilter:string) => {
let done = plugins.q.defer();
let options = {
cwd:dirPath
}
plugins.glob(miniMatchFilter,options,(err,files:string[]) => {
if(err){
console.log(err);
done.reject();
};
done.resolve(files);
});
return done.promise;
}; };

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);

View File

@ -1,13 +1,14 @@
import "typings-global"; import "typings-global";
export let beautylog = require("beautylog"); export import beautylog = require("beautylog");
export let fs = require("fs-extra"); export let fs = require("fs-extra");
export let gulp = require("gulp"); export let gulp = require("gulp");
export let glob = require("glob");
export let g = { export let g = {
remoteSrc: require("gulp-remote-src") remoteSrc: require("gulp-remote-src")
}; };
export import path = require("path"); export let path = require("path");
export let q = require("q"); export let q = require("q");
export import vinyl = require("vinyl"); export let vinyl = require("vinyl");
export let vinylFile = require("vinyl-file"); export let vinylFile = require("vinyl-file");
export let yaml = require("js-yaml"); export let yaml = require("js-yaml");
export let request = require("request"); export let request = require("request");

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"
}
}