Compare commits
70 Commits
Author | SHA1 | Date | |
---|---|---|---|
f48ba50236 | |||
f04833d5b5 | |||
073685e683 | |||
b91b3e0a0c | |||
12d31533f5 | |||
f9b8a356e4 | |||
408b6f8fc5 | |||
80dd3ee970 | |||
717e1d29ed | |||
a8254e6962 | |||
35ee69981d | |||
bd66e9a897 | |||
fc356e62f4 | |||
a34d98b840 | |||
9525f28507 | |||
787aae63d7 | |||
bf2a32a5d5 | |||
7ced66fc28 | |||
d01905ae99 | |||
59c744cc5e | |||
4d23145529 | |||
27e0d7588d | |||
88d4bf6be0 | |||
d4f8215f35 | |||
85f72feeb9 | |||
bd4ccbd215 | |||
79940cec3f | |||
e20508ffbc | |||
21b962b9a8 | |||
f673e8577b | |||
e4278ed270 | |||
8ae0f960ac | |||
c9a3b996cb | |||
d81d19008a | |||
e4ef6bad8f | |||
2873314742 | |||
e26fa92744 | |||
995f296319 | |||
e7866dadb7 | |||
9302e78f86 | |||
0a302bee95 | |||
deb5e1daf9 | |||
5fe27ee706 | |||
b73807baf0 | |||
1e71fc24d5 | |||
e8071e76a1 | |||
b11d03dd41 | |||
72297d2f58 | |||
71b900ac47 | |||
f6d06edced | |||
3e98005843 | |||
7c4673a5b6 | |||
99ec82ab55 | |||
1f0c1964dd | |||
828229872d | |||
0ff482bd01 | |||
39c8da4f74 | |||
fcd2029744 | |||
d89e0a13d5 | |||
64c7815bca | |||
f3e69eb15e | |||
386e4c07c6 | |||
82557c96d6 | |||
c94d89fa8a | |||
639a5eebea | |||
fb88d3384e | |||
e38342604b | |||
390200ad2a | |||
1960b1d125 | |||
7ce6245286 |
18
.gitignore
vendored
18
.gitignore
vendored
@@ -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
|
135
.gitlab-ci.yml
135
.gitlab-ci.yml
@@ -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"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
@@ -18,114 +18,91 @@ stages:
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- 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
|
||||
- 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:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testSTABLE:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
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:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- 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:
|
||||
@@ -133,15 +110,5 @@ pages:
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
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
|
||||
- public
|
||||
allow_failure: true
|
||||
|
54
.snyk
Normal file
54
.snyk
Normal file
@@ -0,0 +1,54 @@
|
||||
# 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'
|
||||
- parcel-bundler > mkdirp > minimist:
|
||||
reason: None given
|
||||
expires: '2020-04-12T18:01:44.139Z'
|
||||
- parcel-bundler > @parcel/fs > mkdirp > minimist:
|
||||
reason: None given
|
||||
expires: '2020-04-12T18:01:44.139Z'
|
||||
- parcel-bundler > htmlnano > svgo > mkdirp > minimist:
|
||||
reason: None given
|
||||
expires: '2020-04-12T18:01:44.139Z'
|
||||
- parcel-bundler > cssnano > cssnano-preset-default > postcss-svgo > svgo > mkdirp > minimist:
|
||||
reason: None given
|
||||
expires: '2020-04-12T18:01:44.139Z'
|
||||
- parcel-bundler > htmlnano > cssnano > cssnano-preset-default > postcss-svgo > svgo > mkdirp > minimist:
|
||||
reason: None given
|
||||
expires: '2020-04-12T18:01:44.139Z'
|
||||
- parcel-bundler > mkdirp > minimist:
|
||||
reason: None given
|
||||
expires: '2020-04-12T18:07:10.923Z'
|
||||
- parcel-bundler > @parcel/fs > mkdirp > minimist:
|
||||
reason: None given
|
||||
expires: '2020-04-12T18:07:10.923Z'
|
||||
- parcel-bundler > htmlnano > svgo > mkdirp > minimist:
|
||||
reason: None given
|
||||
expires: '2020-04-12T18:07:10.923Z'
|
||||
- parcel-bundler > cssnano > cssnano-preset-default > postcss-svgo > svgo > mkdirp > minimist:
|
||||
reason: None given
|
||||
expires: '2020-04-12T18:07:10.923Z'
|
||||
- parcel-bundler > htmlnano > cssnano > cssnano-preset-default > postcss-svgo > svgo > mkdirp > minimist:
|
||||
reason: None given
|
||||
expires: '2020-04-12T18:07:10.923Z'
|
||||
patch: {}
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal 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
26
.vscode/settings.json
vendored
Normal 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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
8640
package-lock.json
generated
8640
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
53
package.json
53
package.json
@@ -1,34 +1,51 @@
|
||||
{
|
||||
"name": "@gitzone/tswatch",
|
||||
"version": "1.0.6",
|
||||
"version": "1.0.42",
|
||||
"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 --timeout 10000",
|
||||
"test2": "(tstest test/)",
|
||||
"build": "(tsbuild)",
|
||||
"format": "(gitzone format)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.11",
|
||||
"@gitzone/tstest": "^1.0.20",
|
||||
"@pushrocks/tapbundle": "^3.0.9",
|
||||
"@types/node": "^12.0.0",
|
||||
"tslint": "^5.16.0",
|
||||
"@gitzone/tsbuild": "^2.1.24",
|
||||
"@gitzone/tstest": "^1.0.28",
|
||||
"@pushrocks/tapbundle": "^3.2.1",
|
||||
"@types/node": "^14.0.5",
|
||||
"tslint": "^6.1.2",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@gitzone/tsrun": "^1.2.6",
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@pushrocks/early": "^3.0.3",
|
||||
"@pushrocks/smartchok": "^1.0.18",
|
||||
"@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"
|
||||
}
|
||||
"@pushrocks/lik": "^4.0.0",
|
||||
"@pushrocks/smartchok": "^1.0.23",
|
||||
"@pushrocks/smartcli": "^3.0.11",
|
||||
"@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.26",
|
||||
"@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
31
readme.md
Normal 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
|
||||
[](https://gitlab.com/gitzone/tswatch/commits/master)
|
||||
[](https://gitlab.com/gitzone/tswatch/commits/master)
|
||||
[](https://www.npmjs.com/package/@gitzone/tswatch)
|
||||
[](https://snyk.io/test/npm/@gitzone/tswatch)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](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)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
15
test/test.ts
15
test/test.ts
@@ -1,23 +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',
|
||||
timeout: 1000
|
||||
});
|
||||
testTsWatchInstance = new tswatch.TsWatch('echoSomething');
|
||||
});
|
||||
|
||||
tap.test('should start the tswatch instance', async () => {
|
||||
testTsWatchInstance.start();
|
||||
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();
|
||||
|
1
ts/interfaces/index.ts
Normal file
1
ts/interfaces/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './interfaces.watchmodes';
|
7
ts/interfaces/interfaces.watchmodes.ts
Normal file
7
ts/interfaces/interfaces.watchmodes.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export type TWatchModes =
|
||||
| 'test'
|
||||
| 'gitzone_npm'
|
||||
| 'gitzone_service'
|
||||
| 'gitzone_element'
|
||||
| 'gitzone_website'
|
||||
| 'echoSomething';
|
37
ts/tswatch.classes.parcel.ts
Normal file
37
ts/tswatch.classes.parcel.ts
Normal 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);
|
||||
}
|
||||
}
|
@@ -1,77 +1,105 @@
|
||||
import * as plugins from './tswatch.plugins';
|
||||
import * as paths from './tswatch.paths';
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
export interface ITsWatchConstructorOptions {
|
||||
filePathToWatch: string;
|
||||
commandToExecute: string;
|
||||
timeout?: number;
|
||||
}
|
||||
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 = new plugins.smartchok.Smartchok([], {});
|
||||
private options: ITsWatchConstructorOptions;
|
||||
public watchmode: interfaces.TWatchModes;
|
||||
public watcherMap = new plugins.lik.Objectmap<Watcher>();
|
||||
public smartserve: plugins.smartserve.SmartServe;
|
||||
|
||||
constructor(optionsArg: ITsWatchConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
constructor(watchmodeArg: interfaces.TWatchModes) {
|
||||
this.watchmode = watchmodeArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* start the file
|
||||
* starts the TsWatch instance
|
||||
*/
|
||||
public async start() {
|
||||
this.setupCleanup();
|
||||
console.log(`Looking at ${this.options.filePathToWatch} for changes`);
|
||||
this.watcher.add([this.options.filePathToWatch]); // __dirname refers to the directory of this very file
|
||||
const changeObservable = await this.watcher.getObservableFor('change');
|
||||
changeObservable.subscribe(() => {
|
||||
this.updateCurrentExecution();
|
||||
})
|
||||
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!'
|
||||
);
|
||||
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.options.commandToExecute);
|
||||
this.currentExecution = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* this method sets up a clean exit strategy
|
||||
* stops the execution of any active Watchers
|
||||
*/
|
||||
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);
|
||||
});
|
||||
public async stop() {
|
||||
if (this.smartserve) {
|
||||
await this.smartserve.stop();
|
||||
}
|
||||
this.watcherMap.forEach(async watcher => {
|
||||
await watcher.stop();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
106
ts/tswatch.classes.watcher.ts
Normal file
106
ts/tswatch.classes.watcher.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
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'
|
||||
});
|
||||
|
||||
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}`);
|
||||
this.currentExecution.kill();
|
||||
} else {
|
||||
logger.log('ok', `executing ${this.options.commandToExecute} for the first time`);
|
||||
}
|
||||
this.currentExecution = await this.smartshellInstance.execStreaming(
|
||||
this.options.commandToExecute
|
||||
);
|
||||
} else {
|
||||
console.log('cannot run execution task');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,21 +8,34 @@ const tswatchCli = new plugins.smartcli.Smartcli();
|
||||
|
||||
// standard behaviour will assume gitzone setup
|
||||
|
||||
tswatchCli.addCommand('test').subscribe(argvArg => {
|
||||
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({
|
||||
filePathToWatch: paths.cwd,
|
||||
commandToExecute: 'npm run test2',
|
||||
timeout: (() => {
|
||||
if (argvArg.timeout) {
|
||||
console.log(`timeing out after ${argvArg.timeout}`);
|
||||
return argvArg.timeout;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})()
|
||||
});
|
||||
tsWatch.start();
|
||||
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();
|
||||
|
@@ -5,7 +5,7 @@ export const logger = new plugins.smartlog.Smartlog({
|
||||
company: 'Some Company',
|
||||
companyunit: 'Some CompanyUnit',
|
||||
containerName: 'Some Containername',
|
||||
environment: "local",
|
||||
environment: 'local',
|
||||
runtime: 'node',
|
||||
zone: 'gitzone'
|
||||
},
|
||||
|
@@ -2,11 +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 { smartchok, smartcli, smartdelay, smartlog, smartlogDestinationLocal, smartshell, };
|
||||
export {
|
||||
lik,
|
||||
smartchok,
|
||||
smartcli,
|
||||
smartdelay,
|
||||
smartlog,
|
||||
smartlogDestinationLocal,
|
||||
smartserve,
|
||||
smartshell,
|
||||
taskbuffer
|
||||
};
|
||||
|
||||
// third party scope
|
||||
import parcel from 'parcel-bundler';
|
||||
|
||||
export { parcel };
|
||||
|
@@ -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"
|
||||
}
|
||||
|
Reference in New Issue
Block a user