Compare commits

...

26 Commits

Author SHA1 Message Date
2aff46eb0e 2.0.1 2022-03-31 01:20:20 +02:00
6aa4b86598 fix(core): update 2022-03-31 01:20:20 +02:00
af30268551 2.0.0 2022-03-31 01:20:01 +02:00
e562e8f099 BREAKING CHANGE(core): switch to esm 2022-03-31 01:20:01 +02:00
01f4a53b5b 1.0.14 2019-02-20 23:18:21 +01:00
f42b77986f fix(structure): cleanup 2019-02-20 23:18:20 +01:00
b7ef295757 1.0.13 2019-02-20 00:40:32 +01:00
2818420ee9 fix(docs): update 2019-02-20 00:40:31 +01:00
d759e2a562 1.0.12 2019-02-19 01:10:56 +01:00
65a97c9ee0 fix(core): update 2019-02-19 01:10:56 +01:00
b036bfcb92 1.0.11 2017-07-07 02:46:22 +02:00
c0304d1d10 update README 2017-07-07 02:46:20 +02:00
26880f9b71 1.0.10 2017-06-30 18:37:51 +02:00
aa7c30a096 update ci 2017-06-30 18:37:48 +02:00
083673f02c 1.0.9 2017-06-30 18:32:34 +02:00
93bcc03e72 update smartstream 2017-06-30 18:32:32 +02:00
f8b79710be 1.0.8 2017-03-04 14:26:10 +01:00
addf20995a fix cleanPipe() 2017-03-04 14:26:10 +01:00
5401e5e008 1.0.7 2017-03-04 13:53:21 +01:00
144295f7c0 update ci 2017-03-04 13:53:18 +01:00
1e0557b722 1.0.6 2017-03-04 13:50:15 +01:00
9b67507acd add cleanPipe() 2017-03-04 13:50:12 +01:00
c7b3f2a228 1.0.5 2016-09-25 19:41:15 +02:00
084a47096d switch to done.reject for error handling 2016-09-25 19:41:12 +02:00
224b39f0a6 1.0.4 2016-09-25 16:28:45 +02:00
b24b564495 improved README 2016-09-25 16:28:42 +02:00
19 changed files with 18558 additions and 302 deletions

20
.gitignore vendored
View File

@ -1,4 +1,20 @@
node_modules/
.nogit/
# artifacts
coverage/
public/
pages/
coverage/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,42 +1,140 @@
image: hosttoday/ht-docker-node:npmts
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- test
- release
- page
testLEGACY:
stage: test
- security
- test
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci test legacy
tags:
- docker
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags:
- docker
release:
stage: release
script:
- npmci publish
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
pages:
image: hosttoday/ht-docker-node:npmpage
stage: page
- notpriv
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npmpage --host gitlab
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

