Compare commits

...

66 Commits

Author SHA1 Message Date
fc356e62f4 1.0.36 2020-03-13 17:48:20 +00:00
a34d98b840 fix(core): update 2020-03-13 17:48:19 +00:00
9525f28507 1.0.35 2020-03-13 17:46:58 +00:00
787aae63d7 fix(core): update 2020-03-13 17:46:57 +00:00
bf2a32a5d5 1.0.34 2020-03-13 17:43:58 +00:00
7ced66fc28 fix(core): update 2020-03-13 17:43:57 +00:00
d01905ae99 1.0.33 2020-03-09 15:08:06 +00:00
59c744cc5e fix(core): update 2020-03-09 15:08:05 +00:00
4d23145529 1.0.32 2020-03-09 14:52:38 +00:00
27e0d7588d fix(core): update 2020-03-09 14:52:37 +00:00
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
82557c96d6 1.0.10 2019-05-13 18:54:06 +02:00
c94d89fa8a fix(core): update 2019-05-13 18:54:05 +02:00
639a5eebea 1.0.9 2019-05-13 09:48:36 +02:00
fb88d3384e fix(core): update 2019-05-13 09:48:35 +02:00
e38342604b 1.0.8 2019-05-09 00:08:41 +02:00
390200ad2a fix(core): update 2019-05-09 00:08:40 +02:00
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
20 changed files with 8464 additions and 629 deletions

18
.gitignore vendored
View File

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

View File

@@ -1,16 +1,16 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
- security
- test
- release
- metadata
# ====================
# security stage
@@ -20,49 +20,27 @@ mirror:
script:
- npmci git mirror
tags:
- lossless
- docker
- notpriv
snyk:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- lossless
- docker
- notpriv
# ====================
# 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:
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:
testStable:
stage: test
script:
- npmci npm prepare
@@ -71,6 +49,20 @@ testSTABLE:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- 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:
- lossless
- docker
- notpriv
@@ -82,6 +74,7 @@ release:
only:
- tags
tags:
- lossless
- docker
- notpriv
@@ -90,20 +83,14 @@ release:
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
script:
- 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]
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
- priv
@@ -114,18 +101,20 @@ trigger:
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
@@ -135,13 +124,3 @@ pages:
paths:
- public
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

24
.snyk Normal file
View File

@@ -0,0 +1,24 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.13.5
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
SNYK-JS-MINIMIST-559764:
- parcel-bundler > @babel/core > json5 > minimist:
reason: None given
expires: '2020-04-12T17:46:49.672Z'
- parcel-bundler > mkdirp > minimist:
reason: None given
expires: '2020-04-12T17:46:49.672Z'
- parcel-bundler > @parcel/fs > mkdirp > minimist:
reason: None given
expires: '2020-04-12T17:46:49.672Z'
- parcel-bundler > htmlnano > svgo > mkdirp > minimist:
reason: None given
expires: '2020-04-12T17:46:49.672Z'
- parcel-bundler > cssnano > cssnano-preset-default > postcss-svgo > svgo > mkdirp > minimist:
reason: None given
expires: '2020-04-12T17:46:49.672Z'
- parcel-bundler > htmlnano > cssnano > cssnano-preset-default > postcss-svgo > svgo > mkdirp > minimist:
reason: None given
expires: '2020-04-12T17:46:49.672Z'
patch: {}

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

@@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

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"]
}
}
}
}
}
}
]
}

View File

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

