Compare commits

...

10 Commits

Author SHA1 Message Date
1960b1d125 1.0.7 2019-05-08 11:16:25 +02:00
7ce6245286 fix(core): update 2019-05-08 11:16:24 +02:00
3a8513d3a0 1.0.6 2019-05-08 11:14:57 +02:00
d425e290dd fix(core): update 2019-05-08 11:14:57 +02:00
483aafd371 1.0.5 2019-05-06 20:13:08 +02:00
2a2a6fe461 fix(core): update 2019-05-06 20:13:08 +02:00
843453f9d4 1.0.4 2019-05-06 20:12:05 +02:00
9b6e3e49f4 fix(core): update 2019-05-06 20:12:05 +02:00
c24c272f6e 1.0.3 2018-10-28 19:28:09 +01:00
4b8bb062c7 fix(core): update 2018-10-28 19:28:08 +01:00
13 changed files with 965 additions and 358 deletions

15
.gitignore vendored
View File

@@ -1,6 +1,19 @@
.nogit/ .nogit/
node_modules/
# artifacts
coverage/ coverage/
public/ public/
pages/ pages/
# installs
node_modules/
# caches and builds
.yarn/ .yarn/
.cache/
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@@ -37,18 +37,6 @@ snyk:
# ==================== # ====================
# test stage # test stage
# ==================== # ====================
testLEGACY:
stage: test
script:
- npmci npm prepare
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
allow_failure: true
testLTS: testLTS:
stage: test stage: test
@@ -135,13 +123,3 @@ pages:
paths: paths:
- public - public
allow_failure: true allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

View File

@@ -2,5 +2,15 @@
"npmci": { "npmci": {
"npmGlobalTools": [], "npmGlobalTools": [],
"npmAccessLevel": "public" "npmAccessLevel": "public"
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "gitzone",
"gitrepo": "tswatch",
"shortDescription": "watch typescript projects during development",
"npmPackagename": "@gitzone/tswatch",
"license": "MIT"
}
} }
} }

1112
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "@gitzone/tswatch", "name": "@gitzone/tswatch",
"version": "1.0.2", "version": "1.0.7",
"private": false, "private": false,
"description": "watch typescript projects during development", "description": "watch typescript projects during development",
"main": "dist/index.js", "main": "dist/index.js",
@@ -8,23 +8,27 @@
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "node ./cli.ts.js test", "test": "node ./cli.ts.js test --timeout 10000",
"test2": "(tstest test/)", "test2": "(tstest test/)",
"build": "(tsbuild)", "build": "(tsbuild)",
"format": "(gitzone format)" "format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.1.11",
"@gitzone/tstest": "^1.0.15", "@gitzone/tstest": "^1.0.20",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.0.9",
"@types/node": "^10.11.7", "@types/node": "^12.0.0",
"tslint": "^5.11.0", "tslint": "^5.16.0",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@gitzone/tsrun": "^1.1.13", "@gitzone/tsrun": "^1.2.6",
"@pushrocks/smartcli": "^3.0.6", "@pushrocks/early": "^3.0.3",
"@pushrocks/smartshell": "^2.0.6", "@pushrocks/smartchok": "^1.0.18",
"filewatcher": "^3.0.1" "@pushrocks/smartcli": "^3.0.7",
"@pushrocks/smartdelay": "^2.0.3",
"@pushrocks/smartlog": "^2.0.19",
"@pushrocks/smartlog-destination-local": "^7.0.5",
"@pushrocks/smartshell": "^2.0.13"
} }
} }

26
readme.md Normal file
View File

