Compare commits

...

105 Commits

Author SHA1 Message Date
760913bad3 4.0.20 2016-09-20 17:56:52 +02:00
f7b8fe5498 now adhering to standard js 2016-09-20 17:56:49 +02:00
37fbf9a409 update 2016-09-20 12:20:46 +02:00
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
eeab2cf0cd 4.0.15 2016-09-02 16:31:50 +02:00
ab76cae75e update 2016-09-02 16:31:39 +02:00
f39daca6aa 4.0.13 2016-08-03 12:25:37 +02:00
e70db71ec4 update type versions 2016-08-03 12:25:15 +02:00
50ef41d5d4 add npm_registry environment 2016-07-20 02:34:14 +02:00
2a417ba18f add npmdocker section to npmextra.json 2016-07-20 02:32:02 +02:00
3516189940 update test js 2016-07-20 02:27:05 +02:00
10e3628a89 4.0.12 2016-07-19 20:28:33 +02:00
86eafe4568 update typings 2016-07-19 20:28:28 +02:00
fddde78b92 4.0.11 2016-07-17 17:36:43 +02:00
2a365b04a6 switched to npmextra for npmts config 2016-07-17 17:36:38 +02:00
df1d82cb7c switched to ES6 and updated deps 2016-07-17 17:34:15 +02:00
d20742f881 fix some things 2016-07-01 06:07:58 +02:00
db2a0c2992 4.0.10 2016-07-01 05:14:37 +02:00
7d806f313b remove @types/gulp 2016-07-01 05:14:16 +02:00
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
ef027d32c7 4.0.0 2016-06-23 18:32:04 +02:00
f5e89c57e5 big consolidation 2016-06-23 18:31:55 +02:00
d02e59a829 restructure 2016-06-23 17:42:08 +02:00
44f3d3597f add badge 2016-05-23 08:26:02 +02:00
322335f2e5 add appveyor.yml 2016-05-23 08:24:17 +02:00
c0b5e2805f 3.0.10 2016-05-23 08:15:53 +02:00
2599753877 now using typings that resolve with modules 2016-05-23 08:15:47 +02:00
66e9d29667 3.0.9 2016-05-23 05:39:26 +02:00
c57b81c901 fix test issue 2016-05-23 05:39:22 +02:00
ed6c730a6c 3.0.8 2016-05-23 04:11:58 +02:00
d77999e62d link typings correctly and update dependencies 2016-05-23 04:11:48 +02:00
8561cfcc5c 3.0.7 2016-05-20 00:32:16 +02:00
f3a81d60e9 updated structure and introduced new Smartfile class 2016-05-20 00:31:53 +02:00
96210fca9f update dependencies 2016-05-19 23:20:26 +02:00
60a2a7fc69 3.0.6 2016-05-01 23:20:06 +02:00
5d898baadf now has typings 2016-05-01 23:19:54 +02:00
9954ae4ba7 3.0.5 2016-04-14 20:34:02 +02:00
4b1f3d234b now has get.folders() and get.foldersSync function 2016-04-14 20:33:58 +02:00
aed2c92b75 added stable to travis.yml 2016-04-09 22:52:47 +02:00
cb805898c9 3.0.4 2016-04-09 22:51:35 +02:00
c09fe29d99 added memory to object function 2016-04-09 22:51:30 +02:00
a787836e56 added toObject function to memory module 2016-04-07 23:38:24 +02:00
287c2fa99f 3.0.3 2016-04-05 01:00:23 +02:00
111b70aefb updated deps 2016-04-05 01:00:23 +02:00
be91e22447 3.0.2 2016-04-05 00:37:15 +02:00
a337663830 now using carets 2016-04-05 00:37:10 +02:00
2cbb14c515 3.0.1 2016-04-05 00:36:23 +02:00
68cc85b684 update deps 2016-04-05 00:36:19 +02:00
7e875212b5 3.0.0 2016-04-05 00:17:33 +02:00
372e00597c update deps 2016-04-05 00:17:08 +02:00
6e32af1c9b 2.3.0 2016-04-04 15:44:04 +02:00
c60eac7787 now has working memory module 2016-04-04 15:44:00 +02:00
581b9e21d3 implemented memory module 2016-04-02 23:03:18 +02:00
0661744614 2.2.0 2016-03-21 00:28:39 +01:00
20a3fdba03 now can remove files 2016-03-21 00:28:29 +01:00
580cb95aa7 2.1.1 2016-03-20 17:36:49 +01:00
9a05df4200 restructure code and make remote and local file delivery conform 2016-03-20 17:36:38 +01:00
9afe7c8a9e 2.1.0 2016-03-19 22:08:13 +01:00
9aac47cae3 now handling gulp streams allright 2016-03-19 22:07:59 +01:00
4e62bbeeea 2.0.0 2016-03-18 17:34:43 +01:00
4a8df9c12f tests running though, can now handle local and remote files 2016-03-18 17:34:31 +01:00
34d38cd3d4 work in progress 2016-03-18 09:19:46 +00:00
834b22ed8d 1.0.1 2016-03-14 04:22:42 +01:00
8e9b080004 update travis 2016-03-14 04:22:36 +01:00
d5d4d3ff67 1.0.0 2016-03-14 03:50:34 +01:00
075ffff713 0.1.0 2016-03-14 03:50:21 +01:00
641218e841 add copy 2016-03-14 03:50:14 +01:00
0ad455a483 cleanup 2016-03-14 01:28:58 +01:00
cf6ea7e373 0.0.12 2016-02-09 20:51:20 +01:00
e9a38ccd2c update npmts 2016-02-09 20:51:13 +01:00
8ddacf51ce 0.0.11 2016-02-04 14:22:02 +01:00
3511f36b67 added checks 2016-02-04 14:21:48 +01:00
c5cfa79f14 0.0.10 2016-02-03 12:52:24 +01:00
32465d2556 add proper mocha tests and update deps 2016-02-03 12:52:09 +01:00
9edab1b3ec 0.0.9 2015-12-08 20:33:32 +01:00
c0ee2996ce added requireReload function 2015-12-08 20:33:13 +01:00
f1d89beb06 0.0.8 2015-12-03 20:48:38 +01:00
0c0449527d added capability to read a file to a vinyl file object 2015-12-03 20:48:32 +01:00
3a76e9b572 updated readme 2015-11-28 15:47:30 +01:00
3dddb80b43 0.0.7 2015-11-24 18:57:00 +01:00
2ba06f27dc now using fs-extra for josn 2015-11-24 18:56:53 +01:00
228f855a39 now can read yaml 2015-11-24 18:52:24 +01:00
46 changed files with 1851 additions and 2220 deletions

