Compare commits

...

40 Commits

Author SHA1 Message Date
88d4bf6be0 1.0.31 2020-03-05 09:26:41 +00:00
d4f8215f35 fix(core): update 2020-03-05 09:26:41 +00:00
85f72feeb9 1.0.30 2019-10-14 14:57:43 +02:00
bd4ccbd215 fix(core): update 2019-10-14 14:57:43 +02:00
79940cec3f 1.0.29 2019-10-14 14:53:56 +02:00
e20508ffbc fix(core): update 2019-10-14 14:53:55 +02:00
21b962b9a8 1.0.28 2019-10-12 18:09:42 +02:00
f673e8577b fix(core): update 2019-10-12 18:09:41 +02:00
e4278ed270 1.0.27 2019-10-12 17:43:44 +02:00
8ae0f960ac fix(core): update 2019-10-12 17:43:43 +02:00
c9a3b996cb 1.0.26 2019-10-12 17:34:05 +02:00
d81d19008a fix(core): update 2019-10-12 17:34:05 +02:00
e4ef6bad8f 1.0.25 2019-10-12 17:31:26 +02:00
2873314742 fix(core): update 2019-10-12 17:31:25 +02:00
e26fa92744 1.0.24 2019-10-12 17:17:32 +02:00
995f296319 fix(core): update 2019-10-12 17:17:31 +02:00
e7866dadb7 1.0.23 2019-10-12 17:12:51 +02:00
9302e78f86 fix(core): update 2019-10-12 17:12:50 +02:00
0a302bee95 1.0.22 2019-10-12 16:54:19 +02:00
deb5e1daf9 1.0.21 2019-10-12 16:54:03 +02:00
5fe27ee706 fix(core): update 2019-10-12 16:54:03 +02:00
b73807baf0 1.0.20 2019-10-12 15:57:44 +02:00
1e71fc24d5 fix(core): update 2019-10-12 15:57:43 +02:00
e8071e76a1 1.0.19 2019-10-12 15:07:45 +02:00
b11d03dd41 fix(core): update 2019-10-12 15:07:44 +02:00
72297d2f58 1.0.18 2019-05-28 14:28:50 +02:00
71b900ac47 fix(core): update 2019-05-28 14:28:50 +02:00
f6d06edced 1.0.17 2019-05-28 11:35:04 +02:00
3e98005843 fix(core): update 2019-05-28 11:35:03 +02:00
7c4673a5b6 1.0.16 2019-05-27 15:38:07 +02:00
99ec82ab55 fix(core): update 2019-05-27 15:38:07 +02:00
1f0c1964dd 1.0.15 2019-05-27 14:46:34 +02:00
828229872d fix(core): update 2019-05-27 14:46:33 +02:00
0ff482bd01 1.0.14 2019-05-27 14:07:14 +02:00
39c8da4f74 fix(core): update 2019-05-27 14:07:13 +02:00
fcd2029744 1.0.13 2019-05-22 16:52:38 +02:00
d89e0a13d5 fix(core): update 2019-05-22 16:52:38 +02:00
64c7815bca 1.0.12 2019-05-22 16:45:49 +02:00
f3e69eb15e fix(core): update 2019-05-22 16:45:48 +02:00
386e4c07c6 1.0.11 2019-05-14 08:45:10 +02:00
11 changed files with 3474 additions and 683 deletions

5
.gitignore vendored
View File

@@ -8,9 +8,12 @@ pages/
# installs # installs
node_modules/ node_modules/
# caches and builds # caches
.yarn/ .yarn/
.cache/ .cache/
.rpt2_cache
# builds
dist/ dist/
dist_web/ dist_web/
dist_serve/ dist_serve/

View File

@@ -1,5 +1,5 @@
# gitzone standard # gitzone ci_default
image: hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
@@ -38,19 +38,7 @@ snyk:
# test stage # test stage
# ==================== # ====================
testLTS: testStable:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
@@ -60,6 +48,18 @@ testSTABLE:
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- priv
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
- notpriv - notpriv
release: release:
@@ -78,19 +78,12 @@ release:
# ==================== # ====================
codequality: codequality:
stage: metadata stage: metadata
image: docker:stable
allow_failure: true allow_failure: true
services:
- docker:stable-dind
script: script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') - npmci command npm install -g tslint typescript
- docker run - npmci npm prepare
--env SOURCE_CODE="$PWD" - npmci npm install
--volume "$PWD":/code - npmci command "tslint -c tslint.json ./ts/**/*.ts"
--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: tags:
- docker - docker
- priv - priv
@@ -106,13 +99,15 @@ trigger:
- notpriv - notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-dbase:npmci
services:
- docker:stable-dind
stage: metadata stage: metadata
script: script:
- npmci command npm install -g typedoc typescript - npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/ - npmci command tsdoc
tags: tags:
- docker - docker
- notpriv - notpriv