@@ -0,0 +1,26 @@
# @gitzone/tswatch
watch typescript projects during development
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@gitzone/tswatch)
* [gitlab.com (source)](https://gitlab.com/gitzone/tswatch)
* [github.com (source mirror)](https://github.com/gitzone/tswatch)
* [docs (typedoc)](https://gitzone.gitlab.io/tswatch/)
## Status for master
[![build status](https://gitlab.com/gitzone/tswatch/badges/master/build.svg)](https://gitlab.com/gitzone/tswatch/commits/master)
[![coverage report](https://gitlab.com/gitzone/tswatch/badges/master/coverage.svg)](https://gitlab.com/gitzone/tswatch/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@gitzone/tswatch.svg)](https://www.npmjs.com/package/@gitzone/tswatch)
[![Known Vulnerabilities](https://snyk.io/test/npm/@gitzone/tswatch/badge.svg)](https://snyk.io/test/npm/@gitzone/tswatch)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
## Usage
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)
[![repo-footer](https://gitzone.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)

View File

@@ -6,16 +6,16 @@ let testTsWatchInstance: tswatch.TsWatch;
tap.test('should create a valid TsWatch instance', async () => { tap.test('should create a valid TsWatch instance', async () => {
testTsWatchInstance = new tswatch.TsWatch({ testTsWatchInstance = new tswatch.TsWatch({
filePathToWatch: process.cwd(), filePathToWatch: process.cwd(),
commandToExecute: 'npm -v' commandToExecute: 'npm -v',
timeout: 1000
}); });
}); });
tap.test('should start the tswatch instance', async () => { tap.test('should start the tswatch instance', async () => {
testTsWatchInstance.start();
console.log('test executed'); console.log('test executed');
}); });
tap.test('should run abitrary commands', async () => { tap.test('should run abitrary commands', async () => {});
});
tap.start(); tap.start();

View File

@@ -1,3 +1,5 @@
import * as early from '@pushrocks/early';
early.start('tswatch');
export * from './tswatch.classes.tswatch'; export * from './tswatch.classes.tswatch';
import './tswatch.cli'; import './tswatch.cli';
early.stop();

View File

@@ -1,5 +1,11 @@
import * as plugins from './tswatch.plugins'; import * as plugins from './tswatch.plugins';
export interface ITsWatchConstructorOptions {
filePathToWatch: string;
commandToExecute: string;
timeout?: number;
}
/** /**
* handles the management of watching for foes * handles the management of watching for foes
*/ */
@@ -8,16 +14,11 @@ export class TsWatch {
executor: 'bash' executor: 'bash'
}); });
private currentExecution: plugins.smartshell.IExecResultStreaming; private currentExecution: plugins.smartshell.IExecResultStreaming;
private watcher = plugins.fileWatcher(); private watcher = new plugins.smartchok.Smartchok([], {});
private filePathToWatch: string; private options: ITsWatchConstructorOptions;
private commandToExecute: string;
constructor(optionsArg: { constructor(optionsArg: ITsWatchConstructorOptions) {
filePathToWatch: string, this.options = optionsArg;
commandToExecute: string
}) {
this.filePathToWatch = optionsArg.filePathToWatch;
this.commandToExecute = optionsArg.commandToExecute;
} }
/** /**
@@ -25,13 +26,10 @@ export class TsWatch {
*/ */
public async start() { public async start() {
this.setupCleanup(); this.setupCleanup();
console.log(`Looking at ${this.filePathToWatch} for changes`); console.log(`Looking at ${this.options.filePathToWatch} for changes`);
this.watcher.add(this.filePathToWatch); // __dirname refers to the directory of this very file this.watcher.add([this.options.filePathToWatch]); // __dirname refers to the directory of this very file
this.watcher.on('change', async (file, stat) => { const changeObservable = await this.watcher.getObservableFor('change');
console.log('Noticed change!'); changeObservable.subscribe(() => {
if (!stat) {
console.log('deleted');
}
this.updateCurrentExecution(); this.updateCurrentExecution();
}); });
this.updateCurrentExecution(); this.updateCurrentExecution();
@@ -41,14 +39,16 @@ export class TsWatch {
if (this.currentExecution) { if (this.currentExecution) {
process.kill(-this.currentExecution.childProcess.pid); process.kill(-this.currentExecution.childProcess.pid);
} }
this.currentExecution = await this.smartshellInstance.execStreaming(this.commandToExecute); this.currentExecution = await this.smartshellInstance.execStreaming(
this.options.commandToExecute
);
this.currentExecution = null; this.currentExecution = null;
} }
/** /**
* this method sets up a clean exit strategy * this method sets up a clean exit strategy
*/ */
private setupCleanup() { private async setupCleanup() {
const cleanup = () => { const cleanup = () => {
if (this.currentExecution) { if (this.currentExecution) {
process.kill(-this.currentExecution.childProcess.pid); process.kill(-this.currentExecution.childProcess.pid);
@@ -66,5 +66,14 @@ export class TsWatch {
cleanup(); cleanup();
process.exit(0); process.exit(0);
}); });
// handle timeout
if (this.options.timeout) {
plugins.smartdelay.delayFor(this.options.timeout).then(() => {
console.log(`timed out afer ${this.options.timeout} milliseconds! exiting!`);
cleanup();
process.exit(0);
});
}
} }
} }

View File

@@ -1,14 +1,26 @@
import * as plugins from './tswatch.plugins'; import * as plugins from './tswatch.plugins';
import * as paths from './tswatch.paths'; import * as paths from './tswatch.paths';
import { logger } from './tswatch.logging';
import { TsWatch } from './tswatch.classes.tswatch'; import { TsWatch } from './tswatch.classes.tswatch';
const tswatchCli = new plugins.smartcli.Smartcli(); const tswatchCli = new plugins.smartcli.Smartcli();
// standard behaviour will assume gitzone setup
tswatchCli.addCommand('test').subscribe(argvArg => { tswatchCli.addCommand('test').subscribe(argvArg => {
logger.log('info', `running test task`);
const tsWatch = new TsWatch({ const tsWatch = new TsWatch({
filePathToWatch: paths.cwd, filePathToWatch: paths.cwd,
commandToExecute: 'npm run test2' commandToExecute: 'npm run test2',
timeout: (() => {
if (argvArg.timeout) {
console.log(`timeing out after ${argvArg.timeout}`);
return argvArg.timeout;
} else {
return null;
}
})()
}); });
tsWatch.start(); tsWatch.start();
}); });

15
ts/tswatch.logging.ts Normal file
View File

@@ -0,0 +1,15 @@
import * as plugins from './tswatch.plugins';
export const logger = new plugins.smartlog.Smartlog({
logContext: {
company: 'Some Company',
companyunit: 'Some CompanyUnit',
containerName: 'Some Containername',
environment: 'local',
runtime: 'node',
zone: 'gitzone'
},
minimumLogLevel: 'silly'
});
logger.addLogDestination(new plugins.smartlogDestinationLocal.DestinationLocal());

View File

@@ -2,12 +2,11 @@ import * as path from 'path';
export { path }; export { path };
// @pushrocks scope // @pushrocks scope
import * as smartchok from '@pushrocks/smartchok';
import * as smartcli from '@pushrocks/smartcli'; import * as smartcli from '@pushrocks/smartcli';
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartlog from '@pushrocks/smartlog';
import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
import * as smartshell from '@pushrocks/smartshell'; import * as smartshell from '@pushrocks/smartshell';
export { smartshell, smartcli }; export { smartchok, smartcli, smartdelay, smartlog, smartlogDestinationLocal, smartshell };
// Third Pary
import * as fileWatcher from 'filewatcher';
export { fileWatcher };

View File

@@ -4,7 +4,14 @@
"semicolon": [true, "always"], "semicolon": [true, "always"],
"no-console": false, "no-console": false,
"ordered-imports": false, "ordered-imports": false,
"object-literal-sort-keys": false "object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
}, },
"defaultSeverity": "warning" "defaultSeverity": "warning"
} }