9
.gitignore vendored
View File

@ -1,6 +1,7 @@
node_modules/
.settings/
.idea/
coverage/
pages/
public/
test/temp/
ts/*.js
ts/*.js.map

37
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,37 @@
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
environment: npm_registry
script:
- npmci publish
only:
- tags
tags:
- docker

4
.npmignore Normal file
View File

@ -0,0 +1,4 @@
coverage/
docs/
test/
ts/

View File

@ -1,16 +0,0 @@
language: node_js
node_js:
- '4.1'
before_install:
- npm install -g tsd
deploy:
provider: npm
email: npm@smart-coordination.com
api_key:
secure: 3RdzAcS9d6sLJs3tHM2uCVU2wV2NsKiLiYWue98DevgijIqTFDHtYuoP29p7fbB4SV87JRbTK1y41QM2u/CCjnbB+mrAUg/Pn08dTibmzi9liom67sLczIPD4eZeMznXPRaddESQdzqrtQfc/6P+1JQO7XWexLNebgYtMrUzYcOrHPWf/Uktk2cKiYfrO8piSR+HOFh2rzC5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1C3uC3z+u3T9UwrbzJ/cZM6r6UQvQmUvIfBNaMlg4I/diQCDIPL+Rhop2nylY3IcHmJnk2itn7kOqj1tohCpFEml5pRuSZy4udWywkdtyBAsHWFLF7oiQ=

View File

@ -1,39 +1,36 @@
# gulp-bootstrap
works with gulp, but does nothing. Use it to bootstrap your own gulp plugin with TypeScript, Travis and npm.
# smartfile
make files easily accessible for processing in javascript.
### Buildstatus/Dependencies
[![Build Status](https://travis-ci.org/pushrocks/gulp-bootstrap.svg?branch=master)](https://travis-ci.org/pushrocks/gulp-bootstrap)
[![devDependency Status](https://david-dm.org/pushrocks/gulp-bootstrap/dev-status.svg)](https://david-dm.org/pushrocks/gulp-bootstrap#info=devDependencies)
## 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/)
### Usage
This npm package comes with everything you need to start your own gulp plugin.
## 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)
[![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/)
Features:
## Usage
smartfile is an approach of being one tool to handle files in diverse environments.
* TypeScript: Code your plugin in TypeScript
* Use gulp to compile TypeScript without the global gulp CLI Tool.
* Use travis to deploy to npm
* Have a master branch for the latest dev version
* Have a release branch for the latest npm version
### Smartfile Sections
smartfile thinks in sections:
This package **doesn't require global gulp** (just local -> simply do npm install`) to compile TypeScript.
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
* to compile TypeScript do `npm test` (You should chain your own tests to this command later on)
* to setup release do `npm run setup`
* to release a patch do `npm run release`
We recommend using travis for npm releasing and test integration.
#### The structure
```
gulp-bootstrap/
|
|- ts/
| |- compile/
| | |- compile.js **** contains gulp task`
| |- index.ts **** Your main TypeScript file.
|
|- index.js **** the compiled module
```
For more information read the docs
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

11
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
import 'typings-global';
import * as SmartfileFs from './smartfile.fs';
import * as SmartfileInterpreter from './smartfile.interpreter';
import * as SmartfileMemory from './smartfile.memory';
import * as SmartfileRemote from './smartfile.remote';
export { Smartfile } from './smartfile.classes.smartfile';
export declare let fs: typeof SmartfileFs;
export declare let interpreter: typeof SmartfileInterpreter;
export declare let memory: typeof SmartfileMemory;
export declare let remote: typeof SmartfileRemote;
export declare let requireReload: (path: string) => any;

14
dist/index.js vendored Normal file
View File

@ -0,0 +1,14 @@
"use strict";
require("typings-global");
const SmartfileFs = require("./smartfile.fs");
const SmartfileInterpreter = require("./smartfile.interpreter");
const SmartfileMemory = require("./smartfile.memory");
const SmartfileRemote = require("./smartfile.remote");
var smartfile_classes_smartfile_1 = require("./smartfile.classes.smartfile");
exports.Smartfile = smartfile_classes_smartfile_1.Smartfile;
exports.fs = SmartfileFs;
exports.interpreter = SmartfileInterpreter;
exports.memory = SmartfileMemory;
exports.remote = SmartfileRemote;
exports.requireReload = SmartfileFs.requireReload;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBR3ZCLDhDQUE2QztBQUM3QyxnRUFBK0Q7QUFDL0Qsc0RBQXFEO0FBQ3JELHNEQUFxRDtBQUVyRCw2RUFBdUQ7QUFBL0Msa0RBQUEsU0FBUyxDQUFBO0FBRU4sUUFBQSxFQUFFLEdBQUcsV0FBVyxDQUFBO0FBQ2hCLFFBQUEsV0FBVyxHQUFHLG9CQUFvQixDQUFBO0FBQ2xDLFFBQUEsTUFBTSxHQUFHLGVBQWUsQ0FBQTtBQUN4QixRQUFBLE1BQU0sR0FBRyxlQUFlLENBQUE7QUFDeEIsUUFBQSxhQUFhLEdBQUcsV0FBVyxDQUFDLGFBQWEsQ0FBQSJ9

3
dist/smartfile.classes.smartfile.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export declare class Smartfile {
constructor();
}

7
dist/smartfile.classes.smartfile.js vendored Normal file
View File

@ -0,0 +1,7 @@
"use strict";
class Smartfile {
constructor() {
}
}
exports.Smartfile = Smartfile;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTtJQUNJO0lBRUEsQ0FBQztDQUNKO0FBSkQsOEJBSUMifQ==

116
dist/smartfile.fs.d.ts vendored Normal file
View File

@ -0,0 +1,116 @@
/// <reference types="q" />
import 'typings-global';
import plugins = require('./smartfile.plugins');
/**
*
* @param filePath
* @returns {boolean}
*/
export declare let fileExistsSync: (filePath: any) => boolean;
/**
*
* @param filePath
* @returns {any}
*/
export declare let fileExists: (filePath: any) => plugins.q.Promise<{}>;
/**
* 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) => plugins.q.Promise<{}>;
/**
* 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) => plugins.q.Promise<{}>;
/**
* copies a file SYNCHRONOUSLY from A to B on the local disk
*/
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<{}>;
/**
* removes a file SYNCHRONOUSLY from local disk
*/
export declare let removeSync: (pathArg: string) => boolean;
/**
*
* @param filePathArg
* @returns {*}
*/
export declare let toGulpStreamSync: (filePathArg: string) => any;
export declare let toGulpDestSync: (folderPathArg: string) => any;
/**
*
* @param filePathArg
* @param fileTypeArg
* @returns {any}
*/
export declare let toObjectSync: (filePathArg: any, fileTypeArg?: any) => any;
/**
* reads a file content to a String
* @param filePath
* @returns {string|Buffer|any}
*/
export declare let toStringSync: (filePath: any) => any;
/**
*
* @param filePathArg
* @param options
* @returns {number}
*/
export declare let toVinylSync: (filePathArg: any, options?: {}) => any;
/**
* lets you reload files hot.
* @param path
* @returns {any}
*/
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<{}>;
/**
* lists Folders SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
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) => plugins.q.Promise<{}>;
/**
* 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<string[]>
*/
export declare let listAllItems: (pathArg: string, regexFilter?: RegExp) => plugins.q.Promise<string[]>;
/**
* 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[];
/**
* 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[]>;

267
dist/smartfile.fs.js vendored Normal file

File diff suppressed because one or more lines are too long

3
dist/smartfile.interpreter.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
import 'typings-global';
export declare let filetype: (pathArg: string) => string;
export declare let objectFile: (fileStringArg: string, fileTypeArg: any) => any;

21
dist/smartfile.interpreter.js vendored Normal file
View File

@ -0,0 +1,21 @@
"use strict";
require("typings-global");
const plugins = require("./smartfile.plugins");
exports.filetype = (pathArg) => {
let extName = plugins.path.extname(pathArg);
let fileType = extName.replace(/\.([a-z]*)/, '$1'); // remove . form fileType
return fileType;
};
exports.objectFile = (fileStringArg, fileTypeArg) => {
switch (fileTypeArg) {
case 'yml':
case 'yaml':
return plugins.yaml.safeLoad(fileStringArg);
case 'json':
return JSON.parse(fileStringArg);
default:
plugins.beautylog.error('file type ' + fileTypeArg.blue + ' not supported');
break;
}
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLmludGVycHJldGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRmaWxlLmludGVycHJldGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFFdkIsK0NBQStDO0FBRXBDLFFBQUEsUUFBUSxHQUFHLENBQUMsT0FBZTtJQUNsQyxJQUFJLE9BQU8sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQTtJQUMzQyxJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLFlBQVksRUFBQyxJQUFJLENBQUMsQ0FBQSxDQUFDLHlCQUF5QjtJQUMzRSxNQUFNLENBQUMsUUFBUSxDQUFBO0FBQ25CLENBQUMsQ0FBQTtBQUVVLFFBQUEsVUFBVSxHQUFHLENBQUMsYUFBcUIsRUFBRSxXQUFXO0lBQ3ZELE1BQU0sQ0FBQyxDQUFDLFdBQVcsQ0FBQyxDQUFDLENBQUM7UUFDbEIsS0FBSyxLQUFLLENBQUU7UUFDWixLQUFLLE1BQU07WUFDUCxNQUFNLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsYUFBYSxDQUFDLENBQUE7UUFDL0MsS0FBSyxNQUFNO1lBQ1AsTUFBTSxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsYUFBYSxDQUFDLENBQUE7UUFDcEM7WUFDSSxPQUFPLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyxZQUFZLEdBQUcsV0FBVyxDQUFDLElBQUksR0FBRyxnQkFBZ0IsQ0FBQyxDQUFBO1lBQzNFLEtBQUssQ0FBQTtJQUNiLENBQUM7QUFDTCxDQUFDLENBQUEifQ==

51
dist/smartfile.memory.d.ts vendored Normal file
View File

@ -0,0 +1,51 @@
/// <reference types="vinyl" />
/// <reference types="q" />
import 'typings-global';
import plugins = require('./smartfile.plugins');
/**
* allows you to create a gulp stream
* from String, from an Array of Strings, from Vinyl File, from an Array of VinylFiles
* @param fileArg
* @returns stream.Readable
* @TODO: make it async;
*/
export declare let toGulpStream: (fileArg: string | string[] | plugins.vinyl | plugins.vinyl[], baseArg?: string) => any;
/**
* converts file to Object
* @param fileStringArg
* @param fileTypeArg
* @returns {any|any}
*/
export declare let toObject: (fileStringArg: string, fileTypeArg: string) => any;
/**
* takes a string and converts it to vinyl file
* @param fileArg
* @param optionsArg
*/
export declare let toVinylFileSync: (fileArg: string, optionsArg?: {
filename?: string;
base?: string;
relPath?: string;
}) => plugins.vinyl;
/**
* takes a string array and some options and returns a vinylfile array
* @param arrayArg
* @param optionsArg
*/
export declare let toVinylArraySync: (arrayArg: string[], optionsArg?: {
filename?: string;
base?: string;
relPath?: string;
}) => any[];
/**
* takes a vinylFile object and converts it to String
*/
export declare let toStringSync: (fileArg: plugins.vinyl) => any;
/**
* writes string or vinyl file to disk.
* @param fileArg
* @param fileNameArg
* @param fileBaseArg
*/
export declare let toFs: (fileContentArg: string | plugins.vinyl, filePathArg: any) => plugins.q.Promise<{}>;
export declare let toFsSync: (fileArg: any, filePathArg: string) => void;

