update ci

This commit is contained in:
Philipp Kunz 2018-03-01 00:08:08 +01:00
parent 9e06369139
commit cb6c8f3c8e
19 changed files with 1017 additions and 670 deletions

View File

@ -7,15 +7,36 @@ cache:
key: "$CI_BUILD_STAGE"
stages:
- mirror
- security
- test
- release
- trigger
- pages
mirror:
stage: mirror
script:
- npmci git mirror
tags:
- docker
security:
stage: security
script:
- npmci command yarn global add snyk
- npmci command yarn install --ignore-scripts
- npmci command snyk test
tags:
- docker
allow_failure: true
testLEGACY:
stage: test
script:
- npmci test legacy
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
@ -24,7 +45,9 @@ testLEGACY:
testLTS:
stage: test
script:
- npmci test lts
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
@ -32,7 +55,9 @@ testLTS:
testSTABLE:
stage: test
script:
- npmci test stable
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
@ -40,7 +65,8 @@ testSTABLE:
release:
stage: release
script:
- npmci publish
- npmci npm prepare
- npmci npm publish
only:
- tags
tags:
@ -60,7 +86,7 @@ pages:
stage: pages
script:
- npmci command yarn global add npmpage
- npmci command npmpage --publish gitlab
- npmci command npmpage
tags:
- docker
only:

View File

@ -1,13 +1,16 @@
# smartchok
smart wrapper for chokidar
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartchok)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartchok)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartchok)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartchok/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartchok/badges/master/build.svg)](https://GitLab.com/pushrocks/smartchok/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartchok/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartchok/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartchok.svg)](https://www.npmjs.com/package/smartchok)
@ -19,34 +22,35 @@ smart wrapper for chokidar
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
Use TypeScript for best in class instellisense.
```javascript
import { Smartchok } from 'smartchok'
import { Smartchok } from 'smartchok';
let mySmartChok = new Smartchok(['some/path/**/*.any','/absolute/*.js'], chokidarOptions)
let mySmartChok = new Smartchok(['some/path/**/*.any', '/absolute/*.js'], chokidarOptions);
mySmartChok.add(['/some/**/*.any']) // add files
mySmartChok.add(['/some/**/*.any']); // add files
mySmartChok.remove('some/**/*.js')
mySmartChok.remove('some/**/*.js');
mySmartChok.start() // starts the watch process
mySmartChok.start(); // starts the watch process
mySmartChok.getObservableFor('change').then((observableArg) => {
mySmartChok.getObservableFor('change').then(observableArg => {
observableArg.subscribe(x => {
// do something here when a change is detected
// possible events are 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw'
// note that the observable is only created once you call .start() on the Smartchok instance
// hence the promise construction
})
})
});
});
mySmartChok.stop()
mySmartChok.stop();
```
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)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

2
dist/index.js vendored
View File

