Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
b7ef295757 | |||
2818420ee9 | |||
d759e2a562 | |||
65a97c9ee0 | |||
b036bfcb92 | |||
c0304d1d10 | |||
26880f9b71 | |||
aa7c30a096 | |||
083673f02c | |||
93bcc03e72 | |||
f8b79710be | |||
addf20995a | |||
5401e5e008 | |||
144295f7c0 | |||
1e0557b722 | |||
9b67507acd | |||
c7b3f2a228 | |||
084a47096d |
132
.gitlab-ci.yml
132
.gitlab-ci.yml
@ -1,42 +1,150 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
# gitzone standard
|
||||||
|
image: hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .npmci_cache/
|
||||||
|
key: "$CI_BUILD_STAGE"
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- page
|
- metadata
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci test legacy
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
snyk:
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install -g snyk
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command snyk test
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
sast:
|
||||||
|
stage: security
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||||
|
variables:
|
||||||
|
DOCKER_DRIVER: overlay2
|
||||||
|
allow_failure: true
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
|
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||||
|
- docker run
|
||||||
|
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
||||||
|
--volume "$PWD:/code"
|
||||||
|
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
||||||
|
artifacts:
|
||||||
|
reports:
|
||||||
|
sast: gl-sast-report.json
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test lts
|
- npmci npm prepare
|
||||||
|
- npmci node install lts
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test stable
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci publish
|
- npmci node install stable
|
||||||
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
pages:
|
- notpriv
|
||||||
image: hosttoday/ht-docker-node:npmpage
|
|
||||||
stage: page
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
image: docker:stable
|
||||||
|
allow_failure: true
|
||||||
|
services:
|
||||||
|
- docker:stable-dind
|
||||||
script:
|
script:
|
||||||
- npmci command npmpage --host gitlab
|
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||||
|
- docker run
|
||||||
|
--env SOURCE_CODE="$PWD"
|
||||||
|
--volume "$PWD":/code
|
||||||
|
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||||
|
artifacts:
|
||||||
|
paths: [codeclimate.json]
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npmci trigger
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
pages:
|
||||||
|
image: hosttoday/ht-docker-node:npmci
|
||||||
|
stage: metadata
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g typedoc typescript
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
32
README.md
32
README.md
@ -1,24 +1,24 @@
|
|||||||
# smartstream
|
# @pushrocks/smartstream
|
||||||
simplifies access to node streams, TypeScript ready!
|
simplifies access to node streams
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty and Links
|
||||||
[](https://www.npmjs.com/package/smartstream)
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartstream)
|
||||||
[](https://gitlab.com/pushrocks/smartstream)
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartstream)
|
||||||
[](https://github.com/pushrocks/smartstream)
|
* [github.com (source mirror)](https://github.com/pushrocks/smartstream)
|
||||||
[](https://pushrocks.gitlab.io/smartstream/gitbook)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartstream/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[](https://gitlab.com/pushrocks/smartstream/commits/master)
|
[](https://gitlab.com/pushrocks/smartstream/commits/master)
|
||||||
[](https://gitlab.com/pushrocks/smartstream/commits/master)
|
[](https://gitlab.com/pushrocks/smartstream/commits/master)
|
||||||
[](https://david-dm.org/pushrocks/smartstream)
|
[](https://www.npmjs.com/package/@pushrocks/smartstream)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartstream/master/dependencies/npm)
|
[](https://snyk.io/test/npm/@pushrocks/smartstream)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartstream)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
We recommend the use of TypeScript for best in class intellisense support.
|
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { Smartstream } from 'smartstream'
|
import { Smartstream } from 'smartstream'
|
||||||
@ -35,3 +35,9 @@ myStream.onCustomEvent('myeventname', (args...) => { /* Do something */ }) // em
|
|||||||
mySmartstream.run().then(() => {/* do something when stream is finished */})
|
mySmartstream.run().then(() => {/* do something when stream is finished */})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
||||||
|
42
dist/index.d.ts
vendored
42
dist/index.d.ts
vendored
@ -1,42 +0,0 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
import * as plugins from './smartstream.plugins';
|
|
||||||
export interface IErrorFunction {
|
|
||||||
(err: any): any;
|
|
||||||
}
|
|
||||||
export interface ICustomEventFunction {
|
|
||||||
(): any;
|
|
||||||
}
|
|
||||||
export interface ICustomEventObject {
|
|
||||||
eventName: string;
|
|
||||||
eventFunction: ICustomEventFunction;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* class Smartstream handles
|
|
||||||
*/
|
|
||||||
export declare class Smartstream {
|
|
||||||
private streamArray;
|
|
||||||
private errorFunction;
|
|
||||||
private customEventObjectArray;
|
|
||||||
private streamStartedDeferred;
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
*/
|
|
||||||
constructor(streamArrayArg: any[]);
|
|
||||||
/**
|
|
||||||
* attach an error handler to the stream to prevent throwing
|
|
||||||
*/
|
|
||||||
onError(errorFunctionArg: IErrorFunction): void;
|
|
||||||
/**
|
|
||||||
* make something with the stream itself
|
|
||||||
*/
|
|
||||||
streamStarted(): plugins.q.Promise<any>;
|
|
||||||
/**
|
|
||||||
* attach listener to custom event
|
|
||||||
*/
|
|
||||||
onCustomEvent(eventNameArg: string, eventFunctionArg: ICustomEventFunction): void;
|
|
||||||
/**
|
|
||||||
* run the stream
|
|
||||||
* @returns Promise
|
|
||||||
*/
|
|
||||||
run(): plugins.q.Promise<void>;
|
|
||||||
}
|
|
81
dist/index.js
vendored
81
dist/index.js
vendored
@ -1,81 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
const plugins = require("./smartstream.plugins");
|
|
||||||
/**
|
|
||||||
* class Smartstream handles
|
|
||||||
*/
|
|
||||||
class Smartstream {
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
*/
|
|
||||||
constructor(streamArrayArg) {
|
|
||||||
this.streamArray = [];
|
|
||||||
this.errorFunction = null;
|
|
||||||
this.customEventObjectArray = [];
|
|
||||||
this.streamStartedDeferred = plugins.q.defer();
|
|
||||||
this.streamArray = streamArrayArg;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* attach an error handler to the stream to prevent throwing
|
|
||||||
*/
|
|
||||||
onError(errorFunctionArg) {
|
|
||||||
this.errorFunction = errorFunctionArg;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* make something with the stream itself
|
|
||||||
*/
|
|
||||||
streamStarted() {
|
|
||||||
return this.streamStartedDeferred.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* attach listener to custom event
|
|
||||||
*/
|
|
||||||
onCustomEvent(eventNameArg, eventFunctionArg) {
|
|
||||||
this.customEventObjectArray.push({
|
|
||||||
eventName: eventNameArg,
|
|
||||||
eventFunction: eventFunctionArg
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
this.streamStartedDeferred.resolve();
|
|
||||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsaURBQWdEO0FBZWhEOztHQUVHO0FBQ0g7SUFNSTs7T0FFRztJQUNILFlBQVksY0FBcUI7UUFSekIsZ0JBQVcsR0FBRyxFQUFFLENBQUE7UUFDaEIsa0JBQWEsR0FBbUIsSUFBSSxDQUFBO1FBQ3BDLDJCQUFzQixHQUF5QixFQUFFLENBQUE7UUFDakQsMEJBQXFCLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQU03QyxJQUFJLENBQUMsV0FBVyxHQUFHLGNBQWMsQ0FBQTtJQUNyQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxPQUFPLENBQUMsZ0JBQWdDO1FBQ3BDLElBQUksQ0FBQyxhQUFhLEdBQUcsZ0JBQWdCLENBQUE7SUFDekMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsYUFBYTtRQUNULE1BQU0sQ0FBQyxJQUFJLENBQUMscUJBQXFCLENBQUMsT0FBTyxDQUFBO0lBQzdDLENBQUM7SUFFRDs7T0FFRztJQUNILGFBQWEsQ0FBQyxZQUFvQixFQUFFLGdCQUFzQztRQUN0RSxJQUFJLENBQUMsc0JBQXNCLENBQUMsSUFBSSxDQUFDO1lBQzdCLFNBQVMsRUFBRSxZQUFZO1lBQ3ZCLGFBQWEsRUFBRSxnQkFBZ0I7U0FDbEMsQ0FBQyxDQUFBO0lBQ04sQ0FBQztJQUVEOzs7T0FHRztJQUNILEdBQUc7UUFDQyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBUSxDQUFBO1FBRWxDLGNBQWM7UUFDZCxJQUFJLG9CQUFvQixHQUFHLEVBQUUsQ0FBQTtRQUM3QixHQUFHLENBQUMsQ0FBQyxJQUFJLFVBQVUsSUFBSSxJQUFJLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQztZQUFDLG9CQUFvQixDQUFDLElBQUksQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUFDLENBQUM7UUFFbEYscUJBQXFCO1FBQ3JCLElBQUksV0FBVyxHQUFHLElBQUksQ0FBQTtRQUN0QixJQUFJLGNBQWMsR0FBWSxJQUFJLENBQUE7UUFDbEMsR0FBRyxDQUFDLENBQUMsSUFBSSxNQUFNLElBQUksb0JBQW9CLENBQUMsQ0FBQyxDQUFDO1lBQ3RDLEVBQUUsQ0FBQyxDQUFDLGNBQWMsS0FBSyxJQUFJLENBQUMsQ0FBQyxDQUFDO2dCQUMxQixXQUFXLEdBQUcsTUFBTSxDQUFBO1lBQ3hCLENBQUM7WUFDRCxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsYUFBYSxLQUFLLElBQUksQ0FBQyxDQUFDLENBQUM7Z0JBQzlCLE1BQU0sQ0FBQyxFQUFFLENBQUMsT0FBTyxFQUFFLElBQUksQ0FBQyxhQUFhLENBQUMsQ0FBQTtZQUMxQyxDQUFDO1lBQ0QsR0FBRyxDQUFDLENBQUMsSUFBSSxpQkFBaUIsSUFBSSxJQUFJLENBQUMsc0JBQXNCLENBQUMsQ0FBQyxDQUFDO2dCQUN4RCxNQUFNLENBQUMsRUFBRSxDQUFDLGlCQUFpQixDQUFDLFNBQVMsRUFBRSxpQkFBaUIsQ0FBQyxhQUFhLENBQUMsQ0FBQTtZQUMzRSxDQUFDO1lBQ0QsRUFBRSxDQUFDLENBQUMsQ0FBQyxjQUFjLENBQUMsQ0FBQyxDQUFDO2dCQUNsQixXQUFXLEdBQUcsV0FBVyxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsQ0FBQTtZQUMxQyxDQUFDO1lBQ0QsY0FBYyxHQUFHLEtBQUssQ0FBQTtRQUMxQixDQUFDO1FBRUQsSUFBSSxDQUFDLHFCQUFxQixDQUFDLE9BQU8sRUFBRSxDQUFBO1FBRXBDLFdBQVcsQ0FBQyxFQUFFLENBQUMsS0FBSyxFQUFDO1lBQ2pCLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNsQixDQUFDLENBQUMsQ0FBQTtRQUNGLFdBQVcsQ0FBQyxFQUFFLENBQUMsT0FBTyxFQUFDO1lBQ25CLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNsQixDQUFDLENBQUMsQ0FBQTtRQUNGLFdBQVcsQ0FBQyxFQUFFLENBQUMsUUFBUSxFQUFDO1lBQ3BCLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNsQixDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7Q0FDSjtBQWhGRCxrQ0FnRkMifQ==
|
|
2
dist/smartstream.plugins.d.ts
vendored
2
dist/smartstream.plugins.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
import 'typings-global';
|
|
||||||
export import q = require('q');
|
|
4
dist/smartstream.plugins.js
vendored
4
dist/smartstream.plugins.js
vendored
@ -1,4 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-global");
|
|
||||||
exports.q = require("q");
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJlYW0ucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c3RyZWFtLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2Qix5QkFBOEIifQ==
|
|
52
docs/index.md
Normal file
52
docs/index.md
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# smartstream
|
||||||
|
|
||||||
|
simplifies access to node streams, TypeScript ready!
|
||||||
|
|
||||||
|
## Availabililty
|
||||||
|
|
||||||
|
[](https://www.npmjs.com/package/smartstream)
|
||||||
|
[](https://GitLab.com/pushrocks/smartstream)
|
||||||
|
[](https://github.com/pushrocks/smartstream)
|
||||||
|
[](https://pushrocks.gitlab.io/smartstream/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
[](https://GitLab.com/pushrocks/smartstream/commits/master)
|
||||||
|
[](https://GitLab.com/pushrocks/smartstream/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/smartstream)
|
||||||
|
[](https://david-dm.org/pushrocks/smartstream)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartstream/master/dependencies/npm)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartstream)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
## 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
|
||||||
|
myStream.onCustomEvent('myeventname', (args...) => { /* Do something */ }) // emit an custom event anywhere in your stream
|
||||||
|
mySmartstream.run().then(() => {/* do something when stream is finished */})
|
||||||
|
```
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this README.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
|
[](https://lossless.com)
|
@ -1 +1,16 @@
|
|||||||
{}
|
{
|
||||||
|
"npmci": {
|
||||||
|
"npmGlobalTools": [],
|
||||||
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartstream",
|
||||||
|
"shortDescription": "simplifies access to node streams",
|
||||||
|
"npmPackagename": "@pushrocks/smartstream",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1663
package-lock.json
generated
Normal file
1663
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
package.json
25
package.json
@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "smartstream",
|
"name": "@pushrocks/smartstream",
|
||||||
"version": "1.0.4",
|
"version": "1.0.13",
|
||||||
"description": "simplifies access to node streams, TypeScript ready!",
|
"private": false,
|
||||||
|
"description": "simplifies access to node streams",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)"
|
"test": "(tstest test/)",
|
||||||
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -18,14 +20,15 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartstream#README",
|
"homepage": "https://gitlab.com/pushrocks/smartstream#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/should": "^8.1.30",
|
"@gitzone/tsbuild": "^2.1.8",
|
||||||
"npmts-g": "^5.2.8",
|
"@gitzone/tstest": "^1.0.18",
|
||||||
"should": "^11.1.0",
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
"typings-test": "^1.0.3"
|
"tslint": "^5.12.1",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/q": "0.x.x",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"q": "^1.4.1",
|
"@types/through2": "^2.0.34",
|
||||||
"typings-global": "^1.0.14"
|
"through2": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
import 'typings-test';
|
|
18
test/test.js
18
test/test.js
@ -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
|
|
25
test/test.ts
25
test/test.ts
@ -1,20 +1,15 @@
|
|||||||
import 'typings-test'
|
import fs = require('fs');
|
||||||
import fs = require('fs')
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as should from 'should'
|
|
||||||
|
|
||||||
import * as smartstream from '../dist/index'
|
import * as smartstream from '../ts/index';
|
||||||
|
|
||||||
let testSmartstream: smartstream.Smartstream
|
let testSmartstream: smartstream.Smartstream;
|
||||||
|
tap.test('should combine a stream', async () => {
|
||||||
describe('smartstream', function() {
|
|
||||||
it('should combine a stream', function(done){
|
|
||||||
this.timeout(5000)
|
|
||||||
testSmartstream = new smartstream.Smartstream([
|
testSmartstream = new smartstream.Smartstream([
|
||||||
fs.createReadStream('./test/assets/test.md'),
|
fs.createReadStream('./test/assets/test.md'),
|
||||||
fs.createWriteStream('./test/assets/testCopy.md')
|
fs.createWriteStream('./test/assets/testCopy.md')
|
||||||
])
|
]);
|
||||||
testSmartstream.run().then(() => {
|
await testSmartstream.run();
|
||||||
done()
|
});
|
||||||
})
|
|
||||||
})
|
tap.start();
|
||||||
})
|
|
||||||
|
100
ts/index.ts
100
ts/index.ts
@ -1,46 +1,41 @@
|
|||||||
import * as plugins from './smartstream.plugins'
|
import * as plugins from './smartstream.plugins';
|
||||||
|
|
||||||
|
// interfaces
|
||||||
|
import { Transform } from 'stream';
|
||||||
|
|
||||||
export interface IErrorFunction {
|
export interface IErrorFunction {
|
||||||
(err): any
|
(err): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICustomEventFunction {
|
export interface ICustomEventFunction {
|
||||||
(): any
|
(): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICustomEventObject {
|
export interface ICustomEventObject {
|
||||||
eventName: string
|
eventName: string;
|
||||||
eventFunction: ICustomEventFunction
|
eventFunction: ICustomEventFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class Smartstream handles
|
* class Smartstream handles
|
||||||
*/
|
*/
|
||||||
export class Smartstream {
|
export class Smartstream {
|
||||||
private streamArray = []
|
private streamArray = [];
|
||||||
private errorFunction: IErrorFunction = null
|
private customEventObjectArray: ICustomEventObject[] = [];
|
||||||
private customEventObjectArray: ICustomEventObject[] = []
|
private streamStartedDeferred = plugins.smartpromise.defer();
|
||||||
private streamStartedDeferred = plugins.q.defer()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
*/
|
*/
|
||||||
constructor(streamArrayArg: any[]) {
|
constructor(streamArrayArg: any[]) {
|
||||||
this.streamArray = streamArrayArg
|
this.streamArray = streamArrayArg;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* attach an error handler to the stream to prevent throwing
|
|
||||||
*/
|
|
||||||
onError(errorFunctionArg: IErrorFunction) {
|
|
||||||
this.errorFunction = errorFunctionArg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* make something with the stream itself
|
* make something with the stream itself
|
||||||
*/
|
*/
|
||||||
streamStarted(): plugins.q.Promise<any> {
|
streamStarted(): Promise<any> {
|
||||||
return this.streamStartedDeferred.promise
|
return this.streamStartedDeferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,50 +45,63 @@ export class Smartstream {
|
|||||||
this.customEventObjectArray.push({
|
this.customEventObjectArray.push({
|
||||||
eventName: eventNameArg,
|
eventName: eventNameArg,
|
||||||
eventFunction: eventFunctionArg
|
eventFunction: eventFunctionArg
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* run the stream
|
* run the stream
|
||||||
* @returns Promise
|
* @returns Promise
|
||||||
*/
|
*/
|
||||||
run(): plugins.q.Promise<void> {
|
run(): Promise<void> {
|
||||||
let done = plugins.q.defer<void>()
|
const done = plugins.smartpromise.defer<void>();
|
||||||
|
|
||||||
// clone Array
|
// clone Array
|
||||||
let streamExecutionArray = []
|
const streamExecutionArray = [];
|
||||||
for (let streamItem of this.streamArray) { streamExecutionArray.push(streamItem) }
|
for (const streamItem of this.streamArray) {
|
||||||
|
streamExecutionArray.push(streamItem);
|
||||||
|
}
|
||||||
|
|
||||||
// combine the stream
|
// combine the stream
|
||||||
let finalStream = null
|
let finalStream = null;
|
||||||
let firstIteration: boolean = true
|
let firstIteration: boolean = true;
|
||||||
for (let stream of streamExecutionArray) {
|
for (const stream of streamExecutionArray) {
|
||||||
if (firstIteration === true) {
|
if (firstIteration === true) {
|
||||||
finalStream = stream
|
finalStream = stream;
|
||||||
}
|
}
|
||||||
if (this.errorFunction !== null) {
|
stream.on('error', err => {
|
||||||
stream.on('error', this.errorFunction)
|
done.reject(err);
|
||||||
}
|
});
|
||||||
for (let customEventObject of this.customEventObjectArray) {
|
for (const customEventObject of this.customEventObjectArray) {
|
||||||
stream.on(customEventObject.eventName, customEventObject.eventFunction)
|
stream.on(customEventObject.eventName, customEventObject.eventFunction);
|
||||||
}
|
}
|
||||||
if (!firstIteration) {
|
if (!firstIteration) {
|
||||||
finalStream = finalStream.pipe(stream)
|
finalStream = finalStream.pipe(stream);
|
||||||
}
|
}
|
||||||
firstIteration = false
|
firstIteration = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.streamStartedDeferred.resolve()
|
this.streamStartedDeferred.resolve();
|
||||||
|
|
||||||
finalStream.on('end',function(){
|
finalStream.on('end', () => {
|
||||||
done.resolve()
|
done.resolve();
|
||||||
})
|
});
|
||||||
finalStream.on('close',function(){
|
finalStream.on('close', () => {
|
||||||
done.resolve()
|
done.resolve();
|
||||||
})
|
});
|
||||||
finalStream.on('finish',function(){
|
finalStream.on('finish', () => {
|
||||||
done.resolve()
|
done.resolve();
|
||||||
})
|
});
|
||||||
return done.promise
|
return done.promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export let cleanPipe = () => {
|
||||||
|
return plugins.through2.obj(
|
||||||
|
(file, enc, cb) => {
|
||||||
|
cb();
|
||||||
|
},
|
||||||
|
cb => {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
import 'typings-global'
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
export import q = require('q')
|
import * as through2 from 'through2';
|
||||||
|
|
||||||
|
export { smartpromise, through2 };
|
||||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "tslint-config-standard"
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user