126
dist/smartfile.memory.js vendored Normal file

File diff suppressed because one or more lines are too long

16
dist/smartfile.plugins.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
import 'typings-global';
export import beautylog = require('beautylog');
export import fs = require('fs');
export import fsExtra = require('fs-extra');
export declare let gulp: any;
export declare let glob: any;
export declare let g: {
remoteSrc: any;
};
export import path = require('path');
export import q = require('q');
export import vinyl = require('vinyl');
export declare let vinylFile: any;
export declare let yaml: any;
export declare let request: any;
export declare let requireReload: any;

18
dist/smartfile.plugins.js vendored Normal file
View File

@ -0,0 +1,18 @@
"use strict";
require("typings-global");
exports.beautylog = require("beautylog");
exports.fs = require("fs");
exports.fsExtra = require("fs-extra");
exports.gulp = require('gulp');
exports.glob = require('glob');
exports.g = {
remoteSrc: require('gulp-remote-src')
};
exports.path = require("path");
exports.q = require("q");
exports.vinyl = require("vinyl");
exports.vinylFile = require('vinyl-file');
exports.yaml = require('js-yaml');
exports.request = require('request');
exports.requireReload = require('require-reload');
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGZpbGUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHlDQUE4QztBQUM5QywyQkFBZ0M7QUFDaEMsc0NBQTJDO0FBQ2hDLFFBQUEsSUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQTtBQUN0QixRQUFBLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUE7QUFDdEIsUUFBQSxDQUFDLEdBQUc7SUFDWCxTQUFTLEVBQUUsT0FBTyxDQUFDLGlCQUFpQixDQUFDO0NBQ3hDLENBQUE7QUFDRCwrQkFBb0M7QUFDcEMseUJBQThCO0FBQzlCLGlDQUFzQztBQUMzQixRQUFBLFNBQVMsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUE7QUFDakMsUUFBQSxJQUFJLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFBO0FBQ3pCLFFBQUEsT0FBTyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQTtBQUM1QixRQUFBLGFBQWEsR0FBRyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FBQSJ9