8342
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,30 +1,51 @@
{
"name": "@gitzone/tswatch",
"version": "1.0.2",
"version": "1.0.36",
"private": false,
"description": "watch typescript projects during development",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"author": "Lossless GmbH",
"license": "MIT",
"bin": {
"tswatch": "cli.js"
},
"scripts": {
"test": "node ./cli.ts.js test",
"test2": "(tstest test/)",
"build": "(tsbuild)",
"format": "(gitzone format)"
"test": "(tstest test/)",
"build": "(tsbuild)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.11.7",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0"
"@gitzone/tsbuild": "^2.1.17",
"@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.2.0",
"@types/node": "^13.9.0",
"tslint": "^6.0.0",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@gitzone/tsrun": "^1.1.13",
"@pushrocks/smartcli": "^3.0.6",
"@pushrocks/smartshell": "^2.0.6",
"filewatcher": "^3.0.1"
}
"@gitzone/tsrun": "^1.2.8",
"@pushrocks/early": "^3.0.3",
"@pushrocks/lik": "^3.0.19",
"@pushrocks/smartchok": "^1.0.23",
"@pushrocks/smartcli": "^3.0.7",
"@pushrocks/smartdelay": "^2.0.6",
"@pushrocks/smartlog": "^2.0.21",
"@pushrocks/smartlog-destination-local": "^8.0.2",
"@pushrocks/smartserve": "^1.1.39",
"@pushrocks/smartshell": "^2.0.25",
"@pushrocks/taskbuffer": "^2.1.1",
"@types/parcel-bundler": "^1.12.1",
"parcel-bundler": "^1.12.4"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_web/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

31
readme.md Normal file
View File

@@ -0,0 +1,31 @@
# @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
[![pipeline status](https://gitlab.com/gitzone/tswatch/badges/master/pipeline.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
## 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 | **©** [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)

View File

@@ -1,21 +1,20 @@
// tslint:disable-next-line: no-implicit-dependencies
import { expect, tap } from '@pushrocks/tapbundle';
import * as tswatch from '../ts/index';
let testTsWatchInstance: tswatch.TsWatch;
tap.test('should create a valid TsWatch instance', async () => {
testTsWatchInstance = new tswatch.TsWatch({
filePathToWatch: process.cwd(),
commandToExecute: 'npm -v'
});
testTsWatchInstance = new tswatch.TsWatch('echoSomething');
});
tap.test('should start the tswatch instance', async () => {
console.log('test executed');
await testTsWatchInstance.start();
});
tap.test('should run abitrary commands', async () => {
tap.test('should stop the instance', async tools => {
tools.delayFor(2000);
testTsWatchInstance.stop();
});
tap.start();

View File

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

1
ts/interfaces/index.ts Normal file
View File

@@ -0,0 +1 @@
export * from './interfaces.watchmodes';

View File

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

View File

@@ -0,0 +1,37 @@
import * as plugins from './tswatch.plugins';
import * as paths from './tswatch.paths';
export class Parcel {
public async start() {
const entryFiles = plugins.path.join(paths.cwd, './html/index.html');
// Bundler options
const options: plugins.parcel.ParcelOptions = {
outDir: './dist_watch', // The out directory to put the build files in, defaults to dist
outFile: 'index.html', // The name of the outputFile
publicUrl: '/', // The url to serve on, defaults to '/'
watch: true, // Whether to watch the files and rebuild them on change, defaults to process.env.NODE_ENV !== 'production'
cache: true, // Enabled or disables caching, defaults to true
cacheDir: '.nogit/.parcelcache', // The directory cache gets put in, defaults to .cache
contentHash: false, // Disable content hash from being included on the filename
global: 'moduleName', // Expose modules as UMD under this name, disabled by default
minify: false, // Minify files, enabled if process.env.NODE_ENV === 'production'
scopeHoist: false, // Turn on experimental scope hoisting/tree shaking flag, for smaller production bundles
target: 'browser', // Browser/node/electron, defaults to browser
bundleNodeModules: true, // By default, package.json dependencies are not included when using 'node' or 'electron' with 'target' option above. Set to true to adds them to the bundle, false by default
https: null,
logLevel: 3, // 5 = save everything to a file, 4 = like 3, but with timestamps and additionally log http requests to dev server, 3 = log info, warnings & errors, 2 = log warnings & errors, 1 = log errors, 0 = log nothing
hmr: true, // Enable or disable HMR while watching
hmrPort: 3003, // The port the HMR socket runs on, defaults to a random free port (0 in node.js resolves to a random free port)
sourceMaps: true, // Enable or disable sourcemaps, defaults to enabled (minified builds currently always create sourcemaps)
hmrHostname: '', // A hostname for hot module reload, default to ''
detailedReport: false // Prints a detailed report of the bundles, assets, filesizes and times, defaults to false, reports are only printed if watch is disabled
};
const bundler = new plugins.parcel(entryFiles, options);
// Run the bundler, this returns the main bundle
// Use the events if you're using watch mode as this promise will only trigger once and not for every rebuild
const bundle = await bundler.serve(3002);
}
}

View File

@@ -1,70 +1,110 @@
import * as plugins from './tswatch.plugins';
import * as paths from './tswatch.paths';
import * as interfaces from './interfaces';
import { Watcher } from './tswatch.classes.watcher';
import { Parcel } from './tswatch.classes.parcel';
/**
* handles the management of watching for foes
*/
export class TsWatch {
private smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
private currentExecution: plugins.smartshell.IExecResultStreaming;
private watcher = plugins.fileWatcher();
private filePathToWatch: string;
private commandToExecute: string;
public watchmode: interfaces.TWatchModes;
public watcherMap = new plugins.lik.Objectmap<Watcher>();
public smartserve: plugins.smartserve.SmartServe;
constructor(optionsArg: {
filePathToWatch: string,
commandToExecute: string
}) {
this.filePathToWatch = optionsArg.filePathToWatch;
this.commandToExecute = optionsArg.commandToExecute;
constructor(watchmodeArg: interfaces.TWatchModes) {
this.watchmode = watchmodeArg;
}
/**
* start the file
* starts the TsWatch instance
*/
public async start() {
this.setupCleanup();
console.log(`Looking at ${this.filePathToWatch} for changes`);
this.watcher.add(this.filePathToWatch); // __dirname refers to the directory of this very file
this.watcher.on('change', async (file, stat) => {
console.log('Noticed change!');
if (!stat) {
console.log('deleted');
}
this.updateCurrentExecution();
switch (this.watchmode) {
case 'test':
this.watcherMap.add(
new Watcher({
filePathToWatch: paths.cwd,
commandToExecute: 'npm run test2',
timeout: null
})
);
break;
case 'gitzone_npm':
this.watcherMap.add(
new Watcher({
filePathToWatch: paths.cwd,
commandToExecute: 'npm run test',
timeout: null
})
);
break;
case 'gitzone_element':
// lets create a standard server
console.log(
'bundling TypeScript files to "dist_watch" Note: This is for development only!'
);
this.smartserve = new plugins.smartserve.SmartServe({
port: 3001,
injectReload: true,
serveDir: plugins.path.join(paths.cwd, './dist_watch/')
});
this.updateCurrentExecution();
}
const parcel = new Parcel();
await parcel.start();
break;
case 'gitzone_website':
this.watcherMap.add(
new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts/'),
commandToExecute: 'npm run startTs',
timeout: null
})
);
private async updateCurrentExecution() {
if (this.currentExecution) {
process.kill(-this.currentExecution.childProcess.pid);
// client directory
this.watcherMap.add(
new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts_web/'),
commandToExecute: 'npm run build',
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;
case 'echoSomething':
const tsWatchInstanceEchoSomething = new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts'),
commandToExecute: 'npm -v',
timeout: null
});
this.watcherMap.add(tsWatchInstanceEchoSomething);
break;
default:
break;
}
this.watcherMap.forEach(async watcher => {
await watcher.start();
});
if (this.smartserve) {
await this.smartserve.start();
}
this.currentExecution = await this.smartshellInstance.execStreaming(this.commandToExecute);
this.currentExecution = null;
}
/**
* this method sets up a clean exit strategy
* stops the execution of any active Watchers
*/
private setupCleanup() {
const cleanup = () => {
if (this.currentExecution) {
process.kill(-this.currentExecution.childProcess.pid);
public async stop() {
if (this.smartserve) {
await this.smartserve.stop();
}
};
process.on('exit', () => {
console.log('');
console.log('now exiting!');
cleanup();
process.exit(0);
});
process.on('SIGINT', () => {
console.log('');
console.log('ok! got SIGINT We are exiting! Just cleaning up to exit neatly :)');
cleanup();
process.exit(0);
this.watcherMap.forEach(async watcher => {
await watcher.stop();
});
}
}

View File

@@ -0,0 +1,122 @@
import * as plugins from './tswatch.plugins';
import { logger } from './tswatch.logging';
export type TCommandFunction = () => Promise<void>;
export interface IWatcherConstructorOptions {
filePathToWatch: string;
commandToExecute: string | TCommandFunction;
timeout?: number;
}
/**
* A watcher keeps track of one child execution
*/
export class Watcher {
/**
* used to execute shell commands
*/
private smartshellInstance = new plugins.smartshell.Smartshell({
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 smartchokWatcher = new plugins.smartchok.Smartchok([], {});
private options: IWatcherConstructorOptions;
constructor(optionsArg: IWatcherConstructorOptions) {
this.options = optionsArg;
}
/**
* start the file
*/
public async start() {
await this.setupCleanup();
console.log(`Looking at ${this.options.filePathToWatch} for changes`);
this.smartchokWatcher.add([this.options.filePathToWatch]); // __dirname refers to the directory of this very file
await this.smartchokWatcher.start();
const changeObservable = await this.smartchokWatcher.getObservableFor('change');
changeObservable.subscribe(() => {
this.updateCurrentExecution();
});
await this.updateCurrentExecution();
}
/**
* updates the current execution
*/
private async updateCurrentExecution() {
if (typeof this.options.commandToExecute === 'string') {
if (this.currentExecution) {
logger.log('ok', `reexecuting ${this.options.commandToExecute}`);
process.kill(-this.currentExecution.childProcess.pid);
} else {
logger.log('ok', `executing ${this.options.commandToExecute} for the first time`);
}
this.currentExecution = await this.smartshellInstance.execStreaming(
this.options.commandToExecute
);
this.currentExecution = null;
} else {
await this.executionTask.trigger();
}
}
/**
* this method sets up a clean exit strategy
*/
private async setupCleanup() {
const cleanup = () => {
if (this.currentExecution) {
process.kill(-this.currentExecution.childProcess.pid);
}
};
process.on('exit', () => {
console.log('');
console.log('now exiting!');
cleanup();
process.exit(0);
});
process.on('SIGINT', () => {
console.log('');
console.log('ok! got SIGINT We are exiting! Just cleaning up to exit neatly :)');
cleanup();
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);
});
}
}
/**
* stops the watcher
*/
public async stop() {
await this.smartchokWatcher.stop();
if (this.currentExecution && !this.currentExecution.childProcess.killed) {
process.kill(-this.currentExecution.childProcess.pid);
}
}
}

View File

@@ -1,16 +1,41 @@
import * as plugins from './tswatch.plugins';
import * as paths from './tswatch.paths';
import { logger } from './tswatch.logging';
import { TsWatch } from './tswatch.classes.tswatch';
const tswatchCli = new plugins.smartcli.Smartcli();
tswatchCli.addCommand('test').subscribe(argvArg => {
const tsWatch = new TsWatch({
filePathToWatch: paths.cwd,
commandToExecute: 'npm run test2'
});
tsWatch.start();
// 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 => {
logger.log('info', `running test task`);
const tsWatch = new TsWatch('test');
await tsWatch.start();
});
tswatchCli.addCommand('website').subscribe(async argvArg => {
logger.log('info', `running watch task for a gitzone website project`);
const tsWatch = new TsWatch('gitzone_website');
await tsWatch.start();
});
tswatchCli.startParse();

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,29 @@ import * as path from 'path';
export { path };
// @pushrocks scope
import * as lik from '@pushrocks/lik';
import * as smartchok from '@pushrocks/smartchok';
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 smartserve from '@pushrocks/smartserve';
import * as smartshell from '@pushrocks/smartshell';
import * as taskbuffer from '@pushrocks/taskbuffer';
export { smartshell, smartcli };
export {
lik,
smartchok,
smartcli,
smartdelay,
smartlog,
smartlogDestinationLocal,
smartserve,
smartshell,
taskbuffer
};
// Third Pary
import * as fileWatcher from 'filewatcher';
// third party scope
import parcel from 'parcel-bundler';
export { fileWatcher };
export { parcel };

View File

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