fix(core): update

This commit is contained in:
2019-10-12 16:54:03 +02:00
parent b73807baf0
commit 5fe27ee706
6 changed files with 85 additions and 29 deletions

View File

@ -1,12 +0,0 @@
import * as plugins from './tswatch.plugins';
/**
* an element server for developing lit elements compliant to gitzone standard
*/
export class ElementServer {
constructor() {
}
}

View File

@ -38,8 +38,13 @@ export class TsWatch {
case 'gitzone_element':
this.watcherMap.add(
new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, 'ts_web'),
commandToExecute: 'npm run build',
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', 'dist_web');
await htmlHandler.copyHtml();
},
timeout: null
})
);

View File

@ -1,9 +1,11 @@
import * as plugins from './tswatch.plugins';
import { logger } from './tswatch.logging';
export type TCommandFunction = () => Promise<void>;
export interface IWatcherConstructorOptions {
filePathToWatch: string;
commandToExecute: string;
commandToExecute: string | TCommandFunction;
timeout?: number;
}
@ -11,9 +13,28 @@ export interface IWatcherConstructorOptions {
* 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;
@ -41,16 +62,20 @@ export class Watcher {
* updates the current execution
*/
private async updateCurrentExecution() {
if (this.currentExecution) {
logger.log('ok', `reexecuting ${this.options.commandToExecute}`);
process.kill(-this.currentExecution.childProcess.pid);
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 {
logger.log('ok', `executing ${this.options.commandToExecute} for the first time`);
await this.executionTask.trigger();
}
this.currentExecution = await this.smartshellInstance.execStreaming(
this.options.commandToExecute
);
this.currentExecution = null;
}
/**

View File

@ -1,6 +1,13 @@
import * as path from 'path';
export { path };
// @gitzone scope
import * as tsbundle from '@gitzone/tsbundle';
export {
tsbundle
};
// @pushrocks scope
import * as lik from '@pushrocks/lik';
import * as smartchok from '@pushrocks/smartchok';
@ -9,5 +16,6 @@ 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 taskbuffer from '@pushrocks/taskbuffer';
export { lik, smartchok, smartcli, smartdelay, smartlog, smartlogDestinationLocal, smartshell };
export { lik, smartchok, smartcli, smartdelay, smartlog, smartlogDestinationLocal, smartshell, taskbuffer };