22
dist/smartfile.remote.d.ts vendored Normal file
View File

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

64
dist/smartfile.remote.js vendored Normal file
View File

@ -0,0 +1,64 @@
"use strict";
require("typings-global");
const plugins = require("./smartfile.plugins");
const SmartfileInterpreter = require("./smartfile.interpreter");
exports.toFs = function (from, toPath) {
let done = plugins.q.defer();
let stream = plugins.request(from).pipe(plugins.fsExtra.createWriteStream(toPath));
stream.on('finish', function () {
done.resolve(toPath);
});
return done.promise;
};
/**
*
* @param filePathArg
* @returns {*}
*/
exports.toGulpStreamSync = function (filePathArg, baseArg) {
let stream = plugins.g.remoteSrc(filePathArg, {
base: baseArg
});
return stream;
};
/**
*
* @param fromArg
* @returns {any}
*/
exports.toObject = function (fromArg) {
let done = plugins.q.defer();
plugins.request.get(fromArg, function (error, response, bodyString) {
let returnObject;
if (!error && response.statusCode === 200) {
returnObject = SmartfileInterpreter.objectFile(bodyString, SmartfileInterpreter.filetype(fromArg));
done.resolve(returnObject);
}
else {
console.log('could not get remote file from ' + fromArg);
returnObject = undefined;
done.reject(returnObject);
}
});
return done.promise;
};
/**
*
* @param fromArg
* @returns {any}
*/
exports.toString = (fromArg) => {
let done = plugins.q.defer();
plugins.request.get(fromArg, function (error, response, bodyString) {
if (!error && response.statusCode === 200) {
done.resolve(bodyString);
}
else {
plugins.beautylog.error('could not get remote file from ' + fromArg);
bodyString = undefined;
done.reject(bodyString);
}
});
return done.promise;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnJlbW90ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QiwrQ0FBK0M7QUFDL0MsZ0VBQWdFO0FBRXJELFFBQUEsSUFBSSxHQUFHLFVBQVMsSUFBWSxFQUFDLE1BQWM7SUFDb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TLENBQUE7WUFDdEIsSUFBSSxDQUFDLE1BQU0sQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUMzQixDQUFDO0lBQ0wsQ0FBQyxDQUFDLENBQUE7SUFDRixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtBQUN2QixDQUFDLENBQUEifQ==

View File

@ -1,12 +0,0 @@
/// <reference path="typings/tsd.d.ts" />
var path = require("path");
var fs = require("fs");
var smartfile = {
//read File to string
readFileToString: function (filePath) {
var fileString;
fileString = fs.readFileSync(filePath, "utf8");
return fileString;
}
};
module.exports = smartfile;

9
npmextra.json Normal file
View File

@ -0,0 +1,9 @@
{
"npmts":{
"mode":"default",
"coverageTreshold":70
},
"npmdocker":{
}
}

View File

@ -1,17 +1,19 @@
{
"name": "smartfile",
"version": "0.0.6",
"version": "4.0.20",
"description": "offers smart ways to work with files in nodejs",
"main": "index.js",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(cd ts/compile && node compile.js) && (node test.js)",
"test": "(npmts)",
"reinstall": "(rm -r node_modules && npm install)",
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
"startdev": "(git checkout master && git pull origin master)"
"update": "(git checkout master && git pull origin master && npm install)",
"upgrade": "(npm run update) && (ncu upgradeAll && npm install)"
},
"repository": {
"type": "git",
"url": "https://github.com/pushrocks/smartfile.git"
"url": "https://gitlab.com/pushrocks/smartfile.git"
},
"keywords": [
"filesystem",
@ -20,15 +22,31 @@
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
"license": "MIT",
"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": {
"beautylog": "^1.0.2"
"@types/fs-extra": "0.x.x",
"@types/q": "0.x.x",
"@types/vinyl": "^1.1.29",
"beautylog": "^5.0.23",
"fs-extra": "^0.30.0",
"glob": "^7.0.6",
"gulp": "^3.9.1",
"gulp-remote-src": "^0.4.1",
"js-yaml": "^3.6.1",
"q": "^1.4.1",
"request": "^2.75.0",
"require-reload": "0.2.2",
"typings-global": "^1.0.14",
"vinyl": "^1.2.0",
"vinyl-file": "^2.0.0"
},
"devDependencies": {
"gulp": "3.9.0",
"gulp-typescript": "2.9.2",
"pushrocks": "^1.0.19"
"@types/should": "^8.1.30",
"gulp-function": "^1.3.6",
"npmts-g": "^5.2.8",
"should": "^11.1.0",
"typings-test": "^1.0.3"
}
}

View File

@ -1,4 +0,0 @@
/// <reference path="typings/tsd.d.ts" />
var smartfile = require("./index.js");
var beautylog = require("beautylog")("os");
beautylog.info(smartfile.readFileToString("./test/mytest.txt"));

8
test/mytest.json Normal file
View File

@ -0,0 +1,8 @@
{
"key1": "this works",
"key2": "this works too",
"key3": {
"nestedkey1": "hello"
}
}

View File

@ -1 +1 @@
This is some test text stored in ./test/mytest.txt -> If this is displayed when running "npm test", then the test has succeeded.
Some TestString &&%$

4
test/mytest.yaml Normal file
View File

@ -0,0 +1,4 @@
key1: this works
key2: this works too
key3:
nestedkey1: hello

1
test/test.d.ts vendored Normal file
View File

@ -0,0 +1 @@
import 'typings-test';

206
test/test.js Normal file

File diff suppressed because one or more lines are too long

1
test/test.js.map Normal file

File diff suppressed because one or more lines are too long

227
test/test.ts Normal file
View File

@ -0,0 +1,227 @@
import 'typings-test'
import * as smartfile from '../dist/index'
import beautylog = require('beautylog')
let gulp = require('gulp')
let gFunction = require('gulp-function')
import path = require('path')
import * as should from 'should'
let vinyl = require('vinyl')
describe('smartfile'.yellow, function () {
describe('.fs'.yellow, function () {
describe('.fileExistsSync'.yellow, function () {
it('should return an accurate boolean', function () {
should(smartfile.fs.fileExistsSync('./test/mytest.json')).be.true()
should(smartfile.fs.fileExistsSync('./test/notthere.json')).be.false()
})
})
describe('.fileExists'.yellow, function () {
it('should return a working promise', function () {
should(smartfile.fs.fileExists('./test/mytest.json')).be.Promise()
should(smartfile.fs.fileExists('./test/mytest.json')).be.fulfilled()
should(smartfile.fs.fileExists('./test/notthere.json')).not.be.fulfilled()
})
})
describe('.listFoldersSync()', function () {
it('should get the file type from a string', function () {
should(smartfile.fs.listFoldersSync('./test/')).containDeep(['testfolder'])
should(smartfile.fs.listFoldersSync('./test/')).not.containDeep(['notExistentFolder'])
})
})
describe('.listFolders()', function () {
it('should get the file type from a string', function (done) {
smartfile.fs.listFolders('./test/')
.then(function (folderArrayArg) {
should(folderArrayArg).containDeep(['testfolder'])
should(folderArrayArg).not.containDeep(['notExistentFolder'])
done()
})
})
})
describe('.listFilesSync()', function () {
it('should get the file type from a string', function () {
should(smartfile.fs.listFilesSync('./test/')).containDeep(['mytest.json'])
should(smartfile.fs.listFilesSync('./test/')).not.containDeep(['notExistentFile'])
should(smartfile.fs.listFilesSync('./test/', /mytest\.json/)).containDeep(['mytest.json'])
should(smartfile.fs.listFilesSync('./test/', /mytests.json/)).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) {
should(folderArrayArg).containDeep(['mytest.json'])
should(folderArrayArg).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) {
should(folderArrayArg).containDeep(['testfolder/testfile1.txt'])
should(folderArrayArg).not.containDeep(['mytest.json'])
done()
})
})
})
describe('.copy()'.yellow, function () {
it('should copy a directory', function () {
smartfile.fs.copy('./test/testfolder/', './test/temp/')
})
it('should copy a file', function () {
smartfile.fs.copy('./test/mytest.yaml', './test/temp/')
})
it('should copy a file and rename it', function () {
smartfile.fs.copy('./test/mytest.yaml', './test/temp/mytestRenamed.yaml')
})
})
describe('.remove()', function () {
it('should remove an entire directory', function () {
})
it('should remove single files', function () {
})
})
})
describe('.interpreter', function () {
describe('.filetype()', function () {
it('should get the file type from a string', function () {
should(smartfile.interpreter.filetype('./somefolder/data.json')).equal('json')
})
})
})
describe('.fs'.yellow, function () {
describe('toGulpStreamSync() and toGulpDestSync', function () {
it('should produce a gulp stream', function (done) {
smartfile.fs.toGulpStreamSync('./test/my*')
.pipe(smartfile.fs.toGulpDestSync('./test/temp/'))
.pipe(gFunction(done, 'atEnd'))
})
})
describe('.toObjectSync()'.yellow, function () {
it('should read an ' + '.yaml'.blue + ' file to an object', function () {
let testData = smartfile.fs.toObjectSync('./test/mytest.yaml')
should(testData).have.property('key1', 'this works')
should(testData).have.property('key2', 'this works too')
})
it('should state unknown file type for unknown file types', function () {
let testData = smartfile.fs.toObjectSync('./test/mytest.txt')
})
it('should read an ' + '.json'.blue + ' file to an object', function () {
let testData = smartfile.fs.toObjectSync('./test/mytest.json')
should(testData).have.property('key1', 'this works')
should(testData).have.property('key2', 'this works too')
})
})
describe('.toStringSync()'.yellow, function () {
it('should read a file to a string', function () {
should.equal(
smartfile.fs.toStringSync('./test/mytest.txt'),
'Some TestString &&%$'
)
})
})
describe('.toVinylSync'.yellow, function () {
it('should read an ' + '.json OR .yaml'.blue + ' file to an ' + 'vinyl file object'.cyan, function () {
let testData = smartfile.fs.toVinylSync('./test/mytest.json')
should(vinyl.isVinyl(testData)).be.true()
})
})
})
describe('.memory', function () {
describe('.toGulpStream()', function () {
it('should produce a valid gulp stream', function () {
let localArray = ['test1', 'test2', 'test3']
smartfile.memory.toGulpStream(localArray)
.pipe(gulp.dest('./test/temp/'))
})
})
describe('toVinylFileSync()', function () {
it('should produce a vinylFile', function () {
let localString = 'myString'
let localOptions = { filename: 'vinylfile2', base: '/someDir' }
should(smartfile.memory.toVinylFileSync(localString, localOptions) instanceof vinyl).be.true()
})
})
describe('toVinylArraySync()', function () {
it('should produce a an array of vinylfiles', function () {
let localStringArray = ['string1', 'string2', 'string3']
let localOptions = { filename: 'vinylfile2', base: '/someDir' }
let testResult = smartfile.memory.toVinylArraySync(localStringArray, localOptions)
should(testResult).be.Array()
should(testResult.length === 3).be.true()
for (let myKey in testResult) {
should(testResult[myKey] instanceof vinyl).be.true()
}
})
})
describe('toStringSync()', function () {
it('should produce a String from vinyl file', function () {
let localString = smartfile.memory.toStringSync(new vinyl({
base: '/',
path: '/test.txt',
contents: new Buffer('myString')
}))
should(localString).equal('myString')
})
})
describe('toFs()', function () {
it('should write a file to disk and return a promise', function (done) {
let localString = 'myString'
smartfile.memory.toFs(
localString,
path.join(process.cwd(), './test/temp/testMemToFs.txt')
).then(done)
})
})
describe('toFsSync()', function () {
it('should write a file to disk and return true if successfull', function () {
let localString = 'myString'
smartfile.memory.toFsSync(
localString,
path.join(process.cwd(), './test/temp/testMemToFsSync.txt')
)
})
})
})
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'))
})
})
describe('.toString()', function () {
it('should load a remote file to a variable', function (done) {
this.timeout(5000)
smartfile.remote.toString(
'https://raw.githubusercontent.com/pushrocks/smartfile/master/test/mytest.txt'
).then(function (responseString) {
should.equal(responseString, 'Some TestString &&%$')
done()
})
})
it('should reject a Promise when the link is false', function (done) {
this.timeout(10000)
smartfile.remote.toString('https://push.rocks/doesnotexist.txt')
.then(function () {
throw new Error('this test should not be resolved')
}, function () {
done()
})
})
})
})
})