11
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@ -1,36 +0,0 @@
# smartstream
simplifies access to node streams, TypeScript ready!
## Availabililty
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartstream)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/smartstream)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartstream)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartstream/gitbook)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartstream/badges/master/build.svg)](https://gitlab.com/pushrocks/smartstream/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartstream/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartstream/commits/master)
[![Dependency Status](https://david-dm.org/pushrocks/smartstream.svg)](https://david-dm.org/pushrocks/smartstream)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartstream/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartstream/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartstream/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartstream)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
We recommend the use of TypeScript for best in class intellisense support.
```typescript
import { Smartstream } from 'smartstream'
import * as gUglify from 'gulp-uglify'
let mySmartstream = new Smartstream([
gulp.src(['./file1.js','./file2.js']),
gUglify(),
gulp.dest('./some/output/path')
])
mySmartstream.onError((err) => {/* handle error */}) // handles all errors in stream
mySmartstream.run().then(() => {/* do something when stream is finished */})
```

38
dist/index.d.ts vendored
View File

@ -1,38 +0,0 @@
/// <reference types="q" />
import * as plugins from './smartstream.plugins';
export interface IErrorFunction {
(err: any): any;
}
export interface IStreamStartFunction {
(stream: any): any;
}
export interface ICustomEventFunction {
(): any;
}
export interface ICustomEventObject {
eventName: string;
eventFunction: ICustomEventFunction;
}
/**
* class Smartstream handles
*/
export declare class Smartstream {
streamArray: any[];
errorFunction: IErrorFunction;
streamStartFunction: IStreamStartFunction;
customEventObjectArray: ICustomEventObject[];
constructor(streamArrayArg: any[]);
/**
* attach an error handler to the stream to prevent throwing
*/
onError(errorFunctionArg: IErrorFunction): void;
/**
* make something with the stream itself
*/
onStreamStart(): plugins.q.Promise<any>;
/**
* run the stream
* @returns Promise
*/
run(): plugins.q.Promise<void>;
}

67
dist/index.js vendored
View File

@ -1,67 +0,0 @@
"use strict";
const plugins = require("./smartstream.plugins");
/**
* class Smartstream handles
*/
class Smartstream {
constructor(streamArrayArg) {
this.streamArray = [];
this.errorFunction = null;
this.streamStartFunction = null;
this.customEventObjectArray = [];
this.streamArray = streamArrayArg;
}
/**
* attach an error handler to the stream to prevent throwing
*/
onError(errorFunctionArg) {
this.errorFunction = errorFunctionArg;
}
/**
* make something with the stream itself
*/
onStreamStart() {
}
/**
* run the stream
* @returns Promise
*/
run() {
let done = plugins.q.defer();
// clone Array
let streamExecutionArray = [];
for (let streamItem of this.streamArray) {
streamExecutionArray.push(streamItem);
}
// combine the stream
let finalStream = null;
let firstIteration = true;
for (let stream of streamExecutionArray) {
if (firstIteration === true) {
finalStream = stream;
}
if (this.errorFunction !== null) {
stream.on('error', this.errorFunction);
}
for (let customEventObject of this.customEventObjectArray) {
stream.on(customEventObject.eventName, customEventObject.eventFunction);
}
if (!firstIteration) {
finalStream = finalStream.pipe(stream);
}
firstIteration = false;
}
finalStream.on('end', function () {
done.resolve();
});
finalStream.on('close', function () {
done.resolve();
});
finalStream.on('finish', function () {
done.resolve();
});
return done.promise;
}
}
exports.Smartstream = Smartstream;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsaURBQWdEO0FBbUJoRDs7R0FFRztBQUNIO0lBS0ksWUFBWSxjQUFxQjtRQUpqQyxnQkFBVyxHQUFHLEVBQUUsQ0FBQTtRQUNoQixrQkFBYSxHQUFtQixJQUFJLENBQUE7UUFDcEMsd0JBQW1CLEdBQXlCLElBQUksQ0FBQTtRQUNoRCwyQkFBc0IsR0FBeUIsRUFBRSxDQUFBO1FBRTdDLElBQUksQ0FBQyxXQUFXLEdBQUcsY0FBYyxDQUFBO0lBQ3JDLENBQUM7SUFFRDs7T0FFRztJQUNILE9BQU8sQ0FBQyxnQkFBZ0M7UUFDcEMsSUFBSSxDQUFDLGFBQWEsR0FBRyxnQkFBZ0IsQ0FBQTtJQUN6QyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxhQUFhO0lBRWIsQ0FBQztJQUVEOzs7T0FHRztJQUNILEdBQUc7UUFDQyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBUSxDQUFBO1FBRWxDLGNBQWM7UUFDZCxJQUFJLG9CQUFvQixHQUFHLEVBQUUsQ0FBQTtRQUM3QixHQUFHLENBQUMsQ0FBQyxJQUFJLFVBQVUsSUFBSSxJQUFJLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQztZQUFDLG9CQUFvQixDQUFDLElBQUksQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUFDLENBQUM7UUFFbEYscUJBQXFCO1FBQ3JCLElBQUksV0FBVyxHQUFHLElBQUksQ0FBQTtRQUN0QixJQUFJLGNBQWMsR0FBWSxJQUFJLENBQUE7UUFDbEMsR0FBRyxDQUFDLENBQUMsSUFBSSxNQUFNLElBQUksb0JBQW9CLENBQUMsQ0FBQyxDQUFDO1lBQ3RDLEVBQUUsQ0FBQyxDQUFDLGNBQWMsS0FBSyxJQUFJLENBQUMsQ0FBQyxDQUFDO2dCQUMxQixXQUFXLEdBQUcsTUFBTSxDQUFBO1lBQ3hCLENBQUM7WUFDRCxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsYUFBYSxLQUFLLElBQUksQ0FBQyxDQUFDLENBQUM7Z0JBQzlCLE1BQU0sQ0FBQyxFQUFFLENBQUMsT0FBTyxFQUFFLElBQUksQ0FBQyxhQUFhLENBQUMsQ0FBQTtZQUMxQyxDQUFDO1lBQ0QsR0FBRyxDQUFDLENBQUMsSUFBSSxpQkFBaUIsSUFBSSxJQUFJLENBQUMsc0JBQXNCLENBQUMsQ0FBQyxDQUFDO2dCQUN4RCxNQUFNLENBQUMsRUFBRSxDQUFDLGlCQUFpQixDQUFDLFNBQVMsRUFBRSxpQkFBaUIsQ0FBQyxhQUFhLENBQUMsQ0FBQTtZQUMzRSxDQUFDO1lBQ0QsRUFBRSxDQUFDLENBQUMsQ0FBQyxjQUFjLENBQUMsQ0FBQyxDQUFDO2dCQUNsQixXQUFXLEdBQUcsV0FBVyxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsQ0FBQTtZQUMxQyxDQUFDO1lBQ0QsY0FBYyxHQUFHLEtBQUssQ0FBQTtRQUMxQixDQUFDO1FBQ0QsV0FBVyxDQUFDLEVBQUUsQ0FBQyxLQUFLLEVBQUM7WUFDakIsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2xCLENBQUMsQ0FBQyxDQUFBO1FBQ0YsV0FBVyxDQUFDLEVBQUUsQ0FBQyxPQUFPLEVBQUM7WUFDbkIsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2xCLENBQUMsQ0FBQyxDQUFBO1FBQ0YsV0FBVyxDQUFDLEVBQUUsQ0FBQyxRQUFRLEVBQUM7WUFDcEIsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2xCLENBQUMsQ0FBQyxDQUFBO1FBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztDQUNKO0FBL0RELGtDQStEQyJ9

View File

@ -1,2 +0,0 @@
import 'typings-global';
export import q = require('q');

View File

@ -1,4 +0,0 @@
"use strict";
require("typings-global");
exports.q = require("q");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJlYW0ucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c3RyZWFtLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2Qix5QkFBOEIifQ==

View File

@ -1 +1,17 @@
{}
{
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartstream",
"description": "simplifies access to node streams",
"npmPackagename": "@pushrocks/smartstream",
"license": "MIT"
}
}
}

18159
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,14 @@
{
"name": "smartstream",
"version": "1.0.3",
"description": "simplifies access to node streams, TypeScript ready!",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"name": "@pushrocks/smartstream",
"version": "2.0.1",
"private": false,
"description": "simplifies access to node streams",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": {
"test": "(npmts)"
"test": "(tstest test/)",
"build": "(tsbuild)"
},
"repository": {
"type": "git",
@ -18,14 +21,30 @@
},
"homepage": "https://gitlab.com/pushrocks/smartstream#README",
"devDependencies": {
"@types/should": "^8.1.30",
"npmts-g": "^5.2.8",
"should": "^11.1.0",
"typings-test": "^1.0.3"
"@gitzone/tsbuild": "^2.1.61",
"@gitzone/tstest": "^1.0.70",
"@pushrocks/tapbundle": "^5.0.3",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@types/q": "0.x.x",
"q": "^1.4.1",
"typings-global": "^1.0.14"
}
"@pushrocks/smartpromise": "^3.1.7",
"@types/through2": "^2.0.36",
"through2": "^4.0.2"
},
"browserslist": [
"last 1 chrome versions"
],
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