3822
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,34 +1,50 @@
{ {
"name": "@gitzone/tswatch", "name": "@gitzone/tswatch",
"version": "1.0.10", "version": "1.0.31",
"private": false, "private": false,
"description": "watch typescript projects during development", "description": "watch typescript projects during development",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"bin": {
"tswatch": "cli.js"
},
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild)", "build": "(tsbuild)"
"format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.11", "@gitzone/tsbuild": "^2.1.17",
"@gitzone/tstest": "^1.0.20", "@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.0.9", "@pushrocks/tapbundle": "^3.2.0",
"@types/node": "^12.0.0", "@types/node": "^13.7.7",
"tslint": "^5.16.0", "tslint": "^6.0.0",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@gitzone/tsrun": "^1.2.6", "@gitzone/tsbundle": "^1.0.50",
"@gitzone/tsrun": "^1.2.8",
"@pushrocks/early": "^3.0.3", "@pushrocks/early": "^3.0.3",
"@pushrocks/lik": "^3.0.5", "@pushrocks/lik": "^3.0.19",
"@pushrocks/smartchok": "^1.0.18", "@pushrocks/smartchok": "^1.0.23",
"@pushrocks/smartcli": "^3.0.7", "@pushrocks/smartcli": "^3.0.7",
"@pushrocks/smartdelay": "^2.0.3", "@pushrocks/smartdelay": "^2.0.6",
"@pushrocks/smartlog": "^2.0.19", "@pushrocks/smartlog": "^2.0.21",
"@pushrocks/smartlog-destination-local": "^7.0.5", "@pushrocks/smartlog-destination-local": "^8.0.2",
"@pushrocks/smartshell": "^2.0.13" "@pushrocks/smartserve": "^1.1.39",
} "@pushrocks/smartshell": "^2.0.25",
"@pushrocks/taskbuffer": "^2.1.1"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_web/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
]
} }

View File

@@ -21,6 +21,6 @@ watch typescript projects during development
For further information read the linked docs at the top of this readme. For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > 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)
[![repo-footer](https://gitzone.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com) [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@@ -12,7 +12,7 @@ tap.test('should start the tswatch instance', async () => {
await testTsWatchInstance.start(); await testTsWatchInstance.start();
}); });
tap.test('should stop the instance', async (tools) => { tap.test('should stop the instance', async tools => {
tools.delayFor(2000); tools.delayFor(2000);
testTsWatchInstance.stop(); testTsWatchInstance.stop();
}); });

View File

@@ -1 +1,7 @@
export type TWatchModes = 'test' | 'gitzone_npm' | 'gitzone_service' | 'gitzone_website' | 'echoSomething'; export type TWatchModes =
| 'test'
| 'gitzone_npm'
| 'gitzone_service'
| 'gitzone_element'
| 'gitzone_website'
| 'echoSomething';

View File