View File

View File

View File

@ -1,30 +0,0 @@
// import gulp
var gulp = require("gulp")
var gulpTypescript = require("gulp-typescript");
var pr = require("pushrocks");
gulp.task('compileTS', function() {
var stream = gulp.src('../index.ts')
.pipe(gulpTypescript({
out: "index.js"
}))
.pipe(gulp.dest("../../"));
return stream;
});
gulp.task('compileTestTS', function() {
var stream = gulp.src('../test.ts')
.pipe(gulpTypescript({
out: "test.js"
}))
.pipe(gulp.dest("../../"));
return stream;
});
gulp.task('default',['compileTS','compileTestTS'], function() {
pr.beautylog.success('Typescript compiled');
});
//lets tell gulp to start with the default task.
pr.beautylog.log('Starting Gulp to compile TypeScript');
gulp.start.apply(gulp, ['default']);

View File

@ -1,2 +0,0 @@
# How to compile.
Make sure gulp and gulp-taypescript from npm are available. Then run the gulpfile in this directory.

View File

@ -1,15 +1,15 @@
/// <reference path="typings/tsd.d.ts" />
var path = require("path");
var fs = require("fs");
import 'typings-global'
var smartfile:any = {
//read File to string
readFileToString: (filePath) => {
var fileString;
fileString = fs.readFileSync(filePath, "utf8");
return fileString;
}
};
import * as plugins from './smartfile.plugins'
import * as SmartfileFs from './smartfile.fs'
import * as SmartfileInterpreter from './smartfile.interpreter'
import * as SmartfileMemory from './smartfile.memory'
import * as SmartfileRemote from './smartfile.remote'
export {Smartfile} from './smartfile.classes.smartfile'
module.exports = smartfile;
export let fs = SmartfileFs
export let interpreter = SmartfileInterpreter
export let memory = SmartfileMemory
export let remote = SmartfileRemote
export let requireReload = SmartfileFs.requireReload