@ -4,4 +4,4 @@ function __export(m) {
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./smartchok.classes.smartchok"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG1EQUE2QyJ9
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG1EQUE4QyJ9

View File

View File

@ -1,3 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNoaWxkLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjaG9rLmNoaWxkLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==

View File

@ -1,12 +1,11 @@
import * as plugins from './smartchok.plugins';
import { Stringmap } from 'lik';
export declare type TSmartchokStatus = 'idle' | 'starting' | 'watching';
export declare type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw';
/**
* Smartchok allows easy wathcing of files
*/
export declare class Smartchok {
watchStringmap: Stringmap;
watchStringmap: plugins.lik.Stringmap;
chokidarOptions: plugins.chokidar.WatchOptions;
status: TSmartchokStatus;
private watcher;
@ -27,7 +26,7 @@ export declare class Smartchok {
/**
* gets an observable for a certain event
*/
getObservableFor(fsEvent: TFsEvent): Promise<plugins.rx.Observable<any>>;
getObservableFor(fsEvent: TFsEvent): Promise<plugins.smartrx.rxjs.Observable<any>>;
/**
* starts the watcher
* @returns Promise<void>

View File

@ -13,7 +13,7 @@ class Smartchok {
this.watchStringmap = new lik_1.Stringmap();
this.status = 'idle';
this.watchingDeferred = plugins.smartq.defer(); // used to run things when watcher is initialized
this.eventObservablemap = new plugins.lik.Observablemap(); // register one observable per event
this.eventObservablemap = new plugins.smartrx.Observablemap(); // register one observable per event
this.watchStringmap.addStringArray(watchArrayArg);
this.chokidarOptions = optionsArg;
}
@ -67,9 +67,11 @@ class Smartchok {
closeWatcher();
}
else if (this.status === 'starting') {
this.watchingDeferred.promise.then(() => { closeWatcher(); });
this.watchingDeferred.promise.then(() => {
closeWatcher();
});
}
}
}
exports.Smartchok = Smartchok;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjaG9rLmNsYXNzZXMuc21hcnRjaG9rLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0NBQThDO0FBQzlDLDZCQUErQjtBQUsvQjs7R0FFRztBQUNIO0lBUUU7O09BRUc7SUFDSCxZQUFhLGFBQXVCLEVBQUUsYUFBNEMsRUFBRTtRQVZwRixtQkFBYyxHQUFHLElBQUksZUFBUyxFQUFFLENBQUE7UUFFaEMsV0FBTSxHQUFxQixNQUFNLENBQUE7UUFFekIscUJBQWdCLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxLQUFLLEVBQVEsQ0FBQSxDQUFDLGlEQUFpRDtRQUNqRyx1QkFBa0IsR0FBRyxJQUFJLE9BQU8sQ0FBQyxHQUFHLENBQUMsYUFBYSxFQUFFLENBQUEsQ0FBQyxvQ0FBb0M7UUFNL0YsSUFBSSxDQUFDLGNBQWMsQ0FBQyxjQUFjLENBQUMsYUFBYSxDQUFDLENBQUE7UUFDakQsSUFBSSxDQUFDLGVBQWUsR0FBRyxVQUFVLENBQUE7SUFDbkMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsR0FBRyxDQUFDLFlBQXNCO1FBQ3hCLElBQUksQ0FBQyxjQUFjLENBQUMsY0FBYyxDQUFDLFlBQVksQ0FBQyxDQUFBO0lBQ2xELENBQUM7SUFFRDs7T0FFRztJQUNILE1BQ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ENBQUMsQ0FBQztZQUN0QyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxHQUFHLEVBQUU7Z0JBQ3RDLFlBQVksRUFBRSxDQUFDO1lBQ2pCLENBQUMsQ0FBQyxDQUFDO1FBQ0wsQ0FBQztJQUNILENBQUM7Q0FDRjtBQWhGRCw4QkFnRkMifQ==

View File

View File

@ -1,3 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLmNsYXNzZXMud2F0Y2hlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2hvay5jbGFzc2VzLndhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9

View File

@ -1,13 +1,5 @@
import 'typings-global';
export import lik = require('lik');
export import chokidar = require('chokidar');
export import path = require('path');
export import smartq = require('smartq');
export import rx = require('rxjs/Rx');
import { Operator } from 'rxjs/Operator';
import { Observable } from 'rxjs/Observable';
declare module 'rxjs/Subject' {
interface Subject<T> {
lift<R>(operator: Operator<T, R>): Observable<R>;
}
}
export import smartrx = require('smartrx');

View File

@ -1,9 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
exports.lik = require("lik");
exports.chokidar = require("chokidar");
exports.path = require("path");
exports.smartq = require("smartq");
exports.rx = require("rxjs/Rx");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qiw2QkFBa0M7QUFDbEMsdUNBQTRDO0FBQzVDLCtCQUFvQztBQUNwQyxtQ0FBd0M7QUFDeEMsZ0NBQXFDIn0=
exports.smartrx = require("smartrx");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjaG9rLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNob2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDZCQUFtQztBQUNuQyx1Q0FBNkM7QUFDN0MsK0JBQXFDO0FBQ3JDLG1DQUF5QztBQUN6QyxxQ0FBMkMifQ==

View File

@ -19,16 +19,16 @@
},
"homepage": "https://gitlab.com/pushrocks/smartchok#README",
"dependencies": {
"@types/chokidar": "^1.7.0",
"chokidar": "^1.7.0",
"lik": "^1.0.32",
"rxjs": "^5.4.1",
"smartipc": "^1.0.9",
"smartq": "^1.1.1",
"typings-global": "^1.0.19"
"@types/chokidar": "^1.7.5",
"chokidar": "^2.0.2",
"lik": "^2.0.5",
"smartipc": "^1.0.11",
"smartq": "^1.1.6",
"smartrx": "^1.0.5"
},
"devDependencies": {
"smartfile": "^4.2.17",
"tapbundle": "^1.0.14"
"@types/node": "^9.4.6",
"smartfile": "^4.2.28",
"tapbundle": "^2.0.0"
}
}

View File

@ -1,5 +1,5 @@
import { tap, expect } from 'tapbundle'
import * as smartchok from '../dist/index'
import * as smartchok from '../ts/index'
import * as smartfile from 'smartfile'
import * as smartq from 'smartq'
import * as rx from 'rxjs/Rx'
@ -11,23 +11,23 @@ let testAddObservable: rx.Observable<any>
let testSubscription: rx.Subscription
tap.test('should create a new instance', async () => {
testSmartchok = new smartchok.Smartchok([])
return expect(testSmartchok).to.be.instanceof(smartchok.Smartchok)
}).catch(tap.threw)
expect(testSmartchok).to.be.instanceof(smartchok.Smartchok)
})
tap.test('should add some files to watch and start', async () => {
testSmartchok.add([ './test/assets/**/*.txt' ])
let localPromise = testSmartchok.start().then(async () => {
testSmartchok.add([ './test/assets/**/*.md' ])
})
return await expect(localPromise).to.eventually.be.fulfilled
}).catch(tap.threw)
await expect(localPromise).to.eventually.be.fulfilled
})
tap.test('should get an observable for a certain event', async () => {
let localPromise = testSmartchok.getObservableFor('add').then(async (observableArg) => {
testAddObservable = observableArg
})
return await expect(localPromise).to.eventually.be.fulfilled
}).catch(tap.threw)
await expect(localPromise).to.eventually.be.fulfilled
})
tap.test('should register an add operation', async () => {
let testDeferred = smartq.defer()
@ -35,11 +35,11 @@ tap.test('should register an add operation', async () => {
testDeferred.resolve()
})
smartfile.memory.toFs('HI', './test/assets/hi.txt')
return await expect(testDeferred.promise).to.eventually.be.fulfilled
}).catch(tap.threw)
await expect(testDeferred.promise).to.eventually.be.fulfilled
})
tap.test('should stop the watch process', async () => {
testSmartchok.stop()
}).catch(tap.threw)
})
tap.start()