@@ -7,6 +7,7 @@ import { Watcher } from './tswatch.classes.watcher';
export class TsWatch { export class TsWatch {
public watchmode: interfaces.TWatchModes; public watchmode: interfaces.TWatchModes;
public watcherMap = new plugins.lik.Objectmap<Watcher>(); public watcherMap = new plugins.lik.Objectmap<Watcher>();
public smartserve: plugins.smartserve.SmartServe;
constructor(watchmodeArg: interfaces.TWatchModes) { constructor(watchmodeArg: interfaces.TWatchModes) {
this.watchmode = watchmodeArg; this.watchmode = watchmodeArg;
@@ -18,39 +19,73 @@ export class TsWatch {
public async start() { public async start() {
switch (this.watchmode) { switch (this.watchmode) {
case 'test': case 'test':
this.watcherMap.add(new Watcher({ this.watcherMap.add(
new Watcher({
filePathToWatch: paths.cwd, filePathToWatch: paths.cwd,
commandToExecute: 'npm run test2', commandToExecute: 'npm run test2',
timeout: null timeout: null
})); })
);
break; break;
case 'gitzone_npm': case 'gitzone_npm':
this.watcherMap.add(new Watcher({ this.watcherMap.add(
new Watcher({
filePathToWatch: paths.cwd, filePathToWatch: paths.cwd,
commandToExecute: 'npm run test', commandToExecute: 'npm run test',
timeout: null timeout: null
})); })
);
break;
case 'gitzone_element':
// lets create a standard server
this.smartserve = new plugins.smartserve.SmartServe({
port: 3001,
injectReload: true,
serveDir: plugins.path.join(paths.cwd, './dist_web/')
});
this.watcherMap.add(
new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts_web/'),
commandToExecute: async () => {
const tsbundle = new plugins.tsbundle.TsBundle();
const htmlHandler = new plugins.tsbundle.HtmlHandler();
await tsbundle.buildProduction('./ts_web/index.ts', './dist_web/bundle.js');
await htmlHandler.copyHtml();
},
timeout: null
})
);
break; break;
case 'gitzone_website': case 'gitzone_website':
// server directory
this.watcherMap.add( this.watcherMap.add(
new Watcher({ new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts/'), filePathToWatch: plugins.path.join(paths.cwd, './ts/'),
commandToExecute: 'npm run start', commandToExecute: 'npm run startTs',
timeout: null timeout: null
}) })
); );
// client directory // client directory
this.watcherMap.add(new Watcher({ this.watcherMap.add(
new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts_web/'), filePathToWatch: plugins.path.join(paths.cwd, './ts_web/'),
commandToExecute: 'npm run build', commandToExecute: 'npm run build',
timeout: null timeout: null
})); })
);
break;
case 'gitzone_service':
this.watcherMap.add(
new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts/'),
commandToExecute: 'npm run startTs',
timeout: null
})
);
break; break;
case 'echoSomething': case 'echoSomething':
const tsWatchInstanceEchoSomething = new Watcher({ const tsWatchInstanceEchoSomething = new Watcher({
filePathToWatch: paths.cwd, filePathToWatch: plugins.path.join(paths.cwd, './ts'),
commandToExecute: 'npm -v', commandToExecute: 'npm -v',
timeout: null timeout: null
}); });
@@ -62,12 +97,18 @@ export class TsWatch {
this.watcherMap.forEach(async watcher => { this.watcherMap.forEach(async watcher => {
await watcher.start(); await watcher.start();
}); });
if (this.smartserve) {
await this.smartserve.start();
}
} }
/** /**
* stops the execution of any active Watchers * stops the execution of any active Watchers
*/ */
public async stop() { public async stop() {
if (this.smartserve) {
await this.smartserve.stop();
}
this.watcherMap.forEach(async watcher => { this.watcherMap.forEach(async watcher => {
await watcher.stop(); await watcher.stop();
}); });

View File

@@ -1,9 +1,11 @@
import * as plugins from './tswatch.plugins'; import * as plugins from './tswatch.plugins';
import { logger } from './tswatch.logging'; import { logger } from './tswatch.logging';
export type TCommandFunction = () => Promise<void>;
export interface IWatcherConstructorOptions { export interface IWatcherConstructorOptions {
filePathToWatch: string; filePathToWatch: string;
commandToExecute: string; commandToExecute: string | TCommandFunction;
timeout?: number; timeout?: number;
} }
@@ -11,9 +13,28 @@ export interface IWatcherConstructorOptions {
* A watcher keeps track of one child execution * A watcher keeps track of one child execution
*/ */
export class Watcher { export class Watcher {
/**
* used to execute shell commands
*/
private smartshellInstance = new plugins.smartshell.Smartshell({ private smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash' executor: 'bash'
}); });
/**
* used to execute
*/
private executionTask: plugins.taskbuffer.Task = new plugins.taskbuffer.Task({
name: 'watcherCommandFunctionTask',
taskFunction: async () => {
if (typeof this.options.commandToExecute === 'string') {
throw new Error('cannot execute string as task');
}
await this.options.commandToExecute();
},
buffered: true,
bufferMax: 1
});
private currentExecution: plugins.smartshell.IExecResultStreaming; private currentExecution: plugins.smartshell.IExecResultStreaming;
private smartchokWatcher = new plugins.smartchok.Smartchok([], {}); private smartchokWatcher = new plugins.smartchok.Smartchok([], {});
private options: IWatcherConstructorOptions; private options: IWatcherConstructorOptions;
@@ -26,7 +47,7 @@ export class Watcher {
* start the file * start the file
*/ */
public async start() { public async start() {
this.setupCleanup(); await this.setupCleanup();
console.log(`Looking at ${this.options.filePathToWatch} for changes`); console.log(`Looking at ${this.options.filePathToWatch} for changes`);
this.smartchokWatcher.add([this.options.filePathToWatch]); // __dirname refers to the directory of this very file this.smartchokWatcher.add([this.options.filePathToWatch]); // __dirname refers to the directory of this very file
await this.smartchokWatcher.start(); await this.smartchokWatcher.start();
@@ -34,13 +55,14 @@ export class Watcher {
changeObservable.subscribe(() => { changeObservable.subscribe(() => {
this.updateCurrentExecution(); this.updateCurrentExecution();
}); });
this.updateCurrentExecution(); await this.updateCurrentExecution();
} }
/** /**
* updates the current execution * updates the current execution
*/ */
private async updateCurrentExecution() { private async updateCurrentExecution() {
if (typeof this.options.commandToExecute === 'string') {
if (this.currentExecution) { if (this.currentExecution) {
logger.log('ok', `reexecuting ${this.options.commandToExecute}`); logger.log('ok', `reexecuting ${this.options.commandToExecute}`);
process.kill(-this.currentExecution.childProcess.pid); process.kill(-this.currentExecution.childProcess.pid);
@@ -51,6 +73,9 @@ export class Watcher {
this.options.commandToExecute this.options.commandToExecute
); );
this.currentExecution = null; this.currentExecution = null;
} else {
await this.executionTask.trigger();
}
} }
/** /**
@@ -90,7 +115,7 @@ export class Watcher {
*/ */
public async stop() { public async stop() {
await this.smartchokWatcher.stop(); await this.smartchokWatcher.stop();
if (this.currentExecution) { if (this.currentExecution && !this.currentExecution.childProcess.killed) {
process.kill(-this.currentExecution.childProcess.pid); process.kill(-this.currentExecution.childProcess.pid);
} }
} }

View File

@@ -8,6 +8,24 @@ const tswatchCli = new plugins.smartcli.Smartcli();
// standard behaviour will assume gitzone setup // standard behaviour will assume gitzone setup
tswatchCli.addCommand('element').subscribe(async argvArg => {
logger.log('info', `running watch task for a gitzone element project`);
const tsWatch = new TsWatch('gitzone_element');
await tsWatch.start();
});
tswatchCli.addCommand('npm').subscribe(async argvArg => {
logger.log('info', `running watch task for a gitzone element project`);
const tsWatch = new TsWatch('gitzone_npm');
await tsWatch.start();
});
tswatchCli.addCommand('service').subscribe(async argvArg => {
logger.log('info', `running test task`);
const tsWatch = new TsWatch('gitzone_service');
await tsWatch.start();
});
tswatchCli.addCommand('test').subscribe(async argvArg => { tswatchCli.addCommand('test').subscribe(async argvArg => {
logger.log('info', `running test task`); logger.log('info', `running test task`);
const tsWatch = new TsWatch('test'); const tsWatch = new TsWatch('test');
@@ -18,6 +36,6 @@ tswatchCli.addCommand('website').subscribe(async argvArg => {
logger.log('info', `running watch task for a gitzone website project`); logger.log('info', `running watch task for a gitzone website project`);
const tsWatch = new TsWatch('gitzone_website'); const tsWatch = new TsWatch('gitzone_website');
await tsWatch.start(); await tsWatch.start();
}) });
tswatchCli.startParse(); tswatchCli.startParse();

View File

@@ -1,6 +1,13 @@
import * as path from 'path'; import * as path from 'path';
export { path }; export { path };
// @gitzone scope
import * as tsbundle from '@gitzone/tsbundle';
export {
tsbundle
};
// @pushrocks scope // @pushrocks scope
import * as lik from '@pushrocks/lik'; import * as lik from '@pushrocks/lik';
import * as smartchok from '@pushrocks/smartchok'; import * as smartchok from '@pushrocks/smartchok';
@@ -8,6 +15,8 @@ import * as smartcli from '@pushrocks/smartcli';
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@pushrocks/smartdelay';
import * as smartlog from '@pushrocks/smartlog'; import * as smartlog from '@pushrocks/smartlog';
import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local'; import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
import * as smartserve from '@pushrocks/smartserve';
import * as smartshell from '@pushrocks/smartshell'; import * as smartshell from '@pushrocks/smartshell';
import * as taskbuffer from '@pushrocks/taskbuffer';
export { lik, smartchok, smartcli, smartdelay, smartlog, smartlogDestinationLocal, smartshell }; export { lik, smartchok, smartcli, smartdelay, smartlog, smartlogDestinationLocal, smartserve, smartshell, taskbuffer };