View File

@ -0,0 +1,5 @@
export class Smartfile {
constructor() {
}
}

290
ts/smartfile.fs.ts Normal file
View File

@ -0,0 +1,290 @@
import 'typings-global'
import plugins = require('./smartfile.plugins')
import SmartfileInterpreter = require('./smartfile.interpreter')
/*===============================================================
============================ Checks =============================
===============================================================*/
/**
*
* @param filePath
* @returns {boolean}
*/
export let fileExistsSync = function(filePath): boolean {
let fileExistsBool: boolean = false
try {
plugins.fsExtra.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(err) : done.resolve()
})
return done.promise
}
/**
* Checks if given path points to an existing directory
*/
export let isDirectory = function(pathArg): boolean{
return plugins.fsExtra.statSync(pathArg).isDirectory()
}
/**
* Checks if a given path points to an existing file
*/
export let isFile = function(pathArg): boolean{
return plugins.fsExtra.statSync(pathArg).isFile()
}
/*===============================================================
============================ FS ACTIONS =========================
===============================================================*/
/**
* ensures that a directory is in place
*/
export let ensureDir = (dirPathArg: string) => {
let done = plugins.q.defer()
plugins.fsExtra.ensureDir(dirPathArg,done.resolve)
return done.promise
}
/**
* ensures that a directory is in place
*/
export let ensureDirSync = (dirPathArg: string) => {
plugins.fsExtra.ensureDirSync(dirPathArg)
}
/**
* copies a file from A to B on the local disk
*/
export let copy = function(fromArg: string, toArg: string){
let done = plugins.q.defer()
plugins.fsExtra.copy(fromArg,toArg,{},function(){
done.resolve()
})
return done.promise
}
/**
* copies a file SYNCHRONOUSLY from A to B on the local disk
*/
export let copySync = function(fromArg: string,toArg: string): boolean{
plugins.fsExtra.copySync(fromArg,toArg)
return true
}
/**
* removes a file or folder from local disk
*/
export let remove = function(pathArg: string){
let done = plugins.q.defer()
plugins.fsExtra.remove(pathArg,function(){
done.resolve()
})
return done.promise
}
/**
* removes a file SYNCHRONOUSLY from local disk
*/
export let removeSync = function(pathArg: string): boolean{
plugins.fsExtra.removeSync(pathArg)
return true
}
/*===============================================================
============================ Write/Read =========================
===============================================================*/
/**
*
* @param filePathArg
* @returns {*}
*/
export let toGulpStreamSync = function(filePathArg: string){
let stream = plugins.gulp.src(filePathArg)
return stream
}
export let toGulpDestSync = function(folderPathArg: string){
return plugins.gulp.dest(folderPathArg)
}
/**
*
* @param filePathArg
* @param fileTypeArg
* @returns {any}
*/
export let toObjectSync = function(filePathArg,fileTypeArg?) {
let fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8')
let fileType
fileTypeArg ? fileType = fileTypeArg : fileType = SmartfileInterpreter.filetype(filePathArg)
return SmartfileInterpreter.objectFile(fileString,fileType)
}
/**
* reads a file content to a String
* @param filePath
* @returns {string|Buffer|any}
*/
export let toStringSync = function(filePath) {
let fileString
fileString = plugins.fsExtra.readFileSync(filePath, 'utf8')
return fileString
}
/**
*
* @param filePathArg
* @param options
* @returns {number}
*/
export let toVinylSync = function(filePathArg,options = {}) {
return plugins.vinylFile.readSync(filePathArg,options)
}
/**
* lets you reload files hot.
* @param path
* @returns {any}
*/
export let requireReload = function(path: string){
return plugins.requireReload(path)
}
/**
* lists Folders in a directory on local disk
* @returns Promise
*/
export let listFolders = function(pathArg: string,regexFilter?: RegExp){
let done = plugins.q.defer()
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory()
})
if (regexFilter) {
folderArray = folderArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
}
done.resolve(folderArray)
return done.promise
}
/**
* lists Folders SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export let listFoldersSync = function(pathArg: string,regexFilter?: RegExp): string[]{
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter(function(file) {
return plugins.fsExtra.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.fsExtra.readdirSync(pathArg).filter(function(file) {
return plugins.fsExtra.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.fsExtra.readdirSync(pathArg).filter(function(file) {
return plugins.fsExtra.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<string[]>
*/
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) => {
return regexFilter.test(fileItem)
})
};
done.resolve(allItmesArray)
return done.promise
}
/**
* 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) {
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile()
})
if (regexFilter) {
allItmesArray = allItmesArray.filter((fileItem) => {
return regexFilter.test(fileItem)
})
}
return allItmesArray
}
/**
* 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
}
plugins.glob(miniMatchFilter,options,(err,files: string[]) => {
if (err) {
console.log(err)
done.reject(err)
}
done.resolve(files)
})
return done.promise
}

View File

@ -0,0 +1,22 @@
import 'typings-global'
import plugins = require('./smartfile.plugins')
export let filetype = (pathArg: string): string => {
let extName = plugins.path.extname(pathArg)
let fileType = extName.replace(/\.([a-z]*)/,'$1') // remove . form fileType
return fileType
}
export let objectFile = (fileStringArg: string, fileTypeArg) => {
switch (fileTypeArg) {
case 'yml' :
case 'yaml':
return plugins.yaml.safeLoad(fileStringArg)
case 'json':
return JSON.parse(fileStringArg)
default:
plugins.beautylog.error('file type ' + fileTypeArg.blue + ' not supported')
break
}
}

139
ts/smartfile.memory.ts Normal file
View File

@ -0,0 +1,139 @@
import 'typings-global'
import plugins = require('./smartfile.plugins')
import SmartfileInterpreter = require('./smartfile.interpreter')
import vinyl = require('vinyl')
let Readable = require('stream').Readable
/**
* allows you to create a gulp stream
* from String, from an Array of Strings, from Vinyl File, from an Array of VinylFiles
* @param fileArg
* @returns stream.Readable
* @TODO: make it async;
*/
export let toGulpStream = function(fileArg: string|string[]|plugins.vinyl|plugins.vinyl[],baseArg: string = '/'){
let fileArray = []
if (typeof fileArg === 'string' || fileArg instanceof plugins.vinyl) { // make sure we work with an array later on
fileArray.push(fileArg)
} else if (Array.isArray(fileArg)) {
fileArray = fileArg
} else {
throw new Error('fileArg has unknown format')
}
let vinylFileArray: plugins.vinyl[] = [] // we want to have an array of vinylFiles
for (let fileIndexArg in fileArray) { // convert fileArray in vinylArray
let file = fileArray[fileIndexArg]
file instanceof plugins.vinyl ?
vinylFileArray.push(file) :
vinylFileArray.push(toVinylFileSync(file,{filename: fileIndexArg,base: baseArg}))
};
let stream = new Readable({ objectMode: true })
for (let vinylFileIndexArg in vinylFileArray) {
let vinylFile = vinylFileArray[vinylFileIndexArg]
stream.push(vinylFile)
};
stream.push(null) // signal end of stream;
return stream
}
/**
* converts file to Object
* @param fileStringArg
* @param fileTypeArg
* @returns {any|any}
*/
export let toObject = function(fileStringArg: string,fileTypeArg: string){
return SmartfileInterpreter.objectFile(fileStringArg,fileTypeArg)
}
/**
* takes a string and converts it to vinyl file
* @param fileArg
* @param optionsArg
*/
export let toVinylFileSync = function(fileArg: string,optionsArg?: {filename?: string,base?: string,relPath?: string}){
optionsArg ? void(0) : optionsArg = {filename: 'vinylfile', base: '/'}
optionsArg.filename ? void(0) : optionsArg.filename = 'vinylfile'
optionsArg.base ? void(0) : optionsArg.base = '/'
optionsArg.relPath ? void('0') : optionsArg.relPath = ''
let vinylFile = new plugins.vinyl({
base: optionsArg.base,
path: plugins.path.join(optionsArg.base,optionsArg.relPath,optionsArg.filename),
contents: new Buffer(fileArg)
})
return vinylFile
};
/**
* takes a string array and some options and returns a vinylfile array
* @param arrayArg
* @param optionsArg
*/
export let toVinylArraySync = function(arrayArg: string[],optionsArg?: {filename?: string,base?: string,relPath?: string}){
let vinylArray = []
for (let stringIndexArg in arrayArg) {
let myString = arrayArg[stringIndexArg]
vinylArray.push(toVinylFileSync(myString,optionsArg))
}
return vinylArray
}
/**
* takes a vinylFile object and converts it to String
*/
export let toStringSync = function(fileArg: plugins.vinyl){
return fileArg.contents.toString('utf8')
};
/**
* writes string or vinyl file to disk.
* @param fileArg
* @param fileNameArg
* @param fileBaseArg
*/
export let toFs = function(fileContentArg: string|vinyl,filePathArg){
let done = plugins.q.defer()
// function checks to abort if needed
if (!fileContentArg || !filePathArg) {
throw new Error('expected valid arguments')
}
// prepare actual write action
let fileString: string
let filePath: string = filePathArg;
if (fileContentArg instanceof plugins.vinyl) {
fileString = toStringSync(fileContentArg)
} else if (typeof fileContentArg === 'string') {
fileString = fileContentArg
}
plugins.fsExtra.writeFile(filePath,fileString,'utf8',done.resolve)
return done.promise
}
export let toFsSync = function(fileArg,filePathArg: string){
// function checks to abort if needed
if (!fileArg || !filePathArg) {
throw new Error('expected a valid arguments')
}
// prepare actual write action
let fileString: string
let filePath: string = filePathArg
if (fileArg instanceof plugins.vinyl) {
fileString = toStringSync(fileArg)
} else if (typeof fileArg === 'string') {
fileString = fileArg
}
plugins.fsExtra.writeFileSync(filePath,fileString,'utf8')
}