54
readme.md Normal file
View File

@ -0,0 +1,54 @@
# @pushrocks/smartstream
simplifies access to node streams
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartstream)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartstream)
* [github.com (source mirror)](https://github.com/pushrocks/smartstream)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartstream/)
## Status for master
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartstream/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartstream/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartstream)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartstream)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartstream)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartstream)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartstream)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage
Use TypeScript for best in class instellisense.
```typescript
import { Smartstream } from 'smartstream'
import * as gUglify from 'gulp-uglify'
let mySmartstream = new Smartstream([
gulp.src(['./file1.js','./file2.js']),
gUglify(),
gulp.dest('./some/output/path')
])
mySmartstream.onError((err) => { /* handle error */ }) // handles all errors in stream
myStream.onCustomEvent('myeventname', (args...) => { /* Do something */ }) // emit an custom event anywhere in your stream
mySmartstream.run().then(() => {/* do something when stream is finished */})
```
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

1
test/test.d.ts vendored
View File

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

View File

@ -1,18 +0,0 @@
"use strict";
require("typings-test");
const fs = require("fs");
const smartstream = require("../dist/index");
let testSmartstream;
describe('smartstream', function () {
it('should combine a stream', function (done) {
this.timeout(5000);
testSmartstream = new smartstream.Smartstream([
fs.createReadStream('./test/assets/test.md'),
fs.createWriteStream('./test/assets/testCopy.md')
]);
testSmartstream.run().then(() => {
done();
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQix5QkFBeUI7QUFHekIsNkNBQTRDO0FBRTVDLElBQUksZUFBd0MsQ0FBQTtBQUU1QyxRQUFRLENBQUMsYUFBYSxFQUFFO0lBQ3BCLEVBQUUsQ0FBQyx5QkFBeUIsRUFBRSxVQUFTLElBQUk7UUFDdkMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUNsQixlQUFlLEdBQUcsSUFBSSxXQUFXLENBQUMsV0FBVyxDQUFDO1lBQzFDLEVBQUUsQ0FBQyxnQkFBZ0IsQ0FBQyx1QkFBdUIsQ0FBQztZQUM1QyxFQUFFLENBQUMsaUJBQWlCLENBQUMsMkJBQTJCLENBQUM7U0FDcEQsQ0FBQyxDQUFBO1FBQ0YsZUFBZSxDQUFDLEdBQUcsRUFBRSxDQUFDLElBQUksQ0FBQztZQUN2QixJQUFJLEVBQUUsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9

View File

@ -1,20 +1,15 @@
import 'typings-test'
import fs = require('fs')
import * as should from 'should'
import fs from 'fs';
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartstream from '../dist/index'
import * as smartstream from '../ts/index.js';
let testSmartstream: smartstream.Smartstream
describe('smartstream', function() {
it('should combine a stream', function(done){
this.timeout(5000)
let testSmartstream: smartstream.Smartstream;
tap.test('should combine a stream', async () => {
testSmartstream = new smartstream.Smartstream([
fs.createReadStream('./test/assets/test.md'),
fs.createWriteStream('./test/assets/testCopy.md')
])
testSmartstream.run().then(() => {
done()
})
})
})
fs.createWriteStream('./test/assets/testCopy.md'),
]);
await testSmartstream.run();
});
tap.start();

View File

@ -1,86 +1,107 @@
import * as plugins from './smartstream.plugins'
import * as plugins from './smartstream.plugins.js';
// interfaces
import { Transform } from 'stream';
export interface IErrorFunction {
(err): any
}
export interface IStreamStartFunction {
(stream): any
(err: Error): any;
}
export interface ICustomEventFunction {
(): any
(): any;
}
export interface ICustomEventObject {
eventName: string
eventFunction: ICustomEventFunction
eventName: string;
eventFunction: ICustomEventFunction;
}
/**
* class Smartstream handles
*/
export class Smartstream {
streamArray = []
errorFunction: IErrorFunction = null
streamStartFunction: IStreamStartFunction = null
customEventObjectArray: ICustomEventObject[] = []
constructor(streamArrayArg: any[]) {
this.streamArray = streamArrayArg
}
private streamArray: Array<plugins.stream.Duplex> = [];
private customEventObjectArray: ICustomEventObject[] = [];
private streamStartedDeferred = plugins.smartpromise.defer();
/**
* attach an error handler to the stream to prevent throwing
* constructor
*/
onError(errorFunctionArg: IErrorFunction) {
this.errorFunction = errorFunctionArg
constructor(streamArrayArg: any[]) {
this.streamArray = streamArrayArg;
}
/**
* make something with the stream itself
*/
onStreamStart(): plugins.q.Promise<any> {
streamStarted(): Promise<any> {
return this.streamStartedDeferred.promise;
}
/**
* attach listener to custom event
*/
onCustomEvent(eventNameArg: string, eventFunctionArg: ICustomEventFunction) {
this.customEventObjectArray.push({
eventName: eventNameArg,
eventFunction: eventFunctionArg,
});
}
/**
* run the stream
* @returns Promise
*/
run(): plugins.q.Promise<void> {
let done = plugins.q.defer<void>()
run(): Promise<void> {
const done = plugins.smartpromise.defer<void>();
// clone Array
let streamExecutionArray = []
for (let streamItem of this.streamArray) { streamExecutionArray.push(streamItem) }
const streamExecutionArray: Array<plugins.stream.Duplex> = [];
for (const streamItem of this.streamArray) {
streamExecutionArray.push(streamItem);
}
// combine the stream
let finalStream = null
let firstIteration: boolean = true
for (let stream of streamExecutionArray) {
let finalStream = null;
let firstIteration: boolean = true;
for (const stream of streamExecutionArray) {
if (firstIteration === true) {
finalStream = stream
finalStream = stream;
}
if (this.errorFunction !== null) {
stream.on('error', this.errorFunction)
}
for (let customEventObject of this.customEventObjectArray) {
stream.on(customEventObject.eventName, customEventObject.eventFunction)
stream.on('error', (err) => {
done.reject(err);
});
for (const customEventObject of this.customEventObjectArray) {
stream.on(customEventObject.eventName, customEventObject.eventFunction);
}
if (!firstIteration) {
finalStream = finalStream.pipe(stream)
finalStream = finalStream.pipe(stream);
}
firstIteration = false
firstIteration = false;
}
finalStream.on('end',function(){
done.resolve()
})
finalStream.on('close',function(){
done.resolve()
})
finalStream.on('finish',function(){
done.resolve()
})
return done.promise
this.streamStartedDeferred.resolve();
finalStream.on('end', () => {
done.resolve();
});
finalStream.on('close', () => {
done.resolve();
});
finalStream.on('finish', () => {
done.resolve();
});
return done.promise;
}
}
export let cleanPipe = () => {
return plugins.through2.obj(
(file, enc, cb) => {
cb();
},
(cb) => {
cb();
}
);
};

View File

@ -1,2 +1,12 @@
import 'typings-global'
export import q = require('q')
import * as stream from 'stream';
export { stream };
// pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
export { smartpromise };
// thirdparty
import * as through2 from 'through2';
export { through2 };

View File

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