View File

@ -1 +1 @@
export * from './smartchok.classes.smartchok'
export * from './smartchok.classes.smartchok';

View File

@ -1 +0,0 @@
import chokidar = require('chokidar')

View File

@ -1,52 +1,64 @@
import * as plugins from './smartchok.plugins'
import { Stringmap } from 'lik'
import * as plugins from './smartchok.plugins';
import { Stringmap } from 'lik';
import { Observablemap } from 'smartrx';
export type TSmartchokStatus = 'idle' | 'starting' | 'watching'
export type TFsEvent = 'add' | 'addDir' | 'change' | 'error' | 'unlink' | 'unlinkDir' | 'ready' | 'raw'
export type TSmartchokStatus = 'idle' | 'starting' | 'watching';
export type TFsEvent =
| 'add'
| 'addDir'
| 'change'
| 'error'
| 'unlink'
| 'unlinkDir'
| 'ready'
| 'raw';
/**
* Smartchok allows easy wathcing of files
*/
export class Smartchok {
watchStringmap = new Stringmap()
chokidarOptions: plugins.chokidar.WatchOptions
status: TSmartchokStatus = 'idle'
private watcher
private watchingDeferred = plugins.smartq.defer<void>() // used to run things when watcher is initialized
private eventObservablemap = new plugins.lik.Observablemap() // register one observable per event
watchStringmap = new Stringmap();
chokidarOptions: plugins.chokidar.WatchOptions;
status: TSmartchokStatus = 'idle';
private watcher;
private watchingDeferred = plugins.smartq.defer<void>(); // used to run things when watcher is initialized
private eventObservablemap = new plugins.smartrx.Observablemap(); // register one observable per event
/**
* constructor of class smartchok
*/
constructor(watchArrayArg: string[], optionsArg: plugins.chokidar.WatchOptions = {}) {
this.watchStringmap.addStringArray(watchArrayArg)
this.chokidarOptions = optionsArg
this.watchStringmap.addStringArray(watchArrayArg);
this.chokidarOptions = optionsArg;
}
/**
* adds files to the list of watched files
*/
add(pathArrayArg: string[]) {
this.watchStringmap.addStringArray(pathArrayArg)
this.watchStringmap.addStringArray(pathArrayArg);
}
/**
* removes files from the list of watched files
*/
remove(pathArg: string) {
this.watchStringmap.removeString(pathArg)
this.watchStringmap.removeString(pathArg);
}
/**
* gets an observable for a certain event
*/
getObservableFor (fsEvent: TFsEvent): Promise<plugins.rx.Observable<any>> {
let done = plugins.smartq.defer<plugins.rx.Observable<any>>()
getObservableFor(fsEvent: TFsEvent): Promise<plugins.smartrx.rxjs.Observable<any>> {
let done = plugins.smartq.defer<plugins.smartrx.rxjs.Observable<any>>();
this.watchingDeferred.promise.then(() => {
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(this.watcher, fsEvent)
done.resolve(eventObservable)
})
return done.promise
let eventObservable = this.eventObservablemap.getObservableForEmitterEvent(
this.watcher,
fsEvent
);
done.resolve(eventObservable);
});
return done.promise;
}
/**
@ -54,15 +66,18 @@ export class Smartchok {
* @returns Promise<void>
*/
start(): Promise<void> {
let done = plugins.smartq.defer<void>()
this.status = 'starting'
this.watcher = plugins.chokidar.watch(this.watchStringmap.getStringArray(), this.chokidarOptions)
let done = plugins.smartq.defer<void>();
this.status = 'starting';
this.watcher = plugins.chokidar.watch(
this.watchStringmap.getStringArray(),
this.chokidarOptions
);
this.watcher.on('ready', () => {
this.status = 'watching'
this.watchingDeferred.resolve()
done.resolve()
})
return done.promise
this.status = 'watching';
this.watchingDeferred.resolve();
done.resolve();
});
return done.promise;
}
/**
@ -70,13 +85,15 @@ export class Smartchok {
*/
stop() {
let closeWatcher = () => {
this.watcher.close()
}
this.watcher.close();
};
if (this.status === 'watching') {
console.log('closing while watching')
closeWatcher()
console.log('closing while watching');
closeWatcher();
} else if (this.status === 'starting') {
this.watchingDeferred.promise.then(() => { closeWatcher() })
this.watchingDeferred.promise.then(() => {
closeWatcher();
});
}
}
}

View File

@ -1,2 +0,0 @@
import * as plugins from './smartchok.plugins'

View File

@ -1,15 +1,5 @@
import 'typings-global'
export import lik = require('lik')
export import chokidar = require('chokidar')
export import path = require('path')
export import smartq = require('smartq')
export import rx = require('rxjs/Rx')
// workaround
import {Operator} from 'rxjs/Operator'
import {Observable} from 'rxjs/Observable'
declare module 'rxjs/Subject' {
interface Subject<T> {
lift<R>(operator: Operator<T, R>): Observable<R>
}
}
export import lik = require('lik');
export import chokidar = require('chokidar');
export import path = require('path');
export import smartq = require('smartq');
export import smartrx = require('smartrx');

1415
yarn.lock

File diff suppressed because it is too large Load Diff