Compare commits
63 Commits
Author | SHA1 | Date | |
---|---|---|---|
ff2e34696a | |||
23188dfe3f | |||
38f10e0d04 | |||
2e2b8351f8 | |||
8c386ee91c | |||
9828689f31 | |||
8205da5284 | |||
2fc132ab20 | |||
e948d08f2e | |||
4362e94a88 | |||
fea9675b2a | |||
4522907af3 | |||
163eb5a70c | |||
fa5371a6bd | |||
5ff7f8c3ac | |||
0c49bbd4b2 | |||
f2e2a22a57 | |||
6ae30110f8 | |||
7b4626586c | |||
ef027d32c7 | |||
f5e89c57e5 | |||
d02e59a829 | |||
44f3d3597f | |||
322335f2e5 | |||
c0b5e2805f | |||
2599753877 | |||
66e9d29667 | |||
c57b81c901 | |||
ed6c730a6c | |||
d77999e62d | |||
8561cfcc5c | |||
f3a81d60e9 | |||
96210fca9f | |||
60a2a7fc69 | |||
5d898baadf | |||
9954ae4ba7 | |||
4b1f3d234b | |||
aed2c92b75 | |||
cb805898c9 | |||
c09fe29d99 | |||
a787836e56 | |||
287c2fa99f | |||
111b70aefb | |||
be91e22447 | |||
a337663830 | |||
2cbb14c515 | |||
68cc85b684 | |||
7e875212b5 | |||
372e00597c | |||
6e32af1c9b | |||
c60eac7787 | |||
581b9e21d3 | |||
0661744614 | |||
20a3fdba03 | |||
580cb95aa7 | |||
9a05df4200 | |||
9afe7c8a9e | |||
9aac47cae3 | |||
4e62bbeeea | |||
4a8df9c12f | |||
34d38cd3d4 | |||
834b22ed8d | |||
8e9b080004 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -8,5 +8,5 @@ ts/*.js
|
|||||||
ts/*.js.map
|
ts/*.js.map
|
||||||
ts/typings/
|
ts/typings/
|
||||||
|
|
||||||
test/assets/
|
test/temp/
|
||||||
|
|
||||||
|
36
.gitlab-ci.yml
Normal file
36
.gitlab-ci.yml
Normal 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
|
@ -1,11 +1,12 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- '4.2.4'
|
- 4
|
||||||
|
- stable
|
||||||
deploy:
|
deploy:
|
||||||
provider: npm
|
provider: npm
|
||||||
email: npm@lossless.digital
|
email: npm@lossless.digital
|
||||||
api_key:
|
api_key:
|
||||||
secure: 3RdzAcS9d6sLJs3tHM2uCVU2wV2NsKiLiYWue98DevgijIqTFDHtYuoP29p7fbB4SV87JRbTK1y41QM2u/CCjnbB+mrAUg/Pn08dTibmzi9liom67sLczIPD4eZeMznXPRaddESQdzqrtQfc/6P+1JQO7XWexLNebgYtMrUzYcOrHPWf/Uktk2cKiYfrO8piSR+HOFh2rzC5HjVZ/7fKDIa9bqTlBETkNc7s2NgB++jKRF9LNMVGI/9EmxjBzSSE1juOz26Ahp4+/+P3Lc5LngnTFOYsPoW5iWNY+AQltZxhu9K+rrtfn90rmQDnO7RCGO5yZgMS2+0UjJedwV+4ancU3nzoNmiuoIL7DjQ7NQlt0QKMmIqZuBFBc3tdxqotxNoJDk8/Ui0yfHWzJz0Fd22OI+VdTWNH1y5Vyywsql6wwkl2+Da1WhZf/Mn2gPgLPI0lssPTIl/u3Bey+167tZ3HvX0yqlvPO/JbqK02+5VrRBaV67vT00DG+dh4nnwqcX14Umx2a3JHt3tSGkDnDKpsLbvqjhPhkMRsCIloju+wMnyKjtScMZW+2FeO2n4PgbjNhF+5SG8pDmTS8p0Vy7iohUOiGIJty7K/1r6sQ1FNluhO5Ol3mBDs6wjg6S5QCSNL9eylpV52FV0UX4cRCijmzso+n48I2BbSwjghTB8=
|
secure: wIOQHE7Jbck2j5lcv1Rc8T9/1wbHNGLxqJ6pttNZ+hG1+w77TYnjNYuGtM2xQCXitXSFDoogU8MpiYieOQHYypFgJ6Ns8MTeKIzNJSnlOWdCSN/lVptscT8pyC6qD4IBAyi8m5F2HoGQR+IzcdDBPjXLaPbH7jn8hc9rNY+LNktmYOXfOr37P40pxYrf16GLwrkjQIK8pbkdIbNA0D0k3apTGqw+HsneN2D/O/zAYaB3ojm40ttgPAGYF5PO5t6uqIbPFgIPkMWsO1HbV6I+vOAuIf0KYUqnR/YZd5yFcxFt3c+bfyc8/LP4vy5FyKMLXHe4IXIjXPYetOSiVHgMMYaxawU51OqwIKO+87FJ1TdaVmacMFO0wagl2QS0ceQBn8KBUhljHu/fDInK82uy15Iddk44EhnTx1MIxxgH5WMM6aQB2vuqnViPghs4nA0Y/Dz2U69267fhvmZvEWWUndz058EksHdZsIt5WCqQErI/dWLXMGom94CuZv6nkoVHCw8CO5dqVvfqUFL7Qyw59kRbiUPItFVoiV8ptLUX9tnQ5xBukNRkFX34ViM9YvBRlGt5e//f+cWjUpXFvbrwkqusXArplpxIaUSsQKh7XaMB5DcZ5jDDdjKzIMDf6QWsMTU1rjfQS5ZS3eV5LPy0UlfpDGK28oK2/o8fM+yydVk=
|
||||||
on:
|
on:
|
||||||
tags: true
|
tags: true
|
||||||
repo: pushrocks/smartfile
|
repo: pushrocks/smartfile
|
||||||
|
10
README.md
10
README.md
@ -2,10 +2,12 @@
|
|||||||
make files easily accessible for processing in javascript.
|
make files easily accessible for processing in javascript.
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
[](https://travis-ci.org/pushrocks/smartfile)
|
[](https://gitlab.com/pushrocks/smartfile/commits/master)
|
||||||
|
[](https://david-dm.org/pushrocks/smartfile)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartfile/master/dependencies/npm)
|
[](https://www.bithound.io/github/pushrocks/smartfile/master/dependencies/npm)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartfile)
|
[](https://www.bithound.io/github/pushrocks/smartfile)
|
||||||
|
[](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.
|
10
appveyor.yml
Normal file
10
appveyor.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
environment:
|
||||||
|
nodejs_version: "4"
|
||||||
|
install:
|
||||||
|
- ps: Install-Product node $env:nodejs_version
|
||||||
|
- npm install
|
||||||
|
test_script:
|
||||||
|
- node --version
|
||||||
|
- npm --version
|
||||||
|
- npm test
|
||||||
|
build: off
|
11
dist/index.d.ts
vendored
Normal file
11
dist/index.d.ts
vendored
Normal 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;
|
26
dist/index.js
vendored
26
dist/index.js
vendored
@ -1,15 +1,15 @@
|
|||||||
/// <reference path="./typings/main.d.ts" />
|
|
||||||
"use strict";
|
"use strict";
|
||||||
var SmartfileChecks = require("./smartfile.checks");
|
require("typings-global");
|
||||||
var SmartfileSimple = require("./smartfile.simple");
|
var SmartfileFs = require("./smartfile.fs");
|
||||||
var smartfile = {
|
var SmartfileInterpreter = require("./smartfile.interpreter");
|
||||||
copy: SmartfileSimple.copy,
|
var SmartfileMemory = require("./smartfile.memory");
|
||||||
checks: SmartfileChecks,
|
var SmartfileRemote = require("./smartfile.remote");
|
||||||
readFileToString: SmartfileSimple.readFileToString,
|
var smartfile_classes_smartfile_1 = require("./smartfile.classes.smartfile");
|
||||||
readFileToObject: SmartfileSimple.readFileToObject,
|
exports.Smartfile = smartfile_classes_smartfile_1.Smartfile;
|
||||||
readFileToVinyl: SmartfileSimple.readFileToVinyl,
|
exports.fs = SmartfileFs;
|
||||||
requireReload: SmartfileSimple.requireReload
|
exports.interpreter = SmartfileInterpreter;
|
||||||
};
|
exports.memory = SmartfileMemory;
|
||||||
module.exports = smartfile;
|
exports.remote = SmartfileRemote;
|
||||||
|
exports.requireReload = SmartfileFs.requireReload;
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDRDQUE0Qzs7QUFHNUMsSUFBTyxlQUFlLFdBQVcsb0JBQW9CLENBQUMsQ0FBQztBQUN2RCxJQUFPLGVBQWUsV0FBVyxvQkFBb0IsQ0FBQyxDQUFDO0FBR3ZELElBQUksU0FBUyxHQUFPO0lBQ2hCLElBQUksRUFBRSxlQUFlLENBQUMsSUFBSTtJQUMxQixNQUFNLEVBQUUsZUFBZTtJQUN2QixnQkFBZ0IsRUFBRSxlQUFlLENBQUMsZ0JBQWdCO0lBQ2xELGdCQUFnQixFQUFFLGVBQWUsQ0FBQyxnQkFBZ0I7SUFDbEQsZUFBZSxFQUFFLGVBQWUsQ0FBQyxlQUFlO0lBQ2hELGFBQWEsRUFBRSxlQUFlLENB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pbGVJbnRlcnByZXRlcjtcbmV4cG9ydCBsZXQgbWVtb3J5ID0gU21hcnRmaWxlTWVtb3J5O1xuZXhwb3J0IGxldCByZW1vdGUgPSBTbWFydGZpbGVSZW1vdGU7XG5leHBvcnQgbGV0IHJlcXVpcmVSZWxvYWQgPSBTbWFydGZpbGVGcy5yZXF1aXJlUmVsb2FkO1xuIl19
|
||||||
|
33
dist/smartfile.checks.js
vendored
33
dist/smartfile.checks.js
vendored
@ -1,33 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
/// <reference path="./typings/main.d.ts" />
|
|
||||||
var plugins = require("./smartfile.plugins");
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param filePath
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
exports.fileExistsSync = function (filePath) {
|
|
||||||
var fileExistsBool = false;
|
|
||||||
try {
|
|
||||||
plugins.fs.readFileSync(filePath);
|
|
||||||
fileExistsBool = true;
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
fileExistsBool = false;
|
|
||||||
}
|
|
||||||
return fileExistsBool;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param filePath
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
exports.fileExists = function (filePath) {
|
|
||||||
var done = plugins.q.defer();
|
|
||||||
plugins.fs.access(filePath, plugins.fs.R_OK, function (err) {
|
|
||||||
err ? done.reject() : done.resolve();
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5jaGVja3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUM1QyxJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBRWhEOzs7O0dBSUc7QUFDUSxzQkFBYyxHQUFHLFVBQVMsUUFB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IGxldCBmaWxlRXhpc3RzU3luYyA9IGZ1bmN0aW9uKGZpbGVQYXRoKTpib29sZWFuIHtcbiAgICBsZXQgZmlsZUV4aXN0c0Jvb2w6Ym9vbGVhbiA9IGZhbHNlO1xuICAgIHRyeSB7XG4gICAgICAgIHBsdWdpbnMuZnMucmVhZEZpbGVTeW5jKGZpbGVQYXRoKTtcbiAgICAgICAgZmlsZUV4aXN0c0Jvb2wgPSB0cnVlXG4gICAgfVxuICAgIGNhdGNoKGVycil7XG4gICAgICAgIGZpbGVFeGlzdHNCb29sID0gZmFsc2U7XG4gICAgfVxuICAgIHJldHVybiBmaWxlRXhpc3RzQm9vbDtcbn07XG5cbi8qKlxuICpcbiAqIEBwYXJhbSBmaWxlUGF0aFxuICogQHJldHVybnMge2FueX1cbiAqL1xuZXhwb3J0IGxldCBmaWxlRXhpc3RzID0gZnVuY3Rpb24oZmlsZVBhdGgpe1xuICAgIGxldCBkb25lID0gcGx1Z2lucy5xLmRlZmVyKCk7XG4gICAgcGx1Z2lucy5mcy5hY2Nlc3MoZmlsZVBhdGgsIHBsdWdpbnMuZnMuUl9PSywgZnVuY3Rpb24gKGVycikge1xuICAgICAgICBlcnIgPyBkb25lLnJlamVjdCgpIDogZG9uZS5yZXNvbHZlKCk7XG4gICAgfSk7XG4gICAgcmV0dXJuIGRvbmUucHJvbWlzZTtcbn07XG4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
|
3
dist/smartfile.classes.smartfile.d.ts
vendored
Normal file
3
dist/smartfile.classes.smartfile.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export declare class Smartfile {
|
||||||
|
constructor();
|
||||||
|
}
|
10
dist/smartfile.classes.smartfile.js
vendored
Normal file
10
dist/smartfile.classes.smartfile.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
var Smartfile = (function () {
|
||||||
|
function Smartfile() {
|
||||||
|
}
|
||||||
|
;
|
||||||
|
return Smartfile;
|
||||||
|
}());
|
||||||
|
exports.Smartfile = Smartfile;
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5jbGFzc2VzLnNtYXJ0ZmlsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7SUFDSTtJQUVBLENBQUM7O0lBQ0wsZ0JBQUM7QUFBRCxDQUpBLEFBSUMsSUFBQTtBQUpZLGlCQUFTLFlBSXJCLENBQUEiLCJmaWxlIjoic21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLmpzIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGNsYXNzIFNtYXJ0ZmlsZSB7XG4gICAgY29uc3RydWN0b3IoKXtcbiAgICAgICAgXG4gICAgfTtcbn0iXX0=
|
109
dist/smartfile.fs.d.ts
vendored
Normal file
109
dist/smartfile.fs.d.ts
vendored
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
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;
|
||||||
|
/**
|
||||||
|
* 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) => any;
|
||||||
|
/**
|
||||||
|
* 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) => any;
|
||||||
|
/**
|
||||||
|
* 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) => 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;
|
269
dist/smartfile.fs.js
vendored
Normal file
269
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
3
dist/smartfile.interpreter.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export declare let filetype: (pathArg: string) => string;
|
||||||
|
export declare let objectFile: (fileStringArg: string, fileTypeArg: any) => any;
|
22
dist/smartfile.interpreter.js
vendored
Normal file
22
dist/smartfile.interpreter.js
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
var plugins = require("./smartfile.plugins");
|
||||||
|
exports.filetype = function (pathArg) {
|
||||||
|
var extName = plugins.path.extname(pathArg);
|
||||||
|
var fileType = extName.replace(/\.([a-z]*)/, "$1"); //remove . form fileType
|
||||||
|
return fileType;
|
||||||
|
};
|
||||||
|
exports.objectFile = function (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;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5pbnRlcnByZXRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBRXhCLElBQU8sT0FBTyxXQUFXLHFCQUFxQixDQUFDLENBQUM7QUFFckMsZ0JBQVEsR0FBRyxVQUFDLE9BQWM7SUFDakMsSUFBSSxPQUFPLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7SUFDNUMsSUFBSSxRQUFRLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxZQUFZLEVBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyx3QkFBd0I7SUFDM0UsTUFBTSxDQUFDLFFBQVEsQ0FBQztBQUNwQixDQUFDLENBQUM7QUFFUyxrQkFBVSxHQUFHLFVBQUMsYUFBb0IsRUFBRSxXQUFXO0lBQ3RELE1BQU0sQ0FBQyxDQUFDLFdBQVcsQ0FBQyxDQUFDLENBQUM7UUFDbEIsS0FBSyxLQUFLLENBQUU7UUFDWixLQUFLLE1BQU07WUFDUCxNQUFNLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsYU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mlsZVN0cmluZ0FyZyk7XG4gICAgICAgIGRlZmF1bHQ6XG4gICAgICAgICAgICBwbHVnaW5zLmJlYXV0eWxvZy5lcnJvcihcImZpbGUgdHlwZSBcIiArIGZpbGVUeXBlQXJnLmJsdWUgKyBcIiBub3Qgc3VwcG9ydGVkXCIpO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgfVxufSJdfQ==
|
48
dist/smartfile.memory.d.ts
vendored
Normal file
48
dist/smartfile.memory.d.ts
vendored
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import "typings-global";
|
||||||
|
/**
|
||||||
|
* 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: any, 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;
|
||||||
|
}) => any;
|
||||||
|
/**
|
||||||
|
* 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: any) => any;
|
||||||
|
/**
|
||||||
|
* writes string or vinyl file to disk.
|
||||||
|
* @param fileArg
|
||||||
|
* @param fileNameArg
|
||||||
|
* @param fileBaseArg
|
||||||
|
*/
|
||||||
|
export declare let toFs: (fileContentArg: any, filePathArg: any) => any;
|
||||||
|
export declare let toFsSync: (fileArg: any, filePathArg: string) => void;
|
126
dist/smartfile.memory.js
vendored
Normal file
126
dist/smartfile.memory.js
vendored
Normal file
File diff suppressed because one or more lines are too long
15
dist/smartfile.plugins.d.ts
vendored
Normal file
15
dist/smartfile.plugins.d.ts
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export import beautylog = require("beautylog");
|
||||||
|
export declare let fs: any;
|
||||||
|
export declare let gulp: any;
|
||||||
|
export declare let glob: any;
|
||||||
|
export declare let g: {
|
||||||
|
remoteSrc: any;
|
||||||
|
};
|
||||||
|
export declare let path: any;
|
||||||
|
export declare let q: any;
|
||||||
|
export declare let vinyl: any;
|
||||||
|
export declare let vinylFile: any;
|
||||||
|
export declare let yaml: any;
|
||||||
|
export declare let request: any;
|
||||||
|
export declare let requireReload: any;
|
11
dist/smartfile.plugins.js
vendored
11
dist/smartfile.plugins.js
vendored
@ -1,13 +1,18 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
/// <reference path="./typings/main.d.ts" />
|
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.glob = require("glob");
|
||||||
|
exports.g = {
|
||||||
|
remoteSrc: require("gulp-remote-src")
|
||||||
|
};
|
||||||
exports.path = require("path");
|
exports.path = require("path");
|
||||||
exports.q = require("q");
|
exports.q = require("q");
|
||||||
exports.vinyl = require("vinyl");
|
exports.vinyl = require("vinyl");
|
||||||
exports.vinylFile = require("vinyl-file");
|
exports.vinylFile = require("vinyl-file");
|
||||||
exports.yaml = require("js-yaml");
|
exports.yaml = require("js-yaml");
|
||||||
|
exports.request = require("request");
|
||||||
exports.requireReload = require("require-reload");
|
exports.requireReload = require("require-reload");
|
||||||
exports.shelljs = require("shelljs");
|
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDakMsaUJBQVMsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7QUFDakMsVUFBRSxHQUFHLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0FBQztBQUN6QixZQUFJLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBQ3ZCLFNBQUMsR0FBRyxPQUFPLENBQUMsR0FBRyxDQUFDLENBQUM7QUFDakIsYUFBSyxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQztBQUN6QixpQkFBUyxHQUFHLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQztBQUNsQyxZQUFJLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0FBQzFCLHFCQUFhLEdBQUcsT0FBTyxDQUFDLGdCQUFnQixDQUFDLENBQUM7QUFDMUMsZUFBTyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQyIsImZpbGUiOiJzbWFydGZpbGUucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbmV4cG9ydCBsZXQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCBsZXQgZnMgPSByZXF1aXJlKFwiZnMtZXh0cmFcIik7XG5leHBvcnQgbGV0IHBhdGggPSByZX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file
20
dist/smartfile.remote.d.ts
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export declare let toFs: (from: string, toPath: string) => any;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param filePathArg
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
export declare let toGulpStreamSync: (filePathArg: string, baseArg: string) => any;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param fromArg
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
|
export declare let toObject: (fromArg: string) => any;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param fromArg
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
|
export declare let toString: (fromArg: string) => any;
|
67
dist/smartfile.remote.js
vendored
Normal file
67
dist/smartfile.remote.js
vendored
Normal file
File diff suppressed because one or more lines are too long
69
dist/smartfile.simple.js
vendored
69
dist/smartfile.simple.js
vendored
@ -1,69 +0,0 @@
|
|||||||
/// <reference path="./typings/main.d.ts" />
|
|
||||||
"use strict";
|
|
||||||
var plugins = require("./smartfile.plugins");
|
|
||||||
exports.copy = function (fromArg, toArg) {
|
|
||||||
plugins.shelljs.cp("-r", fromArg, toArg);
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* reads a file content to a String
|
|
||||||
* @param filePath
|
|
||||||
* @returns {string|Buffer|any}
|
|
||||||
*/
|
|
||||||
exports.readFileToString = function (filePath) {
|
|
||||||
var fileString;
|
|
||||||
fileString = plugins.fs.readFileSync(filePath, "utf8");
|
|
||||||
return fileString;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param filePath
|
|
||||||
* @param fileTypeArg
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
exports.readFileToObject = function (filePath, fileTypeArg) {
|
|
||||||
if (fileTypeArg === void 0) { fileTypeArg = undefined; }
|
|
||||||
var fileType;
|
|
||||||
if (typeof fileTypeArg == "undefined") {
|
|
||||||
fileType = plugins.path.extname(filePath);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fileType = fileTypeArg;
|
|
||||||
}
|
|
||||||
fileType = fileType.replace(/\.([a-z]*)/, "$1"); //remove . form fileType
|
|
||||||
switch (fileType) {
|
|
||||||
case "yml":
|
|
||||||
case "yaml":
|
|
||||||
try {
|
|
||||||
return plugins.yaml.safeLoad(plugins.fs.readFileSync(filePath, 'utf8'));
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
plugins.beautylog.error("check that " + filePath.blue + " points to a valid file");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "json":
|
|
||||||
return plugins.fs.readJsonSync(filePath, {});
|
|
||||||
default:
|
|
||||||
plugins.beautylog.error("file type " + fileType.blue + " not supported");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param filePathArg
|
|
||||||
* @param options
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
exports.readFileToVinyl = function (filePathArg, options) {
|
|
||||||
if (options === void 0) { options = {}; }
|
|
||||||
return plugins.vinylFile.readSync(filePathArg, options);
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* lets you reload files hot.
|
|
||||||
* @param path
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
exports.requireReload = function (path) {
|
|
||||||
return plugins.requireReload(path);
|
|
||||||
};
|
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5zaW1wbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsNENBQTRDOztBQUU1QyxJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBRXJDLFlBQUksR0FBRyxVQUFTLE9BQWMsRUFBQyxLQUFZO0lBQ2xELE9BQU8sQ0FBQyxPQUFPLENBQUMsRUFBRSxDQUFDLElBQUksRUFBQyxPQU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F1aXJlUmVsb2FkID0gZnVuY3Rpb24ocGF0aDpzdHJpbmcpe1xuICAgIHJldHVybiBwbHVnaW5zLnJlcXVpcmVSZWxvYWQocGF0aCk7XG59OyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==
|
|
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"mode":"default",
|
"mode":"default",
|
||||||
"coveralls":true
|
"codecov":true,
|
||||||
|
"coverageTreshold":70
|
||||||
}
|
}
|
35
package.json
35
package.json
@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "smartfile",
|
"name": "smartfile",
|
||||||
"version": "1.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",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)",
|
"test": "(npmts)",
|
||||||
"reinstall": "(rm -r node_modules && npm install)",
|
"reinstall": "(rm -r node_modules && npm install)",
|
||||||
@ -12,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",
|
||||||
@ -21,21 +22,29 @@
|
|||||||
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/pushrocks/smartfile/issues"
|
"url": "https://gitlab.com/pushrocks/smartfile/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/smartfile",
|
"homepage": "https://gitlab.com/pushrocks/smartfile",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "3.1.2",
|
"@types/glob": "^5.0.22-alpha",
|
||||||
"fs-extra": "0.26.5",
|
"@types/gulp": "^3.8.22-alpha",
|
||||||
"js-yaml": "3.5.4",
|
"beautylog": "^5.0.12",
|
||||||
"q": "1.4.1",
|
"fs-extra": "^0.30.0",
|
||||||
|
"glob": "^7.0.5",
|
||||||
|
"gulp": "^3.9.1",
|
||||||
|
"gulp-remote-src": "^0.4.1",
|
||||||
|
"js-yaml": "^3.6.1",
|
||||||
|
"q": "^1.4.1",
|
||||||
|
"request": "^2.72.0",
|
||||||
"require-reload": "0.2.2",
|
"require-reload": "0.2.2",
|
||||||
"shelljs": "^0.6.0",
|
"typings-global": "^1.0.5",
|
||||||
"vinyl": "1.1.1",
|
"vinyl": "^1.1.1",
|
||||||
"vinyl-file": "2.0.0"
|
"vinyl-file": "^2.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts": "3.4.1",
|
"gulp-function": "^1.3.6",
|
||||||
"should": "^8.2.2"
|
"npmts-g": "^5.2.6",
|
||||||
|
"should": "^9.0.2",
|
||||||
|
"typings-test": "^1.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
test/test.d.ts
vendored
Normal file
1
test/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import "typings-test";
|
235
test/test.js
235
test/test.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
266
test/test.ts
266
test/test.ts
@ -1,66 +1,226 @@
|
|||||||
/// <reference path="../ts/typings/main.d.ts" />
|
import "typings-test";
|
||||||
var smartfile = require("../dist/index.js");
|
import * as smartfile from "../dist/index";
|
||||||
var beautylog = require("beautylog");
|
let beautylog = require("beautylog");
|
||||||
var should = require("should");
|
let gulp = require("gulp");
|
||||||
var vinyl = require("vinyl");
|
let gFunction = require("gulp-function");
|
||||||
|
import path = require("path");
|
||||||
|
import should = require("should");
|
||||||
|
let vinyl = require("vinyl");
|
||||||
|
|
||||||
describe("smartfile",function(){
|
describe("smartfile".yellow,function(){
|
||||||
describe(".readFileToString".yellow,function(){
|
describe(".fs".yellow,function(){
|
||||||
it("should read a file to a string",function(){
|
|
||||||
should.equal(
|
|
||||||
smartfile.readFileToString("./test/mytest.txt"),
|
|
||||||
"Some TestString &&%$"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe(".readFileToObject".yellow,function(){
|
|
||||||
it("should read an " + ".yaml".blue + " file to an object",function(){
|
|
||||||
var testData = smartfile.readFileToObject("./test/mytest.yaml");
|
|
||||||
testData.should.have.property("key1","this works");
|
|
||||||
testData.should.have.property("key2","this works too");
|
|
||||||
|
|
||||||
});
|
|
||||||
it("should state unknown file type for unknown file types",function(){
|
|
||||||
var testData = smartfile.readFileToObject("./test/mytest.txt");
|
|
||||||
});
|
|
||||||
it("should read an " + ".json".blue + " file to an object",function(){
|
|
||||||
var testData = smartfile.readFileToObject("./test/mytest.json");
|
|
||||||
testData.should.have.property("key1","this works");
|
|
||||||
testData.should.have.property("key2","this works too");
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe(".readFileToVinyl".yellow,function(){
|
|
||||||
it("should read an " + ".json OR .yaml".blue + " file to an " + "vinyl file object".cyan,function(){
|
|
||||||
var testData = smartfile.readFileToVinyl("./test/mytest.json");
|
|
||||||
(vinyl.isVinyl(testData)).should.be.true();
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe(".checks".yellow,function(){
|
|
||||||
describe(".fileExistsSync".yellow,function(){
|
describe(".fileExistsSync".yellow,function(){
|
||||||
it("should return an accurate boolean",function(){
|
it("should return an accurate boolean",function(){
|
||||||
(smartfile.checks.fileExistsSync("./test/mytest.json")).should.be.true();
|
(smartfile.fs.fileExistsSync("./test/mytest.json")).should.be.true();
|
||||||
(smartfile.checks.fileExistsSync("./test/notthere.json")).should.be.false();
|
(smartfile.fs.fileExistsSync("./test/notthere.json")).should.be.false();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe(".fileExists".yellow,function(){
|
describe(".fileExists".yellow,function(){
|
||||||
it("should return a working promise",function(){
|
it("should return a working promise",function(){
|
||||||
(smartfile.checks.fileExists("./test/mytest.json")).should.be.Promise();
|
(smartfile.fs.fileExists("./test/mytest.json")).should.be.Promise();
|
||||||
(smartfile.checks.fileExists("./test/mytest.json")).should.be.fulfilled();
|
(smartfile.fs.fileExists("./test/mytest.json")).should.be.fulfilled();
|
||||||
(smartfile.checks.fileExists("./test/notthere.json")).should.not.be.fulfilled();
|
(smartfile.fs.fileExists("./test/notthere.json")).should.not.be.fulfilled();
|
||||||
});
|
});
|
||||||
})
|
|
||||||
});
|
|
||||||
describe("copy",function(){
|
|
||||||
it("should copy a directory",function(){
|
|
||||||
smartfile.copy("./test/testfolder/","./test/assets/")
|
|
||||||
});
|
});
|
||||||
it("should copy a file",function(){
|
describe(".listFoldersSync()",function(){
|
||||||
smartfile.copy("./test/mytest.yaml","./test/assets/")
|
it("should get the file type from a string",function(){
|
||||||
|
smartfile.fs.listFoldersSync("./test/").should.containDeep([ "testfolder"]);
|
||||||
|
smartfile.fs.listFoldersSync("./test/").should.not.containDeep([ "notExistentFolder"]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it("should copy a file and rename it",function(){
|
describe(".listFolders()",function(){
|
||||||
smartfile.copy("./test/mytest.yaml","./test/assets/mytestRenamed.yaml")
|
it("should get the file type from a string",function(done){
|
||||||
|
smartfile.fs.listFolders("./test/")
|
||||||
|
.then(function(folderArrayArg){
|
||||||
|
folderArrayArg.should.containDeep([ "testfolder"]);
|
||||||
|
folderArrayArg.should.not.containDeep([ "notExistentFolder"]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
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(){
|
||||||
|
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(){
|
||||||
|
smartfile.interpreter.filetype("./somefolder/data.json").should.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");
|
||||||
|
testData.should.have.property("key1","this works");
|
||||||
|
testData.should.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");
|
||||||
|
testData.should.have.property("key1","this works");
|
||||||
|
testData.should.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");
|
||||||
|
(vinyl.isVinyl(testData)).should.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"};
|
||||||
|
(smartfile.memory.toVinylFileSync(localString,localOptions) instanceof vinyl).should.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);
|
||||||
|
testResult.should.be.Array();
|
||||||
|
(testResult.length === 3).should.be.true();
|
||||||
|
for (let myKey in testResult){
|
||||||
|
(testResult[myKey] instanceof vinyl).should.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")
|
||||||
|
}));
|
||||||
|
localString.should.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){
|
||||||
|
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();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
26
ts/index.ts
26
ts/index.ts
@ -1,17 +1,15 @@
|
|||||||
/// <reference path="./typings/main.d.ts" />
|
import "typings-global";
|
||||||
|
|
||||||
import plugins = require("./smartfile.plugins");
|
import * as plugins from "./smartfile.plugins";
|
||||||
import SmartfileChecks = require("./smartfile.checks");
|
import * as SmartfileFs from "./smartfile.fs";
|
||||||
import SmartfileSimple = require("./smartfile.simple");
|
import * as SmartfileInterpreter from "./smartfile.interpreter"
|
||||||
|
import * as SmartfileMemory from "./smartfile.memory";
|
||||||
|
import * as SmartfileRemote from "./smartfile.remote";
|
||||||
|
|
||||||
|
export {Smartfile} from "./smartfile.classes.smartfile";
|
||||||
|
|
||||||
var smartfile:any = {
|
export let fs = SmartfileFs;
|
||||||
copy: SmartfileSimple.copy,
|
export let interpreter = SmartfileInterpreter;
|
||||||
checks: SmartfileChecks,
|
export let memory = SmartfileMemory;
|
||||||
readFileToString: SmartfileSimple.readFileToString,
|
export let remote = SmartfileRemote;
|
||||||
readFileToObject: SmartfileSimple.readFileToObject,
|
export let requireReload = SmartfileFs.requireReload;
|
||||||
readFileToVinyl: SmartfileSimple.readFileToVinyl,
|
|
||||||
requireReload: SmartfileSimple.requireReload
|
|
||||||
};
|
|
||||||
|
|
||||||
export = smartfile;
|
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
/// <reference path="./typings/main.d.ts" />
|
|
||||||
import plugins = require("./smartfile.plugins");
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @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;
|
|
||||||
};
|
|
5
ts/smartfile.classes.smartfile.ts
Normal file
5
ts/smartfile.classes.smartfile.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export class Smartfile {
|
||||||
|
constructor(){
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
288
ts/smartfile.fs.ts
Normal file
288
ts/smartfile.fs.ts
Normal file
@ -0,0 +1,288 @@
|
|||||||
|
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.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 =========================
|
||||||
|
===============================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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){
|
||||||
|
var done = plugins.q.defer();
|
||||||
|
plugins.fs.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.fs.copySync(fromArg,toArg);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes a file or folder from local disk
|
||||||
|
*/
|
||||||
|
export let remove = function(pathArg:string){
|
||||||
|
var done = plugins.q.defer();
|
||||||
|
plugins.fs.remove(pathArg,function(){
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes a file SYNCHRONOUSLY from local disk
|
||||||
|
*/
|
||||||
|
export let removeSync = function(pathArg:string):boolean{
|
||||||
|
plugins.fs.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.fs.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.fs.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.fs.readdirSync(pathArg).filter(function(file) {
|
||||||
|
return plugins.fs.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.fs.readdirSync(pathArg).filter(function(file) {
|
||||||
|
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isDirectory();
|
||||||
|
});
|
||||||
|
if(regexFilter){
|
||||||
|
folderArray = folderArray.filter((fileItem) => {
|
||||||
|
return regexFilter.test(fileItem);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return folderArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lists Files in a directory on local disk
|
||||||
|
* @returns Promise
|
||||||
|
*/
|
||||||
|
export let listFiles = function(pathArg:string, regexFilter?:RegExp){
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
let fileArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
|
||||||
|
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isFile();
|
||||||
|
});
|
||||||
|
if(regexFilter){
|
||||||
|
fileArray = fileArray.filter((fileItem) => {
|
||||||
|
return regexFilter.test(fileItem);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
done.resolve(fileArray);
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lists Files SYNCHRONOUSLY in a directory on local disk
|
||||||
|
* @returns an array with the folder names as strings
|
||||||
|
*/
|
||||||
|
export let listFilesSync = function(pathArg:string, regexFilter?:RegExp):string[]{
|
||||||
|
let fileArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
|
||||||
|
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isFile();
|
||||||
|
});
|
||||||
|
if(regexFilter){
|
||||||
|
fileArray = fileArray.filter((fileItem) => {
|
||||||
|
return regexFilter.test(fileItem);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return fileArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lists all items (folders AND files) in a directory on local disk
|
||||||
|
* @returns Promise
|
||||||
|
*/
|
||||||
|
export let listAllItems = function(pathArg:string, regexFilter?:RegExp){
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
let allItmesArray = plugins.fs.readdirSync(pathArg);
|
||||||
|
if(regexFilter){
|
||||||
|
allItmesArray = allItmesArray.filter((fileItem) => {
|
||||||
|
return regexFilter.test(fileItem);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
done.resolve(allItmesArray);
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lists all items (folders AND files) SYNCHRONOUSLY in a directory on local disk
|
||||||
|
* @returns an array with the folder names as strings
|
||||||
|
*/
|
||||||
|
export let listAllItemsSync = function(pathArg:string, regexFilter?:RegExp):string[]{
|
||||||
|
let allItmesArray = plugins.fs.readdirSync(pathArg).filter(function(file) {
|
||||||
|
return plugins.fs.statSync(plugins.path.join(pathArg, file)).isFile();
|
||||||
|
});
|
||||||
|
if(regexFilter){
|
||||||
|
allItmesArray = allItmesArray.filter((fileItem) => {
|
||||||
|
return regexFilter.test(fileItem);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return allItmesArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
22
ts/smartfile.interpreter.ts
Normal file
22
ts/smartfile.interpreter.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
133
ts/smartfile.memory.ts
Normal file
133
ts/smartfile.memory.ts
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
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.fs.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.fs.writeFileSync(filePath,fileString,"utf8");
|
||||||
|
};
|
||||||
|
|
@ -1,10 +1,15 @@
|
|||||||
/// <reference path="./typings/main.d.ts" />
|
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 glob = require("glob");
|
||||||
|
export let g = {
|
||||||
|
remoteSrc: require("gulp-remote-src")
|
||||||
|
};
|
||||||
export let path = require("path");
|
export let path = require("path");
|
||||||
export let q = require("q");
|
export let q = require("q");
|
||||||
export let 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 requireReload = require("require-reload");
|
export let requireReload = require("require-reload");
|
||||||
export let shelljs = require("shelljs");
|
|
||||||
|
65
ts/smartfile.remote.ts
Normal file
65
ts/smartfile.remote.ts
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import "typings-global";
|
||||||
|
import plugins = require("./smartfile.plugins");
|
||||||
|
import SmartfileInterpreter = require("./smartfile.interpreter");
|
||||||
|
|
||||||
|
export let toFs = function(from:string,toPath:string) {
|
||||||
|
var done = plugins.q.defer();
|
||||||
|
var stream = plugins.request(from).pipe(plugins.fs.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;
|
||||||
|
};
|
||||||
|
|
@ -1,68 +0,0 @@
|
|||||||
/// <reference path="./typings/main.d.ts" />
|
|
||||||
|
|
||||||
import plugins = require("./smartfile.plugins");
|
|
||||||
|
|
||||||
export let copy = function(fromArg:string,toArg:string){
|
|
||||||
plugins.shelljs.cp("-r",fromArg,toArg);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* reads a file content to a String
|
|
||||||
* @param filePath
|
|
||||||
* @returns {string|Buffer|any}
|
|
||||||
*/
|
|
||||||
export let readFileToString = function(filePath) {
|
|
||||||
let fileString;
|
|
||||||
fileString = plugins.fs.readFileSync(filePath, "utf8");
|
|
||||||
return fileString;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param filePath
|
|
||||||
* @param fileTypeArg
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
export let readFileToObject = function(filePath,fileTypeArg = undefined) {
|
|
||||||
let fileType;
|
|
||||||
if (typeof fileTypeArg == "undefined") {
|
|
||||||
fileType = plugins.path.extname(filePath);
|
|
||||||
} else {
|
|
||||||
fileType = fileTypeArg;
|
|
||||||
}
|
|
||||||
fileType = fileType.replace(/\.([a-z]*)/,"$1"); //remove . form fileType
|
|
||||||
switch (fileType) {
|
|
||||||
case "yml" :
|
|
||||||
case "yaml":
|
|
||||||
try {
|
|
||||||
return plugins.yaml.safeLoad(plugins.fs.readFileSync(filePath, 'utf8'));
|
|
||||||
} catch (e){
|
|
||||||
plugins.beautylog.error("check that " + filePath.blue + " points to a valid file");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "json":
|
|
||||||
return plugins.fs.readJsonSync(filePath,{});
|
|
||||||
default:
|
|
||||||
plugins.beautylog.error("file type " + fileType.blue + " not supported");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param filePathArg
|
|
||||||
* @param options
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
export let readFileToVinyl = 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);
|
|
||||||
};
|
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"ambientDependencies": {
|
|
||||||
"browserify": "github:DefinitelyTyped/DefinitelyTyped/browserify/browserify.d.ts",
|
|
||||||
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts",
|
|
||||||
"mocha": "github:Bartvds/tsd-deftools/typings/DefinitelyTyped/mocha/mocha.d.ts",
|
|
||||||
"node": "registry:dt/node#4.0.0+20160311162451"
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user