16
ts/smartfile.plugins.ts Normal file
View File

@ -0,0 +1,16 @@
import 'typings-global'
export import beautylog = require('beautylog')
export import fs = require('fs')
export import fsExtra = require('fs-extra')
export let gulp = require('gulp')
export let glob = require('glob')
export let g = {
remoteSrc: require('gulp-remote-src')
}
export import path = require('path')
export import q = require('q')
export import vinyl = require('vinyl')
export let vinylFile = require('vinyl-file')
export let yaml = require('js-yaml')
export let request = require('request')
export let requireReload = require('require-reload')

64
ts/smartfile.remote.ts Normal file
View File

@ -0,0 +1,64 @@
import 'typings-global'
import plugins = require('./smartfile.plugins')
import SmartfileInterpreter = require('./smartfile.interpreter')
export let toFs = function(from: string,toPath: string) {
let done = plugins.q.defer()
let stream = plugins.request(from).pipe(plugins.fsExtra.createWriteStream(toPath))
stream.on('finish',function(){
done.resolve(toPath)
})
return done.promise
}
/**
*
* @param filePathArg
* @returns {*}
*/
export let toGulpStreamSync = function(filePathArg: string,baseArg: string){
let stream = plugins.g.remoteSrc(filePathArg, {
base: baseArg
})
return stream
}
/**
*
* @param fromArg
* @returns {any}
*/
export let toObject = function(fromArg: string){
let done = plugins.q.defer()
plugins.request.get(fromArg, function (error, response, bodyString) {
let returnObject
if (!error && response.statusCode === 200) {
returnObject = SmartfileInterpreter.objectFile(bodyString,SmartfileInterpreter.filetype(fromArg))
done.resolve(returnObject)
} else {
console.log('could not get remote file from ' + fromArg)
returnObject = undefined
done.reject(returnObject)
}
})
return done.promise
}
/**
*
* @param fromArg
* @returns {any}
*/
export let toString = (fromArg: string) => {
let done = plugins.q.defer()
plugins.request.get(fromArg, function (error, response, bodyString) {
if (!error && response.statusCode === 200) {
done.resolve(bodyString)
} else {
plugins.beautylog.error('could not get remote file from ' + fromArg)
bodyString = undefined
done.reject(bodyString)
}
})
return done.promise
}

View File

@ -1,4 +0,0 @@
/// <reference path="typings/tsd.d.ts" />
var smartfile = require("./index.js");
var beautylog = require("beautylog")("os");
beautylog.info(smartfile.readFileToString("./test/mytest.txt"));

View File

@ -1,12 +0,0 @@
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"node/node.d.ts": {
"commit": "efa0c1196d7280640e624ac1e7fa604502e7bd63"
}
}
}

File diff suppressed because it is too large Load Diff

1
ts/typings/tsd.d.ts vendored
View File

@ -1 +0,0 @@
/// <reference path="node/node.d.ts" />

3
tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "tslint-config-standard"
}