Compare commits

...

6 Commits

Author SHA1 Message Date
49aba4c85f 4.0.19 2016-09-18 20:09:32 +02:00
37d81fa4c6 improve README 2016-09-18 20:09:17 +02:00
0256166c2f 4.0.18 2016-09-18 12:26:59 +02:00
bef2bd6b3a add vinyl typings 2016-09-18 12:26:43 +02:00
759e1655da 4.0.17 2016-09-17 23:11:58 +02:00
d732d1ba97 4.0.16 2016-09-17 23:11:44 +02:00
17 changed files with 96 additions and 56 deletions

2
.gitignore vendored

@ -1,7 +1,7 @@
node_modules/
coverage/
pages/
public/
test/temp/

@ -1,13 +1,36 @@
# smartfile
make files easily accessible for processing in javascript.
## Status
## Availabililty
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartfile)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/smartfile)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartfile)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartfile/)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartfile/badges/master/build.svg)](https://gitlab.com/pushrocks/smartfile/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartfile/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartfile/commits/master)
[![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 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)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
smartfile is an approach of being one tool to handle files in diverse environments.
It can fetch files from remote locations, work with local disks and do pure memory operations.
### Smartfile Sections
smartfile thinks in sections:
section | description
--- | ---
fs | (object) gets data from fs to somewhere
memory | gets data from memory to somewhere
remote | gets data from remote locations to somewhere
interpreter | (object) handles yaml and json
smartfile | (class) a virtual representation of a file, alternative to vinyl file format
For more information read the docs
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

@ -12,7 +12,7 @@ export declare let fileExistsSync: (filePath: any) => boolean;
* @param filePath
* @returns {any}
*/
export declare let fileExists: (filePath: any) => plugins.Q.Promise<{}>;
export declare let fileExists: (filePath: any) => plugins.q.Promise<{}>;
/**
* Checks if given path points to an existing directory
*/
@ -24,7 +24,7 @@ export declare let isFile: (pathArg: any) => boolean;
/**
* ensures that a directory is in place
*/
export declare let ensureDir: (dirPathArg: string) => plugins.Q.Promise<{}>;
export declare let ensureDir: (dirPathArg: string) => plugins.q.Promise<{}>;
/**
* ensures that a directory is in place
*/
@ -32,7 +32,7 @@ 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) => plugins.Q.Promise<{}>;
export declare let copy: (fromArg: string, toArg: string) => plugins.q.Promise<{}>;
/**
* copies a file SYNCHRONOUSLY from A to B on the local disk
*/
@ -40,7 +40,7 @@ export declare let copySync: (fromArg: string, toArg: string) => boolean;
/**
* removes a file or folder from local disk
*/
export declare let remove: (pathArg: string) => plugins.Q.Promise<{}>;
export declare let remove: (pathArg: string) => plugins.q.Promise<{}>;
/**
* removes a file SYNCHRONOUSLY from local disk
*/
@ -82,7 +82,7 @@ export declare let requireReload: (path: string) => any;
* lists Folders in a directory on local disk
* @returns Promise
*/
export declare let listFolders: (pathArg: string, regexFilter?: RegExp) => plugins.Q.Promise<{}>;
export declare let listFolders: (pathArg: string, regexFilter?: RegExp) => plugins.q.Promise<{}>;
/**
* lists Folders SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
@ -92,7 +92,7 @@ export declare let listFoldersSync: (pathArg: string, regexFilter?: RegExp) => s
* lists Files in a directory on local disk
* @returns Promise
*/
export declare let listFiles: (pathArg: string, regexFilter?: RegExp) => plugins.Q.Promise<{}>;
export declare let listFiles: (pathArg: string, regexFilter?: RegExp) => plugins.q.Promise<{}>;
/**
* lists Files SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
@ -100,12 +100,17 @@ export declare let listFiles: (pathArg: string, regexFilter?: RegExp) => plugins
export declare let listFilesSync: (pathArg: string, regexFilter?: RegExp) => string[];
/**
* lists all items (folders AND files) in a directory on local disk
* @returns Promise
* @returns Promise<string[]>
*/
export declare let listAllItems: (pathArg: string, regexFilter?: RegExp) => plugins.Q.Promise<{}>;
export declare let listAllItems: (pathArg: string, regexFilter?: RegExp) => plugins.q.Promise<string[]>;
/**
* lists all items (folders AND files) SYNCHRONOUSLY in a directory on local disk
* lists all items (folders AND files) in a directory on local disk
* @returns an array with the folder names as strings
* @executes SYNC
*/
export declare let listAllItemsSync: (pathArg: string, regexFilter?: RegExp) => string[];
export declare let listFileTree: (dirPath: string, miniMatchFilter: string) => plugins.Q.Promise<{}>;
/**
* lists a file tree using a miniMatch filter
* @returns Promise<string[]> string array with the absolute paths of all matching files
*/
export declare let listFileTree: (dirPath: string, miniMatchFilter: string) => plugins.q.Promise<string[]>;

27
dist/smartfile.fs.js vendored

File diff suppressed because one or more lines are too long

@ -46,5 +46,5 @@ export declare let toStringSync: (fileArg: any) => any;
* @param fileNameArg
* @param fileBaseArg
*/
export declare let toFs: (fileContentArg: any, filePathArg: any) => plugins.Q.Promise<{}>;
export declare let toFs: (fileContentArg: any, filePathArg: any) => plugins.q.Promise<{}>;
export declare let toFsSync: (fileArg: any, filePathArg: string) => void;

@ -90,7 +90,7 @@ exports.toStringSync = function (fileArg) {
* @param fileBaseArg
*/
exports.toFs = function (fileContentArg, filePathArg) {
let done = plugins.Q.defer();
let done = plugins.q.defer();
//function checks to abort if needed
if (!fileContentArg || !filePathArg)
throw new Error("expected valid arguments");

@ -8,7 +8,7 @@ export declare let g: {
remoteSrc: any;
};
export import path = require("path");
export import Q = require("q");
export import q = require("q");
export declare let vinyl: any;
export declare let vinylFile: any;
export declare let yaml: any;

@ -9,7 +9,7 @@ exports.g = {
remoteSrc: require("gulp-remote-src")
};
exports.path = require("path");
exports.Q = require("q");
exports.q = require("q");
exports.vinyl = require("vinyl");
exports.vinylFile = require("vinyl-file");
exports.yaml = require("js-yaml");

@ -1,7 +1,7 @@
/// <reference types="q" />
import "typings-global";
import plugins = require("./smartfile.plugins");
export declare let toFs: (from: string, toPath: string) => plugins.Q.Promise<{}>;
export declare let toFs: (from: string, toPath: string) => plugins.q.Promise<{}>;
/**
*
* @param filePathArg
@ -13,10 +13,10 @@ export declare let toGulpStreamSync: (filePathArg: string, baseArg: string) => a
* @param fromArg
* @returns {any}
*/
export declare let toObject: (fromArg: string) => plugins.Q.Promise<{}>;
export declare let toObject: (fromArg: string) => plugins.q.Promise<{}>;
/**
*
* @param fromArg
* @returns {any}
*/
export declare let toString: (fromArg: string) => plugins.Q.Promise<{}>;
export declare let toString: (fromArg: string) => plugins.q.Promise<{}>;

@ -3,7 +3,7 @@ require("typings-global");
const plugins = require("./smartfile.plugins");
const SmartfileInterpreter = require("./smartfile.interpreter");
exports.toFs = function (from, toPath) {
var done = plugins.Q.defer();
var done = plugins.q.defer();
var stream = plugins.request(from).pipe(plugins.fsExtra.createWriteStream(toPath));
stream.on('finish', function () {
done.resolve(toPath);
@ -27,7 +27,7 @@ exports.toGulpStreamSync = function (filePathArg, baseArg) {
* @returns {any}
*/
exports.toObject = function (fromArg) {
let done = plugins.Q.defer();
let done = plugins.q.defer();
plugins.request.get(fromArg, function (error, response, bodyString) {
let returnObject;
if (!error && response.statusCode == 200) {
@ -49,7 +49,7 @@ exports.toObject = function (fromArg) {
* @returns {any}
*/
exports.toString = (fromArg) => {
let done = plugins.Q.defer();
let done = plugins.q.defer();
plugins.request.get(fromArg, function (error, response, bodyString) {
if (!error && response.statusCode == 200) {
done.resolve(bodyString);

@ -1,6 +1,6 @@
{
"name": "smartfile",
"version": "4.0.15",
"version": "4.0.19",
"description": "offers smart ways to work with files in nodejs",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
@ -28,7 +28,7 @@
"dependencies": {
"@types/fs-extra": "0.x.x",
"@types/q": "0.x.x",
"beautylog": "^5.0.22",
"beautylog": "^5.0.23",
"fs-extra": "^0.30.0",
"glob": "^7.0.6",
"gulp": "^3.9.1",
@ -46,6 +46,6 @@
"gulp-function": "^1.3.6",
"npmts-g": "^5.2.8",
"should": "^11.1.0",
"typings-test": "^1.0.2"
"typings-test": "^1.0.3"
}
}

File diff suppressed because one or more lines are too long

@ -198,6 +198,7 @@ describe("smartfile".yellow,function(){
describe(".remote",function(){
describe("toGulpStreamSync()",function(){
it("should produce a gulp stream",function(done){
this.timeout(5000)
smartfile.remote.toGulpStreamSync("mytest.txt","https://raw.githubusercontent.com/pushrocks/smartfile/master/test/")
.pipe(smartfile.fs.toGulpDestSync("./test/temp/"))
.pipe(gFunction(done,"atEnd"));

@ -30,7 +30,7 @@ export let fileExistsSync = function(filePath):boolean {
* @returns {any}
*/
export let fileExists = function(filePath){
let done = plugins.Q.defer();
let done = plugins.q.defer();
plugins.fs.access(filePath, plugins.fs.R_OK, function (err) {
err ? done.reject(err) : done.resolve();
});
@ -59,7 +59,7 @@ export let isFile = function(pathArg):boolean{
* ensures that a directory is in place
*/
export let ensureDir = (dirPathArg:string) => {
let done = plugins.Q.defer();
let done = plugins.q.defer();
plugins.fsExtra.ensureDir(dirPathArg,done.resolve);
return done.promise;
}
@ -75,7 +75,7 @@ export let ensureDirSync = (dirPathArg:string) => {
* copies a file from A to B on the local disk
*/
export let copy = function(fromArg:string, toArg:string){
var done = plugins.Q.defer();
var done = plugins.q.defer();
plugins.fsExtra.copy(fromArg,toArg,{},function(){
done.resolve();
});
@ -94,7 +94,7 @@ export let copySync = function(fromArg:string,toArg:string):boolean{
* removes a file or folder from local disk
*/
export let remove = function(pathArg:string){
var done = plugins.Q.defer();
var done = plugins.q.defer();
plugins.fsExtra.remove(pathArg,function(){
done.resolve();
});
@ -176,7 +176,7 @@ export let requireReload = function(path:string){
* @returns Promise
*/
export let listFolders = function(pathArg:string,regexFilter?:RegExp){
let done = plugins.Q.defer();
let done = plugins.q.defer();
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory();
});
@ -211,7 +211,7 @@ export let listFoldersSync = function(pathArg:string,regexFilter?:RegExp):string
* @returns Promise
*/
export let listFiles = function(pathArg:string, regexFilter?:RegExp){
let done = plugins.Q.defer();
let done = plugins.q.defer();
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile();
});
@ -242,10 +242,10 @@ export let listFilesSync = function(pathArg:string, regexFilter?:RegExp):string[
/**
* lists all items (folders AND files) in a directory on local disk
* @returns Promise
* @returns Promise<string[]>
*/
export let listAllItems = function(pathArg:string, regexFilter?:RegExp){
let done = plugins.Q.defer();
export let listAllItems = function(pathArg:string, regexFilter?:RegExp): plugins.q.Promise<string[]> {
let done = plugins.q.defer<string[]>();
let allItmesArray = plugins.fsExtra.readdirSync(pathArg);
if(regexFilter){
allItmesArray = allItmesArray.filter((fileItem) => {
@ -257,8 +257,9 @@ export let listAllItems = function(pathArg:string, regexFilter?:RegExp){
};
/**
* lists all items (folders AND files) SYNCHRONOUSLY in a directory on local disk
* lists all items (folders AND files) in a directory on local disk
* @returns an array with the folder names as strings
* @executes SYNC
*/
export let listAllItemsSync = function(pathArg:string, regexFilter?:RegExp):string[]{
let allItmesArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
@ -272,8 +273,12 @@ export let listAllItemsSync = function(pathArg:string, regexFilter?:RegExp):stri
return allItmesArray;
};
export let listFileTree = (dirPath:string, miniMatchFilter:string) => {
let done = plugins.Q.defer();
/**
* lists a file tree using a miniMatch filter
* @returns Promise<string[]> string array with the absolute paths of all matching files
*/
export let listFileTree = (dirPath:string, miniMatchFilter:string): plugins.q.Promise<string[]> => {
let done = plugins.q.defer<string[]>();
let options = {
cwd:dirPath
}

@ -98,7 +98,7 @@ export let toStringSync = function(fileArg:plugins.vinyl){
* @param fileBaseArg
*/
export let toFs = function(fileContentArg:string|vinyl,filePathArg){
let done = plugins.Q.defer();
let done = plugins.q.defer();
//function checks to abort if needed
if (!fileContentArg || !filePathArg) throw new Error("expected valid arguments");

@ -8,7 +8,7 @@ export let g = {
remoteSrc: require("gulp-remote-src")
};
export import path = require("path");
export import Q = require("q");
export import q = require("q");
export let vinyl = require("vinyl");
export let vinylFile = require("vinyl-file");
export let yaml = require("js-yaml");

@ -3,7 +3,7 @@ import plugins = require("./smartfile.plugins");
import SmartfileInterpreter = require("./smartfile.interpreter");
export let toFs = function(from:string,toPath:string) {
var done = plugins.Q.defer();
var done = plugins.q.defer();
var stream = plugins.request(from).pipe(plugins.fsExtra.createWriteStream(toPath));
stream.on('finish',function(){
done.resolve(toPath);
@ -29,7 +29,7 @@ export let toGulpStreamSync = function(filePathArg:string,baseArg:string){
* @returns {any}
*/
export let toObject = function(fromArg:string){
let done = plugins.Q.defer();
let done = plugins.q.defer();
plugins.request.get(fromArg, function (error, response, bodyString) {
let returnObject;
if (!error && response.statusCode == 200) {
@ -50,7 +50,7 @@ export let toObject = function(fromArg:string){
* @returns {any}
*/
export let toString = (fromArg:string) => {
let done = plugins.Q.defer();
let done = plugins.q.defer();
plugins.request.get(fromArg, function (error, response, bodyString) {
if (!error && response.statusCode == 200) {
done.resolve(bodyString);